Commit 4126a8d8 by fwkz

Adding debug command.

parent eb2b21ab
......@@ -160,6 +160,7 @@ class RoutersploitInterpreter(BaseInterpreter):
self.prompt_hostname = 'rsf'
self.modules_directory = rsf_modules.__path__[0]
self.modules = []
self.modules_with_errors = {}
self.main_modules_dirs = []
self.__parse_prompt()
......@@ -184,6 +185,7 @@ class RoutersploitInterpreter(BaseInterpreter):
def load_modules(self):
self.main_modules_dirs = [module for module in os.listdir(self.modules_directory) if not module.startswith("__")]
self.modules = []
self.modules_with_errors = {}
for root, dirs, files in os.walk(self.modules_directory):
_, package, root = root.rpartition('routersploit')
......@@ -192,8 +194,8 @@ class RoutersploitInterpreter(BaseInterpreter):
for module_path in modules:
try:
module = importlib.import_module(module_path)
except ImportError:
pass
except ImportError as error:
self.modules_with_errors[module_path] = error
else:
klasses = inspect.getmembers(module, inspect.isclass)
exploits = filter(lambda x: issubclass(x[1], Exploit), klasses)
......@@ -257,9 +259,9 @@ class RoutersploitInterpreter(BaseInterpreter):
:return: list of most accurate command suggestions
"""
if self.current_module:
return ['run', 'back', 'set ', 'show ', 'check']
return ['run', 'back', 'set ', 'show ', 'check', 'debug']
else:
return ['use ']
return ['use ', 'debug']
def command_back(self, *args, **kwargs):
self.current_module = None
......@@ -374,3 +376,9 @@ class RoutersploitInterpreter(BaseInterpreter):
utils.print_error("Target is not vulnerable")
else:
utils.print_status("Target could not be verified")
def command_debug(self, *args, **kwargs):
for key, value in self.modules_with_errors.iteritems():
utils.print_info(key)
utils.print_error(value, '\n')
......@@ -30,7 +30,7 @@ class RoutersploitCompleterTest(unittest.TestCase):
def test_raw_commands_no_module(self):
self.rsf.send("\t\t")
self.assertPrompt(self.raw_prompt, 'use ')
self.assertPrompt('debug use \r\n', self.raw_prompt)
def test_complete_use_raw(self):
self.rsf.send("u\t\t")
......@@ -87,7 +87,7 @@ class RoutersploitCompleterTest(unittest.TestCase):
self.set_module()
self.rsf.send("\t\t")
self.assertPrompt(
'back check run set show \r\n',
'back check debug run set show \r\n',
self.module_prompt('FTP Bruteforce')
)
......
......@@ -197,14 +197,14 @@ class RoutersploitInterpreterTest(unittest.TestCase):
def test_suggested_commands_with_loaded_module(self):
self.assertEqual(
self.interpreter.suggested_commands(),
['run', 'back', 'set ', 'show ', 'check'] # Extra space at the end because of following param
['run', 'back', 'set ', 'show ', 'check', 'debug'] # 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 ']
['use ', 'debug']
)
@mock.patch('importlib.import_module')
......@@ -247,7 +247,7 @@ class RoutersploitInterpreterTest(unittest.TestCase):
@mock.patch('importlib.import_module')
@mock.patch('routersploit.utils.print_error')
def test_command_unknown_module(self, mocked_print_error, mocked_import_module):
def test_command_use_unknown_module(self, mocked_print_error, mocked_import_module):
""" Testing command_use()
* Unknown module
......@@ -267,7 +267,7 @@ class RoutersploitInterpreterTest(unittest.TestCase):
@mock.patch('importlib.import_module')
@mock.patch('routersploit.utils.print_error')
def test_command_unknown_extension(self, mocked_print_error, mocked_import_module):
def test_command_use_unknown_extension(self, mocked_print_error, mocked_import_module):
""" Testing command_use()
* Unknown Exploit
......@@ -489,9 +489,10 @@ class RoutersploitInterpreterTest(unittest.TestCase):
mock_walk.return_value = (
('/Abs/Path/routersploit/routersploit/modules', ['asmax', 'creds'], ['__init__.py', '__init__.pyc']),
('/Abs/Path/routersploit/routersploit/modules/creds', [], ['__init__.py', '__init__.pyc', 'ftp_bruteforce.py', 'ftp_bruteforce.pyc']),
('/Abs/Path/routersploit/routersploit/modules/exploits/asmax', [], ['__init__.py', '__init__.pyc', 'asmax_exploit.py', 'asmax_exploit.pyc']),
('/Abs/Path/routersploit/routersploit/modules/exploits/asmax', [], ['__init__.py', '__init__.pyc', 'asmax_exploit.py', 'asmax_exploit.pyc', 'asmax_multi.py', 'asmax_multi.pyc']),
)
mock_import_module.side_effect = [1, 2, ImportError, 4, 5]
import_error = ImportError("No module doopaa")
mock_import_module.side_effect = [1, 2, import_error, 4, 5, import_error]
mock_getmembers.side_effect = [
[],
[],
......@@ -509,7 +510,8 @@ class RoutersploitInterpreterTest(unittest.TestCase):
mock.call('routersploit.modules.creds.__init__'),
mock.call('routersploit.modules.creds.ftp_bruteforce'),
mock.call('routersploit.modules.exploits.asmax.__init__'),
mock.call('routersploit.modules.exploits.asmax.asmax_exploit')
mock.call('routersploit.modules.exploits.asmax.asmax_exploit'),
mock.call('routersploit.modules.exploits.asmax.asmax_multi')
]
)
self.assertEqual(
......@@ -528,5 +530,42 @@ class RoutersploitInterpreterTest(unittest.TestCase):
]
)
self.assertEqual(
self.interpreter.modules_with_errors,
{
"routersploit.modules.creds.ftp_bruteforce": import_error,
'routersploit.modules.exploits.asmax.asmax_multi': import_error,
}
)
@mock.patch('routersploit.utils.print_info')
@mock.patch('routersploit.utils.print_error')
def test_command_debug(self, mocked_print_error, mocked_print_info, ):
self.interpreter.modules_with_errors = {
"foo.bar.exploit": "foo foo error",
"foo.baz.exploit": "foo baz error",
"doo.paa.exploit": "doo paa error",
}
self.interpreter.command_debug()
self.assertItemsEqual(
mocked_print_info.mock_calls,
[
mock.call("foo.baz.exploit"),
mock.call("foo.bar.exploit"),
mock.call("doo.paa.exploit"),
]
)
self.assertItemsEqual(
mocked_print_error.mock_calls,
[
mock.call("doo paa error", '\n'),
mock.call("foo foo error", '\n'),
mock.call("foo baz error", '\n'),
]
)
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