diff --git a/routersploit/utils.py b/routersploit/utils.py index 7c695de..50d4238 100644 --- a/routersploit/utils.py +++ b/routersploit/utils.py @@ -441,6 +441,31 @@ def boolify(value): return bool(value) +def create_exploit(path): + from .templates import exploit + + try: + module_type, vendor, name = path.split(os.sep) + except ValueError: + print_error("Invalid path. ;(") + return + + if module_type not in ['creds', 'exploits', 'scanners']: + print_error("Invalid module type. ;(") + return + + create_resource( + name=os.path.join(module_type, vendor), + 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): """ Creates resource directory in current working directory. """ root_path = os.path.join(MODULES_DIR, name) diff --git a/rsf.py b/rsf.py index 27e1814..06cf4fe 100755 --- a/rsf.py +++ b/rsf.py @@ -1,12 +1,11 @@ #!/usr/bin/env python2 from __future__ import print_function -import os + import argparse from routersploit.interpreter import RoutersploitInterpreter -from routersploit.utils import create_resource, Resource -from routersploit.templates import exploit +from routersploit.utils import create_exploit parser = argparse.ArgumentParser(description='RouterSploit - Router Exploitation Framework') @@ -23,16 +22,6 @@ 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 - ) + create_exploit(args.add_exploit) else: routersploit()