Skip to content

Commit

Permalink
Merge branch 'DeltaHeavy-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkz committed May 14, 2016
2 parents bd731f2 + 17fb3db commit 357c377
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ target/

# VS Code
.vscode

# virtualenv
venv/
32 changes: 28 additions & 4 deletions routersploit/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class BaseInterpreter(object):
history_file = os.path.expanduser("~/.history")
history_length = 100
global_help = ""

def __init__(self):
self.setup()
Expand Down Expand Up @@ -146,6 +147,18 @@ def suggested_commands(self):

class RoutersploitInterpreter(BaseInterpreter):
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):
super(RoutersploitInterpreter, self).__init__()
Expand Down Expand Up @@ -231,9 +244,9 @@ def suggested_commands(self):
:return: list of most accurate command suggestions
"""
if self.current_module:
return ['run', 'back', 'set ', 'show ', 'check', 'exit']
return ['run', 'back', 'set ', 'show ', 'check', 'exec', 'help', 'exit']
else:
return ['use ', 'exit']
return ['use ', 'exec', 'help', 'exit']

def command_back(self, *args, **kwargs):
self.current_module = None
Expand All @@ -259,6 +272,9 @@ def command_run(self, *args, **kwargs):
utils.print_status("Running module...")
try:
self.current_module.run()
except KeyboardInterrupt:
print()
utils.print_error("Operation cancelled by user")
except:
utils.print_error(traceback.format_exc(sys.exc_info()))

Expand Down Expand Up @@ -351,8 +367,8 @@ def complete_show(self, text, *args, **kwargs):
def command_check(self, *args, **kwargs):
try:
result = self.current_module.check()
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")
Expand All @@ -361,5 +377,13 @@ def command_check(self, *args, **kwargs):
else:
utils.print_status("Target could not be verified")

def command_help(self, *args, **kwargs):
print(self.global_help)
if self.current_module:
print("\n", self.module_help)

def command_exec(self, *args, **kwargs):
os.system(args[0])

def command_exit(self, *args, **kwargs):
raise KeyboardInterrupt
4 changes: 2 additions & 2 deletions routersploit/modules/scanners/autopwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ def run(self):
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")
2 changes: 1 addition & 1 deletion routersploit/modules/scanners/dlink_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ def run(self):
print

def check(self):
print_error("Check method is not available")
raise NotImplementedError("Check method is not available")
4 changes: 2 additions & 2 deletions routersploit/test/test_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def set_module(self):

def test_raw_commands_no_module(self):
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):
self.rsf.send("u\t\t")
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_raw_commands_with_module(self):
self.set_module()
self.rsf.send("\t\t")
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')
)

Expand Down
18 changes: 16 additions & 2 deletions routersploit/test/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ def test_command_check_target_could_not_be_verified_2(self, print_status):
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')
@mock.patch('routersploit.utils.print_error')
Expand Down Expand Up @@ -179,14 +188,14 @@ def test_module_prompt_module_has_no_name_key_in_metadata(self):
def test_suggested_commands_with_loaded_module(self):
self.assertEqual(
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):
self.interpreter.current_module = None
self.assertEqual(
self.interpreter.suggested_commands(), # Extra space at the end because of following param
['use ', 'exit']
['use ', 'exec', 'help', 'exit']
)

@mock.patch('importlib.import_module')
Expand Down Expand Up @@ -425,5 +434,10 @@ def test_command_exit(self):
with self.assertRaises(KeyboardInterrupt):
self.interpreter.command_exit()

@mock.patch('os.system')
def test_command_exec(self, mock_system):
self.interpreter.command_exec("foo -bar")
mock_system.assert_called_once_with("foo -bar")

if __name__ == '__main__':
unittest.main()

0 comments on commit 357c377

Please sign in to comment.