-
Notifications
You must be signed in to change notification settings - Fork 1.2k
small refactoring for lib/settings & add forgotten .format() to main.py #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, two small lines will be better than one-time call of locally defined function (in case of optimization too).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay I see what you did, change the variable to path so it doesn't overwrite the built in |
||
| """ | ||
| 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: | ||
| """ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You realize that in order to stop the animation, I have to print a new line character otherwise it does an endless cycle |
||
| 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() | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One variable, or ten more function calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean it's not much different, but I see where you're coming from