-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDomainRecon
More file actions
executable file
·261 lines (218 loc) · 7.76 KB
/
DomainRecon
File metadata and controls
executable file
·261 lines (218 loc) · 7.76 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
#!/usr/bin/env python3
import collections
import tldextract
import traceback
import itertools
import datetime
import argparse
import pprint
import whois
import sys
import os
import re
import utils
# defaults
default_max_threads = 6
def get_whois(domain):
"""
Get whois info for a domain
:param domain: Domain to get info for
:return: Dictionary containing domain info in the format {registrar, org, name
emails, country, creation, expiration}
"""
# clean up domain (remove subdomain and url parts)
extracted = tldextract.extract(domain)
main_domain = '{}.{}'.format(extracted.domain, extracted.suffix)
if main_domain != domain:
utils.debug('Replaced {} with {}'.format(domain, main_domain))
result = whois.whois(main_domain)
# debug
utils.debug('IPWhois result:')
utils.debug(pprint.pformat(result))
# grab these keys
# {key: dest}
keys = {
'registrar': None,
'org': 'organization',
'name': 'registrant',
'emails': None,
'country': None,
'creation_date': 'expiration',
'expiration_date': 'expiration',
'name_servers': None,
'registrant_email': 'emails',
'registrant_name': 'name',
'registrant_country': 'country',
}
# convert these to lowercase
lower = (
'emails',
'name_servers',
)
# reduce the number of these
prune_dates = (
'expiration',
'creation',
)
# grab the info we want
domain_info = collections.defaultdict(list)
for key, dest in keys.items():
# ignore empty or non-existent values
if not (key in result and result[key]):
continue
if not dest:
# default destination is same as key
dest = key
if not isinstance(result[key], list):
# result is a list of values
values = [result[key]]
else:
# result is a single value
values = result[key]
# fix up values
new_values = []
for value in values:
if isinstance(value, datetime.datetime):
# it's a date
value = str(value.date())
else:
# any other value
value = str(value)
# strip
value = value.strip()
# lowercase
if dest in lower:
value = value.lower()
new_values.append(value)
values = new_values
# sort unique values
values = sorted(list(set(values)))
domain_info[dest] += values
if domain_info:
return domain_info
else:
return None
def main():
parser = argparse.ArgumentParser()
group = parser.add_argument_group('input arguments')
group.add_argument('domain', nargs='*',
help='Domain names')
group.add_argument('-f', '--file', action='append',
help='file containing domain names')
group.add_argument('--append', action='append',
help='try appending these strings to each domain')
group.add_argument('-t', '--tld', action='append',
help='add these TLDs (comma-separated or multiple-argument)')
group = parser.add_argument_group('threading arguments')
group.add_argument('-j', '--max-threads', type=int, default=default_max_threads,
help='maximum number of threads to use at once (default: {})'.format(default_max_threads))
group = parser.add_argument_group('output arguments')
group.add_argument('-e', '--expirations', action='store_true',
help='only show domain expirations')
group.add_argument('-a', '--available', action='store_true',
help='only show domains that are available')
group.add_argument('-o', '--output',
help='tee output to a file')
group.add_argument('-q', '--quiet', action='store_true',
help='do not print status messages to stderr')
group.add_argument('-D', '--debug', action='store_true',
help='enable debug output')
group.add_argument('-c', '--check', action='store_true',
help='check domain registration status')
args = parser.parse_args()
# -D/--debug
if args.debug:
# enable debug messages
utils.enable_debug()
# -q/--quiet
if args.quiet:
# disable prefixed stderr messages
utils.disable_status()
# -o/--output
if args.output:
# set log file
utils.set_log(args.output)
domains = iter(())
# <domain>
if args.domain:
domains = iter(args.domain)
# -f/--file
domains = itertools.chain(domains, utils.file_items(args.file))
# check to make sure we got domains
domains = utils.check_iterator(domains)
if not domains:
utils.die('Provide some domains to perform recon on.')
# add permutations
if args.append:
def append_generator(domains):
for domain in domains:
yield domain
for append in utils.combine_comma_lists(args.append):
yield domain + append
domains = append_generator(domains)
# add TLDs
if args.tld:
def tld_generator(domains):
for domain in domains:
for tld in utils.combine_comma_lists(args.tld):
tld = tld.lstrip('.')
yield '{}.{}'.format(domain, tld)
domains = tld_generator(domains)
total_results = 0
for domain, result in utils.threadify(get_whois, domains, max_threads=args.max_threads):
if args.available:
# handle exceptions
if isinstance(result, whois.parser.PywhoisError) and 'No match for' in str(result).splitlines()[0]:
utils.log(domain)
elif isinstance(result, Exception):
utils.debug_exception(result)
utils.bad('{} failed'.format(domain))
else:
# registered
pass
elif args.expirations:
# handle exceptions
if isinstance(result, whois.parser.PywhoisError) and 'No match for' in str(result):
utils.log('{}: unregistered'.format(domain))
elif isinstance(result, Exception):
utils.debug_exception(result)
utils.log('{}: failed'.format(domain))
elif result is None:
utils.log('{}: no results'.format(domain))
else:
utils.log('{}: {}'.format(domain, ', '.join(result['expiration'])))
else:
# show all info
utils.log('Domain: {}'.format(domain))
# debug
utils.debug('Final result:')
utils.debug(pprint.pformat(result))
# handle exceptions
if isinstance(result, Exception):
utils.debug_exception(result)
utils.log('Failure: {}\n'.format(str(result).splitlines()[0]))
continue
elif result is None:
utils.log('Unregistered')
continue
else:
# display results
for key, values in result.items():
value = ', '.join(values)
# replace _ with space
pretty = key.replace('_', ' ')
# uppercase first letter
pretty = pretty[0].upper() + pretty[1:]
if value:
utils.log('{}: {}'.format(pretty, value))
utils.log()
total_results += 1
if not args.expirations:
if total_results:
# print total
utils.good('Retrieved whois info for {} domains'.format(total_results))
else:
# nothing found
utils.bad('All whois queries failed')
if __name__ == '__main__':
main()