From 6383abf69aeb152d82a2537ce49666f0fbdb15ad Mon Sep 17 00:00:00 2001 From: ekultek Date: Fri, 13 Oct 2017 10:06:57 -0500 Subject: [PATCH] patch for an issue where to many sessions would be open, will now auto clean the sessions (issue #92) --- etc/scripts/cleanup.sh | 3 +++ lib/core/settings.py | 5 ++++- var/auto_issue/github.py | 22 ++++++++++++++++++++++ zeus.py | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 etc/scripts/cleanup.sh diff --git a/etc/scripts/cleanup.sh b/etc/scripts/cleanup.sh new file mode 100644 index 0000000..a082616 --- /dev/null +++ b/etc/scripts/cleanup.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +for pid in $(ps -ef | grep "firefox" | awk '{print $2}'); do kill -9 ${pid}; done > /dev/null 2>&1 \ No newline at end of file diff --git a/lib/core/settings.py b/lib/core/settings.py index 152161b..220d538 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -22,7 +22,7 @@ except NameError: # clone link CLONE = "https://github.com/ekultek/zeus-scanner.git" # current version -VERSION = "1.0.42.49ab" +VERSION = "1.0.42.6ad5" # colors to output depending on the version VERSION_TYPE_COLORS = {"dev": 33, "stable": 92, "other": 30} # version string formatting @@ -51,8 +51,11 @@ DEFAULT_USER_AGENT = "Zeus-Scanner(v{})::Python->v{}.{}".format( URL_QUERY_REGEX = re.compile(r"(.*)[?|#](.*){1}\=(.*)") # regex to recognize a URL URL_REGEX = re.compile(r"((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)") +# path to the auto clean tool +CLEANUP_TOOL_PATH = "{}/etc/scripts/cleanup.sh".format(os.getcwd()) # paths to sqlmap and nmap TOOL_PATHS = "{}/bin/paths/path_config.ini".format(os.getcwd()) +# path to store robot.txt page in ROBOTS_PAGE_PATH = "{}/log/robots".format(os.getcwd()) # URL's that are extracted from Google's ban URL EXTRACTED_URL_LOG = "{}/log/extracted-url-log".format(os.getcwd()) diff --git a/var/auto_issue/github.py b/var/auto_issue/github.py index ec08471..48a7ff5 100644 --- a/var/auto_issue/github.py +++ b/var/auto_issue/github.py @@ -1,4 +1,5 @@ import os +import re import sys try: import urllib2 # python 2 @@ -6,6 +7,7 @@ except ImportError: import urllib.request as urllib2 # python 3 import json import platform +import subprocess from base64 import b64decode @@ -21,6 +23,24 @@ from lib.core.settings import ( ) +def get_browser_version(): + try: + output = subprocess.check_output(['firefox', '--version']) + except Exception: + logger.error(set_color( + "failed to run forefox...", level=50 + )) + return "failed to start" + try: + major, minor = map(int, re.search(r"(\d+).(\d+)", output).groups()) + except Exception: + logger.error(set_color( + "failed to parse '{}' for version number...".format(output), level=50 + )) + return "failed to gather" + return "Version: ({}.{})".format(major, minor) + + def __get_encoded_string(filename="{}/var/auto_issue/oauth"): with open(filename.format(os.getcwd())) as data: return data.read() @@ -86,11 +106,13 @@ def request_issue_creation(): issue_data = { "title": issue_title, "body": "Zeus version:\n`{}`\n\n" + "Firefox version:\n`{}`\n\n" "Error info:\n```{}````\n\n" "Running details:\n`{}`\n\n" "Commands used:\n`{}`\n\n" "Log file info:\n```{}```".format( VERSION, + get_browser_version(), str(stacktrace), str(platform.platform()), " ".join(sys.argv), diff --git a/zeus.py b/zeus.py index 7201202..36163dd 100755 --- a/zeus.py +++ b/zeus.py @@ -10,6 +10,7 @@ try: import http.client as http_client # Python 3 except ImportError: import httplib as http_client # Python 2 +from selenium.webdriver.remote.errorhandler import WebDriverException from var import blackwidow from var.google_search import search @@ -48,7 +49,8 @@ from lib.core.settings import ( get_true_url, fix_log_file, DEFAULT_USER_AGENT, - SPIDER_LOG_PATH + SPIDER_LOG_PATH, + CLEANUP_TOOL_PATH ) if __name__ == "__main__": @@ -644,6 +646,35 @@ if __name__ == "__main__": "do not interrupt the browser when selenium is running, " "it will cause Zeus to crash...", level=30 )) + except WebDriverException as e: + if "connection refused" in str(e): + logger.fatal(set_color( + "there are to many sessions of firefox opened and selenium cannot " + "create a new one...", level=50 + )) + do_autoclean = prompt( + "would you like to attempt auto clean", opts="yN" + ) + if do_autoclean.lower().startswith("y"): + logger.warning(set_color( + "this will kill all instances of the firefox web browser...", level=30 + )) + subprocess.call(["sudo", "sh", CLEANUP_TOOL_PATH]) + logger.info(set_color( + "all open sessions of firefox killed, it should be safe to re-run " + "Zeus..." + )) + else: + logger.info(set_color( + "kill off the open sessions of firefox and re-run Zeus..." + )) + shutdown() + else: + logger.exception(set_color( + "Zeus has run into an unexpected error from selenium webdriver and cannot continue " + "error info '{}'...".format(str(e)) + )) + request_issue_creation() except Exception as e: if "url did not match a true url" in str(e).lower(): logger.error(set_color(