Skip to content

Commit

Permalink
Merge branch 'allonhadaya-module-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkz committed May 5, 2016
2 parents 2e2f164 + 17857b6 commit 55fa0b1
Show file tree
Hide file tree
Showing 20 changed files with 258 additions and 216 deletions.
1 change: 1 addition & 0 deletions routersploit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
boolify,
mute,
multi,
index_modules,
)

from routersploit import exploits
Expand Down
52 changes: 8 additions & 44 deletions routersploit/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import sys
import traceback
import atexit
import importlib
import inspect

from routersploit.exceptions import RoutersploitException
from routersploit.exploits import Exploit
from routersploit import utils
from routersploit import modules as rsf_modules

if sys.platform == "darwin":
import gnureadline as readline
Expand Down Expand Up @@ -158,13 +154,11 @@ def __init__(self):
self.raw_prompt_template = None
self.module_prompt_template = None
self.prompt_hostname = 'rsf'
self.modules_directory = rsf_modules.__path__[0]
self.modules = []
self.modules_with_errors = {}
self.main_modules_dirs = []

self.modules = utils.index_modules()
self.main_modules_dirs = [module for module in os.listdir(utils.MODULES_DIR) if not module.startswith("__")]

self.__parse_prompt()
self.load_modules()

self.banner = """ ______ _ _____ _ _ _
| ___ \ | | / ___| | | (_) |
Expand All @@ -182,28 +176,6 @@ def __init__(self):
Total module count: {modules_count}
""".format(modules_count=len(self.modules))

def load_modules(self):
self.main_modules_dirs = [module for module in os.listdir(self.modules_directory) if not module.startswith("__")]
self.modules = []
self.modules_with_errors = {}

for root, dirs, files in os.walk(self.modules_directory):
_, package, root = root.rpartition('routersploit')
root = "".join((package, root)).replace(os.sep, '.')
modules = map(lambda x: '.'.join((root, os.path.splitext(x)[0])), filter(lambda x: x.endswith('.py'), files))
for module_path in modules:
try:
module = importlib.import_module(module_path)
except ImportError as error:
self.modules_with_errors[module_path] = error
else:
klasses = inspect.getmembers(module, inspect.isclass)
exploits = filter(lambda x: issubclass(x[1], Exploit), klasses)
# exploits = map(lambda x: '.'.join([module_path.split('.', 2).pop(), x[0]]), exploits)
# self.modules.extend(exploits)
if exploits:
self.modules.append(module_path.split('.', 2).pop())

def __parse_prompt(self):
raw_prompt_default_template = "\001\033[4m\002{host}\001\033[0m\002 > "
raw_prompt_template = os.getenv("RSF_RAW_PROMPT", raw_prompt_default_template).replace('\\033', '\033')
Expand Down Expand Up @@ -259,9 +231,9 @@ def suggested_commands(self):
:return: list of most accurate command suggestions
"""
if self.current_module:
return ['run', 'back', 'set ', 'show ', 'check', 'debug', 'exit']
return ['run', 'back', 'set ', 'show ', 'check', 'exit']
else:
return ['use ', 'debug', 'exit']
return ['use ', 'exit']

def command_back(self, *args, **kwargs):
self.current_module = None
Expand All @@ -271,12 +243,9 @@ def command_use(self, module_path, *args, **kwargs):
module_path = '.'.join(('routersploit', 'modules', module_path))
# module_path, _, exploit_name = module_path.rpartition('.')
try:
module = importlib.import_module(module_path)
self.current_module = getattr(module, 'Exploit')()
except (ImportError, AttributeError, KeyError):
utils.print_error("Error during loading '{}' module. "
"It should be valid path to the module. "
"Use <tab> key multiple times for completion.".format(utils.humanize_path(module_path)))
self.current_module = utils.import_exploit(module_path)()
except RoutersploitException as err:
utils.print_error(err.message)

@utils.stop_after(2)
def complete_use(self, text, *args, **kwargs):
Expand Down Expand Up @@ -392,10 +361,5 @@ def command_check(self, *args, **kwargs):
else:
utils.print_status("Target could not be verified")

def command_debug(self, *args, **kwargs):
for key, value in self.modules_with_errors.iteritems():
utils.print_info(key)
utils.print_error(value, '\n')

def command_exit(self, *args, **kwargs):
raise KeyboardInterrupt
8 changes: 6 additions & 2 deletions routersploit/modules/creds/ftp_bruteforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'FTP Bruteforce',
'authors': [
'description': 'Module performs bruteforce attack against FTP service.'
'If valid credentials are found, they are displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
]
),
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
8 changes: 6 additions & 2 deletions routersploit/modules/creds/ftp_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'FTP Default Creds',
'authors': [
'description': 'Module perform dictionary attack with default credentials against FTP service. '
'If valid credentials are found, they are displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
]
),
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
8 changes: 6 additions & 2 deletions routersploit/modules/creds/http_basic_bruteforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'HTTP Basic Bruteforce',
'authors': [
'description': 'Module performs bruteforce attack against HTTP Basic Auth service. '
'If valid credentials are found, they are displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
]
),
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
8 changes: 6 additions & 2 deletions routersploit/modules/creds/http_basic_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'HTTP Basic Default Creds',
'authors': [
'description': 'Module perform dictionary attack with default credentials against HTTP Basic Auth service. '
'If valid credentials are found, they are displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
]
),
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
8 changes: 6 additions & 2 deletions routersploit/modules/creds/http_form_bruteforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'HTTP Form Bruteforce',
'authors': [
'description': 'Module performs bruteforce attack against HTTP form service. '
'If valid credentials are found, they are displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
]
),
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
8 changes: 6 additions & 2 deletions routersploit/modules/creds/http_form_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'HTTP Form Default Creds',
'authors': [
'description': 'Module performs dictionary attack with default credentials against HTTP form service. '
'If valid credentials are found, they are displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
]
),
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
8 changes: 7 additions & 1 deletion routersploit/modules/creds/snmp_bruteforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'SNMP Bruteforce',
'authors': 'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
'description': 'Module performs bruteforce attack against SNMP service. '
'If valid community string is found, it is displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>', # routersploit module
),
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
8 changes: 7 additions & 1 deletion routersploit/modules/creds/ssh_bruteforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'SSH Bruteforce',
'authors': 'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
'description': 'Module performs bruteforce attack against SSH service. '
'If valid credentials are found, they are displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>', # routersploit module
),
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
9 changes: 7 additions & 2 deletions routersploit/modules/creds/ssh_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'SSH Default Creds',
'authors': [
'description': 'Module perform dictionary attack with default credentials against SSH service. '
'If valid credentials are found, they are displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
]
),
'references': '',
'devices': 'Multi',

}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
8 changes: 7 additions & 1 deletion routersploit/modules/creds/telnet_bruteforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'Telnet Bruteforce',
'authors': 'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
'description': 'Module performs bruteforce attack against Telnet service. '
'If valid credentials are found, they are displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>', # routersploit module
),
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
8 changes: 6 additions & 2 deletions routersploit/modules/creds/telnet_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ class Exploit(exploits.Exploit):
"""
__info__ = {
'name': 'Telnet Default Creds',
'authors': [
'description': 'Module perform dictionary attack with default credentials against Telnet service. '
'If valid credentials are found, they are displayed to the user.',
'authors': (
'Marcin Bury <marcin.bury[at]reverse-shell.com>' # routersploit module
]
),
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address or file with target:port (file://)')
Expand Down
2 changes: 2 additions & 0 deletions routersploit/modules/scanners/autopwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Exploit(exploits.Exploit):
'authors': [
'Marcin Bury <marcin.bury[at]reverse-shell.com>', # routersploit module
],
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address e.g. 192.168.1.1') # target address
Expand Down
2 changes: 2 additions & 0 deletions routersploit/modules/scanners/dlink_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Exploit(exploits.Exploit):
'authors': [
'Marcin Bury <marcin.bury[at]reverse-shell.com>', # routersploit module
],
'references': '',
'devices': 'Multi',
}

target = exploits.Option('', 'Target IP address e.g. 192.168.1.1') # target address
Expand Down
4 changes: 2 additions & 2 deletions routersploit/test/test_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def set_module(self):

def test_raw_commands_no_module(self):
self.rsf.send("\t\t")
self.assertPrompt('debug exit use \r\n', self.raw_prompt)
self.assertPrompt('exit use \r\n', self.raw_prompt)

def test_complete_use_raw(self):
self.rsf.send("u\t\t")
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_raw_commands_with_module(self):
self.set_module()
self.rsf.send("\t\t")
self.assertPrompt(
'back check debug exit run set show \r\n',
'back check exit run set show \r\n',
self.module_prompt('FTP Bruteforce')
)

Expand Down
Loading

0 comments on commit 55fa0b1

Please sign in to comment.