harden(poison): 修命名段挂牌泄漏——毒化副本改匿名数组分散(对抗自验)
对「链接+strip 的宿主」做攻击者视角自验(nm/otool -l/-tV/strings),揪出上一版
§7.2 的反效果设计:三副本用自定义命名段 __DATA,__ig_p0/p1/p2/pd,而命名段原样留在
Mach-O load command、strip 也抹不掉——otool -l | grep __ig_p 一把定位毒化副本位置,
比匿名 BSS 更糟(等于在 header 上挂牌)。
修法:三真副本+诱饵散进一个匿名数组 g_state[12] 的非相邻下标(IG_LANE={2,7,11}、
IG_DECOY=5,其余陪衬槽),全进匿名 __bss/__data;每槽存 baseline^lane_k(i) 使各槽值
互不相同,消除「数组里几个相同的字=一组健康值」的静态 tell;mask 只读三真副本。
mask 语义不变(健康→0,毒化→非0,无分支),毒化语义测试全过。
回归守卫:tests/test_static_hardening.py 新增 test_no_telegraphing_sections,
守 .a 不再出现 __ig_/__poison 等泄漏性命名段。
另记录自验第二发现(已写进 docs/18 §7.0):四个 public 入口名 _ig_poison_* 的字样
本身泄露用途,strip -x 抹不掉,须 readoor Release 用完整 strip(style=all) 或接入层包中性名。
设备 poison_device.m 全模块 iphoneos 交叉编译 arm64 通过;全量 70 测试通过。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
b76d7cdc21
commit
e3d2a48d56
@@ -125,6 +125,19 @@ class StaticHardeningTests(unittest.TestCase):
|
||||
hit = [m for m in OLD_MAGIC if m in dis]
|
||||
self.assertEqual(hit, [], f'旧基线魔数残留:{hit}')
|
||||
|
||||
def test_no_telegraphing_sections(self):
|
||||
"""§7.2:不得用会「挂牌」的自定义命名 section。
|
||||
|
||||
命名 section(如旧实现的 __ig_p0/p1/p2/pd)会原样留在 Mach-O load command 里,
|
||||
strip 也抹不掉,等于把毒化副本位置写进 header 供 otool -l 一把定位——比匿名 BSS 更糟。
|
||||
毒化状态须存进匿名 __bss/__data。本测试守 .a 不出现 __ig_/__poison 等泄漏性节名。"""
|
||||
out = subprocess.run(['xcrun', '--sdk', 'iphoneos', 'otool', '-l', str(self.lib)],
|
||||
capture_output=True, text=True).stdout.lower()
|
||||
leak = [ln.split('sectname', 1)[1].strip()
|
||||
for ln in out.splitlines() if 'sectname' in ln
|
||||
and ('__ig' in ln or '__poison' in ln or '__ig_p' in ln)]
|
||||
self.assertEqual(leak, [], f'泄漏性命名 section(strip 抹不掉,会挂牌毒化副本位置):{leak}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user