FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Made firefox mode so that windows are invisible. Also fixed bug that … · RLSoftwareDev/httpscreenshot@58b6d41 · GitHub

Commit 58b6d41

Browse files
committed
Made firefox mode so that windows are invisible. Also fixed bug that was sometimes resulting in excessive memory consumption
1 parent 169cba4 commit 58b6d41

3 files changed

Lines changed: 70 additions & 35 deletions

File tree

‎httpscreenshot.py‎

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
import signal
2828
import shutil
2929
import hashlib
30+
from pyvirtualdisplay import Display
31+
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
32+
33+
3034

3135
try:
3236
from urllib.parse import quote
@@ -163,13 +167,15 @@ def parseGnmap(inFile, autodetect):
163167
def setupBrowserProfile(headless,proxy):
164168
browser = None
165169
if(proxy is not None):
166-
service_args=['--ignore-ssl-errors=true','--ssl-protocol=tlsv1','--proxy='+proxy,'--proxy-type=socks5']
170+
service_args=['--ignore-ssl-errors=true','--ssl-protocol=any','--proxy='+proxy,'--proxy-type=socks5']
167171
else:
168-
service_args=['--ignore-ssl-errors=true','--ssl-protocol=tlsv1']
172+
service_args=['--ignore-ssl-errors=true','--ssl-protocol=any']
169173

170174
while(browser is None):
171175
try:
172176
if(not headless):
177+
capabilities = DesiredCapabilities.FIREFOX
178+
capabilities['acceptSslCerts'] = True
173179
fp = webdriver.FirefoxProfile()
174180
fp.set_preference("webdriver.accept.untrusted.certs",True)
175181
fp.set_preference("security.enable_java", False)
@@ -179,9 +185,11 @@ def setupBrowserProfile(headless,proxy):
179185
fp.set_preference("network.proxy.socks",proxyItems[0])
180186
fp.set_preference("network.proxy.socks_port",int(proxyItems[1]))
181187
fp.set_preference("network.proxy.type",1)
182-
browser = webdriver.Firefox(fp)
188+
browser = webdriver.Firefox(firefox_profile=fp,capabilities=capabilities)
183189
else:
184190
browser = webdriver.PhantomJS(service_args=service_args, executable_path="phantomjs")
191+
browser.set_window_size(1024, 768)
192+
185193
except Exception as e:
186194
print e
187195
time.sleep(1)
@@ -206,14 +214,21 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
206214
print '[*] Starting worker'
207215

208216
browser = None
217+
display = None
209218
try:
219+
if(tryGUIOnFail or not headless):
220+
display = Display(visible=0, size=(800, 600))
221+
display.start()
222+
210223
browser = setupBrowserProfile(headless,proxy)
211224

212225
except:
213226
print "[-] Oh no! Couldn't create the browser, Selenium blew up"
214227
exc_type, exc_value, exc_traceback = sys.exc_info()
215228
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
216229
print ''.join('!! ' + line for line in lines)
230+
browser.quit()
231+
display.stop()
217232
return
218233

219234
while True:
@@ -268,50 +283,68 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
268283
hash_basket[resp_hash] = screenshotName
269284

270285

271-
browser.set_window_size(1024, 768)
286+
#browser.set_window_size(1024, 768)
272287
browser.set_page_load_timeout((tout))
273288
old_url = browser.current_url
274289
browser.get(curUrl[0].strip())
275290
if(browser.current_url == old_url):
276291
print "[-] Error fetching in browser but successfully fetched with Requests: "+curUrl[0]
277292
if(headless):
293+
browser2 = None
278294
if(debug):
279295
print "[+] Trying with sslv3 instead of TLS - known phantomjs bug: "+curUrl[0]
280-
browser2 = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true'], executable_path="phantomjs")
281-
old_url = browser2.current_url
282-
browser2.get(curUrl[0].strip())
283-
if(browser2.current_url == old_url):
284-
if(debug):
285-
print "[-] Didn't work with SSLv3 either..."+curUrl[0]
286-
browser2.close()
296+
if(proxy is not None):
297+
browser2 = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true','--proxy='+proxy,'--proxy-type=socks5'], executable_path="phantomjs")
287298
else:
288-
print '[+] Saving: '+screenshotName
289-
html_source = browser2.page_source
290-
f = open(screenshotName+".html",'w')
291-
f.write(html_source)
292-
f.close()
293-
browser2.save_screenshot(screenshotName+".png")
294-
browser2.close()
295-
continue
299+
browser2 = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true'], executable_path="phantomjs")
300+
#print "Launched browser2: "+str(browser2.service.process.pid)
301+
302+
old_url = browser2.current_url
303+
try:
304+
browser2.get(curUrl[0].strip())
305+
if(browser2.current_url == old_url):
306+
if(debug):
307+
print "[-] Didn't work with SSLv3 either..."+curUrl[0]
308+
browser2.quit()
309+
else:
310+
print '[+] Saving: '+screenshotName
311+
html_source = browser2.page_source
312+
f = open(screenshotName+".html",'w')
313+
f.write(html_source)
314+
f.close()
315+
browser2.save_screenshot(screenshotName+".png")
316+
browser2.quit()
317+
continue
318+
except:
319+
browser2.quit()
320+
print "[-] Didn't work with SSLv3 either - exception..."+curUrl[0]
296321

297322
if(tryGUIOnFail and headless):
323+
display = Display(visible=0, size=(1024, 768))
324+
display.start()
298325
print "[+] Attempting to fetch with FireFox: "+curUrl[0]
299326
browser2 = setupBrowserProfile(False,proxy)
300327
old_url = browser2.current_url
301-
browser2.get(curUrl[0].strip())
302-
if(browser2.current_url == old_url):
328+
try:
329+
browser2.get(curUrl[0].strip())
330+
if(browser2.current_url == old_url):
331+
print "[-] Error fetching in GUI browser as well..."+curUrl[0]
332+
browser2.quit()
333+
continue
334+
else:
335+
print '[+] Saving: '+screenshotName
336+
html_source = browser2.page_source
337+
f = open(screenshotName+".html",'w')
338+
f.write(html_source)
339+
f.close()
340+
browser2.save_screenshot(screenshotName+".png")
341+
browser2.quit()
342+
continue
343+
except:
344+
browser2.quit()
345+
display.stop()
303346
print "[-] Error fetching in GUI browser as well..."+curUrl[0]
304-
browser2.close()
305-
continue
306-
else:
307-
print '[+] Saving: '+screenshotName
308-
html_source = browser2.page_source
309-
f = open(screenshotName+".html",'w')
310-
f.write(html_source)
311-
f.close()
312-
browser2.save_screenshot(screenshotName+".png")
313-
browser2.close()
314-
continue
347+
315348
else:
316349
continue
317350

@@ -331,11 +364,12 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
331364
if(debug):
332365
exc_type, exc_value, exc_traceback = sys.exc_info()
333366
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
334-
print ''.join('!! ' + line for line in lines)
367+
print ''.join('!! ' + line for line in lines)
335368
browser.quit()
336369
browser = setupBrowserProfile(headless,proxy)
337370
continue
338-
371+
browser.quit()
372+
display.stop()
339373

340374
def doGet(*args, **kwargs):
341375
url = args[0]

‎install-dependencies.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Error out if one fails
77
set -e
88

9-
apt-get install -y swig swig3.0 libssl-dev python-dev libjpeg-dev
9+
apt-get install -y swig swig3.0 libssl-dev python-dev libjpeg-dev xvfb
1010

1111
# Newer version in PyPI
1212
#apt-get install -y python-requests

‎requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ beautifulsoup4
55
pillow
66
requesocks
77
python-libnmap
8+
pyvirtualdisplay

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL