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

Added SOCKS5 proxy support to httpscreenshot · RLSoftwareDev/httpscreenshot@cc951d4 · GitHub

Commit cc951d4

Browse files
committed
Added SOCKS5 proxy support to httpscreenshot
1 parent 09845c8 commit cc951d4

3 files changed

Lines changed: 58 additions & 28 deletions

File tree

‎README.md‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,31 @@ YMMV
3636

3737
The options are as follows:
3838

39-
-h, --help show this help message and exit
40-
-l LIST, --list LIST List of input URLs
41-
-i INPUT, --input INPUT
42-
nmap gnmap output file
43-
-p, --headless Run in headless mode (using phantomjs)
44-
-w WORKERS, --workers WORKERS
45-
number of threads
46-
-t TIMEOUT, --timeout TIMEOUT
39+
-h, --help show this help message and exit
40+
-l LIST, --list LIST List of input URLs
41+
-i INPUT, --input INPUT
42+
nmap gnmap output file
43+
-p, --headless Run in headless mode (using phantomjs)
44+
-w WORKERS, --workers WORKERS
45+
number of threads
46+
-t TIMEOUT, --timeout TIMEOUT
4747
time to wait for pageload before killing the browser
48-
-v, --verbose turn on verbose debugging
48+
-v, --verbose turn on verbose debugging
4949
-a, --autodetect Automatically detect if listening services are HTTP or
50-
HTTPS. Ignores NMAP service detction and URL schemes.
51-
-vH, --vhosts Attempt to scrape hostnames from SSL certificates and
52-
add these to the URL queue
53-
-dB DNS_BRUTE, --dns_brute DNS_BRUTE
54-
Specify a DNS subdomain wordlist for bruteforcing on
55-
wildcard SSL certs
56-
-r RETRIES, --retries RETRIES
57-
Number of retries if a URL fails or timesout
50+
HTTPS. Ignores NMAP service detction and URL schemes.
51+
-vH, --vhosts Attempt to scrape hostnames from SSL certificates and
52+
add these to the URL queue
53+
-dB DNS_BRUTE, --dns_brute DNS_BRUTE
54+
Specify a DNS subdomain wordlist for bruteforcing on
55+
wildcard SSL certs
56+
-r RETRIES, --retries RETRIES
57+
Number of retries if a URL fails or timesout
58+
-tG, --trygui Try to fetch the page with FireFox when headless fails
59+
-sF, --smartfetch Enables smart fetching to reduce network traffic, also
60+
increases speed if certain conditions are met.
61+
-pX PROXY, --proxy PROXY
62+
SOCKS5 Proxy in host:port format
63+
5864

5965
Some of the above options have non-obvious use-cases, so the following provides some more detail:
6066

@@ -90,5 +96,7 @@ Some of the above options have non-obvious use-cases, so the following provides
9096

9197
-r, --retries -> Sometimes Firefox or ghostscript timeout when fetching a page. This could be due to a number of factors, sometimes you just have too many threads going, a network hiccup, etc. This specifies the number of times to "retry" a given host when it fails.
9298

99+
-tG, --trygui -> Upon failure to fetch with the headless browser phantomJS, will pop open FireFox and try again.
100+
93101
-sF, --smartfetch -> Enables smart fetching to reduce network traffic, also increases speed if certain conditions are met.
94102

‎httpscreenshot.py‎

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import sys
2020
import traceback
2121
import os.path
22-
import requests
2322
import ssl
2423
import M2Crypto
2524
import re
@@ -33,6 +32,12 @@
3332
except:
3433
from urllib import quote
3534

35+
try:
36+
import requesocks as requests
37+
except:
38+
print "requesocks library not found - proxy support will not be available"
39+
import requests
40+
3641
reload(sys)
3742
sys.setdefaultencoding("utf8")
3843

@@ -131,18 +136,28 @@ def parseGnmap(inFile, autodetect):
131136
return targets
132137

133138

134-
def setupBrowserProfile(headless):
139+
def setupBrowserProfile(headless,proxy):
135140
browser = None
141+
if(proxy is not None):
142+
service_args=['--ignore-ssl-errors=true','--ssl-protocol=tlsv1','--proxy='+proxy,'--proxy-type=socks5']
143+
else:
144+
service_args=['--ignore-ssl-errors=true','--ssl-protocol=tlsv1']
145+
136146
while(browser is None):
137147
try:
138148
if(not headless):
139149
fp = webdriver.FirefoxProfile()
140150
fp.set_preference("webdriver.accept.untrusted.certs",True)
141151
fp.set_preference("security.enable_java", False)
142152
fp.set_preference("webdriver.load.strategy", "fast");
153+
if(proxy is not None):
154+
proxyItems = proxy.split(":")
155+
fp.set_preference("network.proxy.socks",proxyItems[0])
156+
fp.set_preference("network.proxy.socks_port",int(proxyItems[1]))
157+
fp.set_preference("network.proxy.type",1)
143158
browser = webdriver.Firefox(fp)
144159
else:
145-
browser = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true','--ssl-protocol=tlsv1'], executable_path="phantomjs")
160+
browser = webdriver.PhantomJS(service_args=service_args, executable_path="phantomjs")
146161
except Exception as e:
147162
print e
148163
time.sleep(1)
@@ -162,13 +177,13 @@ def writeImage(text, filename, fontsize=40, width=1024, height=200):
162177
image.save(filename)
163178

164179

165-
def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts, tryGUIOnFail, smartFetch):
180+
def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts, tryGUIOnFail, smartFetch,proxy):
166181
if(debug):
167182
print '[*] Starting worker'
168183

169184
browser = None
170185
try:
171-
browser = setupBrowserProfile(headless)
186+
browser = setupBrowserProfile(headless,proxy)
172187

173188
except:
174189
print "[-] Oh no! Couldn't create the browser, Selenium blew up"
@@ -201,9 +216,9 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
201216

202217
try:
203218
if(doProfile):
204-
[resp,curUrl] = autodetectRequest(curUrl, timeout=tout, vhosts=vhosts, urlQueue=urlQueue, subs=subs, extraHosts=extraHosts)
219+
[resp,curUrl] = autodetectRequest(curUrl, timeout=tout, vhosts=vhosts, urlQueue=urlQueue, subs=subs, extraHosts=extraHosts,proxy=proxy)
205220
else:
206-
resp = doGet(curUrl, verify=False, timeout=tout, vhosts=vhosts, urlQueue=urlQueue, subs=subs, extraHosts=extraHosts)
221+
resp = doGet(curUrl, verify=False, timeout=tout, vhosts=vhosts, urlQueue=urlQueue, subs=subs, extraHosts=extraHosts,proxy=proxy)
207222
if(resp is not None and resp.status_code == 401):
208223
print curUrl[0]+" Requires HTTP Basic Auth"
209224
f = open(screenshotName+".html",'w')
@@ -299,10 +314,14 @@ def doGet(*args, **kwargs):
299314
urlQueue = kwargs.pop('urlQueue' ,None)
300315
subs = kwargs.pop('subs' ,None)
301316
extraHosts = kwargs.pop('extraHosts',None)
317+
proxy = kwargs.pop('proxy',None)
302318

303319
kwargs['allow_redirects'] = False
304320

305-
resp = requests.get(url[0],**kwargs)
321+
session = requests.session()
322+
if(proxy is not None):
323+
session.proxies={'http':'socks5://'+proxy,'https':'socks5://'+proxy}
324+
resp = session.get(url[0],**kwargs)
306325

307326

308327
#If we have an https URL and we are configured to scrape hosts from the cert...
@@ -352,7 +371,7 @@ def doGet(*args, **kwargs):
352371
return resp
353372

354373

355-
def autodetectRequest(url, timeout, vhosts=False, urlQueue=None, subs=None, extraHosts=None):
374+
def autodetectRequest(url, timeout, vhosts=False, urlQueue=None, subs=None, extraHosts=None,proxy=None):
356375
'''Takes a URL, ignores the scheme. Detect if the host/port is actually an HTTP or HTTPS
357376
server'''
358377
resp = None
@@ -384,7 +403,7 @@ def autodetectRequest(url, timeout, vhosts=False, urlQueue=None, subs=None, extr
384403
url[0] = url[0].replace('https','http')
385404
#print 'Changing to HTTP '+url[0]
386405
try:
387-
resp = doGet(url,verify=False, timeout=timeout, vhosts=vhosts, urlQueue=urlQueue, subs=subs, extraHosts=extraHosts)
406+
resp = doGet(url,verify=False, timeout=timeout, vhosts=vhosts, urlQueue=urlQueue, subs=subs, extraHosts=extraHosts, proxy=proxy)
388407
except Exception as e:
389408
print 'HTTP GET Error: '+str(e)
390409
print url[0]
@@ -418,6 +437,8 @@ def signal_handler(signal, frame):
418437
parser.add_argument("-r","--retries",type=int,default=0,help='Number of retries if a URL fails or timesout')
419438
parser.add_argument("-tG","--trygui",action='store_true',default=False,help='Try to fetch the page with FireFox when headless fails')
420439
parser.add_argument("-sF","--smartfetch",action='store_true',default=False,help='Enables smart fetching to reduce network traffic, also increases speed if certain conditions are met.')
440+
parser.add_argument("-pX","--proxy",default=None,help='SOCKS5 Proxy in host:port format')
441+
421442

422443
args = parser.parse_args()
423444

@@ -468,7 +489,7 @@ def signal_handler(signal, frame):
468489
hash_basket = {}
469490

470491
for i in range(args.workers):
471-
p = multiprocessing.Process(target=worker, args=(urlQueue, args.timeout, args.verbose, args.headless, args.autodetect, args.vhosts, subs, hostsDict, args.trygui, args.smartfetch))
492+
p = multiprocessing.Process(target=worker, args=(urlQueue, args.timeout, args.verbose, args.headless, args.autodetect, args.vhosts, subs, hostsDict, args.trygui, args.smartfetch,args.proxy))
472493
workers.append(p)
473494
p.start()
474495

‎requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ requests
33
selenium
44
beautifulsoup4
55
pillow
6+
requesocks

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL