Commit 0783f8af by fwkz

Merge branch 'add-test-from-template'

parents e09b224e cea89787
from routersploit import (
exploits,
mute,
validators,
)
class Exploit(exploits.Exploit):
""" Exploit template. """
__info__ = {
'name': '',
'authors': [
'', # vulnerability discovery
'', # routersploit module
],
'description': '',
'references': [
'',
],
'devices': [
'',
],
}
target = exploits.Option('', 'Target address e.g. http://192.168.1.1', validators=validators.url)
port = exploits.Option(80, 'Target Port')
def run(self):
pass
@mute
def check(self):
pass
...@@ -11,6 +11,7 @@ import string ...@@ -11,6 +11,7 @@ import string
import importlib import importlib
import select import select
import socket import socket
import errno
from functools import wraps from functools import wraps
from distutils.util import strtobool from distutils.util import strtobool
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
...@@ -34,6 +35,8 @@ colors = { ...@@ -34,6 +35,8 @@ colors = {
# Disable certificate verification warnings # Disable certificate verification warnings
requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning) requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
Resource = collections.namedtuple("Resource", ["name", "template_path", "context"])
def index_modules(modules_directory=MODULES_DIR): def index_modules(modules_directory=MODULES_DIR):
""" Return list of all exploits modules """ """ Return list of all exploits modules """
...@@ -528,3 +531,76 @@ def tokenize(token_specification, text): ...@@ -528,3 +531,76 @@ def tokenize(token_specification, text):
else: else:
column = mo.start() - line_start column = mo.start() - line_start
yield Token(kind, value, line_num, column, mo) yield Token(kind, value, line_num, column, mo)
def create_exploit(path): # TODO: cover with tests
from .templates import exploit
parts = path.split(os.sep)
module_type, name = parts[0], parts[-1]
if not name:
print_error("Invalid exploit name. ;(")
return
if module_type not in ['creds', 'exploits', 'scanners']:
print_error("Invalid module type. ;(")
return
create_resource(
name=os.path.join(*parts[:-1]),
content=(
Resource(
name="{}.py".format(name),
template_path=os.path.abspath(exploit.__file__.rstrip("c")),
context={}),
),
python_package=True
)
def create_resource(name, content=(), python_package=False): # TODO: cover with tests
""" Creates resource directory in current working directory. """
root_path = os.path.join(MODULES_DIR, name)
mkdir_p(root_path)
if python_package:
open(os.path.join(root_path, "__init__.py"), "a").close()
for name, template_path, context in content:
if os.path.splitext(name)[-1] == "": # Checking if resource has extension if not it's directory
mkdir_p(os.path.join(root_path, name))
else:
try:
with open(template_path, "rb") as template_file:
template = string.Template(template_file.read())
except (IOError, TypeError):
template = string.Template("")
try:
file_handle = os.open(os.path.join(root_path, name), os.O_CREAT | os.O_EXCL | os.O_WRONLY)
except OSError as e:
if e.errno == errno.EEXIST:
print_status("{} already exist.".format(name))
else:
raise
else:
with os.fdopen(file_handle, 'w') as target_file:
target_file.write(template.substitute(**context))
print_success("{} successfully created.".format(name))
def mkdir_p(path): # TODO: cover with tests
"""
Simulate mkdir -p shell command. Creates directory with all needed parents.
:param path: Directory path that may include non existing parent directories
:return:
"""
try:
os.makedirs(path)
print_success("Directory {path} successfully created.".format(path=path))
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
print_success("Directory {path}".format(path=path))
else:
raise
#!/usr/bin/env python2 #!/usr/bin/env python2
from __future__ import print_function
import argparse
from routersploit.interpreter import RoutersploitInterpreter from routersploit.interpreter import RoutersploitInterpreter
from routersploit.utils import create_exploit
parser = argparse.ArgumentParser(description='RouterSploit - Router Exploitation Framework')
parser.add_argument('-a',
'--add-exploit',
metavar='exploit_path',
help='Add exploit using default template.')
def routersploit(): def routersploit():
...@@ -8,4 +20,9 @@ def routersploit(): ...@@ -8,4 +20,9 @@ def routersploit():
rsf.start() rsf.start()
if __name__ == "__main__": if __name__ == "__main__":
routersploit() args = parser.parse_args()
if args.add_exploit:
create_exploit(args.add_exploit)
else:
routersploit()
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