Skip to content

Commit cba2861

Browse files
committed
- Add switch to cli to allow choice between Chrome/Firefox, keeping the
-p headless flag as an option for both Default is Firefox as the previous changes defaulting to Chrome breaks previous functionality
1 parent 4397b57 commit cba2861

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

httpscreenshot.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def parseGnmap(inFile, autodetect):
164164
return targets
165165

166166

167-
def setupBrowserProfile(headless, proxy):
167+
def setupBrowserProfile(headless, proxy, browserType):
168168
browser = None
169169
if (proxy is not None):
170170
service_args = ['--ignore-ssl-errors=true', '--ssl-protocol=any', '--proxy=' + proxy, '--proxy-type=socks5']
@@ -173,7 +173,18 @@ def setupBrowserProfile(headless, proxy):
173173

174174
while (browser is None):
175175
try:
176-
if (not headless):
176+
if (browserType == 'Chrome' or browserType == 'Chromium'):
177+
service = Service(ChromeDriverManager(log_level=0).install())
178+
coptions = Options()
179+
if headless:
180+
coptions.add_argument("--headless")
181+
coptions.add_argument("--no-sandbox")
182+
coptions.add_argument("--window-size=1024x768")
183+
coptions.add_argument("--ignore-certificate-errors")
184+
coptions.add_argument("--ssl-version-min=tls1")
185+
186+
browser = webdriver.Chrome(service=service, options=coptions)
187+
else:
177188
capabilities = DesiredCapabilities.FIREFOX
178189
capabilities['acceptSslCerts'] = True
179190
fp = webdriver.FirefoxProfile()
@@ -185,17 +196,15 @@ def setupBrowserProfile(headless, proxy):
185196
fp.set_preference("network.proxy.socks", proxyItems[0])
186197
fp.set_preference("network.proxy.socks_port", int(proxyItems[1]))
187198
fp.set_preference("network.proxy.type", 1)
188-
browser = webdriver.Firefox(firefox_profile=fp, capabilities=capabilities)
189-
else:
190-
service = Service(ChromeDriverManager(log_level=0).install())
191-
coptions = Options()
192-
coptions.add_argument("--headless")
193-
coptions.add_argument("--no-sandbox")
194-
coptions.add_argument("--window-size=1024x768")
195-
coptions.add_argument("--ignore-certificate-errors")
196-
coptions.add_argument("--ssl-version-min=tls1")
197199

198-
browser = webdriver.Chrome(service=service, options=coptions)
200+
fireFoxOptions = webdriver.FirefoxOptions()
201+
if headless:
202+
fireFoxOptions.headless = True
203+
204+
browser = webdriver.Firefox(firefox_profile=fp,
205+
capabilities=capabilities,
206+
options=fireFoxOptions)
207+
browser.set_window_size(1024, 768)
199208

200209
except Exception as e:
201210
print(e)
@@ -230,6 +239,7 @@ def worker(
230239
tryGUIOnFail,
231240
smartFetch,
232241
proxy,
242+
browserType
233243
):
234244
if debug:
235245
print("[*] Starting worker")
@@ -241,7 +251,7 @@ def worker(
241251
display = Display(visible=0, size=(800, 600))
242252
display.start()
243253

244-
browser = setupBrowserProfile(headless, proxy)
254+
browser = setupBrowserProfile(headless, proxy, browserType)
245255

246256
except Exception:
247257
print("[-] Oh no! Couldn't create the browser, Selenium blew up")
@@ -341,7 +351,7 @@ def worker(
341351
display.start()
342352
print("[+] Attempting to fetch with FireFox: " +
343353
curUrl)
344-
browser2 = setupBrowserProfile(False, proxy)
354+
browser2 = setupBrowserProfile(False, proxy, "Firefox")
345355
old_url = browser2.current_url
346356
try:
347357
browser2.get(curUrl.strip())
@@ -385,7 +395,7 @@ def worker(
385395
exc_traceback)
386396
print("".join("!! " + line for line in lines))
387397
browser.quit()
388-
browser = setupBrowserProfile(headless, proxy)
398+
browser = setupBrowserProfile(headless, proxy, "Firefox")
389399
continue
390400
browser.quit()
391401
display.stop()
@@ -513,6 +523,12 @@ def signal_handler(signal, frame):
513523
default=False,
514524
help="Run in headless mode (using phantomjs)",
515525
)
526+
parser.add_argument(
527+
"-b",
528+
"--browsertype",
529+
default="Firefox",
530+
help="Choose webdriver {Firefox, Chrome}"
531+
)
516532
parser.add_argument("-w",
517533
"--workers",
518534
default=1,
@@ -653,6 +669,7 @@ def signal_handler(signal, frame):
653669
args.trygui,
654670
args.smartfetch,
655671
args.proxy,
672+
args.browsertype
656673
),
657674
)
658675
workers.append(p)

0 commit comments

Comments
 (0)