-
Notifications
You must be signed in to change notification settings - Fork 166
/
argparsing.py
190 lines (160 loc) · 5.16 KB
/
argparsing.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
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
import colorama
import argparse
from os import linesep, environ
import sys
import providers
import inspect
runtime = environ.get("SM_COMMAND", f"{sys.argv[0]}")
banner = """\
____ __ _____ _ __
/ __ \__ ______ / /__/ ___/___ _______ _______(_) /___ __
/ /_/ / / / / __ \/ //_/\__ \/ _ \/ ___/ / / / ___/ / __/ / / /
/ ____/ /_/ / / / / ,< ___/ / __/ /__/ /_/ / / / / /_/ /_/ /
/_/ \__,_/_/ /_/_/|_|/____/\___/\___/\__,_/_/ /_/\__/\__, /
PRESENTS /____/
DNS Reaper ☠️
Scan all your DNS records for subdomain takeovers!
"""
banner_with_colour = (
colorama.Fore.GREEN
+ """\
____ __ _____ _ __
/ __ \__ ______ / /__/ ___/___ _______ _______(_) /___ __
/ /_/ / / / / __ \/ //_/\__ \/ _ \/ ___/ / / / ___/ / __/ / / /
/ ____/ /_/ / / / / ,< ___/ / __/ /__/ /_/ / / / / /_/ /_/ /
/_/ \__,_/_/ /_/_/|_|/____/\___/\___/\__,_/_/ /_/\__/\__, /
PRESENTS /____/"""
+ colorama.Fore.RED
+ """
DNS Reaper ☠️"""
+ colorama.Fore.CYAN
+ """
Scan all your DNS records for subdomain takeovers!
"""
+ colorama.Fore.RESET
)
class CustomParser(argparse.ArgumentParser):
def error(self, message):
sys.stdout.write(f" ❌ error: {message}{linesep}{linesep}")
self.print_usage()
sys.exit(2)
parser = CustomParser(
usage=f"""
{runtime} provider [options]
output:
findings output to screen and (by default) results.csv
help:
{runtime} --help
providers:
{ linesep.join([f" > {provider} - {getattr(providers, provider).description}" for provider in providers.__all__ ]) }
""",
formatter_class=argparse.RawDescriptionHelpFormatter,
description="",
add_help=False,
)
parser.add_argument(
"provider",
type=str,
choices=providers.__all__,
)
for provider in providers.__all__:
group = parser.add_argument_group(provider)
module = getattr(providers, provider)
group.description = module.description
signature = inspect.signature(module.fetch_domains)
parameters = signature.parameters.items()
for parameter in [
x[1]
for x in parameters
if x[1].kind != x[1].VAR_KEYWORD and x[1].kind != x[1].VAR_POSITIONAL
]:
group.add_argument(
f"--{parameter.name.replace('_','-')}",
type=str,
help=(
"Required"
if isinstance(parameter.default, type(parameter.empty))
else "Optional"
),
)
parser.add_argument(
"-h",
"--help",
action="help",
help="Show this help message and exit",
)
parser.add_argument(
"--out",
type=str,
default="results",
help="Output file (default: %(default)s) - use 'stdout' to stream out",
)
parser.add_argument(
"--out-format",
type=str,
default="csv",
choices=["csv", "json"],
)
parser.add_argument(
"--resolver",
type=str,
default="8.8.8.8,8.8.4.4,1.1.1.1,1.0.0.1,208.67.222.2,208.67.220.2",
help="Provide a custom DNS resolver (or multiple seperated by commas), or '' to use system resolver. We loadbalance a public resolver list by default",
)
parser.add_argument(
"--parallelism",
type=int,
default=30,
help="Number of domains to test in parallel - too high and you may see odd DNS results (default: %(default)s)",
)
parser.add_argument(
"--disable-probable",
action="store_true",
help="Do not check for probable conditions",
)
parser.add_argument(
"--enable-unlikely",
action="store_true",
help="Check for more conditions, but with a high false positive rate",
)
parser.add_argument(
"--signature",
action="append",
help="Only scan with this signature (multiple accepted)",
)
parser.add_argument(
"--exclude-signature",
action="append",
help="Do not scan with this signature (multiple accepted)",
)
parser.add_argument(
"--pipeline",
action="store_true",
help="Exit Non-Zero on detection (used to fail a pipeline)",
)
parser.add_argument(
"-v",
"--verbose",
action="count",
default=0,
help="-v for verbose, -vv for extra verbose",
)
parser.add_argument("--nocolour", help="Turns off coloured text", action="store_true")
def parse_args():
args = parser.parse_args()
module = getattr(providers, args.provider)
signature = inspect.signature(module.fetch_domains)
parameters = signature.parameters.items()
for parameter in [
x[1]
for x in parameters
if x[1].kind != x[1].VAR_KEYWORD and x[1].kind != x[1].VAR_POSITIONAL
]:
# If provider function signature has a default value, the command line option is optional!
if args.__dict__[parameter.name] is None and isinstance(
parameter.default, type(parameter.empty)
):
parser.error(
f" {args.provider} provider requires --{parameter.name.replace('_', '-')}"
)
return args