Tang-ZW

Untitled

Feb 4th, 2026
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. #define _GNU_SOURCE
  2.  
  3. #include <endian.h>
  4. #include <fcntl.h>
  5. #include <stdint.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <sys/stat.h>
  10. #include <sys/syscall.h>
  11. #include <sys/types.h>
  12. #include <unistd.h>
  13.  
  14. static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
  15. {
  16. if (a0 == 0xc || a0 == 0xb) {
  17. char buf[128];
  18. sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1,
  19. (uint8_t)a2);
  20. return open(buf, O_RDWR, 0);
  21. } else {
  22. unsigned long nb = a1;
  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)(nb % 10);
  29. nb /= 10;
  30. }
  31. return open(buf, a2, 0);
  32. }
  33. }
  34.  
  35. uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff};
  36.  
  37. int main(void)
  38. {
  39. syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  40. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  41. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  42. syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul,
  43. /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
  44. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  45. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  46. syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  47. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  48. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  49. const char* reason;
  50. (void)reason;
  51. intptr_t res = 0;
  52. if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  53. }
  54. // syz_open_dev$sg arguments: [
  55. // dev: ptr[in, buffer] {
  56. // buffer: {2f 64 65 76 2f 73 67 23 00} (length 0x9)
  57. // }
  58. // id: intptr = 0x0 (8 bytes)
  59. // flags: open_flags = 0x0 (8 bytes)
  60. // ]
  61. // returns fd_sg
  62. memcpy((void*)0x2000000000c0, "/dev/sg#\000", 9);
  63. res = -1;
  64. res = syz_open_dev(/*dev=*/0x2000000000c0, /*id=*/0, /*flags=*/0);
  65. if (res != -1)
  66. r[0] = res;
  67. // mmap arguments: [
  68. // addr: VMA[0x3000]
  69. // len: len = 0x3000 (8 bytes)
  70. // prot: mmap_prot = 0x3 (8 bytes)
  71. // flags: mmap_flags = 0x12 (8 bytes)
  72. // fd: fd (resource)
  73. // offset: intptr = 0x0 (8 bytes)
  74. // ]
  75. syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x3000ul,
  76. /*prot=PROT_WRITE|PROT_READ*/ 3ul,
  77. /*flags=MAP_FIXED|MAP_PRIVATE*/ 0x12ul, /*fd=*/r[0], /*offset=*/0ul);
  78. // openat$sysctl arguments: [
  79. // fd: const = 0xffffffffffffff9c (8 bytes)
  80. // file: ptr[in, buffer] {
  81. // buffer: {2f 70 72 6f 63 2f 73 79 73 2f 76 6d 2f 64 72 6f 70 5f 63 61
  82. // 63 68 65 73 00} (length 0x19)
  83. // }
  84. // flags: const = 0x1 (4 bytes)
  85. // mode: const = 0x0 (2 bytes)
  86. // ]
  87. // returns fd_sysctl
  88. memcpy((void*)0x200000001040, "/proc/sys/vm/drop_caches\000", 25);
  89. res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul,
  90. /*file=*/0x200000001040ul, /*flags=*/1, /*mode=*/0);
  91. if (res != -1)
  92. r[1] = res;
  93. // write$sysctl arguments: [
  94. // fd: fd_sysctl (resource)
  95. // val: ptr[in, buffer] {
  96. // buffer: {32 00} (length 0x2)
  97. // }
  98. // len: len = 0xfffe (8 bytes)
  99. // ]
  100. memcpy((void*)0x2000000000c0, "2\000", 2);
  101. syscall(__NR_write, /*fd=*/r[1], /*val=*/0x2000000000c0ul, /*len=*/0xfffeul);
  102. // madvise arguments: [
  103. // addr: VMA[0x600000]
  104. // len: len = 0x600000 (8 bytes)
  105. // advice: madvise_flags = 0x64 (8 bytes)
  106. // ]
  107. syscall(__NR_madvise, /*addr=*/0x200000000000ul, /*len=*/0x600000ul,
  108. /*advice=MADV_HWPOISON*/ 0x64ul);
  109. return 0;
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment