-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrelated-domains.py
executable file
·281 lines (218 loc) · 8.86 KB
/
related-domains.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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/usr/bin/python3
import os
import sys
import re
import json
import requests
import argparse
import tldextract
from colored import fg, bg, attr
w_blacklist = [ 'privacy', 'redacted', 'destination', 'dnstination', 'west', 'select request email', 'markmonitor' ]
# https://twitter.com/intigriti/status/1639610098954932225
def searchDomainBuiltwith( _domain ):
global _verbose, t_data
if _verbose:
sys.stdout.write( '%s[+] calling builtwith targeting domain%s\n' % (fg('green'),attr(0)) )
try:
url = 'https://builtwith.com/relationships/'+_domain
r = requests.get( url )
except Exception as e:
sys.stdout.write( "%s[-] error occurred: %s%s\n" % (fg('red'),e,attr(0)) )
return
rgxp = r'("https://builtwith.com/relationships/[^"]+)'
matches = re.findall( rgxp, r.text, re.IGNORECASE )
if matches:
for m in matches:
if not '/tag/' in m:
domain = m.replace('https://builtwith.com/relationships/','').replace('"','')
domain = domain.lower()
if not domain in t_data['domains']:
t_data['domains'].append( domain )
print( domain )
def searchDomainCrtsh( _domain ):
global _verbose, t_data
if _verbose:
sys.stdout.write( '%s[+] calling crtsh targeting domain%s\n' % (fg('green'),attr(0)) )
parse = tldextract.extract( _domain )
# print(parse)
url = 'https://crt.sh/?q=%25'+parse.domain+'%25&output=json'
if _verbose:
sys.stdout.write( '%s[+] %s%s\n' % (fg('white'),url,attr(0)) )
try:
r = requests.get( url )
t_json = r.json()
# print(t_json)
except Exception as e:
sys.stdout.write( "%s[-] error occurred: %s%s\n" % (fg('red'),e,attr(0)) )
return
# f = open("crtsh.json")
# t_json = json.load(f)
# f.close()
for item in t_json:
if 'common_name' in item:
try:
parse = tldextract.extract( item['common_name'] )
domain = parse.domain + '.' + parse.suffix
domain = domain.lower()
if not domain in t_data['domains']:
t_data['domains'].append( domain )
print( domain )
except Exception as e:
pass
def searchCompanyWhoxy( _whoxy_key ):
global _verbose, t_data
if _verbose:
sys.stdout.write( '%s[+] whoxy key found, calling whoxy api targeting company%s\n' % (fg('green'),attr(0)) )
for company in t_data['companies']:
page = 1
company = company.replace( ' ', '+' )
if _verbose:
sys.stdout.write( '%s[+] search for company: %s%s\n' % (fg('green'),company,attr(0)) )
while True:
url = 'http://api.whoxy.com/?key='+_whoxy_key+'&reverse=whois&company='+company+'&mode=micro&page='+str(page)
page = page + 1
if _verbose:
sys.stdout.write( '%s[+] %s%s\n' % (fg('white'),url,attr(0)) )
try:
r = requests.get( url )
t_json = r.json()
# print(t_json)
except Exception as e:
sys.stdout.write( "%s[-] error occurred: %s%s\n" % (fg('red'),e,attr(0)) )
continue
if 'search_result' in t_json and len(t_json['search_result']):
for result in t_json['search_result']:
if not result['domain_name'] in t_data['domains']:
t_data['domains'].append( result['domain_name'] )
print( result['domain_name'] )
else:
break
def searchEmailWhoxy( _whoxy_key ):
global _verbose, t_data
if _verbose:
sys.stdout.write( '%s[+] whoxy key found, calling whoxy api targeting email%s\n' % (fg('green'),attr(0)) )
for email in t_data['emails']:
page = 1
if _verbose:
sys.stdout.write( '%s[+] search for email: %s%s\n' % (fg('green'),email,attr(0)) )
while True:
url = 'http://api.whoxy.com/?key='+_whoxy_key+'&reverse=whois&email='+email+'&mode=micro&page='+str(page)
page = page + 1
if _verbose:
sys.stdout.write( '%s[+] %s%s\n' % (fg('white'),url,attr(0)) )
try:
r = requests.get( url )
t_json = r.json()
# print(t_json)
except Exception as e:
sys.stdout.write( "%s[-] error occurred: %s%s\n" % (fg('red'),e,attr(0)) )
continue
if 'search_result' in t_json and len(t_json['search_result']):
for result in t_json['search_result']:
if not result['domain_name'] in t_data['domains']:
t_data['domains'].append( result['domain_name'] )
print( result['domain_name'] )
else:
break
def searchDomainWhoxy( _domain, _whoxy_key ):
global _verbose, t_data
if _verbose:
sys.stdout.write( '%s[+] whoxy key found, calling whoxy api targeting domain%s\n' % (fg('green'),attr(0)) )
url = 'http://api.whoxy.com/?key='+_whoxy_key+'&whois='+_domain
if _verbose:
sys.stdout.write( '%s[+] %s%s\n' % (fg('white'),url,attr(0)) )
try:
r = requests.get( url )
t_json = r.json()
# print(t_json)
except Exception as e:
sys.stdout.write( "%s[-] error occurred: %s%s\n" % (fg('red'),e,attr(0)) )
return
extractDatasWhoxy( t_json )
if _verbose:
print(t_data['companies'])
print(t_data['emails'])
def extractDatasWhoxy( t_json ):
global _verbose, t_data
for index in ['technical_contact','registrant_contact','administrative_contact']:
if index in t_json:
company,email = extractDataWhoxy( t_json, t_json[index] )
if company and company not in t_data['companies']:
t_data['companies'].append( company )
if email and email not in t_data['emails']:
t_data['emails'].append( email )
return
def extractDataWhoxy( t_json, tab ):
global _verbose, t_data
if not 'company_name' in tab:
company = False
elif 'registrant_contact' in t_json and 'company_name' in t_json['registrant_contact']:
company = t_json['registrant_contact']['company_name']
for wbl in w_blacklist:
if wbl in company.lower():
company = False
break
else:
company = False
if not 'email_address' in tab:
email = False
elif 'registrant_contact' in t_json and 'email_address' in t_json['registrant_contact']:
email = t_json['registrant_contact']['email_address']
for wbl in w_blacklist:
if wbl in email.lower():
email = False
break
else:
email = False
return company,email
parser = argparse.ArgumentParser()
parser.add_argument( "-e","--email",help="email you are looking for (required or -d or -c)" )
parser.add_argument( "-b","--builtwith",help="use builtwith as an additional source", action="store_true" )
parser.add_argument( "-c","--company",help="company you are looking for (required or -d or -e)" )
parser.add_argument( "-d","--domain",help="domain you already know (required or -c)" )
parser.add_argument( "-k","--key",help="whoxy api key (required)" )
parser.add_argument( "-s","--source",help="list of sources separated by comma, available sources are: builtwith,crtsh,whoxy (default=whoxy)" )
parser.add_argument( "-v","--verbose",help="enable verbose mode, default off", action="store_true" )
parser.parse_args()
args = parser.parse_args()
t_data = { 'domains':[], 'companies':[], 'emails':[] }
if args.verbose:
_verbose = True
else:
_verbose = False
if args.company:
t_data['companies'].append( args.company )
if args.email:
t_data['emails'].append( args.email )
if args.domain:
_domain = args.domain
else:
_domain = False
if not _domain and not len(t_data['companies']) and not len(t_data['emails']):
parser.error( 'domain or company or email required' )
if not args.source:
t_sources = "whoxy"
else:
t_sources = args.source.split(',')
if "whoxy" in t_sources:
if args.key:
_whoxy_key = args.key
else:
_whoxy_key = os.getenv('WHOXY_KEY')
if not _whoxy_key:
_whoxy_key = ""
if _domain:
if _verbose:
sys.stdout.write( '%s[+] search for domain: %s%s\n' % (fg('green'),_domain,attr(0)) )
if "crtsh" in t_sources:
searchDomainCrtsh( _domain )
if "builtwith" in t_sources:
searchDomainBuiltwith( _domain )
if "whoxy" in t_sources:
if len(_whoxy_key):
searchDomainWhoxy( _domain, _whoxy_key )
if "whoxy" in t_sources:
if len(_whoxy_key) and len(t_data['companies']):
searchCompanyWhoxy( _whoxy_key )
if len(_whoxy_key) and len(t_data['emails']):
searchEmailWhoxy( _whoxy_key )