@@ -199,7 +199,7 @@ def setupBrowserProfile(headless,proxy):
199199 return browser
200200
201201
202- def writeImage (text , filename , fontsize = 40 , width = 1024 , height = 200 ):
202+ def writeImage (text , filename , outputdir , fontsize = 40 , width = 1024 , height = 200 ):
203203 image = Image .new ("RGBA" , (width ,height ), (255 ,255 ,255 ))
204204 draw = ImageDraw .Draw (image )
205205 if (os .path .exists ("/usr/share/httpscreenshot/LiberationSerif-BoldItalic.ttf" )):
@@ -208,10 +208,10 @@ def writeImage(text, filename, fontsize=40, width=1024, height=200):
208208 font_path = os .path .dirname (os .path .realpath (__file__ ))+ "/LiberationSerif-BoldItalic.ttf"
209209 font = ImageFont .truetype (font_path , fontsize )
210210 draw .text ((10 , 0 ), text , (0 ,0 ,0 ), font = font )
211- image .save (filename )
211+ image .save (os . path . join ( outputdir , filename ) )
212212
213213
214- def worker (urlQueue , tout , debug , headless , doProfile , vhosts , subs , extraHosts , tryGUIOnFail , smartFetch ,proxy ):
214+ def worker (urlQueue , tout , debug , headless , doProfile , vhosts , subs , extraHosts , tryGUIOnFail , smartFetch , proxy , outputdir ):
215215 if (debug ):
216216 print '[*] Starting worker'
217217
@@ -245,7 +245,7 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
245245 if (debug ):
246246 print '[+] Got URL: ' + curUrl [0 ]
247247 print '[+] screenshotName: ' + screenshotName
248- if (os .path .exists (screenshotName + ".png" )):
248+ if (os .path .exists (os . path . join ( outputdir , screenshotName + ".png" ) )):
249249 if (debug ):
250250 print "[-] Screenshot already exists, skipping"
251251 continue
@@ -262,11 +262,11 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
262262 resp = doGet (curUrl , verify = False , timeout = tout , vhosts = vhosts , urlQueue = urlQueue , subs = subs , extraHosts = extraHosts ,proxy = proxy )
263263 if (resp is not None and resp .status_code == 401 ):
264264 print curUrl [0 ]+ " Requires HTTP Basic Auth"
265- f = open (screenshotName + ".html" ,'w' )
265+ f = open (os . path . join ( outputdir , screenshotName + ".html" ) ,'w' )
266266 f .write (resp .headers .get ('www-authenticate' ,'NONE' ))
267267 f .write ('<title>Basic Auth</title>' )
268268 f .close ()
269- writeImage (resp .headers .get ('www-authenticate' ,'NO WWW-AUTHENTICATE HEADER' ),screenshotName + ".png" )
269+ writeImage (resp .headers .get ('www-authenticate' ,'NO WWW-AUTHENTICATE HEADER' ),screenshotName + ".png" , outputdir )
270270 continue
271271
272272 elif (resp is not None ):
@@ -311,10 +311,10 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
311311 else :
312312 print '[+] Saving: ' + screenshotName
313313 html_source = browser2 .page_source
314- f = open (screenshotName + ".html" ,'w' )
314+ f = open (os . path . join ( outputdir , screenshotName + ".html" ) ,'w' )
315315 f .write (html_source )
316316 f .close ()
317- browser2 .save_screenshot (screenshotName + ".png" )
317+ browser2 .save_screenshot (os . path . join ( outputdir , screenshotName + ".png" ) )
318318 browser2 .quit ()
319319 continue
320320 except :
@@ -336,10 +336,10 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
336336 else :
337337 print '[+] Saving: ' + screenshotName
338338 html_source = browser2 .page_source
339- f = open (screenshotName + ".html" ,'w' )
339+ f = open (os . path . join ( outputdir , screenshotName + ".html" ) ,'w' )
340340 f .write (html_source )
341341 f .close ()
342- browser2 .save_screenshot (screenshotName + ".png" )
342+ browser2 .save_screenshot (os . path . join ( outputdir , screenshotName + ".png" ) )
343343 browser2 .quit ()
344344 continue
345345 except :
@@ -352,10 +352,10 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
352352
353353 print '[+] Saving: ' + screenshotName
354354 html_source = browser .page_source
355- f = open (screenshotName + ".html" ,'w' )
355+ f = open (os . path . join ( outputdir , screenshotName + ".html" ) ,'w' )
356356 f .write (html_source )
357357 f .close ()
358- browser .save_screenshot (screenshotName + ".png" )
358+ browser .save_screenshot (os . path . join ( outputdir , screenshotName + ".png" ) )
359359
360360 except Exception as e :
361361 print e
@@ -489,6 +489,7 @@ def signal_handler(signal, frame):
489489
490490 parser .add_argument ("-l" ,"--list" ,help = 'List of input URLs' )
491491 parser .add_argument ("-i" ,"--input" ,help = 'nmap gnmap/xml output file' )
492+ parser .add_argument ("-o" ,"--output_dir" ,help = 'directory to store screenshots' )
492493 parser .add_argument ("-p" ,"--headless" ,action = 'store_true' ,default = False ,help = 'Run in headless mode (using phantomjs)' )
493494 parser .add_argument ("-w" ,"--workers" ,default = 1 ,type = int ,help = 'number of threads' )
494495 parser .add_argument ("-t" ,"--timeout" ,type = int ,default = 10 ,help = 'time to wait for pageload before killing the browser' )
@@ -554,7 +555,11 @@ def signal_handler(signal, frame):
554555 else :
555556 print "No input specified"
556557 sys .exit (0 )
557-
558+
559+ if (args .output_dir is not None ):
560+ output_dir = args .output_dir
561+ else :
562+ output_dir = os .getcwd ()
558563
559564 #shuffle the url list
560565 shuffle (urls )
@@ -572,7 +577,7 @@ def signal_handler(signal, frame):
572577 hash_basket = {}
573578
574579 for i in range (args .workers ):
575- 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 ))
580+ 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 , output_dir ))
576581 workers .append (p )
577582 p .start ()
578583
0 commit comments