Commit 75bbdfde by fwkz

Keyword coloring

parent b3ec1e82
......@@ -457,11 +457,19 @@ class RoutersploitInterpreter(BaseInterpreter):
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
......@@ -48,7 +48,8 @@ class Exploit(exploits.Exploit):
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.")
......
......@@ -621,6 +621,56 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
]
)
@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()
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