daily pastebin goal
90%
SHARE
TWEET

LDAP Amp Scanner

wtfbbq Aug 10th, 2017 (edited) 3,026 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //working LDAP scanner since LiGhT can't code to save his life
  2.  
  3. #include <pthread.h>
  4. #include <unistd.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <sys/socket.h>
  9. #include <netinet/in.h>
  10. #include <signal.h>
  11. #include <sys/time.h>
  12. #include <sys/types.h>
  13. #include <math.h>
  14. #include <ctype.h>
  15. #include <errno.h>
  16. #include <arpa/inet.h>
  17. #include <netinet/ip.h>
  18. #include <netinet/udp.h>
  19.  
  20. volatile int running_threads = 0;
  21. volatile int found_srvs = 0;
  22. volatile unsigned long per_thread = 0;
  23. volatile unsigned long start = 0;
  24. volatile unsigned long scanned = 0;
  25. volatile int sleep_between = 0;
  26. volatile int bytes_sent = 0;
  27. volatile unsigned long hosts_done = 0;
  28. FILE *fd;
  29. char payload[] =
  30. "\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";
  31.  
  32. size = sizeof(payload);
  33.  
  34. void *flood(void *par1)
  35. {
  36.     running_threads++;
  37.     int thread_id = (int)par1;
  38.     unsigned long start_ip = htonl(ntohl(start)+(per_thread*thread_id));
  39.     unsigned long end = htonl(ntohl(start)+(per_thread*(thread_id+1)));
  40.     unsigned long w;
  41.     int y;
  42.     unsigned char buf[65536];
  43.     memset(buf, 0x01, 51);
  44.     int sizeofpayload = 51;
  45.     int sock;
  46.     if((sock=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))<0) {
  47.         perror("cant open socket");
  48.         exit(-1);
  49.     }
  50.     for(w=ntohl(start_ip);w<htonl(end);w++)
  51.     {
  52.         struct sockaddr_in servaddr;
  53.         bzero(&servaddr, sizeof(servaddr));
  54.         servaddr.sin_family = AF_INET;
  55.         servaddr.sin_addr.s_addr=htonl(w);
  56.         servaddr.sin_port=htons(389);
  57.         sendto(sock,payload,size,0, (struct sockaddr *)&servaddr,sizeof(servaddr));
  58.         bytes_sent+=size;
  59.         scanned++;
  60.         hosts_done++;
  61.     }
  62.     close(sock);
  63.     running_threads--;
  64.     return;
  65. }
  66.  
  67. void sighandler(int sig)
  68. {
  69.     fclose(fd);
  70.     printf("\n");
  71.     exit(0);
  72. }
  73.  
  74. void *recievethread()
  75. {
  76.     printf("\n");
  77.     int saddr_size, data_size, sock_raw;
  78.     struct sockaddr_in saddr;
  79.     struct in_addr in;
  80.  
  81.     unsigned char *buffer = (unsigned char *)malloc(65536);
  82.     sock_raw = socket(AF_INET , SOCK_RAW , IPPROTO_UDP);
  83.     if(sock_raw < 0)
  84.     {
  85.         printf("Socket Error\n");
  86.         exit(1);
  87.     }
  88.     while(1)
  89.     {
  90.         saddr_size = sizeof saddr;
  91.         data_size = recvfrom(sock_raw , buffer , 65536 , 0 , (struct sockaddr *)&saddr , &saddr_size);
  92.         if(data_size <0 )
  93.         {
  94.             printf("Recvfrom error , failed to get packets\n");
  95.             exit(1);
  96.         }
  97.         struct iphdr *iph = (struct iphdr*)buffer;
  98.         if(iph->protocol == 17)
  99.         {
  100.             unsigned short iphdrlen = iph->ihl*4;
  101.             struct udphdr *udph = (struct udphdr*)(buffer + iphdrlen);
  102.             unsigned char* payload = buffer + iphdrlen + 51;
  103.             if(ntohs(udph->source) == 389)
  104.             {
  105.                 int body_length = data_size - iphdrlen - 51;
  106.                 if (body_length > 40)
  107.                 {
  108.                 found_srvs++;
  109.                 fprintf(fd,"%s %d\n",inet_ntoa(saddr.sin_addr),body_length);
  110.                 fflush(fd);
  111.                 }
  112.             }
  113.         }
  114.     }
  115.     close(sock_raw);
  116. }
  117. int main(int argc, char *argv[ ])
  118. {
  119.     if(argc < 6){
  120.     fprintf(stderr, "Invalid parameters!\n");
  121.     fprintf(stdout, "Usage: %s <ip range start (1.0.0.0)> <ip range end (255.255.255)> <outfile> <threads> <scan delay in ms>\n", argv[0]);
  122.     exit(-1);
  123.     }
  124.     fd = fopen(argv[3], "a");
  125.     sleep_between = atoi(argv[5]);
  126.     signal(SIGINT, &sighandler);
  127.     int threads = atoi(argv[4]);
  128.     pthread_t thread;
  129.     pthread_t listenthread;
  130.     pthread_create( &listenthread, NULL, &recievethread, NULL);
  131.     char *str_start = malloc(18);
  132.     memset(str_start, 0, 18);
  133.     str_start = argv[1];
  134.     char *str_end = malloc(18);
  135.     memset(str_end, 0, 18);
  136.     str_end = argv[2];
  137.     start = inet_addr(str_start);
  138.     per_thread = (ntohl(inet_addr(str_end)) - ntohl(inet_addr(str_start))) / threads;
  139.     unsigned long toscan = (ntohl(inet_addr(str_end)) - ntohl(inet_addr(str_start)));
  140.     int i;
  141.     for(i = 0;i<threads;i++){
  142.         pthread_create( &thread, NULL, &flood, (void *) i);
  143.     }
  144.     sleep(1);
  145.     printf("Scan in Progress \n");
  146.     char *temp = (char *)malloc(17);
  147.     memset(temp, 0, 17);
  148.     sprintf(temp, "Found");
  149.     printf("%-16s", temp);
  150.     memset(temp, 0, 17);
  151.     sprintf(temp, "IP/s");
  152.     printf("%-16s", temp);
  153.     memset(temp, 0, 17);
  154.     sprintf(temp, "Bytes/s");
  155.     printf("%-16s", temp);
  156.     memset(temp, 0, 17);
  157.     sprintf(temp, "Threads");
  158.     printf("%-16s", temp);
  159.     memset(temp, 0, 17);
  160.     sprintf(temp, "Percent Done");
  161.     printf("%s", temp);
  162.     printf("\n");
  163.     char *new;
  164.     new = (char *)malloc(16*6);
  165.     while (running_threads > 0)
  166.     {
  167.         printf("\r");
  168.         memset(new, '\0', 16*6);
  169.         sprintf(new, "%s|%-15lu", new, found_srvs);
  170.         sprintf(new, "%s|%-15d", new, scanned);
  171.         sprintf(new, "%s|%-15d", new, bytes_sent);
  172.         sprintf(new, "%s|%-15d", new, running_threads);
  173.         memset(temp, 0, 17);
  174.         int percent_done=((double)(hosts_done)/(double)(toscan))*100;
  175.         sprintf(temp, "%d%%", percent_done);
  176.         sprintf(new, "%s|%s", new, temp);
  177.         printf("%s", new);
  178.         fflush(stdout);
  179.         bytes_sent=0;
  180.         scanned = 0;
  181.         sleep(1);
  182.     }
  183.     printf("\n");
  184.     fclose(fd);
  185.     return 0;
  186. }
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