forked from p15670423/monkey
Merge pull request #1025 from guardicore/config_template_to_file
Utility script for translating config templates to config files
This commit is contained in:
commit
728b26e87e
|
@ -1,4 +1,4 @@
|
|||
from envs.monkey_zoo.blackbox.island_configs.config_template import ConfigTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
# Disables a lot of config values not required for a specific feature test
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class Drupal(BaseTemplate):
|
||||
class Drupal(ConfigTemplate):
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
||||
config_values.update({
|
|
@ -1,7 +1,7 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.island_configs.config_template import ConfigTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class Elastic(ConfigTemplate):
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class Hadoop(BaseTemplate):
|
||||
class Hadoop(ConfigTemplate):
|
||||
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class Mssql(BaseTemplate):
|
||||
class Mssql(ConfigTemplate):
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
||||
config_values.update({
|
|
@ -1,4 +1,4 @@
|
|||
from envs.monkey_zoo.blackbox.island_configs.config_template import ConfigTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class Performance(ConfigTemplate):
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class ShellShock(BaseTemplate):
|
||||
class ShellShock(ConfigTemplate):
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
||||
config_values.update({
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class SmbMimikatz(BaseTemplate):
|
||||
class SmbMimikatz(ConfigTemplate):
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
||||
config_values.update({
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class SmbPth(BaseTemplate):
|
||||
class SmbPth(ConfigTemplate):
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
||||
config_value_list = {
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class Ssh(BaseTemplate):
|
||||
class Ssh(ConfigTemplate):
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
||||
config_values.update({
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class Struts2(BaseTemplate):
|
||||
class Struts2(ConfigTemplate):
|
||||
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class Tunneling(BaseTemplate):
|
||||
class Tunneling(ConfigTemplate):
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
||||
config_values.update({
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class Weblogic(BaseTemplate):
|
||||
class Weblogic(ConfigTemplate):
|
||||
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class WmiMimikatz(BaseTemplate):
|
||||
class WmiMimikatz(ConfigTemplate):
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
||||
config_values.update({
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class WmiPth(BaseTemplate):
|
||||
class WmiPth(ConfigTemplate):
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
||||
config_values.update({
|
|
@ -1,9 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_configs.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class Zerologon(BaseTemplate):
|
||||
class Zerologon(ConfigTemplate):
|
||||
|
||||
config_values = copy(BaseTemplate.config_values)
|
||||
|
|
@ -4,7 +4,7 @@ import dpath.util
|
|||
from typing_extensions import Type
|
||||
|
||||
from envs.monkey_zoo.blackbox.island_client.monkey_island_client import MonkeyIslandClient
|
||||
from envs.monkey_zoo.blackbox.island_configs.config_template import ConfigTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
|
||||
|
||||
class IslandConfigParser:
|
||||
|
|
|
@ -12,22 +12,22 @@ from envs.monkey_zoo.blackbox.island_client.island_config_parser import \
|
|||
IslandConfigParser
|
||||
from envs.monkey_zoo.blackbox.island_client.monkey_island_client import \
|
||||
MonkeyIslandClient
|
||||
from envs.monkey_zoo.blackbox.island_configs.config_template import ConfigTemplate
|
||||
from envs.monkey_zoo.blackbox.island_configs.drupal import Drupal
|
||||
from envs.monkey_zoo.blackbox.island_configs.elastic import Elastic
|
||||
from envs.monkey_zoo.blackbox.island_configs.hadoop import Hadoop
|
||||
from envs.monkey_zoo.blackbox.island_configs.mssql import Mssql
|
||||
from envs.monkey_zoo.blackbox.island_configs.performance import Performance
|
||||
from envs.monkey_zoo.blackbox.island_configs.shellshock import ShellShock
|
||||
from envs.monkey_zoo.blackbox.island_configs.smb_mimikatz import SmbMimikatz
|
||||
from envs.monkey_zoo.blackbox.island_configs.smb_pth import SmbPth
|
||||
from envs.monkey_zoo.blackbox.island_configs.ssh import Ssh
|
||||
from envs.monkey_zoo.blackbox.island_configs.struts2 import Struts2
|
||||
from envs.monkey_zoo.blackbox.island_configs.tunneling import Tunneling
|
||||
from envs.monkey_zoo.blackbox.island_configs.weblogic import Weblogic
|
||||
from envs.monkey_zoo.blackbox.island_configs.wmi_mimikatz import WmiMimikatz
|
||||
from envs.monkey_zoo.blackbox.island_configs.wmi_pth import WmiPth
|
||||
from envs.monkey_zoo.blackbox.island_configs.zerologon import Zerologon
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.drupal import Drupal
|
||||
from envs.monkey_zoo.blackbox.config_templates.elastic import Elastic
|
||||
from envs.monkey_zoo.blackbox.config_templates.hadoop import Hadoop
|
||||
from envs.monkey_zoo.blackbox.config_templates.mssql import Mssql
|
||||
from envs.monkey_zoo.blackbox.config_templates.performance import Performance
|
||||
from envs.monkey_zoo.blackbox.config_templates.shellshock import ShellShock
|
||||
from envs.monkey_zoo.blackbox.config_templates.smb_mimikatz import SmbMimikatz
|
||||
from envs.monkey_zoo.blackbox.config_templates.smb_pth import SmbPth
|
||||
from envs.monkey_zoo.blackbox.config_templates.ssh import Ssh
|
||||
from envs.monkey_zoo.blackbox.config_templates.struts2 import Struts2
|
||||
from envs.monkey_zoo.blackbox.config_templates.tunneling import Tunneling
|
||||
from envs.monkey_zoo.blackbox.config_templates.weblogic import Weblogic
|
||||
from envs.monkey_zoo.blackbox.config_templates.wmi_mimikatz import WmiMimikatz
|
||||
from envs.monkey_zoo.blackbox.config_templates.wmi_pth import WmiPth
|
||||
from envs.monkey_zoo.blackbox.config_templates.zerologon import Zerologon
|
||||
from envs.monkey_zoo.blackbox.log_handlers.test_logs_handler import \
|
||||
TestLogsHandler
|
||||
from envs.monkey_zoo.blackbox.tests.exploitation import ExploitationTest
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# BlackBox utility scripts
|
||||
|
||||
## Config generation script
|
||||
|
||||
This script is used to generate config files for manual tests.
|
||||
Config file will be generated according to the templates in `envs/monkey_zoo/blackbox/config_templates`.
|
||||
|
||||
Run `envs/monkey_zoo/blackbox/utils/config_generation_script.py island_ip:5000` to populate
|
||||
`envs/monkey_zoo/blackbox/utils/generated_configs` directory with configuration files.
|
|
@ -0,0 +1,78 @@
|
|||
import argparse
|
||||
import pathlib
|
||||
from typing import Type
|
||||
|
||||
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
|
||||
from envs.monkey_zoo.blackbox.config_templates.drupal import Drupal
|
||||
from envs.monkey_zoo.blackbox.config_templates.elastic import Elastic
|
||||
from envs.monkey_zoo.blackbox.config_templates.hadoop import Hadoop
|
||||
from envs.monkey_zoo.blackbox.config_templates.mssql import Mssql
|
||||
from envs.monkey_zoo.blackbox.config_templates.performance import Performance
|
||||
from envs.monkey_zoo.blackbox.config_templates.shellshock import ShellShock
|
||||
from envs.monkey_zoo.blackbox.config_templates.smb_mimikatz import SmbMimikatz
|
||||
from envs.monkey_zoo.blackbox.config_templates.smb_pth import SmbPth
|
||||
from envs.monkey_zoo.blackbox.config_templates.ssh import Ssh
|
||||
from envs.monkey_zoo.blackbox.config_templates.struts2 import Struts2
|
||||
from envs.monkey_zoo.blackbox.config_templates.tunneling import Tunneling
|
||||
from envs.monkey_zoo.blackbox.config_templates.weblogic import Weblogic
|
||||
from envs.monkey_zoo.blackbox.config_templates.wmi_mimikatz import WmiMimikatz
|
||||
from envs.monkey_zoo.blackbox.config_templates.wmi_pth import WmiPth
|
||||
from envs.monkey_zoo.blackbox.config_templates.zerologon import Zerologon
|
||||
from envs.monkey_zoo.blackbox.island_client.island_config_parser import (
|
||||
IslandConfigParser,
|
||||
)
|
||||
from envs.monkey_zoo.blackbox.island_client.monkey_island_client import (
|
||||
MonkeyIslandClient,
|
||||
)
|
||||
|
||||
DST_DIR_NAME = "generated_configs"
|
||||
DST_DIR_PATH = pathlib.Path(pathlib.Path(__file__).parent.absolute(), DST_DIR_NAME)
|
||||
|
||||
parser = argparse.ArgumentParser(description="Generate config files.")
|
||||
parser.add_argument(
|
||||
"island_ip",
|
||||
metavar="IP:PORT",
|
||||
help="Island endpoint. Example: 123.123.123.123:5000",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
island_client = MonkeyIslandClient(args.island_ip)
|
||||
|
||||
|
||||
CONFIG_TEMPLATES = [
|
||||
Elastic,
|
||||
Hadoop,
|
||||
Mssql,
|
||||
Performance,
|
||||
ShellShock,
|
||||
SmbMimikatz,
|
||||
SmbPth,
|
||||
Ssh,
|
||||
Struts2,
|
||||
Tunneling,
|
||||
Weblogic,
|
||||
WmiMimikatz,
|
||||
WmiPth,
|
||||
Zerologon,
|
||||
Drupal,
|
||||
]
|
||||
|
||||
|
||||
def generate_templates():
|
||||
for template in CONFIG_TEMPLATES:
|
||||
save_template_as_config(template)
|
||||
|
||||
|
||||
def save_template_as_config(template: Type[ConfigTemplate]):
|
||||
file_path = pathlib.Path(DST_DIR_PATH, f"{template.__name__}.conf")
|
||||
file_contents = IslandConfigParser.get_raw_config(template, island_client)
|
||||
save_to_file(file_path, file_contents)
|
||||
|
||||
|
||||
def save_to_file(file_path, contents):
|
||||
with open(file_path, "w") as file:
|
||||
file.write(contents)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
generate_templates()
|
|
@ -0,0 +1 @@
|
|||
.
|
Loading…
Reference in New Issue