-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathurl1.py
More file actions
156 lines (142 loc) · 5.8 KB
/
url1.py
File metadata and controls
156 lines (142 loc) · 5.8 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
import bs4
from selenium import webdriver
import getopt
import sys
import time
import os
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
def printLogo():
print("""
________ __ .__
/ _____/_____ _/ |_| |__ ___________
/ \ ___\__ \\\ _\ | \_/ __ \_ __ \\
\ \_\ \/ __ \| | | | \ ___/| | \/
\______ (____ /__| |___| /\___ >__|
\/ \/ \/ \/
by Ben Heald
https://healdb.tech
https://github.com/Healdb/Gather
https://twitter.com/heald_ben
""")
print("URL Screenshot Utility\n")
def checkURL(potentialUrl, driver, disallowed):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36',
}
driver.get(potentialUrl)
html = driver.page_source
soup = bs4.BeautifulSoup(html, features="lxml")
# Catch chrome error pages
chromeErrorDivs = soup.findAll("div", {"class": "error-code"})
if (any(ele in html for ele in disallowed) or len(chromeErrorDivs) > 0):
return False
return len(html) > 10
def assembleHTML(name, outputDir):
urls = open(outputDir + "/" + name + "/" + name + ".txt", "r").readlines()
outHTML = open(outputDir + "/" + name + "/" + name + ".html", "w")
outHTML.write("<html><center>")
outText = ""
i = 0
for url in urls:
outText = outText + "<h3><a href='" + url + "' target='_blank'>" + url + "</a></h3><img src='" + outputDir + "/" + name + "/screenshots/" + str(
i) + "_screenshot.png'><br>\n"
i += 1
outHTML.write(outText)
outHTML.write("</center></html>")
outHTML.close()
def gatherScreenshots(driver, urlFile, name, disallowed, ports, outputDir):
i = 0
total = len(urlFile)
try:
os.mkdir(outputDir + "/" + name)
except FileExistsError:
pass
try:
os.mkdir(outputDir + "/" + name + "/screenshots/")
except FileExistsError:
pass
outputFile = open(outputDir + "/" + name + "/" + name + ".txt", "w")
for url in urlFile:
url = url.strip()
try:
for port in ports:
if port == "80":
if checkURL("http://" + url.strip(), driver, disallowed):
print("http://" + url)
driver.save_screenshot(outputDir + "/" + name + "/screenshots/" + str(i) + "_screenshot.png")
outputFile.write('http://' + url.strip() + "\n")
i += 1
elif port == "443":
if checkURL("https://" + url.strip(), driver, disallowed):
print("https://" + url)
driver.save_screenshot(outputDir + "/" + name + "/screenshots/" + str(i) + "_screenshot.png")
outputFile.write('https://' + url.strip() + "\n")
i += 1
else:
if checkURL("http://" + url.strip() + ":" + port, driver, disallowed):
print("http://" + url + ":" + port)
driver.save_screenshot(outputDir + "/" + name + "/screenshots/" + str(i) + "_screenshot.png")
outputFile.write('https://' + url.strip() + ":" + port + "\n")
i += 1
except Exception as e:
print(e)
pass
outputFile.close()
driver.close()
def gather(argv):
desired_capabilities = DesiredCapabilities.CHROME.copy()
desired_capabilities['acceptInsecureCerts'] = True
fileName = ""
outDirName = ""
chromeDriver = ""
verbose = False
disallowed = []
ports = ["80", "443"]
outputDir = os.getcwd()
try:
(opts, args) = getopt.getopt(argv, 'h:f:c:d:p:o:')
except getopt.GetoptError:
print(
'gather.py -f <url_file> -c <Chrome Driver Path> -d <Disallowed Words> -p <Ports to scan> -o <Output directory path>')
sys.exit(2)
for (opt, arg) in opts:
if opt == '-h':
print(
'gather.py -f <url_file> -c <Chrome Driver Path> -d <Disallowed Words> -p <Ports to scan> -o <Output directory path>')
sys.exit()
elif opt in '-f':
fileName = arg
outDirName = (os.path.split(fileName)[1]).split(".")[0]
elif opt in '-c':
chromeDriver = arg
elif opt in '-d':
if arg != "":
for word in arg.split(","):
disallowed.append(word)
elif opt in '-p':
if arg == "":
arg = "80,443"
for port in arg.split(","):
ports = []
ports.append(port)
elif opt in '-v':
verbose = True
elif opt in '-o':
outputDir = arg
try:
urlFile = open(fileName, "r").readlines()
except:
raise Exception("No file provided in the -f flag")
options = Options()
# options.headless = True
driver = webdriver.Chrome(executable_path=chromeDriver, options=options, desired_capabilities=desired_capabilities,
service_args=["--headless", "--allow-running-insecure-content", "--test-type",
"--ignore-certificate-errors", "--ignore-ssl-errors=true",
"--ssl-protocol=any"])
driver.set_page_load_timeout(8)
gatherScreenshots(driver, urlFile, outDirName, disallowed, ports, outputDir)
assembleHTML(outDirName, outputDir)
if __name__ == '__main__':
printLogo()
gather(sys.argv[1:])