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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <sys/types.h>
  6. #include <sys/socket.h>
  7. #include <sys/wait.h>
  8. #include <sys/ioctl.h>
  9. #include <sys/stat.h>
  10. #include <netdb.h>
  11. #include <net/if.h>
  12. #include <linux/if_ether.h>
  13. #include <netinet/in.h>
  14. #include <netinet/ip.h>
  15. #include <netinet/ip_icmp.h>
  16. #include <netinet/ip_tcp.h>
  17. #include "spoof.c"
  18.  
  19. #define ERROR      -1
  20. #define ETHHDRSIZE 14
  21.  
  22. #ifdef SYSV
  23. #define bcopy(s1,s2,len) memcpy(s2,s1,len)
  24. #endif
  25.  
  26. char buffcmp[255];
  27.  
  28. unsigned long host2ip(char *serv)
  29. {
  30.    struct sockaddr_in sinn;
  31.    struct hostent     *hent;
  32.       
  33.   if ((hent = gethostbyname(serv)) == NULL) {
  34.      herror("gethostbyname");
  35.      exit(ERROR);
  36.   }
  37.   
  38.   bzero((char *)&sinn, sizeof(sinn));
  39.   bcopy(hent->h_addr, (char *)&sinn.sin_addr, hent->h_length);
  40.   return sinn.sin_addr.s_addr;
  41. }
  42.  
  43. char *Lookit(char *buff, char *file)
  44. {
  45.   FILE *fd;
  46.   bzero(buffcmp, 255);
  47.  
  48.   if ((fd = fopen(file, "r")) == NULL) {
  49.      perror("fopen");
  50.      exit(ERROR);
  51.   }
  52.   
  53.   while (!feof(fd)){
  54.      fscanf(fd, "%s", buffcmp); 
  55.      if(strstr(buff, (char *)&buffcmp)) {
  56.        fclose(fd);
  57.        return((char *)&buffcmp);
  58.        
  59.      }
  60.   }
  61.   fclose(fd);    
  62.   return NULL;
  63. }     
  64.                      
  65. void main(int argc, char **argv)
  66. {
  67.    
  68.   int s;
  69.   int i, x;
  70.  
  71.   struct ifreq  ifr;
  72.   struct iphdr  *ip;
  73.   struct tcphdr *tcp;
  74.  
  75.   char *data;
  76.   char *BANWORD;
  77.   char buffer[4000];
  78.  
  79.  
  80.   printf("w00w00!\n");
  81.  
  82.   if(argc < 3) {
  83.      printf(" usage: %s <device> <banwordlist>\n", argv[1]);
  84.      exit(ERROR);
  85.   }
  86.   
  87.    /*************************** TCP-IP STUFF   *****************************/
  88.   ip   = (struct iphdr  *)(buffer+ETHHDRSIZE);
  89.   tcp  = (struct tcphdr *)(buffer+ETHHDRSIZE+IPHDRSIZE);
  90.   data = (char *)(buffer+ETHHDRSIZE+IPHDRSIZE+TCPHDRSIZE);
  91.  
  92.   bzero(buffer, sizeof(buffer));          
  93.   /************************** INTERFACE STUFF  ***************************/   
  94.    
  95.   strcpy(ifr.ifr_name, argv[1]);
  96.   if ((s = socket(AF_INET, SOCK_PACKET,IPPROTO_EGP)) == ERROR) {
  97.      perror("socket");
  98.      exit(ERROR);
  99.   }
  100.    
  101.   if(ioctl(s, SIOCGIFFLAGS, &ifr) == ERROR) {
  102.        perror("ioctl");
  103.        close(s);
  104.        exit(ERROR);
  105.   }
  106.    
  107.   ifr.ifr_flags |= IFF_PROMISC; 
  108.   if(ioctl(s, SIOCSIFFLAGS, &ifr) == ERROR) {
  109.         perror("ioctl");
  110.         close(s);
  111.         exit(ERROR);
  112.   }
  113.  
  114.   while(1) {
  115.  
  116.     if ((x = read(s, buffer, 400)) == ERROR) {
  117.        perror("read");
  118.        close(s);
  119.        exit(ERROR);
  120.     }
  121.  
  122.     if(ip->protocol == 6)
  123.        if((BANWORD = Lookit(data, argv[2])) != NULL) {
  124.             printf("BANWORD !!!\033[05m\033[01m\033[31m%s\033[0m!!!\n",
  125.                BANWORD);   
  126.             printf("%s:%d->", 
  127.         (char *)inet_ntoa(ip->saddr), ntohs(tcp->th_sport));
  128.             printf("%s:%d",
  129.         (char *)inet_ntoa(ip->daddr), ntohs(tcp->th_dport)); 
  130.             printf("-->");
  131.                  
  132.             for(i=0; i < ntohs(ip->tot_len)-IPHDRSIZE-TCPHDRSIZE; i++)
  133.             printf("%c", *(data + i));
  134.             printf("<--\n");
  135.        }
  136.   }
  137. }
  138.  
  139.