Commit 66be5de2 by fwkz

'show' command available globally

parent ac339a95
...@@ -255,7 +255,7 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -255,7 +255,7 @@ class RoutersploitInterpreter(BaseInterpreter):
return itertools.chain(module_commands, ('unsetg ',)) return itertools.chain(module_commands, ('unsetg ',))
return module_commands return module_commands
else: else:
return ['use ', 'exec', 'help', 'exit'] return ['use ', 'exec', 'help', 'exit', 'show ']
def command_back(self, *args, **kwargs): def command_back(self, *args, **kwargs):
self.current_module = None self.current_module = None
...@@ -352,6 +352,7 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -352,6 +352,7 @@ class RoutersploitInterpreter(BaseInterpreter):
else: else:
yield opt_key, opt_value, opt_description yield opt_key, opt_value, opt_description
@utils.module_required
def _show_info(self, *args, **kwargs): def _show_info(self, *args, **kwargs):
utils.pprint_dict_in_order( utils.pprint_dict_in_order(
self.module_metadata, self.module_metadata,
...@@ -359,6 +360,7 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -359,6 +360,7 @@ class RoutersploitInterpreter(BaseInterpreter):
) )
utils.print_info() utils.print_info()
@utils.module_required
def _show_options(self, *args, **kwargs): def _show_options(self, *args, **kwargs):
target_opts = {'port', 'target'} target_opts = {'port', 'target'}
module_opts = set(self.current_module.options) - target_opts module_opts = set(self.current_module.options) - target_opts
...@@ -373,6 +375,7 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -373,6 +375,7 @@ class RoutersploitInterpreter(BaseInterpreter):
utils.print_info() utils.print_info()
@utils.module_required
def _show_devices(self, *args, **kwargs): # TODO: cover with tests def _show_devices(self, *args, **kwargs): # TODO: cover with tests
try: try:
devices = self.current_module._Exploit__info__['devices'] devices = self.current_module._Exploit__info__['devices']
...@@ -389,7 +392,6 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -389,7 +392,6 @@ class RoutersploitInterpreter(BaseInterpreter):
except KeyError: except KeyError:
print("\nTarget devices are not defined") print("\nTarget devices are not defined")
@utils.module_required
def command_show(self, *args, **kwargs): def command_show(self, *args, **kwargs):
sub_commands = ('info', 'options', 'devices') sub_commands = ('info', 'options', 'devices')
sub_command = args[0] sub_command = args[0]
......
...@@ -32,7 +32,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase): ...@@ -32,7 +32,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
def test_raw_commands_no_module(self): def test_raw_commands_no_module(self):
self.rsf.send("\t\t") self.rsf.send("\t\t")
self.assertPrompt('exec exit help use \r\n', self.raw_prompt) self.assertPrompt('exec exit help show use \r\n', self.raw_prompt)
def test_complete_use_raw(self): def test_complete_use_raw(self):
self.rsf.send("u\t\t") self.rsf.send("u\t\t")
......
...@@ -266,7 +266,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -266,7 +266,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
self.interpreter.current_module = None self.interpreter.current_module = None
self.assertEqual( self.assertEqual(
self.interpreter.suggested_commands(), # Extra space at the end because of following param self.interpreter.suggested_commands(), # Extra space at the end because of following param
['use ', 'exec', 'help', 'exit'] ['use ', 'exec', 'help', 'exit', 'show ']
) )
@mock.patch('importlib.import_module') @mock.patch('importlib.import_module')
...@@ -491,9 +491,21 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -491,9 +491,21 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
"module_required" "module_required"
) )
def test_if_command_show_has_module_required_decorator(self): def test_if_command_show_info_has_module_required_decorator(self):
self.assertIsDecorated( self.assertIsDecorated(
self.interpreter.command_show, self.interpreter._show_info,
"module_required"
)
def test_if_command_show_options_has_module_required_decorator(self):
self.assertIsDecorated(
self.interpreter._show_options,
"module_required"
)
def test_if_command_show_devices_has_module_required_decorator(self):
self.assertIsDecorated(
self.interpreter._show_devices,
"module_required" "module_required"
) )
......
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