Files
iOSGuard/defender/anti_tamper/IGAntiTamper.h
T
shenleiandClaude Opus 4.8 cb51fdc6f0 feat(anti_tamper): IGAntiTamper——二进制完整性/防重打包探针(cryptid+csops)
补 anti_hook 只盯固定函数之外的空洞,正面反制 App Store 标准破解链
(脱壳解密→patch→重签):
- FairPlay cryptid(reason=500):cryptid==0 或 LC_ENCRYPTION_INFO 被剥除=脱壳/重打包
- 代码签名 csops CS_OPS_STATUS(reason=501):CS_VALID 失效/ad-hoc 重签/分发包带 get-task-allow

误报底线:两条均按 expect_encrypted/expect_distribution 构建上下文开关,
dev/诊断/TestFlight 传 0→UNAVAILABLE,绝不在非分发构建误报。作为独立探针
由 Swift 策略层/observer 带构建上下文单独调用,不并入 ig_defender_scan(不破坏现有签名)。

回归:tests/test_anti_tamper.py 合成 Mach-O 头跑 cryptid 核心五例(加密正常/脱壳/
剥除/非分发跳过/NULL);模块接入 poison_host 与 device 链接列表。全量 73 过,
iphoneos arm64 交叉编译通过。csops+真实主镜像验证待设备。docs/18 §7.7。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-13 11:44:56 +09:00

56 lines
2.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* IGAntiTamper.h — 二进制完整性 / 防重打包探针。
*
* 定位:anti_hook 只校验固定一批关键函数的序言/GOT——攻击者 patch 这批之外的任意指令(含
* NOP 掉某条检测/毒化调用边、改业务层比较)它看不见。本模块从「镜像整体」角度补这个空洞,
* 正面反制 App Store 应用的标准破解链:**脱壳解密(Clutch/frida-ios-dump)→ patch → 重签**。
*
* 两条检查(均只采集证据、不处置,经 sink 上报;判级交 policy):
* 1. FairPlay cryptid:App Store 分发包由 Apple 加密(LC_ENCRYPTION_INFO_64.cryptid=1)。
* 脱壳 dump 会把 cryptid 改 0;重打包可能整条剥除加密命令。→ IG_REASON_BINARY_DECRYPTED。
* 2. 代码签名状态(csops CS_OPS_STATUS):ad-hoc 重签、分发包却带 get-task-allow(被重签成
* 可调试)、CS_VALID 失效。→ IG_REASON_CODESIGN_INVALID。
*
* 【误报底线】这两条都**依赖构建上下文**:dev/TestFlight/诊断构建本就未 FairPlay 加密、且带
* get-task-allow——那是正常的,不是篡改。故由调用方按构建类型传 expect_* 开关:只有
* 「本应是 App Store 分发包」时才判 DETECTED;否则返回 UNAVAILABLE(无法断言,不上报 DETECTED)。
* expect 开关应由 Release/App Store 构建配置注入(见 docs/18),绝不在 dev 构建置 1。
*
* 【边界】csops 经 libc 调用,可被 hook 伪造(若攻击者已能 hook csops,说明环境已失陷,
* 届时 anti_hook/anti_inject 会先命中);cryptid 读的是进程内 Mach-O 头,patch 头部也能伪装,
* 但那要求攻击者已定位该检查——与整体「抬成本、非不可破」哲学一致,不作为唯一安全锚点。
*/
#ifndef IG_ANTI_TAMPER_H
#define IG_ANTI_TAMPER_H
#include <mach-o/loader.h>
#include "IGDefender.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* 真机入口:对当前进程主可执行镜像做 cryptid + 代码签名检查。
* expect_encrypted:本构建是否「本应 FairPlay 加密」(App Store 分发=1,dev/诊断=0)。
* expect_distribution:本构建是否「本应分发签名」(不含 get-task-allow;App Store=1,dev=0)。
* 两者为 0 时对应检查返回 UNAVAILABLE(不误报)。返回 DETECTED 证据条数。
*/
int ig_anti_tamper_check(int expect_encrypted, int expect_distribution,
IGFindingSink sink, void *ctx);
/*
* 可测核心:对给定 Mach-O 头做 cryptid 检查(与真机入口共用逻辑,便于用合成头单测)。
* mh:指向 mach_header_64。expect_encrypted:同上。
* 返回 DETECTED 条数(0=CLEAR 或 UNAVAILABLE)。
*/
int ig_tamper_scan_cryptid(const struct mach_header_64 *mh, int expect_encrypted,
IGFindingSink sink, void *ctx);
#ifdef __cplusplus
}
#endif
#endif /* IG_ANTI_TAMPER_H */