draft yaml parser
This commit is contained in:
@@ -17,17 +17,26 @@ game_config:
|
||||
- ref: client_1_green_user
|
||||
team: GREEN
|
||||
team: SCRIPTED_GREEN_<class>
|
||||
observation_space:
|
||||
...
|
||||
observation_space: null
|
||||
action_space:
|
||||
...
|
||||
reward_function:
|
||||
- type: null_reward
|
||||
# node_ref: client_1
|
||||
# service: WebBrowser
|
||||
# pol:
|
||||
# - step: 1
|
||||
# action: START
|
||||
actions:
|
||||
- type: DONOTHING
|
||||
nodes:
|
||||
- ref: client_2
|
||||
actions:
|
||||
- type: LOGON
|
||||
- type: LOGOFF
|
||||
applications:
|
||||
- ref: client_2_web_browser
|
||||
actions:
|
||||
- type: EXECUTE
|
||||
execution_definition:
|
||||
target_address: arcd.com
|
||||
reward_function: null
|
||||
agent_settings:
|
||||
start_step: 5
|
||||
frequency: 4
|
||||
variance: 3
|
||||
|
||||
- ref: client_1_data_manipulation_red_bot
|
||||
team: RED
|
||||
@@ -36,38 +45,37 @@ game_config:
|
||||
network:
|
||||
nodes:
|
||||
- ref: client_1
|
||||
observations:
|
||||
- logon_status
|
||||
- operating_status
|
||||
services:
|
||||
- ref: data_manipulation_bot
|
||||
observations:
|
||||
- operating_status
|
||||
- health_status
|
||||
folders:
|
||||
files: {}
|
||||
nics: {}
|
||||
|
||||
folders: {}
|
||||
action_space:
|
||||
actions:
|
||||
- DO_NOTHING
|
||||
- type: DO_NOTHING
|
||||
network:
|
||||
nodes:
|
||||
- ref: client_1
|
||||
- ref: client_1
|
||||
actions:
|
||||
- type: SCAN
|
||||
- type: LOGON
|
||||
- type: LOGOFF
|
||||
services:
|
||||
- ref: data_manipulation_bot
|
||||
actions:
|
||||
- SCAN
|
||||
- LOGON
|
||||
- LOGOFF
|
||||
services:
|
||||
- ref: data_manipulation_bot
|
||||
actions:
|
||||
- type: COMPROMISE
|
||||
execution_definition:
|
||||
server_ip: 192.168.1.14
|
||||
payload: "DROP TABLE IF EXISTS user;"
|
||||
success_rate: 80%
|
||||
folders:
|
||||
files: {}
|
||||
- type: COMPROMISE
|
||||
execution_definition:
|
||||
server_ip: 192.168.1.14
|
||||
payload: "DROP TABLE IF EXISTS user;"
|
||||
success_rate: 80%
|
||||
folders:
|
||||
files: {}
|
||||
reward_function: null
|
||||
options: # options specific to this particular agent type, basically args of __init__(self)
|
||||
agent_settings: # options specific to this particular agent type, basically args of __init__(self)
|
||||
start_step: 25
|
||||
frequency: 20
|
||||
variance: 5
|
||||
@@ -81,11 +89,32 @@ game_config:
|
||||
observation_space:
|
||||
network:
|
||||
nodes:
|
||||
- ref: <noderef>
|
||||
- ref: router_1 #TODO: more sub-options here
|
||||
- ref: switch_1
|
||||
- ref: switch_2
|
||||
- ref: domain_controller
|
||||
- ref: web_server
|
||||
- ref: database_server
|
||||
- ref: backup_server
|
||||
- ref: security_suite
|
||||
- ref: client_1
|
||||
- ref: client_2
|
||||
links:
|
||||
- ref: ... #
|
||||
acl: ... #
|
||||
ics: ... #
|
||||
|
||||
|
||||
action_space:
|
||||
...
|
||||
actions:
|
||||
- type: DO_NOTHING
|
||||
network:
|
||||
nodes:
|
||||
- ref: router_1
|
||||
reward_function:
|
||||
...
|
||||
# ...
|
||||
agent_settings:
|
||||
# ...
|
||||
|
||||
|
||||
|
||||
@@ -173,7 +202,7 @@ simulation:
|
||||
|
||||
|
||||
- ref: backup_server
|
||||
type: node
|
||||
type: server
|
||||
hostname: backup_server
|
||||
ip_address: 192.168.1.16
|
||||
subnet_mask: 255.255.255.0
|
||||
@@ -199,7 +228,7 @@ simulation:
|
||||
- ref: client_1
|
||||
type: computer
|
||||
hostname: client_1
|
||||
ip_address: 192.168.10.21.
|
||||
ip_address: 192.168.10.21
|
||||
subnet_mask: 255.255.255.0
|
||||
default_gateway: 192.168.10.1
|
||||
dns_server: 192.168.1.10
|
||||
@@ -217,7 +246,7 @@ simulation:
|
||||
default_gateway: 192.168.10.1
|
||||
dns_server: 192.168.1.10
|
||||
services:
|
||||
- ref: web_browser
|
||||
- ref: client_2_web_browser
|
||||
type: web_browser
|
||||
- ref: client_2_dns_client
|
||||
type: dns_client
|
||||
|
||||
250
sandbox.ipynb
250
sandbox.ipynb
@@ -1,14 +1,31 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%load_ext autoreload\n",
|
||||
"%autoreload 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import yaml"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from primaite.simulator.network.networks import arcd_uc2_network\n",
|
||||
"%load_ext autoreload\n",
|
||||
"%autoreload 2"
|
||||
"from primaite.simulator.network.networks import arcd_uc2_network\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -62,31 +79,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2023-09-21 10:41:35,339: Added node f03fec1b-927d-4d5a-8de9-1ef426052932 to Network f7400348-31e5-440e-8eb5-42366326d9d1\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'health_status': 1}"
|
||||
]
|
||||
},
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from primaite.simulator.sim_container import Simulation\n",
|
||||
"from primaite.simulator.network.hardware.nodes.computer import Computer\n",
|
||||
"from primaite.game.actor.observations import FileObservation\n",
|
||||
"from primaite.game.actor.observations import FileObservation, FolderObservation\n",
|
||||
"\n",
|
||||
"sim = Simulation()\n",
|
||||
"pc = Computer(hostname=\"beep\", ip_address=\"123.123.123.123\", subnet_mask=\"255.255.255.0\")\n",
|
||||
@@ -96,28 +95,207 @@
|
||||
"state = sim.describe_state()\n",
|
||||
"\n",
|
||||
"dog_file_obs = FileObservation(where=['network','nodes',pc.uuid,'file_system', 'folders','root','files','dog.png'])\n",
|
||||
"o = dog_file_obs(state)\n",
|
||||
"o"
|
||||
"root_folder_obs = FolderObservation(where=['network','nodes',pc.uuid,'file_system', 'folders','root'],files=[dog_file_obs])\n",
|
||||
"print(dog_file_obs(state))\n",
|
||||
"print(root_folder_obs(state))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"dog_file_obs.space"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"root_folder_obs.space"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"state"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import yaml"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"with open('example_config.yaml', 'r') as file:\n",
|
||||
" conf = yaml.safe_load(file)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"conf['simulation']"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import yaml\n",
|
||||
"from primaite.simulator.sim_container import Simulation\n",
|
||||
"from primaite.simulator.network.hardware.nodes.computer import Computer\n",
|
||||
"from primaite.simulator.network.hardware.nodes.server import Server\n",
|
||||
"from primaite.simulator.network.hardware.nodes.switch import Switch\n",
|
||||
"from primaite.simulator.network.hardware.nodes.router import Router\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 33,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Dict(health_status:Discrete(6))"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2023-09-25 17:38:39,385: Added node b5486651-1c6f-449a-8019-6a3641cfb998 to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n",
|
||||
"2023-09-25 17:38:39,391: Added node 1533c2f7-389e-4e03-95b3-9cf059086490 to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n",
|
||||
"2023-09-25 17:38:39,395: Added node 6b6c3b24-61d4-46ac-9364-11d726e50ccb to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n",
|
||||
"2023-09-25 17:38:39,398: Added node a0bee8d0-2ab8-4e29-9a2c-23c6757b240c to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n",
|
||||
"2023-09-25 17:38:39,401: Added node 7cb2c102-62ba-4859-94f2-5d724de38733 to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n",
|
||||
"2023-09-25 17:38:39,403: Added node bec38db7-520e-4044-93db-08308278d66f to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n",
|
||||
"2023-09-25 17:38:39,407: Added node ae0c2253-3ec8-48c3-b5d2-0b37c19c885d to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"3\n",
|
||||
"3\n",
|
||||
"3\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dog_file_obs.space"
|
||||
"# import yaml\n",
|
||||
"\n",
|
||||
"from primaite.simulator.network.hardware.nodes.router import ACLAction\n",
|
||||
"from primaite.simulator.network.transmission.network_layer import IPProtocol\n",
|
||||
"from primaite.simulator.network.transmission.transport_layer import Port\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class PrimaiteSession:\n",
|
||||
"\n",
|
||||
" def __init__(self):\n",
|
||||
" self.simulation: Simulation\n",
|
||||
" self.agents = []\n",
|
||||
"\n",
|
||||
" @classmethod\n",
|
||||
" def from_config(cls, cfg_path):\n",
|
||||
" ref_to_uuid = {}\n",
|
||||
"\n",
|
||||
" game = cls()\n",
|
||||
" with open(cfg_path, 'r') as file:\n",
|
||||
" conf = yaml.safe_load(file)\n",
|
||||
" \n",
|
||||
" #1. create nodes \n",
|
||||
" sim = Simulation()\n",
|
||||
" net = sim.network\n",
|
||||
" nodes_cfg = conf['simulation']['network']['nodes']\n",
|
||||
" links_cfg = conf['simulation']['network']['links']\n",
|
||||
" for node_cfg in nodes_cfg:\n",
|
||||
" ref = node_cfg['ref']\n",
|
||||
" n_type = node_cfg['type']\n",
|
||||
" if n_type == 'computer':\n",
|
||||
" new_node = Computer(hostname = node_cfg['hostname'], \n",
|
||||
" ip_address = node_cfg['ip_address'], \n",
|
||||
" subnet_mask = node_cfg['subnet_mask'], \n",
|
||||
" default_gateway = node_cfg['default_gateway'],\n",
|
||||
" dns_server = node_cfg['dns_server'])\n",
|
||||
" elif n_type == 'server':\n",
|
||||
" new_node = Server(hostname = node_cfg['hostname'], \n",
|
||||
" ip_address = node_cfg['ip_address'], \n",
|
||||
" subnet_mask = node_cfg['subnet_mask'], \n",
|
||||
" default_gateway = node_cfg['default_gateway'],\n",
|
||||
" dns_server = node_cfg.get('dns_server'))\n",
|
||||
" elif n_type == 'switch':\n",
|
||||
" new_node = Switch(hostname = node_cfg['hostname'],\n",
|
||||
" num_ports = node_cfg.get('num_ports'))\n",
|
||||
" elif n_type == 'router':\n",
|
||||
" new_node = Router(hostname=node_cfg['hostname'],\n",
|
||||
" num_ports = node_cfg.get('num_ports'))\n",
|
||||
" if 'ports' in node_cfg:\n",
|
||||
" for port_num, port_cfg in node_cfg['ports'].items():\n",
|
||||
" new_node.configure_port(port=port_num, \n",
|
||||
" ip_address=port_cfg['ip_address'],\n",
|
||||
" subnet_mask=port_cfg['subnet_mask'])\n",
|
||||
" if 'acl' in node_cfg:\n",
|
||||
" for r_num, r_cfg in node_cfg['acl'].items():\n",
|
||||
" new_node.acl.add_rule(\n",
|
||||
" action = ACLAction[r_cfg['action']],\n",
|
||||
" src_port = Port[r_cfg.get('port')],\n",
|
||||
" dst_port = Port[r_cfg.get('port')],\n",
|
||||
" protocol = IPProtocol[r_cfg.get('protocol')],\n",
|
||||
" src_ip = r_cfg.get('ip_address'),\n",
|
||||
" dst_ip = r_cfg.get('ip_address'),\n",
|
||||
" position = r_num\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" try:\n",
|
||||
" net.add_node(new_node)\n",
|
||||
" ref_to_uuid[ref] = new_node.uuid\n",
|
||||
" except BaseException:\n",
|
||||
" print(3)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" #2. start/setup simulation objects\n",
|
||||
" #3. create agents\n",
|
||||
" #4. set up agents' actions and observation spaces.\n",
|
||||
" game.simulation = sim\n",
|
||||
" return game\n",
|
||||
"\n",
|
||||
"s = PrimaiteSession.from_config('example_config.yaml')\n",
|
||||
"# print(s.simulation.describe_state())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'uuid': 'ceeb8791-b140-43d0-b59e-c3c3f533309b', 'network': {'uuid': 'ff176601-4e1d-4f89-8db4-33c0598ee105', 'nodes': {'6b9afe70-913b-40ce-9cee-1ee3648e43ce': {'uuid': '6b9afe70-913b-40ce-9cee-1ee3648e43ce', 'hostname': 'client_1', 'operating_state': 2, 'NICs': {'108c797d-32ca-4e93-8476-6b13cda6cf37': {'uuid': '108c797d-32ca-4e93-8476-6b13cda6cf37', 'ip_adress': '192.168.10.21', 'subnet_mask': '255.255.255.0', 'mac_address': 'af:5f:0c:00:d3:63', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '32062959-b2ed-4d24-b5a9-7e99b7ebfcfe', 'folders': {'root': {'uuid': '8876d59b-d46d-414d-9ae2-5e948f65b175', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, '227d1fb7-fc64-4273-9817-0f32280a0859': {'uuid': '227d1fb7-fc64-4273-9817-0f32280a0859', 'hostname': 'client_2', 'operating_state': 2, 'NICs': {'22119571-b47d-4ffb-998c-62173c670f78': {'uuid': '22119571-b47d-4ffb-998c-62173c670f78', 'ip_adress': '192.168.10.22', 'subnet_mask': '255.255.255.0', 'mac_address': '7c:fe:81:20:96:96', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '1a6eb561-c7fc-40f0-a288-d56af08c8f0c', 'folders': {'root': {'uuid': 'd129d4a6-5098-41ee-b9b3-033895a2288c', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}}, 'links': {}}, 'domain': {'uuid': 'db0e6d12-7cc6-4828-ba9b-4110e7f14bc2', 'accounts': {}}}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(s.simulation.describe_state())"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user