Commit a665f517 by fwkz

Merge branch 'master' of https://github.com/DeltaHeavy/routersploit into DeltaHeavy-master

parents bd731f2d 1c0648e5
...@@ -64,3 +64,6 @@ target/ ...@@ -64,3 +64,6 @@ target/
# VS Code # VS Code
.vscode .vscode
# virtualenv
venv/
...@@ -3,6 +3,7 @@ import os ...@@ -3,6 +3,7 @@ import os
import sys import sys
import traceback import traceback
import atexit import atexit
from subprocess import call
from routersploit.exceptions import RoutersploitException from routersploit.exceptions import RoutersploitException
from routersploit import utils from routersploit import utils
...@@ -16,6 +17,8 @@ else: ...@@ -16,6 +17,8 @@ else:
class BaseInterpreter(object): class BaseInterpreter(object):
history_file = os.path.expanduser("~/.history") history_file = os.path.expanduser("~/.history")
history_length = 100 history_length = 100
global_help = ""
def __init__(self): def __init__(self):
self.setup() self.setup()
...@@ -146,6 +149,18 @@ class BaseInterpreter(object): ...@@ -146,6 +149,18 @@ class BaseInterpreter(object):
class RoutersploitInterpreter(BaseInterpreter): class RoutersploitInterpreter(BaseInterpreter):
history_file = os.path.expanduser("~/.rsf_history") 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): def __init__(self):
super(RoutersploitInterpreter, self).__init__() super(RoutersploitInterpreter, self).__init__()
...@@ -231,9 +246,9 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -231,9 +246,9 @@ class RoutersploitInterpreter(BaseInterpreter):
:return: list of most accurate command suggestions :return: list of most accurate command suggestions
""" """
if self.current_module: if self.current_module:
return ['run', 'back', 'set ', 'show ', 'check', 'exit'] return ['run', 'back', 'set ', 'show ', 'check', 'exec', 'help', 'exit']
else: else:
return ['use ', 'exit'] return ['use ', 'exec', 'help', 'exit']
def command_back(self, *args, **kwargs): def command_back(self, *args, **kwargs):
self.current_module = None self.current_module = None
...@@ -259,6 +274,9 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -259,6 +274,9 @@ class RoutersploitInterpreter(BaseInterpreter):
utils.print_status("Running module...") utils.print_status("Running module...")
try: try:
self.current_module.run() self.current_module.run()
except KeyboardInterrupt:
print()
utils.print_error("Operation cancelled by user")
except: except:
utils.print_error(traceback.format_exc(sys.exc_info())) utils.print_error(traceback.format_exc(sys.exc_info()))
...@@ -351,6 +369,11 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -351,6 +369,11 @@ 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:
return
if not self.current_module.target:
utils.print_error("No target set")
return
except: except:
utils.print_error(traceback.format_exc(sys.exc_info())) utils.print_error(traceback.format_exc(sys.exc_info()))
else: else:
...@@ -361,5 +384,14 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -361,5 +384,14 @@ class RoutersploitInterpreter(BaseInterpreter):
else: else:
utils.print_status("Target could not be verified") utils.print_status("Target could not be verified")
def command_help(self, *args, **kwargs):
print(self.global_help)
if self.current_module:
print()
print(self.module_help)
def command_exec(self, *args, **kwargs):
call(' '.join(args))
def command_exit(self, *args, **kwargs): def command_exit(self, *args, **kwargs):
raise KeyboardInterrupt raise KeyboardInterrupt
...@@ -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('exit use \r\n', self.raw_prompt) self.assertPrompt('exec exit help 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")
...@@ -89,7 +89,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase): ...@@ -89,7 +89,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self.set_module() self.set_module()
self.rsf.send("\t\t") self.rsf.send("\t\t")
self.assertPrompt( 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') self.module_prompt('FTP Bruteforce')
) )
......
...@@ -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_1(self, print_status): def test_command_check_target_could_not_be_verified(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,12 +102,9 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -102,12 +102,9 @@ 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_target_could_not_be_verified_2(self, print_status): def test_command_check_not_supported_by_module(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('sys.exc_info') @mock.patch('sys.exc_info')
@mock.patch('traceback.format_exc') @mock.patch('traceback.format_exc')
...@@ -179,14 +176,14 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -179,14 +176,14 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
def test_suggested_commands_with_loaded_module(self): def test_suggested_commands_with_loaded_module(self):
self.assertEqual( self.assertEqual(
self.interpreter.suggested_commands(), 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): def test_suggested_commands_without_loaded_module(self):
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 ', 'exit'] ['use ', 'exec', 'help', 'exit']
) )
@mock.patch('importlib.import_module') @mock.patch('importlib.import_module')
......
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