Commit bf5a036e by fwkz

Adding command-line utility for adding modules.

parent 2a73e612
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
...@@ -8,6 +8,8 @@ import random ...@@ -8,6 +8,8 @@ import random
import string import string
import socket import socket
import importlib import importlib
import errno
from collections import namedtuple
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
...@@ -31,6 +33,8 @@ colors = { ...@@ -31,6 +33,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 = 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 """
...@@ -435,3 +439,44 @@ def boolify(value): ...@@ -435,3 +439,44 @@ def boolify(value):
return False return False
else: else:
return bool(value) return bool(value)
def create_resource(name, content=(), python_package=False):
""" 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()
print_success("__init__.py successfully created.")
for name, template_path, context in content:
if os.path.splitext(name)[-1] == "": # Checking if resource has extension if not it's directory
os.mkdir(os.path.join(root_path, name))
print_success("Sub-directory /{name} successfully created.".format(name=name))
else:
try:
with open(template_path, "rb") as template_file:
template = string.Template(template_file.read())
except (IOError, TypeError):
template = string.Template("")
finally:
with open(os.path.join(root_path, name), "wb") as target_file:
target_file.write(template.substitute(**context))
print_success("{file} successfully created.".format(file=name))
def mkdir_p(path):
"""
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} sucessfully 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
\ No newline at end of file
#!/usr/bin/env python2 #!/usr/bin/env python2
from __future__ import print_function
import os
import argparse
from routersploit.interpreter import RoutersploitInterpreter from routersploit.interpreter import RoutersploitInterpreter
from routersploit.utils import create_resource, Resource
from routersploit.templates import exploit
parser = argparse.ArgumentParser(description='RouterSploit - Router Exploitation Framework')
parser.add_argument('--add-exploit',
metavar='exploit_path',
help='Add exploit using default template.')
def routersploit(): def routersploit():
...@@ -8,4 +20,19 @@ def routersploit(): ...@@ -8,4 +20,19 @@ def routersploit():
rsf.start() rsf.start()
if __name__ == "__main__": if __name__ == "__main__":
args = parser.parse_args()
if args.add_exploit:
base, _, name = args.add_exploit.rpartition(os.sep)
create_resource(
name=base,
content=(
Resource(
name="{}.py".format(name),
template_path=os.path.abspath(exploit.__file__.rstrip("c")),
context={}),
),
python_package=True
)
else:
routersploit() 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