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,71 @@
|
||||
"""宿主探针正反例与 iOS 编译验证;不替代真机 inline Hook 测试。"""
|
||||
from pathlib import Path
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SOURCES = ['IGDefender.c','anti_hook/IGAntiHook.c','anti_hook/IGObjCBaseline.c',
|
||||
'anti_frida/IGAntiInject.c','anti_debug/IGAntiDebug.c',
|
||||
'syscall/IGSyscall.c','resolve/IGResolve.c','dispatch/IGDispatch.c']
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform=='darwin' and shutil.which('xcrun'), '需要 Xcode/macOS')
|
||||
class DefenderTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.tmp = tempfile.TemporaryDirectory()
|
||||
cls.folder = Path(cls.tmp.name)
|
||||
cls.exe = cls.folder/'defender-host'
|
||||
cls.env = dict(os.environ)
|
||||
cls.env.pop('DYLD_INSERT_LIBRARIES', None)
|
||||
cls.compile(['xcrun','--sdk','macosx','clang','-O2',
|
||||
'-I',str(ROOT/'defender/include'),'-I',str(ROOT/'defender'),
|
||||
str(ROOT/'tests/fixtures/defender_host.c'),
|
||||
*(str(ROOT/'defender'/p) for p in SOURCES),
|
||||
'-lobjc','-o',str(cls.exe)])
|
||||
fixture = cls.folder/'empty.c'
|
||||
fixture.write_text('int ig_fixture_marker(void) { return 1; }\n')
|
||||
cls.image = cls.folder/'fixture_frida.dylib'
|
||||
cls.compile(['xcrun','--sdk','macosx','clang','-dynamiclib',str(fixture),'-o',str(cls.image)])
|
||||
|
||||
@classmethod
|
||||
def compile(cls, args):
|
||||
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 check_mode(self, mode, *args):
|
||||
p = subprocess.run([str(self.exe),mode,*map(str,args)],
|
||||
capture_output=True,text=True,env=self.env)
|
||||
self.assertEqual(p.returncode,0,p.stdout+p.stderr)
|
||||
# 保留各探针证据到 unittest 日志。
|
||||
print(mode+': '+p.stdout.strip(), flush=True)
|
||||
|
||||
def test_clean(self): self.check_mode('clean')
|
||||
def test_unavailable(self): self.check_mode('unresolved')
|
||||
def test_function_provenance(self): self.check_mode('verify')
|
||||
def test_environment_entries(self): self.check_mode('env')
|
||||
def test_loaded_image(self): self.check_mode('image',self.image)
|
||||
def test_got_rebinding(self): self.check_mode('got')
|
||||
def test_debugger_clean(self): self.check_mode('debugger')
|
||||
def test_objc_baseline_clean(self): self.check_mode('objc-clean')
|
||||
def test_objc_baseline_swap(self): self.check_mode('objc-swap')
|
||||
|
||||
def test_iphoneos_cross_compile(self):
|
||||
for i, source in enumerate(SOURCES):
|
||||
self.compile(['xcrun','--sdk','iphoneos','clang','-arch','arm64',
|
||||
'-miphoneos-version-min=15.0','-O2',
|
||||
'-I',str(ROOT/'defender/include'),'-I',str(ROOT/'defender'),
|
||||
'-c',str(ROOT/'defender'/source),'-o',str(self.folder/f'{i}.o')])
|
||||
|
||||
|
||||
if __name__ == '__main__': unittest.main()
|
||||
Reference in New Issue
Block a user