From 1094cc27603ef248f9b99cbf177121b16d27cbbc Mon Sep 17 00:00:00 2001 From: shenlei Date: Fri, 13 Nov 2026 12:14:37 +0900 Subject: [PATCH] =?UTF-8?q?test(anti=5Ftamper):=20IGAntiTamper=20=E7=9C=9F?= =?UTF-8?q?=E6=9C=BA=E6=AD=A3=E5=8F=8D=E5=8F=8C=E5=90=91=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E8=BE=BE=E6=A0=87=EF=BC=88D9=EF=BC=8CiPhone=2016=20Plus=20?= =?UTF-8?q?=E9=9D=9E=E8=B6=8A=E7=8B=B1=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit poison_device.m 加 D9a–d 四条环境无关不变量 + csops_status/501 两条观察, 复用 build/run_poison_device harness。实测(verdict PASS,不变量 9/9): - 误报底线:expect_*=0 → 零 DETECTED,对应 finding UNAVAILABLE - cryptid 真读主镜像:expect=1 → reason500=1(dev 包 cryptid==0),mh=0x104390000 - 整入口贯通:ig_anti_tamper_check(1,1) → 500 + 501 - csops 真机活性:rc=0 status=0x22003305 valid=1 adhoc=0 get_task_allow=1 (坐实 csops 在 iOS arm64 活着,排除 501 假阴性) 残留缺口(只能在真 App Store/TestFlight 包验):cryptid==1 正向 CLEAR + 分发签名零误触——dev profile 无法复现 FairPlay 加密/分发签名。docs/18 §7.7、docs/19 §6。 证据 test-results/step12-device-poison/20261113-antitamper-R/(gitignore)。 Co-Authored-By: Claude Opus 4.8 --- docs/18_READOOR_DEFENDER_INTEGRATION.md | 4 +- ...9_DISPOSITION_CHAIN_DEVICE_VERIFICATION.md | 11 +++ tests/fixtures/poison_device.m | 89 +++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/docs/18_READOOR_DEFENDER_INTEGRATION.md b/docs/18_READOOR_DEFENDER_INTEGRATION.md index 4443987..9a73649 100644 --- a/docs/18_READOOR_DEFENDER_INTEGRATION.md +++ b/docs/18_READOOR_DEFENDER_INTEGRATION.md @@ -210,7 +210,9 @@ ig_poison_mix_key_inline(key, key_len); // 健康→key 不变→正常解密 **边界**:`csops` 经 libc,可被 hook 伪造(但攻击者若已能 hook csops,环境已失陷,anti_hook/anti_inject 会先命中);`cryptid` 读进程内 Mach-O 头,patch 头部也能伪装——与整体「抬成本、非不可破」哲学一致,不作唯一安全锚点。 -回归:`tests/test_anti_tamper.py`(合成 Mach-O 头跑 cryptid 核心:加密正常/脱壳/剥除/非分发跳过/NULL 五例)。csops 与真实主镜像那部分由设备测试覆盖(待设备解锁)。 +回归:`tests/test_anti_tamper.py`(合成 Mach-O 头跑 cryptid 核心:加密正常/脱壳/剥除/非分发跳过/NULL 五例)。 + +**真机验证已达标(2026-11-13,iPhone 16 Plus 非越狱,dev 包 `poison_device.m` D9a–d)**:`expect_*=0` 零 DETECTED(误报底线);`expect_*=1` cryptid 命中 500、csops 读到 get-task-allow 命中 501;`csops_status rc=0 status=0x22003305 valid=1 get_task_allow=1` 坐实 csops 在真机 arm64 活着。详见 docs/19 §6。**残留缺口**:cryptid==1 正向 CLEAR 与分发签名零误触只能在真 App Store/TestFlight 包验(dev profile 无法复现 FairPlay 加密)。 --- diff --git a/docs/19_DISPOSITION_CHAIN_DEVICE_VERIFICATION.md b/docs/19_DISPOSITION_CHAIN_DEVICE_VERIFICATION.md index d58d961..c5f9a40 100644 --- a/docs/19_DISPOSITION_CHAIN_DEVICE_VERIFICATION.md +++ b/docs/19_DISPOSITION_CHAIN_DEVICE_VERIFICATION.md @@ -46,6 +46,10 @@ | D6 | ctor_clean_start | 进程启动后**未** mark 时读 `ig_poison_mask()` | 两组同:==0(证构造期三副本初始化干净,无启动即毒化) | | D7 | policy_grades | 喂合成 finding(弱/单 MEDIUM/双 MEDIUM/单 STRONG) | 两组同:弱&单 MEDIUM 不触发,双 MEDIUM&单 STRONG 触发(真机复核分级) | | D8 | svc_access_live | 自身沙盒 Documents 建真实可访问文件,喂 `ig_anti_jb_check_paths` | 两组同:命中 400(证 svc 直发 access 在真机 iOS arm64 能命中,**无需越狱**即排除「探针静默失败」假阴性) | +| D9a | at_cryptid_expect0_clean | `ig_tamper_scan_cryptid(mh, expect_encrypted=0)` | 两组同:零 DETECTED(非分发构建跳过=误报底线,dev 包不误触) | +| D9b | at_cryptid_expect1_detects | `ig_tamper_scan_cryptid(mh, expect_encrypted=1)` | 两组同:命中 500(dev 包无 FairPlay 加密 cryptid==0;**证探针真读到进程主镜像头**,非空转) | +| D9c | at_tamper_gated_off | `ig_anti_tamper_check(0,0)` 整入口 | 两组同:零 DETECTED(两检查都 expect=0 → 全 UNAVAILABLE,误报底线贯整入口) | +| D9d | at_tamper_on_detects | `ig_anti_tamper_check(1,1)` 整入口 | 两组同:≥1 DETECTED 且含 500(整入口真机贯通;dev 包另命中 501 get-task-allow,见观察 csops_status) | > D4–D7 与宿主自测同构,但要在真机二进制里再跑一遍,排除交叉编译/优化差异。D1–D3 是真机独有(依赖真实 svc + 真实文件系统)。 > @@ -119,6 +123,13 @@ runner 退出码:D4–D7 不变量全过 **且** 环境判定与 `--expect` - D1 baseline_scan:`triggered=0 mask=0x0`(**非越狱聚合扫描零毒化** — §4.1 核心反向门槛)✓ - D2/D3:`reason400=0 reason401=0`,`jailbroken=no` ✓ - 证据:`test-results/step12-device-poison/20261113-R-final/`(gitignore,不进库)。 +- [x] **IGAntiTamper 真机正反双向达标(2026-11-13)**:同机(iPhone 16 Plus,非越狱,专用 BID `cn.touchv.iosguard.poisonpilot.antitamper`,测后卸载)。`run_poison_device.py --expect clean` → **verdict PASS,不变量 9/9**(原 5 + 新 D9a–d 4)。 + - D9a/D9c(误报底线):`expect_*=0` → 零 DETECTED,对应 finding 为 UNAVAILABLE(dev 包不误触)✓ + - **D9b:`hits=1 reason500=1 mh=0x104390000`**(cryptid 探针真读进程主镜像头,dev 包 `cryptid==0` 命中 500;证非空转)✓ + - **D9d:`hits=2 reason500=1 reason501=1`**(整入口贯通:cryptid 500 + csops get-task-allow 501)✓ + - **csops_status 观察:`rc=0 status=0x22003305 valid=1 adhoc=0 get_task_allow=1`**——**坐实 csops 在真机 iOS arm64 活着**(CS_VALID 置位、非 ad-hoc、dev 包带 get-task-allow),排除「csops 静默失败=501 假阴性」。 + - 证据:`test-results/step12-device-poison/20261113-antitamper-R/`(gitignore,不进库)。 + - **残留缺口(分发包侧,只能在真 App Store 包验)**:cryptid==1 的正向 CLEAR、分发签名下 501 零误触——dev profile 无法复现 FairPlay 加密/分发签名,待 TestFlight/App Store 构建侧补验。 - [ ] **J 组无法执行(环境天花板:无越狱设备)**。残留缺口仅剩两项,均只能在越狱机证:① 真实越狱特征文件命中 400;② 沙盒逃逸 401。 **已有替代证据把缺口收窄到最小**:D8 已证 svc-access 检测机制在真机活跃(命中逻辑真机可工作),R 组已证反向零误报。即「机制能命中 + 非越狱不误报」在真机成立,唯独缺「真越狱环境里的端到端正向」——补一台越狱机 `--expect jailbroken` 即可闭合,harness 现成。 - [ ] 达标后进入 docs/18 §5 灰度(observer 打点 → 开毒化)。 diff --git a/tests/fixtures/poison_device.m b/tests/fixtures/poison_device.m index 00b1a86..b6d6871 100644 --- a/tests/fixtures/poison_device.m +++ b/tests/fixtures/poison_device.m @@ -27,8 +27,34 @@ #include "poison/IGPoison.h" #include "policy/IGPolicy.h" #include "anti_jailbreak/IGAntiJailbreak.h" +#include "anti_tamper/IGAntiTamper.h" #include +#include +#include +#include + +/* 原始 csops(与 IGAntiTamper 同,供 .m 直读状态字作真机观察,坐实 csops 活性) */ +#ifndef CS_OPS_STATUS +#define CS_OPS_STATUS 0 +#endif +#define IG_CS_VALID 0x00000001u +#define IG_CS_ADHOC 0x00000002u +#define IG_CS_GET_TASK_ALLOW 0x00000004u +extern int csops(pid_t pid, unsigned int ops, void *useraddr, size_t usersize); + +/* 进程主可执行镜像头(与 IGAntiTamper 内部同逻辑,便于直接喂给可测核心) */ +static const struct mach_header_64 *dev_main_image_header(void) { + uint32_t n = _dyld_image_count(); + for (uint32_t i = 0; i < n; ++i) { + const struct mach_header *h = _dyld_get_image_header(i); + if (h && h->magic == MH_MAGIC_64 && + ((const struct mach_header_64 *)h)->filetype == MH_EXECUTE) { + return (const struct mach_header_64 *)h; + } + } + return NULL; +} /* ---------- 发现收集 ---------- */ #define IG_MAXF 64 @@ -167,6 +193,69 @@ int main(int argc, char **argv) { reset_findings(); } + /* ===== D9 anti_tamper:二进制完整性探针真机验证 ===== + * dev 签名包是环境无关不变量:本地编译=无 FairPlay 加密(无 LC_ENCRYPTION_INFO + * 或 cryptid=0)、且带 get-task-allow。据此双向验证 IGAntiTamper: + * expect=0(dev 正确配置)→ 全 UNAVAILABLE、零 DETECTED(误报底线); + * expect=1(假装分发)→ cryptid 命中 500、csops 读到 get-task-allow 命中 501 + * (坐实探针真读到真实镜像头/签名状态,逻辑正确)。 */ + const struct mach_header_64 *mh = dev_main_image_header(); + + /* D9a cryptid_expect0_clean:非分发构建跳过,零 DETECTED(误报底线) */ + { + reset_findings(); + int hits = ig_tamper_scan_cryptid(mh, /*expect_encrypted=*/0, collect, NULL); + mark_case("at_cryptid_expect0_clean", hits == 0 && g_detected == 0, + "dev build, expect_encrypted=0 must not flag"); + reset_findings(); + } + + /* D9b cryptid_expect1_detects:dev 包无 FairPlay 加密 → 命中 500(探针真读主镜像头) */ + { + reset_findings(); + int hits = ig_tamper_scan_cryptid(mh, /*expect_encrypted=*/1, collect, NULL); + int r500 = count_reason(IG_REASON_BINARY_DECRYPTED); + char d[96]; snprintf(d, sizeof(d), "hits=%d reason500=%d mh=%p", hits, r500, (void *)mh); + mark_case("at_cryptid_expect1_detects", hits >= 1 && r500 >= 1, d); + reset_findings(); + } + + /* D9c tamper_gated_off:两检查都 expect=0 → 零 DETECTED(误报底线整入口) */ + { + reset_findings(); + int hits = ig_anti_tamper_check(/*expect_encrypted=*/0, /*expect_distribution=*/0, + collect, NULL); + mark_case("at_tamper_gated_off", hits == 0 && g_detected == 0, + "dev build, expect_*=0 whole-entry must not flag"); + reset_findings(); + } + + /* D9d tamper_on_detects:expect_*=1 → 至少 cryptid 500 命中(整入口贯通真机) */ + { + reset_findings(); + int hits = ig_anti_tamper_check(/*expect_encrypted=*/1, /*expect_distribution=*/1, + collect, NULL); + int r500 = count_reason(IG_REASON_BINARY_DECRYPTED); + int r501 = count_reason(IG_REASON_CODESIGN_INVALID); + char d[112]; snprintf(d, sizeof(d), "hits=%d reason500=%d reason501=%d", hits, r500, r501); + mark_case("at_tamper_on_detects", hits >= 1 && r500 >= 1, d); + /* 501(csops 代码签名)作观察:dev 包带 get-task-allow 应命中,但 csops 语义真机坐实为准 */ + char o[64]; snprintf(o, sizeof(o), "reason501_codesign_hits=%d", r501); + observe("at_codesign_501", o); + reset_findings(); + } + + /* D9e csops_status(观察):直读 csops 状态字,坐实 csops 在真机 iOS arm64 活着 */ + { + uint32_t st = 0; + int rc = csops(getpid(), CS_OPS_STATUS, &st, sizeof(st)); + char o[128]; + snprintf(o, sizeof(o), "rc=%d status=0x%x valid=%d adhoc=%d get_task_allow=%d", + rc, st, (st & IG_CS_VALID) != 0, (st & IG_CS_ADHOC) != 0, + (st & IG_CS_GET_TASK_ALLOW) != 0); + observe("csops_status", o); + } + /* ===== D2 jb_file(观察):内置越狱特征表直发 access ===== */ reset_findings(); ig_anti_jb_check(collect, NULL);