Skip to content

Commit

Permalink
Keyword coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkz committed Feb 3, 2017
1 parent b3ec1e8 commit 75bbdfd
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
18 changes: 13 additions & 5 deletions routersploit/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,19 @@ def command_help(self, *args, **kwargs):
def command_exec(self, *args, **kwargs):
os.system(args[0])

def command_search(self, *args, **kwargs): # TODO cover with unit tests
for arg in args:
matches = [s for s in self.modules if arg in s]
for match in matches:
utils.print_info(match.replace('.', '/'))
def command_search(self, *args, **kwargs):
keyword = args[0]

if not keyword:
utils.print_error("Please specify search keyword. e.g. 'search cisco'")
return

for module in self.modules:
if keyword in module:
module = utils.humanize_path(module)
utils.print_info(
"{}\033[31m{}\033[0m{}".format(*module.partition(keyword))
)

def command_exit(self, *args, **kwargs):
raise EOFError
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def run(self):
conn.read_until("> ")
conn.write("quit\r\n")
conn.close()
print_success("SQLI successful, going to telnet into port 20000 with username root and no password to get shell")
print_success("SQLI successful, going to telnet into port 20000 "
"with username root and no password to get shell")
except Exception:
print_error("Exploit failed. Could not log in.")

Expand Down
50 changes: 50 additions & 0 deletions routersploit/test/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,56 @@ def test_command_help_with_module_loaded(self, mock_print):
]
)

@mock.patch('routersploit.utils.print_info')
def test_command_search_01(self, mock_print):
self.interpreter.modules = [
'exploits.asus.foo',
'exploits.asus.bar',
'exploits.linksys.baz',
'exploits.cisco.foo',
]
self.interpreter.command_search("asus")
self.assertEqual(
mock_print.mock_calls,
[
mock.call('exploits/\x1b[31masus\x1b[0m/foo'),
mock.call('exploits/\x1b[31masus\x1b[0m/bar'),
]
)

@mock.patch('routersploit.utils.print_info')
def test_command_search_02(self, mock_print):
self.interpreter.modules = [
'exploits.asus.foo',
'exploits.asus.bar',
'exploits.linksys.baz',
'exploits.cisco.foo',
]
self.interpreter.command_search("foo")
self.assertEqual(
mock_print.mock_calls,
[
mock.call('exploits/asus/\x1b[31mfoo\x1b[0m'),
mock.call('exploits/cisco/\x1b[31mfoo\x1b[0m')
]
)

@mock.patch('routersploit.utils.print_error')
def test_command_search_03(self, print_error):
self.interpreter.modules = [
'exploits.asus.foo',
'exploits.asus.bar',
'exploits.linksys.baz',
'exploits.cisco.foo',
]
self.interpreter.command_search("")
self.assertEqual(
print_error.mock_calls,
[
mock.call("Please specify search keyword. e.g. 'search cisco'"),
]
)


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

0 comments on commit 75bbdfd

Please sign in to comment.