This repository has been archived by the owner on Mar 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
domaindouche.py
172 lines (146 loc) · 5.29 KB
/
domaindouche.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
#!/usr/bin/env python3
"""Domain enumeration script abusing the 'suggestions' feature
when typing out domains on https://securitytrails.com/dns-trails.
Very handy for quickly finding potentially related domains from a name."""
import argparse
import json
import multiprocessing
import signal
import string
import sys
from argparse import RawTextHelpFormatter
from http.cookies import SimpleCookie
from itertools import product
import requests
from rich.console import Console
from rich.progress import Progress
parser = argparse.ArgumentParser(
formatter_class=RawTextHelpFormatter,
prog=sys.argv[0],
description="""Abuses SecurityTrails API to find related domains by keyword.
Go to https://securitytrails.com/dns-trails, solve any CAPTCHA you might encounter,
copy the raw value of your Cookie and User-Agent headers and use them with \
the -c and -a arguments.""",
)
parser.add_argument("keyword", help="keyword to append brute force string to")
parser.add_argument(
"-n",
"--num",
metavar="N",
type=int,
default=2,
required=False,
help="number of characters to brute force (default: 2)",
)
parser.add_argument(
"-c",
"--cookie",
metavar="COOKIE",
type=str,
required=True,
help="raw cookie string",
)
parser.add_argument(
"-a",
"--useragent",
metavar="USER_AGENT",
type=str,
required=True,
help="user-agent string (must match the browser where the cookies are from)",
)
parser.add_argument(
"-w",
"--workers",
metavar="NUM",
type=str,
required=False,
help="number of workers (default: 5)",
)
parser.add_argument(
"-o", "--output", metavar="OUTFILE", required=False, help="output file path"
)
args = parser.parse_args()
cookie = SimpleCookie()
cookie.load(args.cookie)
cookies = {k: v.value for k, v in cookie.items()}
headers = {
"Upgrade-Insecure-Requests": "1",
"User-Agent": args.useragent,
"Accept": "text/html,application/xhtml+xml,application/xml;\
q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
"Sec-Gpc": "1",
"Accept-Language": "da-DK,da;q=0.6",
"Sec-Fetch-Site": "none",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-User": "?1",
"Sec-Fetch-Dest": "document",
"Accept-Encoding": "gzip, deflate",
}
def get_suggestions(brute_string):
"""Makes the HTTP request and returns a list of suggested domains"""
url = f"https://securitytrails.com/app/api/autocomplete/domain/{args.keyword}{brute_string}"
req = requests.get(url, cookies=cookies, headers=headers, timeout=3)
return json.loads(req.text)["suggestions"]
def call_get_suggestions(params):
"""Call the worker function"""
return get_suggestions(*params)
def initializer():
"""Ignore SIGINT in child workers."""
signal.signal(signal.SIGINT, signal.SIG_IGN)
combinations = []
for letter_count in range(1, args.num + 1):
combinations = combinations + [
"".join(i) for i in list(product(string.ascii_lowercase, repeat=letter_count))
]
progress_console = Console(log_time=False, log_path=False, file=sys.stderr)
results = []
if __name__ == "__main__":
try:
try:
algo_params = []
results = []
for x in combinations:
algo_params.append([x])
with Progress(
console=progress_console,
redirect_stdout=False,
redirect_stderr=False,
transient=True,
) as progress:
task_id = progress.add_task("[bold magenta]Brute-forcing...", total=len(algo_params))
progress.print("""[green]
_ _
| \ _ __ _ o __ | \ _ _ |_ _
|_/(_)|||(_| | | ||_/(_)|_|(_ | |(/_
_________________________________[/green]
by [bold magenta]@[email protected][/bold magenta]""")
progress.print("\nStarting enumeration...\n", style="bold magenta")
with multiprocessing.Pool(processes=5, initializer=initializer) as pool:
for result in pool.imap(call_get_suggestions, algo_params):
new_found = list(set(result) - set(results))
results = results + new_found
for domain in new_found:
progress.print(domain, style="green")
if args.output:
with open(args.output, "w+", encoding="utf-8") as outfile:
outfile.write(f"{domain}\n")
progress.advance(task_id)
except (KeyError, json.decoder.JSONDecodeError):
progress.stop()
progress_console.print(
"[bold red]UNRECOGNIZED REPLY! TRY WITH FRESH COOKIE.[/bold red]"
)
sys.exit()
except KeyboardInterrupt:
progress_console.print(
"\n[bold magenta]Ctrl-C detected. Exiting...[/bold magenta]\n"
)
progress_console.print(
f"\n[green]Found {len(results)} domains starting with '{args.keyword}'[/green]\n"
)
# If script output is piped, print results to stdout
# (progress prints to stderr only)
if not sys.stdout.isatty():
for result in results:
for domain in results:
print(domain)