From ac9211be01076af6e283fc7697feea5a219bcc30 Mon Sep 17 00:00:00 2001 From: Vovche Date: Thu, 1 Mar 2018 22:21:05 +0200 Subject: [PATCH] small refactoring for lib/settings & add forgotten .format() to main.py --- autosploit/main.py | 2 +- lib/settings.py | 47 ++++++++++++++++++++-------------------------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/autosploit/main.py b/autosploit/main.py index 5ca5312..b48ee83 100644 --- a/autosploit/main.py +++ b/autosploit/main.py @@ -30,7 +30,7 @@ def main(): service_names = ("postgresql", "apache") for service in list(service_names): if not check_services(service): - choice = prompt("it appears that service {} is not enabled, would you like us to enable it for you[y/N]") + choice = prompt("it appears that service {} is not enabled, would you like us to enable it for you[y/N]".format(service)) if choice.lower().startswith("y"): if "postgre" in service: cmdline("sudo bash {}".format(START_POSTGRESQL_PATH)) diff --git a/lib/settings.py b/lib/settings.py index e8050e3..ba136c6 100644 --- a/lib/settings.py +++ b/lib/settings.py @@ -13,21 +13,22 @@ import lib.output import lib.banner +CUR_DIR = "{}".format(os.getcwd()) # path to the file containing all the discovered hosts -HOST_FILE = "{}/hosts.txt".format(os.getcwd()) +HOST_FILE = "{}/hosts.txt".format(CUR_DIR) # path to the folder containing all the JSON exploit modules -EXPLOIT_FILES_PATH = "{}/etc/json".format(os.getcwd()) +EXPLOIT_FILES_PATH = "{}/etc/json".format(CUR_DIR) # path to the usage and legal file -USAGE_AND_LEGAL_PATH = "{}/etc/text_files/general".format(os.getcwd()) +USAGE_AND_LEGAL_PATH = "{}/etc/text_files/general".format(CUR_DIR) # path to the bash script to stack the PostgreSQL service -START_POSTGRESQL_PATH = "{}/etc/scripts/start_postgre.sh".format(os.getcwd()) +START_POSTGRESQL_PATH = "{}/etc/scripts/start_postgre.sh".format(CUR_DIR) # path to the bash script to start the Apache service -START_APACHE_PATH = "{}/etc/scripts/start_apache.sh".format(os.getcwd()) +START_APACHE_PATH = "{}/etc/scripts/start_apache.sh".format(CUR_DIR) # path to the file that will contain our query QUERY_FILE_PATH = tempfile.NamedTemporaryFile(delete=False).name @@ -45,8 +46,8 @@ # all the paths to the API tokens API_KEYS = { - "censys": ("{}/etc/tokens/censys.key".format(os.getcwd()), "{}/etc/tokens/censys.id".format(os.getcwd())), - "shodan": ("{}/etc/tokens/shodan.key".format(os.getcwd()), ) + "censys": ("{}/etc/tokens/censys.key".format(CUR_DIR), "{}/etc/tokens/censys.id".format(CUR_DIR)), + "shodan": ("{}/etc/tokens/shodan.key".format(CUR_DIR), ) } # all the URLs that we will use while doing the searching @@ -80,8 +81,7 @@ def validate_ip_addr(provided): return True except: return False - else: - return False + return False def check_services(service_name): @@ -109,11 +109,8 @@ def write_to_file(data_to_write, filename, mode="a+"): is_append = lib.output.prompt("would you like to (a)ppend or (o)verwrite the file") if is_append == "o": mode = "w" - elif is_append == "a": - mode = "a+" - else: + elif is_append != "a": lib.output.warning("invalid input provided ('{}'), appending to file".format(is_append)) - mode = "a+" with open(filename, mode) as log: if isinstance(data_to_write, (tuple, set, list)): for item in list(data_to_write): @@ -124,20 +121,18 @@ def write_to_file(data_to_write, filename, mode="a+"): return filename -def load_api_keys(path="{}/etc/tokens".format(os.getcwd())): +def load_api_keys(path="{}/etc/tokens".format(CUR_DIR)): """ load the API keys from their .key files """ - def makedir(dir): - """ - make the directory if it does not exist - """ - if not os.path.exists(dir): - os.mkdir(dir) + """ + make the directory if it does not exist + """ + if not os.path.exists(path): + os.mkdir(path) - makedir(path) for key in API_KEYS.keys(): if not os.path.isfile(API_KEYS[key][0]): access_token = lib.output.prompt("enter your {} API token".format(key.title()), lowercase=False) @@ -179,10 +174,7 @@ def check_for_msf(): """ check the ENV PATH for msfconsole """ - in_env = os.getenv("msfconsole", False) - if not in_env: - return False - + return os.getenv("msfconsole", False) def logo(): """ @@ -200,8 +192,10 @@ def animation(text): global stop_animation i = 0 while not stop_animation: + """ if stop_animation is True: print("\n") + """ temp_text = list(text) if i >= len(temp_text): i = 0 @@ -236,13 +230,12 @@ def close(warning, status=1): lib.output.error(warning) sys.exit(status) - def grab_random_agent(): """ get a random HTTP User-Agent """ user_agent_path = "{}/etc/text_files/agents.txt" - with open(user_agent_path.format(os.getcwd())) as agents: + with open(user_agent_path.format(CUR_DIR)) as agents: return random.choice(agents.readlines()).strip()