Skip to content
This repository was archived by the owner on Apr 11, 2021. It is now read-only.

Commit b3975cd

Browse files
authored
Merge pull request #34 from mzfr/opening
Refactor the subdomainfile function
2 parents 7ea9094 + 995a70b commit b3975cd

File tree

1 file changed

+43
-137
lines changed

1 file changed

+43
-137
lines changed

domained.py

Lines changed: 43 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -304,150 +304,56 @@ def upgradeFiles():
304304
print("Changing back to old working directory: {}".format(old_wd))
305305
os.chdir(old_wd)
306306

307-
308-
def subdomainfile():
309-
sublist3rFileName = "{}_sublist3r.txt".format(output_base)
310-
enumallFileName = "{}.lst".format(domain)
307+
def writeFiles(name):
308+
"""Writes info of all hosts from subhosts
309+
"""
310+
subdomainCounter = 0
311311
subdomainAllFile = "{}-all.txt".format(output_base)
312-
knockpyFileName = "{}_knock.csv.txt".format(output_base)
313-
massdnsFileName = "{}-massdns.txt".format(output_base)
314-
amassFileName = "{}_amass.txt".format(output_base)
315-
subfinderFileName = "{}_subfinder.txt".format(output_base)
316-
f1 = open(subdomainAllFile, "w")
317-
f1.close()
318-
print("\nOpening Sublist3r File\n")
319-
try:
320-
with open(sublist3rFileName) as f:
321-
SubHosts = f.read().splitlines()
322-
f.close()
323-
time.sleep(2)
324-
subdomainCounter = 0
325-
f1 = open(subdomainAllFile, "a")
326-
f1.writelines("\n\nsublist3r")
327-
for hosts in SubHosts:
328-
hosts = "".join(hosts)
329-
f1.writelines("\n" + hosts)
330-
subdomainCounter = subdomainCounter + 1
331-
f1.close()
332-
os.remove(sublist3rFileName)
333-
print("\n{} Subdomains discovered by Sublist3r".format(subdomainCounter))
334-
except:
335-
print("\nError Opening Sublist3r File!\n")
336-
print("\nOpening Enumall File\n")
337-
try:
338-
with open(enumallFileName) as f:
339-
SubHosts = f.read().splitlines()
340-
f.close()
341-
time.sleep(2)
342-
subdomainCounter = 0
343-
f1 = open(subdomainAllFile, "a")
344-
f1.writelines("\n\nenumall")
345-
for hosts in SubHosts:
346-
hosts = "".join(hosts)
347-
f1.writelines("\n" + hosts)
348-
subdomainCounter = subdomainCounter + 1
349-
f1.close()
350-
os.remove(enumallFileName)
351-
enumallFileNamecsv = domain + ".csv"
352-
os.remove(enumallFileNamecsv)
353-
print("\n{} Subdomains discovered by Enumall".format(subdomainCounter))
354-
except:
355-
print("\nError Opening Enumall File!\n")
356-
print("\nOpening Knock File\n")
357-
try:
358-
with open(knockpyFileName) as f:
359-
SubHosts = f.read().splitlines()
360-
f.close()
361-
time.sleep(1)
362-
subdomainCounter = 0
363-
f1 = open(subdomainAllFile, "a")
364-
f1.writelines("\n\nknock")
365-
for hosts in SubHosts:
366-
hosts = "".join(hosts)
367-
f1.writelines("\n{}".format(hosts))
368-
subdomainCounter = subdomainCounter + 1
369-
f1.close()
370-
knockpyFileNamecsv = "{}_knock.csv".format(output_base)
371-
os.remove(knockpyFileName)
372-
os.remove(knockpyFileNamecsv)
373-
print("\n{} Subdomains discovered by Knock".format(subdomainCounter))
374-
except:
375-
print("\nError Opening Knock File!\n")
376-
print("\nOpening massdns File\n")
377-
try:
378-
with open(massdnsFileName) as f:
379-
SubHosts = f.read().splitlines()
380-
f.close()
381-
time.sleep(1)
382-
subdomainCounter = 0
383-
f1 = open(subdomainAllFile, "a")
384-
f1.writelines("\n\nmassdns")
385-
for hosts in SubHosts:
386-
hosts = hosts.split(". ")[0]
387-
if domain in hosts:
388-
hosts = "".join(hosts)
389-
f1.writelines("\n" + hosts)
390-
subdomainCounter = subdomainCounter + 1
391-
f1.close()
392-
os.remove(massdnsFileName)
393-
print("\n{} Subdomains discovered by massdns".format(subdomainCounter))
394-
except:
395-
print("\nError Opening massdns File!\n")
396-
print("\nOpening Amass File\n")
312+
fileExt = {'Sublist3r':'.txt', 'knock':'.csv.txt', 'enumall': '.lst',
313+
'massdns': '.txt', 'amass': '.txt', 'SubFinder': '.txt'}
314+
fileName = "output/" + name + fileExt[name]
315+
316+
print("\n Opening %s File" % name)
397317
try:
398-
with open(amassFileName) as f:
318+
with open(fileName, 'w') as f:
399319
SubHosts = f.read().splitlines()
400-
f.close()
401-
time.sleep(1)
402-
subdomainCounter = 0
403-
f1 = open(subdomainAllFile, "a")
404-
f1.writelines("\n\namass")
405-
for hosts in SubHosts:
406-
hosts = hosts.split(". ")[0]
407-
if domain in hosts:
320+
321+
with open(subdomainAllFile, 'a') as f:
322+
f.writelines("\n\n" + name)
323+
for hosts in SubHosts:
408324
hosts = "".join(hosts)
409-
f1.writelines("\n" + hosts)
410-
subdomainCounter = subdomainCounter + 1
411-
f1.close()
412-
os.remove(amassFileName)
413-
print("\n{} Subdomains discovered by Amass".format(subdomainCounter))
414-
except:
415-
print("\nError Opening Amass File!\n")
416-
print("\nOpening Subfinder File\n")
417-
try:
418-
with open(subfinderFileName) as f:
419-
SubHosts = f.read().splitlines()
420-
f.close()
421-
time.sleep(2)
422-
subdomainCounter = 0
423-
f1 = open(subdomainAllFile, "a")
424-
f1.writelines("\n\nsubfinder")
425-
for hosts in SubHosts:
426-
hosts = "".join(hosts)
427-
f1.writelines("\n" + hosts)
428-
subdomainCounter = subdomainCounter + 1
429-
f1.close()
430-
os.remove(subfinderFileName)
431-
print("\n{} Subdomains discovered by Subfinder".format(subdomainCounter))
325+
f.writelines("\n" + hosts)
326+
subdomainCounter += 1
327+
os.remove(fileName)
328+
print("\n%s Subdomains discovered by %s" % (subdomainCounter, name))
432329
except:
433-
print("\nError Opening Subfinder File!\n")
330+
print("\nError Opening %s File!\n" % name)
331+
return subdomainCounter
332+
333+
334+
def subdomainfile():
335+
subdomainAllFile = "{}-all.txt".format(output_base)
336+
names = ['Sublist3r', 'knock', 'enumall', 'massdns', 'amass', 'SubFinder']
337+
338+
for name in names:
339+
writeFiles(name)
340+
434341
print("\nCombining Domains Lists\n")
435-
domainList = open(subdomainAllFile, "r")
436-
uniqueDomains = set(domainList)
437-
domainList.close()
438-
subdomainUniqueFile = "{}-unique.txt".format(output_base)
439-
uniqueDomainsOut = open(subdomainUniqueFile, "w")
440-
for domains in uniqueDomains:
441-
domains = domains.replace("\n", "")
442-
if domains.endswith(domain):
443-
uniqueDomainsOut.writelines("https://{}\n".format(domains))
444-
if ports is not False:
445-
uniqueDomainsOut.writelines("https://{}:8443\n".format(domains))
446-
if secure is False:
447-
uniqueDomainsOut.writelines("http://{}\n".format(domains))
342+
with open(subdomainAllFile, "r") as domainList:
343+
uniqueDomains = set(domainList)
344+
domainList.close()
345+
subdomainUniqueFile = "{}-unique.txt".format(output_base)
346+
uniqueDomainsOut = open(subdomainUniqueFile, "w")
347+
for domains in uniqueDomains:
348+
domains = domains.replace("\n", "")
349+
if domains.endswith(domain):
350+
uniqueDomainsOut.writelines("https://{}\n".format(domains))
448351
if ports is not False:
449-
uniqueDomainsOut.writelines("http://{}:8080\n".format(domains))
450-
uniqueDomainsOut.close()
352+
uniqueDomainsOut.writelines("https://{}:8443\n".format(domains))
353+
if secure is False:
354+
uniqueDomainsOut.writelines("http://{}\n".format(domains))
355+
if ports is not False:
356+
uniqueDomainsOut.writelines("http://{}:8080\n".format(domains))
451357
time.sleep(1)
452358
rootdomainStrip = domain.replace(".", "_")
453359
print("\nCleaning Up Old Files\n")

0 commit comments

Comments
 (0)