forked from c0dejump/HExHTTP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
180 lines (161 loc) · 5.93 KB
/
cli.py
File metadata and controls
180 lines (161 loc) · 5.93 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
#!/usr/bin/env python3
from modules.logging_config import valid_log_level
from static.banner import run_banner
from utils.style import Colors
from utils.utils import argparse, sys, random
USER_AGENTS = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
"(KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
"AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
"Mozilla/5.0 (X11; Linux x86_64) Gecko/20100101 Firefox/118.0",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:143.0) Gecko/20100101 Firefox/143.0"
]
DEFAULT_USER_AGENT = random.choice(USER_AGENTS)
def args() -> argparse.Namespace:
"""
Parses command-line arguments and returns them.
This function uses argparse to define and parse command-line arguments for the script.
It includes options for specifying a URL, a file of URLs, custom HTTP headers, user agents,
authentication, verbosity, logging, and threading.
Returns:
argparse.Namespace: Parsed command-line arguments.
Arguments:
-u, --url (str): URL to test [required].
-f, --file (str): File of URLs.
-H, --header (str): Add a custom HTTP Header.
-A, --user-agent (str): Add a custom User Agent.
-a, --auth (str): Add an HTTP authentication. Ex: --auth admin:admin.
-t, --threads (int): Threads numbers for multiple URLs. Default: 10.
-l, --log (str): Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL).
Default: WARNING.
-L, --log-file (str): The file path pattern for the log file.
Default: ./error_logs/%Y%m%d_%H%M.log.
-v, --verbose (int): Increase verbosity (can be used multiple times).
-hu, --humans: Performs a timesleep to reproduce human behavior (Default: 0s) value: 'r' or 'random'
-p, --proxy: proxy all requests through this proxy (format: host:port, default: 127.0.0.1:8080)
--burp: send behavior and confirmed requests to Burp proxy (format: host:port, default: 127.0.0.1:8080)
--ocp, --only-cp: Only cache poisoning modules
If no argument is provided, the function will print the help message and exit.
"""
parser = argparse.ArgumentParser(description=run_banner())
group = parser.add_argument_group(f"{Colors.BLUE}> General{Colors.RESET}")
group.add_argument(
"-u",
"--url",
dest="url",
help=f"URL to test {Colors.RED}[required]{Colors.RESET} if no -f/--file provided",
)
group.add_argument(
"-f",
"--file",
dest="url_file",
help="File of URLs",
required=False,
)
group = parser.add_argument_group(f"{Colors.BLUE}> Request Settings{Colors.RESET}")
group.add_argument(
"-H",
"--header",
dest="custom_header",
help="Add a custom HTTP Header",
action="append",
required=False,
)
group.add_argument(
"-A",
"--user-agent",
dest="user_agent",
help="Add a custom User Agent",
default=DEFAULT_USER_AGENT,
)
group.add_argument(
"-a",
"--auth",
dest="auth",
help=f"Add an HTTP authentication.{Colors.YELLOW} Ex: --auth admin:admin{Colors.RESET}",
required=False,
)
group.add_argument(
"-hu",
"--humans",
dest="humans",
help="Performs a timesleep to reproduce human behavior (Default: 0s) value: 'r' or 'random'",
default="0",
required=False,
)
group.add_argument(
"-t",
"--threads",
dest="threads",
help=f"Threads numbers for multiple URLs. {Colors.GREEN}Default: 10{Colors.RESET}",
type=int,
default=10,
required=False,
)
group = parser.add_argument_group(f"{Colors.BLUE}> Log settings{Colors.RESET}")
group.add_argument(
"-l",
"--log",
type=valid_log_level,
default="WARNING",
help="Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
)
group.add_argument(
"-L",
"--log-file",
dest="log_file",
default="./error_logs/%Y%m%d_%H%M.log",
help=f"The file path pattern for the log file. {Colors.GREEN}Default: error_logs/{Colors.RESET}",
required=False,
)
group.add_argument(
"-v",
"--verbose",
action="count",
default=0,
help="Increase verbosity (can be used multiple times)",
)
group.add_argument(
"-o",
"--output-html",
dest="output_html",
type=str, nargs='?', const='default',
metavar='FILE',
help=f'Generate HTML report. {Colors.GREEN}Default: results/<date>_report.html{Colors.RESET})'
)
group = parser.add_argument_group(f"{Colors.BLUE}> Proxy Settings{Colors.RESET}")
group.add_argument(
"-p",
"--proxy",
dest="proxy",
nargs='?',
const='', # Default value when --proxy is provided without argument
help="Proxy all requests through this proxy (format: host:port, default: 127.0.0.1:8080)",
required=False,
)
group.add_argument(
"--burp",
dest="burp",
nargs='?',
const='', # Default value when --burp is provided without argument
help="Send behavior and confirmed requests to Burp proxy (format: host:port, default: 127.0.0.1:8080)",
required=False,
)
group = parser.add_argument_group(f"{Colors.BLUE}> Tips{Colors.RESET}")
group.add_argument(
"--ocp",
"--only-cp",
action="store_true",
dest="only_cp",
help="Only cache poisoning modules",
required=False,
)
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
# Validate that either URL or file is provided
if not args.url and not args.url_file:
parser.error("Either -u/--url or -f/--file must be provided.")
return args