Recover and verify static collision traversal and body contracts
This commit is contained in:
1 parent
7c0d1a4b0c
commit
df0263b26e
34 files changed
+1962
-17
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Guard the expanded original dispatcher probe callgraph; never execute originals."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
from collision_response import collect as kernel_collect, header, TARGETS
|
||||
from checkpoint_script_state import find_case, read_va
|
||||
from pe_inspect import PE
|
||||
|
||||
EXTRA=(
|
||||
('static_dispatch',0x47B4B0,0x47B889,'da4ca56149636d5fc5059403a0ef81a0007c96972e3c12f2a8dedfa7568dd160'),
|
||||
('polygon_dispatch',0x47BBB0,0x47BD73,'b583bb88a97bef45961ad64a6b21533e9149d3dcb4a292d5dbe27db98d4dd325'),
|
||||
('polygon_vertex',0x477F10,0x477F5F,'b5460f170b2315a462700d585b0626321186977a7bc192ede831a1e1ba60677c'),
|
||||
('truncate',0x47F940,0x47F96A,'b1c1cecad44192fa8b32676658fcfea569fa1810741a5a5321c77f488c90b0b7'))
|
||||
POINTERS=(*TARGETS,0x509B24,0x49B1FC,0x4D6A04,0x4F69E5,0x695D46,0x695D4C,0x695D70,0x695D78)
|
||||
|
||||
|
||||
def collect(original):
|
||||
report=kernel_collect(original);pe=PE(find_case(Path(original),'Neutron.exe'))
|
||||
for name,start,end,digest in EXTRA:
|
||||
body=read_va(pe,start,end-start)
|
||||
if hashlib.sha256(body).hexdigest()!=digest:raise ValueError(f'Changed body {name}')
|
||||
report['bodies'].append(dict(name=name,va=hex(start),file_offset=hex(pe.offset(start-pe.base)),length=end-start,sha256=digest))
|
||||
for target in POINTERS:
|
||||
value=struct.pack('<I',target)
|
||||
for index in range(len(body)-3):
|
||||
if body[index:index+4]==value:report['probe_operands'].append(dict(va=start+index,target=target))
|
||||
report['probe_operands'].sort(key=lambda p:p['va'])
|
||||
return report
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
cli=argparse.ArgumentParser(description=__doc__);cli.add_argument('original',type=Path)
|
||||
cli.add_argument('--probe-header',type=Path);cli.add_argument('--target-copy',type=Path)
|
||||
args=cli.parse_args();report=collect(args.original)
|
||||
if args.target_copy:
|
||||
target=args.target_copy.resolve(strict=True)
|
||||
if target.is_relative_to(args.original.resolve()):cli.error('Use a generated target copy')
|
||||
if hashlib.sha256(target.read_bytes()).hexdigest()!=report['sha256']:cli.error('Unexpected target copy hash')
|
||||
if args.probe_header:
|
||||
output=args.probe_header.resolve()
|
||||
if output.is_relative_to(args.original.resolve()):cli.error('Header must be outside originals')
|
||||
output.write_text(header(report))
|
||||
print(json.dumps(report,indent=2))
|
||||
Reference in new issue
Block a user