Basic working config verifier. Not yet wired in or prepared for documentation

pull/14/head
Thorsten Sick 3 years ago
parent b1e13da419
commit 5dfd9d6a12

@ -0,0 +1,90 @@
#!/usr/bin/env python3
""" Pydantic verifier for config structure """
from pydantic.dataclasses import dataclass
from pydantic import conlist, BaseModel
from typing import Literal, Optional, TypedDict, Union
from enum import Enum
class OSEnum(str, Enum):
linux = "linux"
windows = "windows"
@dataclass
class CalderaConfig:
apikey: str
@dataclass
class Attacker:
name: str
vm_controller: dict
vm_name: str
machinepath: str
os: OSEnum
use_existing_machine: bool = False
@dataclass
class VMController:
type: str
vagrantfilepath: str
ip: Optional[str] = ""
@dataclass
class Target:
name: str
vm_controller: VMController
vm_name: str
os: OSEnum
paw: str
group: str
machinepath: str
sensors: Optional[list[str]]
active: bool = True
use_existing_machine: bool = False
playground: Optional[str] = None
halt_needs_force: Optional[str] = None
ssh_user: Optional[str] = None
ssh_password: Optional[str] = None
ssh_keyfile: Optional[str] = None
vulnerabilities: list[str] = None
@dataclass
class AttackConfig:
nap_time: int
caldera_obfuscator: str
caldera_jitter: str
@dataclass
class AttackList:
linux: Optional[list[str]]
windows: Optional[list[str]]
@dataclass
class Results:
loot_dir: str
@dataclass
class MainConfig():
caldera: CalderaConfig
attackers: conlist(Attacker, min_items=1)
targets: conlist(Target, min_items=1)
attacks: AttackConfig
caldera_attacks: AttackList
plugin_based_attacks: AttackList
results: Results
# Free form configuration for plugins
attack_conf: dict
sensor_conf: dict
# TODO: Check for name duplication

@ -0,0 +1,27 @@
#!/usr/bin/env python3
import argparse
import yaml
from app.config_verifier import MainConfig
def load(filename):
with open(filename) as fh:
data = yaml.safe_load(fh)
return MainConfig(**data)
def create_parser():
""" Creates the parser for the command line arguments"""
parser = argparse.ArgumentParser("Parse a config file and verifies it")
parser.add_argument('--filename', default="experiment_ng.yaml")
return parser
if __name__ == "__main__":
arguments = create_parser().parse_args()
r = load(arguments.filename)
print(r)
print(r.caldera.apikey)

@ -3,21 +3,25 @@ fabric==2.6.0
requests==2.25.1
simplejson==3.17.2
tox==3.22.0
sphinx-argparse==0.2.5
sphinxcontrib-autoyaml==0.6.1
sphinx-pyreverse==0.0.13
coverage==5.4
PyYAML==5.4.1
straight.plugin==1.5.0
sphinxcontrib.asciinema==0.3.2
paramiko==2.7.2
pymetasploit3==1.0.3
pylint
flask
pylint==2.9.3
flask==2.0.2
pydantic==1.8.2
# Sphinx stuff
sphinx-argparse==0.2.5
sphinxcontrib-autoyaml==0.6.1
sphinx-pyreverse==0.0.13
sphinxcontrib.asciinema==0.3.2
sphinx-pydantic
# Mypy stuff
mypy
types-PyYAML
types-requests
types-simplejson
types-paramiko
mypy==0.910
types-PyYAML==5.4.6
types-requests==2.25.6
types-simplejson==3.17.0
types-paramiko==2.7.0

Loading…
Cancel
Save