Skip to content

Commit bd554a3

Browse files
committed
fixes issue #170, fixes issue #171, fixes issue #196, fixes issue #189
1 parent 713670a commit bd554a3

File tree

5 files changed

+77
-41
lines changed

5 files changed

+77
-41
lines changed

autosploit/main.py

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,41 +53,47 @@ def main():
5353
misc_info("checking for disabled services")
5454
# according to ps aux, postgre and apache2 are the names of the services on Linux systems
5555
service_names = ("postgres", "apache2")
56-
if "darwin" in platform_running.lower():
57-
service_names = ("postgres", "apachectl")
58-
59-
for service in list(service_names):
60-
while not check_services(service):
61-
choice = prompt(
62-
"it appears that service {} is not enabled, would you like us to enable it for you[y/N]".format(
63-
service.title()
64-
)
65-
)
66-
if choice.lower().startswith("y"):
67-
try:
68-
if "darwin" in platform_running.lower():
69-
cmdline("{} darwin".format(START_SERVICES_PATH))
70-
elif "linux" in platform_running.lower():
71-
cmdline("{} linux".format(START_SERVICES_PATH))
72-
else:
73-
close("your platform is not supported by AutoSploit at this time", status=2)
74-
75-
# moving this back because it was funky to see it each run
76-
info("services started successfully")
77-
# this tends to show up when trying to start the services
78-
# I'm not entirely sure why, but this fixes it
79-
except psutil.NoSuchProcess:
80-
pass
81-
else:
82-
process_start_command = "`sudo service {} start`"
56+
try:
57+
for service in list(service_names):
58+
while not check_services(service):
8359
if "darwin" in platform_running.lower():
84-
process_start_command = "`brew services start {}`"
85-
close(
86-
"service {} is required to be started for autosploit to run successfully (you can do it manually "
87-
"by using the command {}), exiting".format(
88-
service.title(), process_start_command.format(service)
60+
info(
61+
"seems you're on macOS, skipping service checks "
62+
"(make sure that Apache2 and PostgreSQL are running)"
63+
)
64+
break
65+
choice = prompt(
66+
"it appears that service {} is not enabled, would you like us to enable it for you[y/N]".format(
67+
service.title()
8968
)
9069
)
70+
if choice.lower().startswith("y"):
71+
try:
72+
if "darwin" in platform_running.lower():
73+
cmdline("{} darwin".format(START_SERVICES_PATH))
74+
elif "linux" in platform_running.lower():
75+
cmdline("{} linux".format(START_SERVICES_PATH))
76+
else:
77+
close("your platform is not supported by AutoSploit at this time", status=2)
78+
79+
# moving this back because it was funky to see it each run
80+
info("services started successfully")
81+
# this tends to show up when trying to start the services
82+
# I'm not entirely sure why, but this fixes it
83+
except psutil.NoSuchProcess:
84+
pass
85+
else:
86+
process_start_command = "`sudo service {} start`"
87+
if "darwin" in platform_running.lower():
88+
process_start_command = "`brew services start {}`"
89+
close(
90+
"service {} is required to be started for autosploit to run successfully (you can do it manually "
91+
"by using the command {}), exiting".format(
92+
service.title(), process_start_command.format(service)
93+
)
94+
)
95+
except Exception:
96+
pass
9197

9298
if len(sys.argv) > 1:
9399
info("attempting to load API keys")
@@ -107,7 +113,7 @@ def main():
107113
else:
108114
warning(
109115
"no arguments have been parsed, defaulting to terminal session. "
110-
"press 99 to quit and help to get help"
116+
"press 99 to quit and type `help` to view the help menus"
111117
)
112118
misc_info("checking if there are multiple exploit files")
113119
loaded_exploits = load_exploits(EXPLOIT_FILES_PATH)
@@ -121,11 +127,12 @@ def main():
121127
print(
122128
"\033[31m[!] AutoSploit has hit an unhandled exception: '{}', "
123129
"in order for the developers to troubleshoot and repair the "
124-
"issue AutoSploit will need to gather your OS information, metasploit version, "
130+
"issue AutoSploit will need to gather your OS information, "
125131
"current arguments, the error message, and a traceback. "
126132
"None of this information can be used to identify you in any way\033[0m".format(str(e))
127133
)
128134
error_traceback = ''.join(traceback.format_tb(sys.exc_info()[2]))
129-
error_file = save_error_to_file(str(error_traceback))
135+
error_class = str(e.__class__).split(" ")[1].split(".")[1].strip(">").strip("'")
136+
error_file = save_error_to_file(str(error_traceback), str(e), error_class)
130137
request_issue_creation(error_file, hide_sensitive(), str(e))
131138

lib/creation/issue_creator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,6 @@ def request_issue_creation(path, arguments, error_message):
164164
else:
165165
lib.output.error(
166166
"someone has already created this issue here: {}".format(find_url(identifier))
167-
)
167+
)
168+
else:
169+
lib.output.info("the issue has been logged to a file in path: '{}'".format(path))

lib/exploitation/exploiter.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ def start_exploit(self, sep="*" * 10):
116116
use_ruby = "ruby" if self.ruby_exec else ""
117117
msf_path = self.msf_path if self.msf_path is not None else "msfconsole"
118118

119-
120-
121119
# What's the point of having a workspace if you overwrite it every fucking time..
122120
rc_script_template = (
123121
"workspace -a {workspace}\n"

lib/settings.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
# path to the file containing all the discovered hosts
2323
HOST_FILE = "{}/hosts.txt".format(CUR_DIR)
24+
try:
25+
open(HOST_FILE).close()
26+
except:
27+
open(HOST_FILE, "a+").close()
2428

2529
# path to the folder containing all the JSON exploit modules
2630
EXPLOIT_FILES_PATH = "{}/etc/json".format(CUR_DIR)
@@ -304,7 +308,7 @@ def configure_requests(proxy=None, agent=None, rand_agent=False):
304308
return proxy_dict, header_dict
305309

306310

307-
def save_error_to_file(error_info):
311+
def save_error_to_file(error_info, error_message, error_class):
308312
"""
309313
save an error traceback to log file for further use
310314
"""
@@ -320,5 +324,7 @@ def save_error_to_file(error_info):
320324
filename = ''.join(filename) + "_AS_error.txt"
321325
file_path = "{}/{}".format(ERROR_FILES_LOCATION, filename)
322326
with open(file_path, "a+") as log:
323-
log.write(error_info)
327+
log.write(
328+
"Traceback (most recent call):\n " + error_info.strip() + "\n{}: {}".format(error_class, error_message)
329+
)
324330
return file_path

lib/term/terminal.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import lib.settings
55
import lib.output
6+
import lib.errors
67
import lib.exploitation.exploiter
78
import api_calls.shodan
89
import api_calls.zoomeye
@@ -26,6 +27,23 @@ def __init__(self, tokens):
2627
lib.output.warning("no hosts file present, you need to gather some hosts")
2728
self.host_path = lib.settings.HOST_FILE
2829

30+
@staticmethod
31+
def help_menu_full():
32+
seperator = "-" * 30
33+
help_choices = [
34+
(0, "usage"),
35+
(1, "view"),
36+
(2, "single"),
37+
(3, "exit"),
38+
(4, "gather"),
39+
(5, "exploit"),
40+
(6, "custom"),
41+
]
42+
print("\n{}\nPossible help choices:".format(seperator))
43+
for i, _ in enumerate(help_choices):
44+
print("{}- `help {}`".format(" " * 3, help_choices[i][1]))
45+
print("{}\n".format(seperator))
46+
2947
def usage_and_legal(self):
3048
"""
3149
shows a display of the output and legal information that resides
@@ -166,6 +184,10 @@ def gather_hosts(self, query, given_choice=None, proxy=None, agent=None):
166184
else:
167185
lib.output.warning("must be integer between 1-{} not string".format(len(lib.settings.API_URLS.keys())))
168186
self.gather_hosts(query, proxy=proxy, agent=agent)
187+
except Exception as e:
188+
lib.settings.stop_animation = True
189+
lib.output.error("unable to search API got error: {}".format(str(e)))
190+
break
169191

170192
def exploit_gathered_hosts(self, loaded_mods, hosts=None):
171193
"""
@@ -184,6 +206,7 @@ def exploit_gathered_hosts(self, loaded_mods, hosts=None):
184206
try:
185207
host_file = open(self.host_path).readlines()
186208
except Exception:
209+
sys.stdout.flush()
187210
lib.output.error("no host file is present, did you gather hosts?")
188211
return
189212
else:
@@ -339,7 +362,7 @@ def __config_headers():
339362
else:
340363
lib.output.warning("option must be integer not string")
341364
elif choice == "help":
342-
lib.output.error("must provide an argument for help IE 'help exploit'")
365+
AutoSploitTerminal.help_menu_full()
343366

344367
except KeyboardInterrupt:
345368
print("\n")

0 commit comments

Comments
 (0)