feat(defender): 可集成静态库 + readoor 接入方案(检测→分级→数据毒化闭环)
在 iOSGuard 侧产出可集成产物与接入文档,不修改 readoor 代码。 - defender/: anti_hook/anti_frida/anti_debug/anti_jailbreak 探针 + syscall 直发、 policy 分级层、poison 数据依赖毒化、dispatch/resolve/call_bridge 等子模块 - poison: 三副本冗余、无分支掩码;健康恒等、毒化破坏 key(替代 if-exit 处置) - policy: STRONG/MEDIUM/WEAK 分级,守误报底线,仅 DETECTED 参与、组合命中才毒化 - anti_jailbreak: IGSyscall 直发 svc 检测越狱文件(400)/沙盒逃逸(401),绕 libc hook - tools/build_defender_lib.sh: 一键交叉编译打包 libIGDefender.a(arm64) + umbrella 头 - docs/18_READOOR_DEFENDER_INTEGRATION.md: 精确到文件/bridging/替换点/代码片段 - docs/05-17 + evidence + tests + macho_guard/static_sdk_redirect 工具链 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ff0aee7f47
commit
599e1da5ce
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env python3
|
||||
"""安装并运行 step11 HOOK 正向验证诊断 App,收集/解析结果。
|
||||
|
||||
两相位:
|
||||
A 干净启动(受控攻击形态:GOT/蹦床/线程名/注入 dylib,见 hook_device.m)
|
||||
B 以 DYLD_INSERT_LIBRARIES 启动(真实 dyld 注入,使用相位 A 回显的 dylib 路径)
|
||||
结束即卸载诊断 App;全部证据与哈希写入输出目录(必须不存在)。
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
CASE_RE = re.compile(r'IG_HOOK_CASE (\S+) (PASS|FAIL)(?: detail=(.*))?$')
|
||||
SUITE_RE = re.compile(r'IG_HOOK_SUITE (PASS|FAIL)')
|
||||
TIMING_RE = re.compile(r'IG_HOOK_TIMING (.+)$')
|
||||
DYLIB_RE = re.compile(r'IG_HOOK_DYLIB_PATH (\S+)$')
|
||||
INSERT_RE = re.compile(r'IG_HOOK_INSERT_SUMMARY (.+)$')
|
||||
|
||||
|
||||
def run(args, log: Path, label: str, timeout: int = 240):
|
||||
r = subprocess.run(list(map(str, args)), capture_output=True, text=True, timeout=timeout)
|
||||
log.write_text(r.stdout + r.stderr)
|
||||
return r
|
||||
|
||||
|
||||
def parse_console(path: Path):
|
||||
cases, timing, insert_summary = [], None, None
|
||||
for line in path.read_text(errors='replace').splitlines():
|
||||
m = CASE_RE.search(line)
|
||||
if m:
|
||||
cases.append(dict(name=m.group(1), result=m.group(2), detail=m.group(3) or ''))
|
||||
continue
|
||||
m = TIMING_RE.search(line)
|
||||
if m:
|
||||
timing = m.group(1)
|
||||
continue
|
||||
m = INSERT_RE.search(line)
|
||||
if m:
|
||||
insert_summary = m.group(1)
|
||||
return cases, timing, insert_summary
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser(description=__doc__)
|
||||
p.add_argument('--device', required=True)
|
||||
p.add_argument('--app', type=Path, required=True)
|
||||
p.add_argument('--bundle-id', required=True)
|
||||
p.add_argument('--output', type=Path, required=True)
|
||||
a = p.parse_args()
|
||||
out = a.output.resolve()
|
||||
if out.exists():
|
||||
raise ValueError('输出目录必须不存在')
|
||||
out.mkdir(parents=True)
|
||||
base = ['xcrun', 'devicectl'] # --device 为子命令级参数,逐条拼接
|
||||
|
||||
r = run(base + ['device', 'info', 'details', '--device', a.device], out / 'device-details.log', 'device info')
|
||||
(out / 'device-details.json').write_text(r.stdout)
|
||||
|
||||
run(base + ['device', 'install', 'app', '--device', a.device, '--timeout', '60',
|
||||
'--json-output', out / 'install.json', a.app],
|
||||
out / 'install.log', 'install')
|
||||
|
||||
# 相位 A:干净启动,收集受控攻击形态结果与可注入 dylib 路径。
|
||||
run(base + ['device', 'process', 'launch', '--device', a.device, '--console', '--timeout', '90',
|
||||
'--json-output', out / 'launch-clean.json', a.bundle_id],
|
||||
out / 'console-clean.log', 'launch clean')
|
||||
cases, timing, _ = parse_console(out / 'console-clean.log')
|
||||
dylib = None
|
||||
for line in (out / 'console-clean.log').read_text(errors='replace').splitlines():
|
||||
m = DYLIB_RE.search(line)
|
||||
if m and m.group(1) != 'none':
|
||||
dylib = m.group(1)
|
||||
break
|
||||
|
||||
# 相位 B:DYLD_INSERT_LIBRARIES 真实注入(复用相位 A 验证可装载的路径)。
|
||||
if dylib:
|
||||
r = run(base + ['device', 'process', 'launch', '--device', a.device, '--console', '--timeout', '90',
|
||||
'-e', json.dumps({'DYLD_INSERT_LIBRARIES': dylib}),
|
||||
'--json-output', out / 'launch-insert.json', a.bundle_id],
|
||||
out / 'console-insert.log', 'launch insert')
|
||||
b_cases, _, insert_summary = parse_console(out / 'console-insert.log')
|
||||
cases += b_cases
|
||||
else:
|
||||
insert_summary = 'skipped:相位 A 未能装载模拟 dylib'
|
||||
(out / 'console-insert.log').write_text(insert_summary + '\n')
|
||||
|
||||
run(base + ['device', 'uninstall', 'app', '--device', a.device, '--timeout', '60',
|
||||
'--json-output', out / 'uninstall.json', a.bundle_id],
|
||||
out / 'uninstall.log', 'uninstall')
|
||||
|
||||
failed = [c for c in cases if c['result'] != 'PASS']
|
||||
verification = dict(
|
||||
device=a.device, bundle_id=a.bundle_id, app=str(a.app),
|
||||
cases=cases, case_count=len(cases),
|
||||
passed=len(cases) - len(failed), failed=len(failed),
|
||||
suite='PASS' if cases and not failed else 'FAIL',
|
||||
scan_timing=timing, insert_summary=insert_summary, injected_dylib=dylib,
|
||||
limitations=[
|
||||
'inline-hook 用例针对受控导出符号的真实字节,不是对系统函数的实际 patch',
|
||||
'特征名/线程名/端口可被攻击者改名规避,未命中不等于干净',
|
||||
'本诊断为独立进程,不等同于业务 App 内的完整验收',
|
||||
])
|
||||
(out / 'device-verification.json').write_text(
|
||||
json.dumps(verification, ensure_ascii=False, indent=2) + '\n')
|
||||
|
||||
hashes = {}
|
||||
for f in sorted(out.rglob('*')):
|
||||
if f.is_file() and f.name != 'evidence-hashes.json':
|
||||
hashes[str(f.relative_to(out))] = hashlib.sha256(f.read_bytes()).hexdigest()
|
||||
(out / 'evidence-hashes.json').write_text(
|
||||
json.dumps(hashes, ensure_ascii=False, indent=2) + '\n')
|
||||
print(json.dumps({k: verification[k] for k in
|
||||
('suite', 'passed', 'failed', 'case_count', 'scan_timing')},
|
||||
ensure_ascii=False))
|
||||
raise SystemExit(0 if verification['suite'] == 'PASS' else 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user