Commit a940aadd by fwkz

Handling check() method in scanners

parent a665f517
......@@ -18,7 +18,6 @@ class BaseInterpreter(object):
history_file = os.path.expanduser("~/.history")
history_length = 100
global_help = ""
def __init__(self):
self.setup()
......@@ -369,13 +368,8 @@ class RoutersploitInterpreter(BaseInterpreter):
def command_check(self, *args, **kwargs):
try:
result = self.current_module.check()
if result is None:
return
if not self.current_module.target:
utils.print_error("No target set")
return
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")
......@@ -387,10 +381,10 @@ class RoutersploitInterpreter(BaseInterpreter):
def command_help(self, *args, **kwargs):
print(self.global_help)
if self.current_module:
print()
print(self.module_help)
print("\n", self.module_help)
def command_exec(self, *args, **kwargs):
print(' '.join(args))
call(' '.join(args))
def command_exit(self, *args, **kwargs):
......
......@@ -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")
......@@ -94,7 +94,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
print_error.assert_called_once_with('Target is not vulnerable')
@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:
mock_check.return_value = "something"
self.interpreter.command_check()
......@@ -102,9 +102,21 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
print_status.assert_called_once_with('Target could not be verified')
@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:
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('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