Added default config for plugins

pull/3/head
Thorsten Sick 4 years ago
parent 3d9780d57e
commit 89b73a7262

@ -206,6 +206,8 @@ class ExperimentConfig():
res = self.raw_config["kali_conf"][attack]
except KeyError as exception:
raise ConfigurationError from exception
if res is None:
res = {}
return res

@ -12,6 +12,16 @@ from plugins.base.sensor import SensorPlugin
from plugins.base.vulnerability_plugin import VulnerabilityPlugin
# from app.interface_sfx import CommandlineColors
sections = [{"name": "Vulnerabilities",
"subclass": VulnerabilityPlugin},
{"name": "Machinery",
"subclass": MachineryPlugin},
{"name": "Kali",
"subclass": KaliPlugin},
{"name": "Sensors",
"subclass": SensorPlugin},
]
class PluginManager():
""" Manage plugins """
@ -55,16 +65,6 @@ class PluginManager():
def print_list(self):
""" Print a pretty list of all available plugins """
sections = [{"name": "Vulnerabilities",
"subclass": VulnerabilityPlugin},
{"name": "Machinery",
"subclass": MachineryPlugin},
{"name": "Kali",
"subclass": KaliPlugin},
{"name": "Sensors",
"subclass": SensorPlugin},
]
for section in sections:
print(f'\t\t{section["name"]}')
plugins = self.get_plugins(section["subclass"])
@ -72,3 +72,18 @@ class PluginManager():
print(f"Name: {plugin.get_name()}")
print(f"Description: {plugin.get_description()}")
print("\t")
def print_default_config(self, subclass_name, name):
subclass = None
for a in sections:
if a["name"] == subclass_name:
subclass = a["subclass"]
if subclass is None:
print("Use proper subclass. Available subclasses are: ")
"\n- ".join([a for a in sections["name"]])
plugins = self.get_plugins(subclass, [name])
for plugin in plugins:
print(plugin.get_raw_default_config())

@ -6,10 +6,17 @@ from app.pluginmanager import PluginManager
def list_plugins(arguments):
""" List plugins """
p = PluginManager()
p.print_list()
def get_default_config(arguments):
""" print default config of a specific plugin """
p = PluginManager()
p.print_default_config(arguments.subclass_name, arguments.plugin_name)
def create_parser():
""" Creates the parser for the command line arguments"""
@ -17,9 +24,14 @@ def create_parser():
subparsers = main_parser.add_subparsers(help="sub-commands")
# Sub parser for machine creation
parser_create = subparsers.add_parser("list", help="list plugins")
parser_create.set_defaults(func=list_plugins)
# parser_create.add_argument("--configfile", default="experiment.yaml", help="Config file to create from")
parser_list = subparsers.add_parser("list", help="list plugins")
parser_list.set_defaults(func=list_plugins)
# parser_list.add_argument("--configfile", default="experiment.yaml", help="Config file to create from")
parser_default_config = subparsers.add_parser("raw_config", help="print raw default config of the given plugin")
parser_default_config.set_defaults(func=get_default_config)
parser_default_config.add_argument("subclass_name", help="name of the subclass")
parser_default_config.add_argument("plugin_name", help="name of the plugin")
# TODO: Get default config
return main_parser

@ -23,6 +23,19 @@ class KaliPlugin(BasePlugin):
self.sysconf = {} # System configuration. common for all plugins
self.attack_logger = None
def process_config(self, config):
""" process config and use defaults if stuff is missing
@param config: The config dict
"""
# TODO: Move to python 3.9 syntax z = x | y
self.conf = {**self.conf, **config}
print("\n\n\n\n\n")
print(self.conf)
def teardown(self):
""" Cleanup afterwards """
pass # pylint: disable=unnecessary-pass

@ -2,6 +2,7 @@
""" Base class for all plugin types """
import os
import yaml
# from shutil import copy
@ -18,6 +19,9 @@ class BasePlugin():
self.plugin_path = None
self.machine_plugin = None
self.sysconf = {}
self.conf = {}
self.default_config_name = "default_config.yaml"
def setup(self):
""" Prepare everything for the plugin """
@ -43,6 +47,7 @@ class BasePlugin():
self.sysconf["abs_machinepath_internal"] = config["abs_machinepath_internal"]
self.sysconf["abs_machinepath_external"] = config["abs_machinepath_external"]
self.load_default_config()
def copy_to_machine(self, filename):
""" Copies a file shipped with the plugin to the machine share folder
@ -101,3 +106,22 @@ class BasePlugin():
return self.description
raise NotImplementedError
def get_default_config_filename(self):
""" Generate the default filename of the default configuration file """
return os.path.join(os.path.dirname(self.plugin_path), self.default_config_name)
def get_raw_default_config(self):
""" Returns the default config as string. Usable as an example and for documentation """
with open(self.get_default_config_filename(), "rt") as fh:
return fh.read()
def load_default_config(self):
""" Reads and returns the default config as dict """
with open(self.get_default_config_filename()) as fh:
self.conf = yaml.safe_load(fh)
if self.conf is None:
self.conf = {}

@ -0,0 +1,12 @@
###
# A list of protocols to brute force against. Supported: "ssh"
protocols:
- ssh
- rdp
#- ftps
###
# A file containing potential user names
userfile: users.txt
###
# A file containing potential passwords
pwdfile: passwords.txt

@ -21,16 +21,6 @@ class HydraPlugin(KaliPlugin):
# print("Init hydra")
def process_config(self, config):
""" process config and use defaults if stuff is missing
@param config: The config dict
"""
# TODO Create kali specific config class, send this to the plugins
self.conf["protocols"] = config.get("protocols", ["ssh"])
self.conf["userfile"] = config.get("userfile", "users.txt")
self.conf["pwdfile"] = config.get("pwdfile", "passwords.txt")
def command(self, targets, config):
""" Generate the command (having a separate step assists on debugging)

@ -51,14 +51,6 @@ class NmapPlugin(KaliPlugin):
super().__init__()
self.plugin_path = __file__
def process_config(self, config):
""" process config and use defaults if stuff is missing
@param config: The config dict
"""
# TODO Create kali specific config class, send this to the plugins
# TODO: NMap specific config should be added. So far we only have the basic scan
def command(self, targets, config):
""" Generate the command (having a separate step assists on debugging)

@ -31,6 +31,7 @@ class RunningVMPlugin(MachineryPlugin):
""" Machine specific processing of configuration """
# TODO: Rename vagrantfilepath in the whole project
# TODO: Is this a copy&paste artefact ?
self.vagrantfilepath = os.path.abspath(self.config.vagrantfilepath())
self.vagrantfile = os.path.join(self.vagrantfilepath, "Vagrantfile")
if not os.path.isfile(self.vagrantfile):

Loading…
Cancel
Save