Commit a940aadd by fwkz

Handling check() method in scanners

parent a665f517
...@@ -19,7 +19,6 @@ class BaseInterpreter(object): ...@@ -19,7 +19,6 @@ class BaseInterpreter(object):
history_length = 100 history_length = 100
global_help = "" global_help = ""
def __init__(self): def __init__(self):
self.setup() self.setup()
self.banner = "" self.banner = ""
...@@ -369,13 +368,8 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -369,13 +368,8 @@ class RoutersploitInterpreter(BaseInterpreter):
def command_check(self, *args, **kwargs): def command_check(self, *args, **kwargs):
try: try:
result = self.current_module.check() result = self.current_module.check()
if result is None: except Exception as error:
return utils.print_error(error)
if not self.current_module.target:
utils.print_error("No target set")
return
except:
utils.print_error(traceback.format_exc(sys.exc_info()))
else: else:
if result is True: if result is True:
utils.print_success("Target is vulnerable") utils.print_success("Target is vulnerable")
...@@ -387,10 +381,10 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -387,10 +381,10 @@ class RoutersploitInterpreter(BaseInterpreter):
def command_help(self, *args, **kwargs): def command_help(self, *args, **kwargs):
print(self.global_help) print(self.global_help)
if self.current_module: if self.current_module:
print() print("\n", self.module_help)
print(self.module_help)
def command_exec(self, *args, **kwargs): def command_exec(self, *args, **kwargs):
print(' '.join(args))
call(' '.join(args)) call(' '.join(args))
def command_exit(self, *args, **kwargs): def command_exit(self, *args, **kwargs):
......
...@@ -71,4 +71,4 @@ class Exploit(exploits.Exploit): ...@@ -71,4 +71,4 @@ class Exploit(exploits.Exploit):
print_error("Device is not vulnerable to any exploits!\n") print_error("Device is not vulnerable to any exploits!\n")
def check(self): 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): ...@@ -68,4 +68,4 @@ class Exploit(exploits.Exploit):
print print
def check(self): def check(self):
print_error("Check method is not available") raise NotImplementedError("Check method is not available")
...@@ -94,7 +94,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -94,7 +94,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
print_error.assert_called_once_with('Target is not vulnerable') print_error.assert_called_once_with('Target is not vulnerable')
@mock.patch('routersploit.utils.print_status') @mock.patch('routersploit.utils.print_status')
def test_command_check_target_could_not_be_verified(self, print_status): def test_command_check_target_could_not_be_verified_1(self, print_status):
with mock.patch.object(self.interpreter.current_module, 'check') as mock_check: with mock.patch.object(self.interpreter.current_module, 'check') as mock_check:
mock_check.return_value = "something" mock_check.return_value = "something"
self.interpreter.command_check() self.interpreter.command_check()
...@@ -102,9 +102,21 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -102,9 +102,21 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
print_status.assert_called_once_with('Target could not be verified') print_status.assert_called_once_with('Target could not be verified')
@mock.patch('routersploit.utils.print_status') @mock.patch('routersploit.utils.print_status')
def test_command_check_not_supported_by_module(self, print_status): def test_command_check_target_could_not_be_verified_2(self, print_status):
with mock.patch.object(self.interpreter.current_module, 'check') as mock_check: with mock.patch.object(self.interpreter.current_module, 'check') as mock_check:
mock_check.return_value = None mock_check.return_value = None
self.interpreter.command_check()
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('sys.exc_info')
@mock.patch('traceback.format_exc') @mock.patch('traceback.format_exc')
......
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