zzqq0103

Untitled

Mar 14th, 2024
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1.  
  2. #define _GNU_SOURCE
  3.  
  4. #include <endian.h>
  5. #include <fcntl.h>
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <sys/stat.h>
  11. #include <sys/syscall.h>
  12. #include <sys/types.h>
  13. #include <unistd.h>
  14.  
  15. static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
  16. {
  17.   if (a0 == 0xc || a0 == 0xb) {
  18.     char buf[128];
  19.     sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1,
  20.             (uint8_t)a2);
  21.     return open(buf, O_RDWR, 0);
  22.   } else {
  23.     char buf[1024];
  24.     char* hash;
  25.     strncpy(buf, (char*)a0, sizeof(buf) - 1);
  26.     buf[sizeof(buf) - 1] = 0;
  27.     while ((hash = strchr(buf, '#'))) {
  28.       *hash = '0' + (char)(a1 % 10);
  29.       a1 /= 10;
  30.     }
  31.     return open(buf, a2, 0);
  32.   }
  33. }
  34.  
  35. uint64_t r[1] = {0xffffffffffffffff};
  36.  
  37. int main(void)
  38. {
  39.   syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  40.           /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
  41.           /*offset=*/0ul);
  42.   syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul,
  43.           /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
  44.           /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
  45.           /*offset=*/0ul);
  46.   syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  47.           /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
  48.           /*offset=*/0ul);
  49.   intptr_t res = 0;
  50.   syscall(__NR_socket, /*domain=*/0xaul, /*type=*/2ul, /*proto=*/0);
  51.   memcpy((void*)0x20000080, "/dev/cpu/#/msr\000", 15);
  52.   res = -1;
  53.   res = syz_open_dev(/*dev=*/0x20000080, /*id=*/0x201, /*flags=*/0);
  54.   if (res != -1)
  55.     r[0] = res;
  56.   syscall(__NR_read, /*fd=*/r[0], /*buf=*/0x200002c0ul, /*count=*/0xfffffebeul);
  57.   return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment