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

Add single target option by njfox · Pull Request #29 · breenmachine/httpscreenshot · GitHub

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
117 changes: 67 additions & 50 deletions httpscreenshot.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def setupBrowserProfile(headless,proxy):
return browser


def writeImage(text, filename, fontsize=40, width=1024, height=200):
def writeImage(text, filename, outputdir, fontsize=40, width=1024, height=200):
image = Image.new("RGBA", (width,height), (255,255,255))
draw = ImageDraw.Draw(image)
if (os.path.exists("/usr/share/httpscreenshot/LiberationSerif-BoldItalic.ttf")):
Expand All @@ -208,10 +208,10 @@ def writeImage(text, filename, fontsize=40, width=1024, height=200):
font_path = os.path.dirname(os.path.realpath(__file__))+"/LiberationSerif-BoldItalic.ttf"
font = ImageFont.truetype(font_path, fontsize)
draw.text((10, 0), text, (0,0,0), font=font)
image.save(filename)
image.save(os.path.join(outputdir, filename))


def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts, tryGUIOnFail, smartFetch,proxy):
def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts, tryGUIOnFail, smartFetch, proxy, outputdir, filename):
if(debug):
print '[*] Starting worker'

Expand Down Expand Up @@ -241,11 +241,14 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
except Queue.Empty:
continue
print '[+] '+str(urlQueue.qsize())+' URLs remaining'
screenshotName = quote(curUrl[0], safe='')
if not filename:
screenshotName = quote(curUrl[0], safe='')
else:
screenshotName = filename
if(debug):
print '[+] Got URL: '+curUrl[0]
print '[+] screenshotName: '+screenshotName
if(os.path.exists(screenshotName+".png")):
if(os.path.exists(os.path.join(outputdir, screenshotName+".png"))):
if(debug):
print "[-] Screenshot already exists, skipping"
continue
Expand All @@ -262,11 +265,11 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
resp = doGet(curUrl, verify=False, timeout=tout, vhosts=vhosts, urlQueue=urlQueue, subs=subs, extraHosts=extraHosts,proxy=proxy)
if(resp is not None and resp.status_code == 401):
print curUrl[0]+" Requires HTTP Basic Auth"
f = open(screenshotName+".html",'w')
f = open(os.path.join(outputdir, screenshotName+".html"),'w')
f.write(resp.headers.get('www-authenticate','NONE'))
f.write('<title>Basic Auth</title>')
f.close()
writeImage(resp.headers.get('www-authenticate','NO WWW-AUTHENTICATE HEADER'),screenshotName+".png")
writeImage(resp.headers.get('www-authenticate','NO WWW-AUTHENTICATE HEADER'),screenshotName+".png", outputdir)
continue

elif(resp is not None):
Expand Down Expand Up @@ -311,10 +314,10 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
else:
print '[+] Saving: '+screenshotName
html_source = browser2.page_source
f = open(screenshotName+".html",'w')
f = open(os.path.join(outputdir, screenshotName+".html"),'w')
f.write(html_source)
f.close()
browser2.save_screenshot(screenshotName+".png")
browser2.save_screenshot(os.path.join(outputdir, screenshotName+".png"))
browser2.quit()
continue
except:
Expand All @@ -336,10 +339,10 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,
else:
print '[+] Saving: '+screenshotName
html_source = browser2.page_source
f = open(screenshotName+".html",'w')
f = open(os.path.join(outputdir, screenshotName+".html"),'w')
f.write(html_source)
f.close()
browser2.save_screenshot(screenshotName+".png")
browser2.save_screenshot(os.path.join(outputdir, screenshotName+".png"))
browser2.quit()
continue
except:
Expand All @@ -352,10 +355,10 @@ def worker(urlQueue, tout, debug, headless, doProfile, vhosts, subs, extraHosts,

print '[+] Saving: '+screenshotName
html_source = browser.page_source
f = open(screenshotName+".html",'w')
f = open(os.path.join(outputdir, screenshotName+".html"),'w')
f.write(html_source)
f.close()
browser.save_screenshot(screenshotName+".png")
browser.save_screenshot(os.path.join(outputdir, screenshotName+".png"))

except Exception as e:
print e
Expand Down Expand Up @@ -489,6 +492,9 @@ def signal_handler(signal, frame):

parser.add_argument("-l","--list",help='List of input URLs')
parser.add_argument("-i","--input",help='nmap gnmap/xml output file')
parser.add_argument("-H","--host",help='Run against a single host')
parser.add_argument("-oD","--output_dir",help='Directory to store screenshots')
parser.add_argument("-oF","--output_filename",help='Filename of screenshot')
parser.add_argument("-p","--headless",action='store_true',default=False,help='Run in headless mode (using phantomjs)')
parser.add_argument("-w","--workers",default=1,type=int,help='number of threads')
parser.add_argument("-t","--timeout",type=int,default=10,help='time to wait for pageload before killing the browser')
Expand Down Expand Up @@ -516,45 +522,56 @@ def signal_handler(signal, frame):
uris = open(args.uri_list,'r').readlines()
uris.append('')

if(args.input is not None):
inFile = open(args.input,'rU')
if(detectFileType(inFile) == 'gnmap'):
hosts = parseGnmap(inFile,args.autodetect)
urls = []
for host,ports in hosts.items():
for port in ports:
for uri in uris:
url = ''
if port[1] == True:
url = ['https://'+host+':'+port[0]+uri.strip(),args.vhosts,args.retries]
else:
url = ['http://'+host+':'+port[0]+uri.strip(),args.vhosts,args.retries]
urls.append(url)
elif(detectFileType(inFile) == 'xml'):
hosts = parsexml(inFile)
urls = []
output_filename = None
if(args.host is not None):
urls.append([args.host, args.vhosts, args.retries])
if(args.output_filename is not None):
output_filename = args.output_filename
else:
if(args.input is not None):
inFile = open(args.input,'rU')
if(detectFileType(inFile) == 'gnmap'):
hosts = parseGnmap(inFile,args.autodetect)
urls = []
for host,ports in hosts.items():
for port in ports:
for uri in uris:
url = ''
if port[1] == True:
url = ['https://'+host+':'+port[0]+uri.strip(),args.vhosts,args.retries]
else:
url = ['http://'+host+':'+port[0]+uri.strip(),args.vhosts,args.retries]
urls.append(url)
elif(detectFileType(inFile) == 'xml'):
hosts = parsexml(inFile)
urls = []
for host,ports in hosts.items():
for port in ports:
for uri in uris:
url = ''
if port[1] == True:
url = ['https://'+host+':'+port[0]+uri.strip(),args.vhosts,args.retries]
else:
url = ['http://'+host+':'+port[0]+uri.strip(),args.vhosts,args.retries]
urls.append(url)
else:
print 'Invalid input file - must be Nmap GNMAP or Nmap XML'

elif (args.list is not None):
f = open(args.list,'r')
lst = f.readlines()
urls = []
for host,ports in hosts.items():
for port in ports:
for uri in uris:
url = ''
if port[1] == True:
url = ['https://'+host+':'+port[0]+uri.strip(),args.vhosts,args.retries]
else:
url = ['http://'+host+':'+port[0]+uri.strip(),args.vhosts,args.retries]
urls.append(url)
for url in lst:
urls.append([url.strip(),args.vhosts,args.retries])
else:
print 'Invalid input file - must be Nmap GNMAP or Nmap XML'

elif (args.list is not None):
f = open(args.list,'r')
lst = f.readlines()
urls = []
for url in lst:
urls.append([url.strip(),args.vhosts,args.retries])
print "No input specified"
sys.exit(0)

if (args.output_dir is not None):
output_dir = args.output_dir
else:
print "No input specified"
sys.exit(0)

output_dir = os.getcwd()

#shuffle the url list
shuffle(urls)
Expand All @@ -572,7 +589,7 @@ def signal_handler(signal, frame):
hash_basket = {}

for i in range(args.workers):
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))
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, output_filename))
workers.append(p)
p.start()

Expand Down

Back | FazBrowse Home | New Git URL