Skip to content

Commit eb01da6

Browse files
New version v1.2
1. Added Multithreading for fast working 2. Fixed #3 3. Some Enhancement to reduce false positive.
1 parent 13e3b20 commit eb01da6

File tree

1 file changed

+94
-71
lines changed

1 file changed

+94
-71
lines changed

SubDomainizer.py

Lines changed: 94 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import tldextract
2020
import sys
2121
import socket
22+
from multiprocessing.dummy import Pool as ThreadPool
23+
from itertools import repeat
2224

2325
parse = argparse.ArgumentParser()
2426
parse.add_argument('-u', '--url', help="Enter the URL in which you want to find (sub)domains.")
@@ -86,10 +88,7 @@ def IntJsExtract(self, url, heads):
8688
html = req.content.decode(decoding)
8789
minhtml = htmlmin.minify(html, remove_empty_space=True)
8890
minhtml = minhtml.replace('\n', '')
89-
compiledInline = re.compile(r"<script.*?>(.*?)</script>")
90-
jss = compiledInline.findall(minhtml)
91-
for js in jss:
92-
finallist.append(js)
91+
finallist.append(minhtml)
9392
print(termcolor.colored("Successfully got all the Inline Scripts.", color='blue', attrs=['bold']))
9493
except UnicodeDecodeError:
9594
print("Decoding error.")
@@ -135,8 +134,7 @@ def ExtJsExtract(self, url, heads):
135134
print("Decoding error, Exiting...")
136135
sys.exit(1)
137136

138-
def SaveExtJsContent(self, lst):
139-
for js in lst:
137+
def SaveExtJsContent(self, js):
140138
try:
141139
req = requests.get(js)
142140
content = req.text
@@ -162,10 +160,7 @@ def getDomain(url):
162160
return ext.registered_domain
163161

164162

165-
def getSubdomainsfromFile(filesname, url):
166-
print(termcolor.colored("Finding Subdomains and cloud data of given domain in all Javascript files...", color='yellow',
167-
attrs=['bold']))
168-
163+
def getSubdomainsfromFile(file, url):
169164
# cloud services regex:
170165
cfreg = re.compile(r'([\w]+.cloudfront\.net)', re.IGNORECASE)
171166
s3bucketreg = re.compile(r'([\w\-.]*s3[\w\-.]*\.?amazonaws\.com/?[\w\-.]*)', re.IGNORECASE)
@@ -191,42 +186,62 @@ def getSubdomainsfromFile(filesname, url):
191186
# domain regex
192187
regex = re.compile(r'([\w\-.]+\.' + getDomain(url) + ')', re.IGNORECASE)
193188

194-
195-
for file in filesname:
196-
#cloud services
197-
for x in cloudlist:
198-
for item in x.findall(str(file)):
199-
cloudurlset.add(item)
200-
201-
#ip finding
202-
st = file.split(' ')
203-
for i in st:
204-
match = ipv4reg.search(i)
205-
if match:
206-
ipv4list.add(match.group())
207-
208-
#for subdomains
209-
for subdomain in regex.findall(file):
189+
#cloud services
190+
for x in cloudlist:
191+
for item in x.findall(str(file)):
192+
cloudurlset.add(item)
193+
194+
#ip finding
195+
st = file.split(' ')
196+
for i in st:
197+
match = ipv4reg.search(i)
198+
if match:
199+
ipv4list.add(match.group())
200+
201+
# for subdomains
202+
for subdomain in regex.findall(file):
203+
if subdomain.startswith('u002F') or subdomain.startswith('u002f'):
204+
subdomain = subdomain.lstrip('u002f')
205+
subdomain = subdomain.lstrip('u002F')
210206
finalset.add(subdomain)
211-
212-
# given domain regex
213-
if args.domain:
214-
domainreg = re.compile(r'([\w\-.]+\.' + args.domain + ')', re.IGNORECASE)
215-
for subdomain in domainreg.findall(file):
207+
elif subdomain.startswith('2F') or subdomain.startswith('2f'):
208+
if socket.getfqdn(subdomain) != subdomain:
216209
finalset.add(subdomain)
217-
print(termcolor.colored("Got all the important data.\n", color='green', attrs=['bold']))
210+
else:
211+
subdomain = subdomain.lstrip('2F')
212+
subdomain = subdomain.lstrip('2f')
213+
finalset.add(subdomain)
214+
else:
215+
finalset.add(subdomain)
216+
217+
# given domain regex
218+
if args.domain:
219+
domainreg = re.compile(r'([\w\-.]+\.' + args.domain + ')', re.IGNORECASE)
220+
for subdomain in domainreg.findall(file):
221+
finalset.add(subdomain)
218222

219223

220224
def subextractor(url):
221225
jsfile = JsExtract()
222226
jsfile.IntJsExtract(url, heads)
223227
jsfile.ExtJsExtract(url, heads)
224-
jsfile.SaveExtJsContent(jsLinkList)
225-
getSubdomainsfromFile(finallist, url)
228+
jsthread = ThreadPool(25)
229+
jsthread.map(jsfile.SaveExtJsContent,jsLinkList)
230+
jsthread.close()
231+
jsthread.join()
232+
print(termcolor.colored("Finding Subdomains and cloud data of given domain in all Javascript files...",
233+
color='yellow',
234+
attrs=['bold']))
235+
threads = ThreadPool(25)
236+
237+
threads.starmap(getSubdomainsfromFile,zip(finallist,repeat(url)))
238+
threads.close()
239+
threads.join()
240+
print(termcolor.colored("Got all the important data.\n", color='green', attrs=['bold']))
226241

227242

228243
def saveandprintdomains():
229-
print("\n~~~~~~~~~~~~~~~~~~~~~~~RESULTS~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
244+
print(termcolor.colored("\n~~~~~~~~~~~~~~~~~~~~~~~RESULTS~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",color='red', attrs=['bold']))
230245
if cloudurlset:
231246
print(termcolor.colored("Some cloud services url's found. They might be interesting, Here are the URLs:\n",
232247
color='blue', attrs=['bold']))
@@ -255,53 +270,61 @@ def savecloudresults():
255270
def ipv4add():
256271
print(termcolor.colored("Got Some IPv4 addresses:\n", color='blue', attrs=['bold']))
257272
for ip in ipv4list:
258-
print(termcolor.colored(ip, color='green', attrs=['bold']))
273+
if socket.getfqdn(ip) != ip:
274+
print(termcolor.colored(ip + ' - ' + socket.getfqdn(ip), color='green', attrs=['bold']))
259275

260276

261277
def printlogo():
262278
return termcolor.colored(logo(), color='red', attrs=['bold'])
263279

264280

265281
if __name__ == "__main__":
266-
print(printlogo())
267-
argerror(url, listfile)
268-
if listfile:
269-
urllist = getUrlsFromFile()
270-
if urllist:
271-
for i in urllist:
272-
print(termcolor.colored("Extracting data from internal and external js for url:", color='blue',
273-
attrs=['bold']))
274-
print(termcolor.colored(i, color='red', attrs=['bold']))
275-
try:
282+
try:
283+
print(printlogo())
284+
argerror(url, listfile)
285+
if listfile:
286+
urllist = getUrlsFromFile()
287+
if urllist:
288+
for i in urllist:
289+
print(termcolor.colored("Extracting data from internal and external js for url:", color='blue',
290+
attrs=['bold']))
291+
print(termcolor.colored(i, color='red', attrs=['bold']))
276292
try:
277-
subextractor(i)
278-
except requests.exceptions.ConnectionError:
279-
print('An error occured while fetching URL, Might be URL is wrong, Please check!')
280-
except requests.exceptions.InvalidSchema:
281-
print("Invalid Schema Provided!")
282-
sys.exit(1)
283-
else:
284-
try:
293+
try:
294+
subextractor(i)
295+
except requests.exceptions.ConnectionError:
296+
print('An error occured while fetching URL, Might be URL is wrong, Please check!')
297+
except requests.exceptions.InvalidSchema:
298+
print("Invalid Schema Provided!")
299+
sys.exit(1)
300+
else:
285301
try:
286-
subextractor(url)
287-
except requests.exceptions.ConnectionError:
288-
print(
289-
'An error occured while fetching URL, Might be server is down, or domain does not exist, Please check!')
302+
try:
303+
subextractor(url)
304+
except requests.exceptions.ConnectionError:
305+
print(
306+
'An error occured while fetching URL, Might be server is down, or domain does not exist, Please check!')
307+
sys.exit(1)
308+
except requests.exceptions.InvalidSchema:
309+
print("Invalid Schema Provided!")
290310
sys.exit(1)
291-
except requests.exceptions.InvalidSchema:
292-
print("Invalid Schema Provided!")
293-
sys.exit(1)
294311

295-
saveandprintdomains()
312+
saveandprintdomains()
296313

297-
print('\n')
314+
print('\n')
298315

299-
if ipv4list:
300-
ipv4add()
316+
if ipv4list:
317+
ipv4add()
301318

302-
if cloudop:
303-
print(
304-
termcolor.colored("\nWriting all the cloud services URL's to given file...", color='blue', attrs=['bold']))
305-
savecloudresults()
306-
print(
307-
termcolor.colored("Written cloud services URL's in file: ", color='blue', attrs=['bold']) + cloudop + '\n')
319+
if cloudop:
320+
print(
321+
termcolor.colored("\nWriting all the cloud services URL's to given file...", color='blue', attrs=['bold']))
322+
savecloudresults()
323+
print(
324+
termcolor.colored("Written cloud services URL's in file: ", color='blue', attrs=['bold']) + cloudop + '\n')
325+
except KeyboardInterrupt:
326+
print(termcolor.colored("\nKeyboard Interrupt. Exiting...\n", color='red', attrs=['bold']))
327+
sys.exit(1)
328+
except FileNotFoundError:
329+
print(termcolor.colored("\nFile Not found, Please check filename. Exiting...\n", color='yellow', attrs=['bold']))
330+
sys.exit(1)

0 commit comments

Comments
 (0)