Commit 357c377c by fwkz

Merge branch 'DeltaHeavy-master'

parents bd731f2d 17fb3dbb
......@@ -64,3 +64,6 @@ target/
# VS Code
.vscode
# virtualenv
venv/
......@@ -16,6 +16,7 @@ else:
class BaseInterpreter(object):
history_file = os.path.expanduser("~/.history")
history_length = 100
global_help = ""
def __init__(self):
self.setup()
......@@ -146,6 +147,18 @@ class BaseInterpreter(object):
class RoutersploitInterpreter(BaseInterpreter):
history_file = os.path.expanduser("~/.rsf_history")
global_help = """Global commands:
help Print this help menu
use <module> Select a module for usage
exec <shell command> <args> Execute a command in a shell
exit Exit RouterSploit"""
module_help = """Module commands:
run Run the selected module with the given options
back De-select the current module
set <option name> <option value> Set an option for the selected module
show [info|options|devices] Print information, options, or target devices for a module
check Check if a given target is vulnerable to a selected module's exploit"""
def __init__(self):
super(RoutersploitInterpreter, self).__init__()
......@@ -231,9 +244,9 @@ class RoutersploitInterpreter(BaseInterpreter):
:return: list of most accurate command suggestions
"""
if self.current_module:
return ['run', 'back', 'set ', 'show ', 'check', 'exit']
return ['run', 'back', 'set ', 'show ', 'check', 'exec', 'help', 'exit']
else:
return ['use ', 'exit']
return ['use ', 'exec', 'help', 'exit']
def command_back(self, *args, **kwargs):
self.current_module = None
......@@ -259,6 +272,9 @@ class RoutersploitInterpreter(BaseInterpreter):
utils.print_status("Running module...")
try:
self.current_module.run()
except KeyboardInterrupt:
print()
utils.print_error("Operation cancelled by user")
except:
utils.print_error(traceback.format_exc(sys.exc_info()))
......@@ -351,8 +367,8 @@ class RoutersploitInterpreter(BaseInterpreter):
def command_check(self, *args, **kwargs):
try:
result = self.current_module.check()
except:
utils.print_error(traceback.format_exc(sys.exc_info()))
except Exception as error:
utils.print_error(error)
else:
if result is True:
utils.print_success("Target is vulnerable")
......@@ -361,5 +377,13 @@ class RoutersploitInterpreter(BaseInterpreter):
else:
utils.print_status("Target could not be verified")
def command_help(self, *args, **kwargs):
print(self.global_help)
if self.current_module:
print("\n", self.module_help)
def command_exec(self, *args, **kwargs):
os.system(args[0])
def command_exit(self, *args, **kwargs):
raise KeyboardInterrupt
......@@ -69,6 +69,6 @@ class Exploit(exploits.Exploit):
print_info(" - {}".format(v))
else:
print_error("Device is not vulnerable to any exploits!\n")
def check(self):
print_error("Check method is not available")
raise NotImplementedError("Check method is not available")
......@@ -68,4 +68,4 @@ class Exploit(exploits.Exploit):
print
def check(self):
print_error("Check method is not available")
raise NotImplementedError("Check method is not available")
......@@ -32,7 +32,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
def test_raw_commands_no_module(self):
self.rsf.send("\t\t")
self.assertPrompt('exit use \r\n', self.raw_prompt)
self.assertPrompt('exec exit help use \r\n', self.raw_prompt)
def test_complete_use_raw(self):
self.rsf.send("u\t\t")
......@@ -89,7 +89,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self.set_module()
self.rsf.send("\t\t")
self.assertPrompt(
'back check exit run set show \r\n',
'back check exec exit help run set show \r\n',
self.module_prompt('FTP Bruteforce')
)
......
......@@ -109,6 +109,15 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
mock_check.assert_called_once_with()
print_status.assert_called_once_with('Target could not be verified')
@mock.patch('routersploit.utils.print_error')
def test_command_check_not_supported_by_module(self, print_error):
with mock.patch.object(self.interpreter.current_module, 'check') as mock_check:
exception = NotImplementedError("Not available")
mock_check.side_effect = exception
self.interpreter.command_check()
mock_check.assert_called_once_with()
print_error.assert_called_once_with(exception)
@mock.patch('sys.exc_info')
@mock.patch('traceback.format_exc')
@mock.patch('routersploit.utils.print_error')
......@@ -179,14 +188,14 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
def test_suggested_commands_with_loaded_module(self):
self.assertEqual(
self.interpreter.suggested_commands(),
['run', 'back', 'set ', 'show ', 'check', 'exit'] # Extra space at the end because of following param
['run', 'back', 'set ', 'show ', 'check', 'exec', 'help', 'exit'] # Extra space at the end because of following param
)
def test_suggested_commands_without_loaded_module(self):
self.interpreter.current_module = None
self.assertEqual(
self.interpreter.suggested_commands(), # Extra space at the end because of following param
['use ', 'exit']
['use ', 'exec', 'help', 'exit']
)
@mock.patch('importlib.import_module')
......@@ -425,5 +434,10 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
with self.assertRaises(KeyboardInterrupt):
self.interpreter.command_exit()
@mock.patch('os.system')
def test_command_exec(self, mock_system):
self.interpreter.command_exec("foo -bar")
mock_system.assert_called_once_with("foo -bar")
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment