Files
iOSGuard/tests/test_poison_policy.py
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

58 lines
2.2 KiB
Python

"""处置链宿主自测:poison + policy + anti_jailbreak 闭环(检测→分级→数据毒化)。
固化此前只在临时目录跑过的闭环为可复现基线,作为真机验证(docs/19)前的宿主绿灯。
编译 tests/fixtures/poison_host.c 并运行,退出码 0=全部用例通过。
"""
from pathlib import Path
import os
import shutil
import subprocess
import sys
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
SOURCES = [
'poison/IGPoison.c', 'policy/IGPolicy.c',
'anti_jailbreak/IGAntiJailbreak.c', 'syscall/IGSyscall.c',
'IGDefender.c', 'anti_hook/IGAntiHook.c', 'anti_hook/IGObjCBaseline.c',
'anti_frida/IGAntiInject.c', 'anti_debug/IGAntiDebug.c',
'resolve/IGResolve.c', 'dispatch/IGDispatch.c',
'dispatch/IGArchiveGuard.c', 'call_bridge/IGFileBridge.c',
'anti_tamper/IGAntiTamper.c',
]
@unittest.skipUnless(sys.platform == 'darwin' and shutil.which('xcrun'), '需要 Xcode/macOS')
class PoisonPolicyTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.tmp = tempfile.TemporaryDirectory()
folder = Path(cls.tmp.name)
cls.exe = folder / 'poison-host'
cls.env = dict(os.environ)
cls.env.pop('DYLD_INSERT_LIBRARIES', None)
args = ['xcrun', '--sdk', 'macosx', 'clang', '-O2',
'-I', str(ROOT / 'defender/include'), '-I', str(ROOT / 'defender'),
str(ROOT / 'tests/fixtures/poison_host.c'),
*(str(ROOT / 'defender' / p) for p in SOURCES),
'-framework', 'Foundation', '-lobjc', '-o', str(cls.exe)]
p = subprocess.run(args, capture_output=True, text=True, env=cls.env)
if p.returncode:
raise RuntimeError(p.stdout + p.stderr)
@classmethod
def tearDownClass(cls):
cls.tmp.cleanup()
def test_chain(self):
p = subprocess.run([str(self.exe)], capture_output=True, text=True, env=self.env)
# 保留逐例证据到 unittest 日志。
print(p.stdout.strip(), flush=True)
self.assertEqual(p.returncode, 0, p.stdout + p.stderr)
self.assertIn('0 fail', p.stdout)
if __name__ == '__main__':
unittest.main()