home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / misc / statscan.c < prev   
Encoding:
C/C++ Source or Header  |  1998-08-13  |  2.3 KB  |  116 lines

  1. /* Statd scanner.......         */
  2.  
  3. #include <stdio.h>
  4. #include <netdb.h>
  5. #include <stdlib.h>
  6. #include <signal.h>
  7. #include <rpc/rpc.h>
  8. #include <arpa/inet.h>
  9. #include <sys/socket.h>
  10. #include <netinet/in.h>
  11. #include <netinet/ip.h>
  12. #include <rpc/pmap_prot.h>
  13. #include <rpc/pmap_clnt.h>
  14.  
  15. #define ERROR -1
  16.  
  17. void woopy(int s);
  18. void usage(char *s);
  19. void scan(char *i, char *o);
  20.  
  21. int statd(char *host);
  22. unsigned long int res(char *p);
  23.  
  24. void usage(char *s)
  25. {
  26.   printf("Usage: %s <inputfile> <outputfile>\n",s);
  27.   exit(ERROR);
  28. }
  29.  
  30. void main(int argc, char **argv)
  31. {
  32.   if(argc < 3) usage(argv[0]);
  33.   scan(argv[1], argv[2]);
  34. }
  35.  
  36. void scan(char *i, char *o)
  37. {
  38.   FILE *iff, *of;
  39.   char buf[512];
  40.   
  41.   if((iff=fopen(i,"r")) == NULL)
  42.     return;
  43.   while(fgets(buf,512,iff) != NULL) 
  44.   {
  45.     if(buf[strlen(buf)-1]=='\n')
  46.       buf[strlen(buf)-1]=0;
  47.     if(statd(buf) && (of=fopen(o,"a")) != NULL) {
  48.       buf[strlen(buf)+1]=0;
  49.       buf[strlen(buf)]='\n';
  50.       
  51.       fputs(buf,of);
  52.       fclose(of);
  53.     }  
  54.   }
  55.   fclose(iff);
  56. }
  57.  
  58. void woopy(int s)
  59. {
  60.   return;
  61. }
  62.  
  63. int statd(char *host)
  64. {
  65.   struct sockaddr_in server_addr;
  66.   struct pmaplist *head = NULL;
  67.   int sockett = RPC_ANYSOCK;
  68.   struct timeval minutetimeout;
  69.   register CLIENT *client;
  70.   struct rpcent *rpc;
  71.  
  72.   server_addr.sin_addr.s_addr=res(host);
  73.   server_addr.sin_family=AF_INET;
  74.   server_addr.sin_port = htons(PMAPPORT);
  75.   minutetimeout.tv_sec = 15;
  76.   minutetimeout.tv_usec = 0;
  77.   
  78.   /* cause clnttcp_create uses connect() */
  79.   signal(SIGALRM,woopy);
  80.   alarm(15);
  81.   
  82.   if ((client = clnttcp_create(&server_addr, PMAPPROG,
  83.       PMAPVERS, &sockett, 50, 500)) == NULL) {
  84.     alarm(0);
  85.     signal(SIGALRM,SIG_DFL);
  86.     return 0;
  87.   }
  88.   alarm(0);
  89.   signal(SIGALRM,SIG_DFL);
  90.   
  91.   if (clnt_call(client, PMAPPROC_DUMP, (xdrproc_t) xdr_void, NULL, 
  92.       (xdrproc_t) xdr_pmaplist, &head, minutetimeout) != RPC_SUCCESS)
  93.     return 0;
  94.   if (head != NULL) 
  95.     for (; head != NULL; head = head->pml_next)
  96.       if((rpc = getrpcbynumber(head->pml_map.pm_prog)))
  97.         if(strcmp(rpc->r_name,"rstatd") == 0)
  98.           return 1;              
  99.    
  100.   return 0;
  101. }
  102.  
  103. unsigned long int res(char *p)
  104. {
  105.    struct hostent *h;
  106.    unsigned long int rv;
  107.     
  108.    h=gethostbyname(p);
  109.    if(h!=NULL)
  110.      memcpy(&rv,h->h_addr,h->h_length);
  111.    else
  112.      rv=inet_addr(p);
  113.    return rv;
  114. }
  115.                     
  116.