Added check to verify existence of output directory and pep8 fixes.

This commit is contained in:
NotoriousRebel 2020-07-04 22:04:15 -04:00
parent 4b04c70beb
commit 5ee07edb3f
3 changed files with 47 additions and 27 deletions

View file

@ -593,31 +593,39 @@ async def handler(lst):
from aiomultiprocess import Pool from aiomultiprocess import Pool
from theHarvester.screenshot.screenshot import ScreenShotter from theHarvester.screenshot.screenshot import ScreenShotter
screen_shotter = ScreenShotter(args.screenshot) screen_shotter = ScreenShotter(args.screenshot)
await screen_shotter.verify_installation() path_exists = screen_shotter.verify_path()
print(f'Screenshots can be found: {screen_shotter.output}{screen_shotter.slash}') # Verify path exists if not create it or if user does not create it skip screenshot
start = time.perf_counter() if path_exists:
print('Filtering domains for ones we can reach') await screen_shotter.verify_installation()
unique_resolved_domains = {url.split(':')[0]for url in full if ':' in url and 'www.' not in url} print(f'Screenshots can be found: {screen_shotter.output}{screen_shotter.slash}')
if len(unique_resolved_domains) > 0: start = time.perf_counter()
# First filter out ones that didn't resolve print('Filtering domains for ones we can reach')
print('Attempting to visit unique resolved domains, this is ACTIVE RECON') unique_resolved_domains = {url.split(':')[0]for url in full if ':' in url and 'www.' not in url}
async with Pool(15) as pool: if len(unique_resolved_domains) > 0:
results = await pool.map(screen_shotter.visit, list(unique_resolved_domains)) # First filter out ones that didn't resolve
# Filter out domains that we couldn't connect to print('Attempting to visit unique resolved domains, this is ACTIVE RECON')
unique_resolved_domains = list(sorted({tup[0] for tup in results if len(tup[1]) > 0})) async with Pool(15) as pool:
async with Pool(3) as pool: results = await pool.map(screen_shotter.visit, list(unique_resolved_domains))
print(f'Length of unique resolved domains: {len(unique_resolved_domains)} chunking now!\n') # Filter out domains that we couldn't connect to
# If you have the resources you could make the function faster by increasing the chunk number unique_resolved_domains = list(sorted({tup[0] for tup in results if len(tup[1]) > 0}))
chunk_number = 25 async with Pool(3) as pool:
for chunk in screen_shotter.chunk_list(unique_resolved_domains, chunk_number): print(f'Length of unique resolved domains: {len(unique_resolved_domains)} chunking now!\n')
try: # If you have the resources you could make the function faster by increasing the chunk number
screenshot_tups.extend(await pool.map(screen_shotter.take_screenshot, chunk)) chunk_number = 25
except Exception as ee: for chunk in screen_shotter.chunk_list(unique_resolved_domains, chunk_number):
print(f'An exception has occurred while mapping: {ee}') try:
end = time.perf_counter() screenshot_tups.extend(await pool.map(screen_shotter.take_screenshot, chunk))
print(f"Finished taking screenshots in {end - start} seconds") except Exception as ee:
print('[+] Note there may be leftover chrome processes you may have to kill manually\n') print(f'An exception has occurred while mapping: {ee}')
end = time.perf_counter()
# There is probably an easier way to do this
total = end - start
mon, sec = divmod(total, 60)
hr, mon = divmod(mon, 60)
total_time = "%02d:%02d" % (mon, sec)
print(f"Finished taking screenshots in {total_time} seconds")
print('[+] Note there may be leftover chrome processes you may have to kill manually\n')
# Shodan # Shodan
shodanres = [] shodanres = []
if shodan is True: if shodan is True:

View file

@ -303,7 +303,6 @@ async def generatescreenshots(tups: List):
<p>&nbsp;</p> <p>&nbsp;</p>
<p>&nbsp;</p> <p>&nbsp;</p>
''' '''
base = 'var tabledata = [ ' base = 'var tabledata = [ '
for tup in tups: for tup in tups:
date = tup[0] date = tup[0]

View file

@ -7,7 +7,7 @@
import aiohttp import aiohttp
import asyncio import asyncio
from datetime import datetime from datetime import datetime
import json import os
import sys import sys
@ -18,6 +18,19 @@ def __init__(self, output):
self.slash = "\\" if 'win' in sys.platform else '/' self.slash = "\\" if 'win' in sys.platform else '/'
self.slash = "" if (self.output[-1] == "\\" or self.output[-1] == "/") else self.slash self.slash = "" if (self.output[-1] == "\\" or self.output[-1] == "/") else self.slash
def verify_path(self):
try:
if not os.path.isdir(self.output):
answer = input(f'[+] The output path you have entered does not exist would you like to create it (y/n): ')
if answer.lower() == 'yes' or answer.lower() == 'y':
os.mkdir(self.output)
return True
print('path is a directory')
return True
except Exception as e:
print(f"An exception has occurred while attempting to verify output path's existence: {e}")
return False
@staticmethod @staticmethod
async def verify_installation(): async def verify_installation():
# Helper function that verifies pyppeteer & chromium are installed # Helper function that verifies pyppeteer & chromium are installed