From 5099df6ddca2c5f07322e1a151869d5596ae5c4a Mon Sep 17 00:00:00 2001 From: ekultek Date: Tue, 27 Feb 2018 13:11:13 -0600 Subject: [PATCH] fixes the issue --- api_calls/censys.py | 9 ++++----- api_calls/shodan.py | 8 +++----- api_calls/zoomeye.py | 8 +++----- autosploit.py | 3 --- lib/settings.py | 16 ++++++++++++---- lib/term/terminal.py | 17 +---------------- 6 files changed, 23 insertions(+), 38 deletions(-) diff --git a/api_calls/censys.py b/api_calls/censys.py index edf8128..080d4c9 100644 --- a/api_calls/censys.py +++ b/api_calls/censys.py @@ -1,10 +1,9 @@ import requests +import threading +import lib.settings +from lib.output import error from lib.errors import AutoSploitAPIConnectionError -from lib.output import ( - error, - info -) from lib.settings import ( HOST_FILE, API_URLS, @@ -28,9 +27,9 @@ def censys(self): """ connect to the Censys API and pull all IP addresses from the provided query """ - info("searching Censys with given query '{}'".format(self.query)) discovered_censys_hosts = set() try: + lib.settings.start_animation("searching Censys with given query '{}'".format(self.query)) req = requests.post(API_URLS["censys"], auth=(self.id, self.token), json={"query": self.query}) json_data = req.json() for item in json_data["results"]: diff --git a/api_calls/shodan.py b/api_calls/shodan.py index 0736cfc..d0a63a5 100644 --- a/api_calls/shodan.py +++ b/api_calls/shodan.py @@ -2,11 +2,9 @@ import requests +from lib.settings import start_animation +from lib.output import error from lib.errors import AutoSploitAPIConnectionError -from lib.output import ( - error, - info -) from lib.settings import ( API_URLS, HOST_FILE, @@ -30,7 +28,7 @@ def shodan(self): """ connect to the API and grab all IP addresses associated with the provided query """ - info("searching Shodan with given query '{}'".format(self.query)) + start_animation("search Shodan with given query '{}'".format(self.query)) discovered_shodan_hosts = set() try: req = requests.get(API_URLS["shodan"].format(query=self.query, token=self.token)) diff --git a/api_calls/zoomeye.py b/api_calls/zoomeye.py index cb9dab2..e135ed4 100644 --- a/api_calls/zoomeye.py +++ b/api_calls/zoomeye.py @@ -4,11 +4,9 @@ import requests +from lib.settings import start_animation from lib.errors import AutoSploitAPIConnectionError -from lib.output import ( - error, - info -) +from lib.output import error from lib.settings import ( API_URLS, HOST_FILE, @@ -59,7 +57,7 @@ def zoomeye(self): connect to the API and pull all the IP addresses that are associated with the given query """ - info("searching ZoomEye with given query '{}'".format(self.query)) + start_animation("searching ZoomEye with given query '{}'".format(self.query)) discovered_zoomeye_hosts = set() try: token = self.__get_auth() diff --git a/autosploit.py b/autosploit.py index 9cdd195..437f282 100644 --- a/autosploit.py +++ b/autosploit.py @@ -22,11 +22,8 @@ import shlex import pickle import threading -import subprocess import censysSearch import shodan -# idk if you're going to need this since retrying is a decorator (see line 410) -# from retrying import retry from lib.jsonize import load_exploits from lib.cmdline.cmd import AutoSploitParser diff --git a/lib/settings.py b/lib/settings.py index 487fc9b..37a7acb 100644 --- a/lib/settings.py +++ b/lib/settings.py @@ -4,7 +4,7 @@ import socket import getpass import tempfile -import subprocess +# import subprocess import psutil @@ -73,7 +73,10 @@ def write_to_file(data_to_write, filename, mode="a+"): """ write data to a specified file, if it exists, ask to overwrite """ + global stop_animation + if os.path.exists(filename): + stop_animation = True is_append = lib.output.prompt("would you like to (a)ppend or (o)verwrite the file") if is_append == "o": mode = "w" @@ -162,7 +165,6 @@ def animation(text): single threaded so that it will not screw with the current running process """ - # TODO:/ this will not stop when stop animation is True global stop_animation i = 0 while not stop_animation: @@ -177,5 +179,11 @@ def animation(text): sys.stdout.flush() i += 1 time.sleep(0.1) - else: - print("\n") \ No newline at end of file + + +def start_animation(text): + import threading + + t = threading.Thread(target=animation, args=(text,)) + t.daemon = True + t.start() \ No newline at end of file diff --git a/lib/term/terminal.py b/lib/term/terminal.py index a7eb526..b30efcc 100644 --- a/lib/term/terminal.py +++ b/lib/term/terminal.py @@ -1,6 +1,5 @@ import os import sys -# import threading import lib.settings import lib.output @@ -10,9 +9,6 @@ import api_calls.censys -stop_animation = False - - class AutoSploitTerminal(object): """ @@ -109,8 +105,6 @@ def gather_hosts(self, query, given_choice=None): option 2 must be provided """ - global stop_animation - choice_dict = { 1: api_calls.shodan.ShodanAPIHook, 2: api_calls.zoomeye.ZoomEyeAPIHook, @@ -118,7 +112,7 @@ def gather_hosts(self, query, given_choice=None): } searching = False if given_choice is None: - lib.output.info("please choose an API to gather from (choosing two " + lib.output.info("please choose an API to gather from (choosing two or more " "separate by comma IE; 1,2)") for i, api in enumerate(lib.settings.API_URLS.keys(), start=1): print("{}. {}".format(i, api.title())) @@ -128,23 +122,14 @@ def gather_hosts(self, query, given_choice=None): while not searching: try: choice = int(choice) - # t = threading.Thread( - # target=lib.settings.animation, - # args=("performing lookup for provided query '{}'".format(query),) - # ) - # t.daemon = True - # t.start() if choice == 1: choice_dict[choice](self.tokens["shodan"][0], query).shodan() - # stop_animation = True break elif choice == 2: choice_dict[choice](query).zoomeye() - # stop_animation = True break elif choice == 3: choice_dict[choice](self.tokens["censys"][1], self.tokens["censys"][0], query).censys() - # stop_animation = True break else: lib.output.warning("invalid option provided")