-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathox4shell.py
97 lines (77 loc) · 2.74 KB
/
ox4shell.py
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
from lib.utils import setup_logger, set_debug_level
from lib.usage import usage
from lib.deobfuscate import deobfuscate, DEFAULT_MAX_DEPTH
from lib.mock import Mock
from argparse import ArgumentParser, RawTextHelpFormatter, ArgumentDefaultsHelpFormatter
from pathlib import Path
import logging
logger = logging.getLogger("Ox4Shell")
setup_logger(logger)
class CustomArgumentFormatter(ArgumentDefaultsHelpFormatter, RawTextHelpFormatter):
...
def main() -> None:
parser = ArgumentParser(
prog="ox4shell",
description=usage,
formatter_class=CustomArgumentFormatter,
add_help=False,
)
general_group = parser.add_argument_group(title="General")
general_group.add_argument(
"-h", "--help", action="help", help="Show this help message and exit"
)
general_group.add_argument(
"-d", "--debug", default=False, help="Enable debug mode", action="store_true"
)
general_group.add_argument(
"-m",
"--mock",
default=Path("mock.json"),
help="The location of the mock data JSON file that replaces certain values in the payload",
type=Path,
)
general_group.add_argument(
"--max-depth",
default=DEFAULT_MAX_DEPTH,
help="The maximum number of iteration to perform on a given payload",
type=int,
)
general_group.add_argument(
"--decode-base64",
default=False,
help="Payloads containing base64 will be decoded",
action="store_true",
)
target_group = parser.add_argument_group(
title="Targets", description="Choose which target payloads to run Ox4Shell on"
)
target_mutex_group = target_group.add_mutually_exclusive_group(required=True)
target_mutex_group.add_argument(
"-p",
"--payload",
type=str,
help="A single payload to deobfuscate, make sure to escape '$' signs",
)
target_mutex_group.add_argument(
"-f",
"--file",
type=Path,
help="A file containing payloads delimited by newline",
)
args = parser.parse_args()
if args.debug:
set_debug_level(logger)
logger.debug(f"Using mock file: {args.mock}")
Mock.populate(args.mock)
if args.payload:
deobfuscated = deobfuscate(args.payload, max_depth=args.max_depth, decode_base64=args.decode_base64)
logger.info(deobfuscated)
if args.file:
if not args.file.exists():
raise Exception(f"File {args.file} does not exists!")
with args.file.open("r") as f:
for line in f:
deobfuscated = deobfuscate(line.strip(), max_depth=args.max_depth, decode_base64=args.decode_base64)
logger.info(deobfuscated)
if __name__ == "__main__":
main()