Files
PrimAITE/src/primaite/simulator/_package_data/create-simulation_demo.ipynb

805 lines
44 KiB
Plaintext
Raw Normal View History

2023-08-17 15:32:12 +01:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-08-20 18:43:21 +01:00
"# Build a simulation using the Python API\n",
"\n",
"Currently, this notbook manipulates the simulation by directly placing objects inside of the attributes of the network and domain. It should be refactored when proper methods exist for adding these objects.\n"
2023-08-17 15:32:12 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Import the Simulation class"
]
},
{
"cell_type": "code",
"execution_count": 119,
2023-08-17 15:32:12 +01:00
"metadata": {},
"outputs": [],
"source": [
"from primaite.simulator.sim_container import Simulation\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create an empty simulation. By default this has a network with no nodes or links, and a domain controller with no accounts.\n",
"\n",
"Let's use the simulation's `describe_state()` method to verify that it is empty."
]
},
{
"cell_type": "code",
"execution_count": 120,
2023-08-17 15:32:12 +01:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'uuid': '42d005b2-4dc8-4aec-be54-3493242eee32',\n",
" 'network': {'uuid': '069f61a4-ac40-431f-ad13-2fc9b26dc091',\n",
" 'nodes': {},\n",
" 'links': {}},\n",
" 'domain': {'uuid': 'f0629156-e9af-493d-b098-f47d73126122', 'accounts': {}}}"
]
},
"execution_count": 120,
"metadata": {},
"output_type": "execute_result"
}
],
2023-08-17 15:32:12 +01:00
"source": [
"my_sim = Simulation()\n",
"net = my_sim.network\n",
2023-08-17 15:32:12 +01:00
"my_sim.describe_state()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add nodes"
]
},
{
"cell_type": "code",
"execution_count": 121,
2023-08-17 15:32:12 +01:00
"metadata": {},
"outputs": [],
"source": [
"from primaite.simulator.network.hardware.nodes.host.computer import Computer\n",
"from primaite.simulator.network.hardware.nodes.host.server import Server"
2023-08-17 15:32:12 +01:00
]
},
{
"cell_type": "code",
"execution_count": 122,
2023-08-17 15:32:12 +01:00
"metadata": {},
2023-08-20 18:43:21 +01:00
"outputs": [],
2023-08-17 15:32:12 +01:00
"source": [
"my_pc = Computer(hostname=\"primaite_pc\", ip_address=\"192.168.1.10\", subnet_mask=\"255.255.255.0\")\n",
"net.add_node(my_pc)\n",
"my_server = Server(hostname=\"google_server\", ip_address=\"192.168.1.11\", subnet_mask=\"255.255.255.0\")\n",
"net.add_node(my_server)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Connect the nodes"
]
},
{
"cell_type": "code",
"execution_count": 123,
"metadata": {},
"outputs": [],
"source": [
"from primaite.simulator.network.hardware.nodes.host.host_node import NIC\n",
"from primaite.simulator.network.hardware.nodes.network.switch import Switch\n"
]
},
{
"cell_type": "code",
"execution_count": 124,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Link(uuid='42b8f911-3640-4ccb-b277-b48b294a1fc8', endpoint_a=NIC(ip_address=IPv4Address('130.1.1.2'), subnet_mask=IPv4Address('255.255.255.0'), uuid='53993d8f-216e-4c00-9b03-c6bb9e2437b5', mac_address='17:9d:82:db:ca:c8', speed=100, mtu=1500, enabled=False, port_num=2, port_name=None, pcap=None, nmne={}, wake_on_lan=False, gateway='130.1.1.255'), endpoint_b=SwitchPort(uuid='c03d4d22-f309-49b6-a1ad-45a04c40d25e', mac_address='84:01:f3:bb:47:1c', speed=100, mtu=1500, enabled=False, port_num=2, port_name=None, pcap=None, nmne={}), bandwidth=100.0, current_load=0.0)"
]
},
"execution_count": 124,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_switch = Switch(hostname=\"switch1\", num_ports=12)\n",
"net.add_node(my_switch)\n",
"\n",
"pc_nic = NIC(ip_address=\"130.1.1.1\", gateway=\"130.1.1.255\", subnet_mask=\"255.255.255.0\")\n",
"my_pc.connect_nic(pc_nic)\n",
"\n",
"server_nic = NIC(ip_address=\"130.1.1.2\", gateway=\"130.1.1.255\", subnet_mask=\"255.255.255.0\")\n",
"my_server.connect_nic(server_nic)\n",
"\n",
"net.connect(pc_nic, my_switch.network_interface[1])\n",
"net.connect(server_nic, my_switch.network_interface[2])\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add files and folders to nodes\n"
]
},
{
"cell_type": "code",
"execution_count": 125,
"metadata": {},
"outputs": [],
"source": [
"from primaite.simulator.file_system.file_type import FileType\n",
"from primaite.simulator.file_system.file_system import File\n",
"from primaite.simulator.system.core.sys_log import SysLog"
]
},
{
"cell_type": "code",
"execution_count": 126,
"metadata": {},
"outputs": [],
"source": [
"my_pc_downloads_folder = my_pc.file_system.create_folder(\"downloads\")\n",
"my_pc_downloads_folder.add_file(File(name=\"firefox_installer.zip\",folder_id=\"Test\", folder_name=\"downloads\" ,file_type=FileType.ZIP, sys_log=SysLog(hostname=\"Test\")))"
]
},
{
"cell_type": "code",
"execution_count": 127,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"File(uuid='24789051-6762-48f4-8a56-c28882374273', name='favicon.ico', health_status=<FileSystemItemHealthStatus.GOOD: 1>, visible_health_status=<FileSystemItemHealthStatus.GOOD: 1>, previous_hash=None, revealed_to_red=False, sys_log=<primaite.simulator.system.core.sys_log.SysLog object at 0x000002923D79AC50>, deleted=False, folder_id='7a86576b-607f-468b-826f-4834cf2b3511', folder_name='root', file_type=<FileType.UNKNOWN: 0>, sim_size=0, real=False, sim_path=None, sim_root=WindowsPath('C:/Projects/PrimAITE/simulation_output/2024-04-08_12-19-36/google_server/fs'), num_access=0, folder=Folder(uuid='7a86576b-607f-468b-826f-4834cf2b3511', name='root', health_status=<FileSystemItemHealthStatus.GOOD: 1>, visible_health_status=<FileSystemItemHealthStatus.GOOD: 1>, previous_hash=None, revealed_to_red=False, sys_log=<primaite.simulator.system.core.sys_log.SysLog object at 0x000002923D79AC50>, deleted=False, files={'24789051-6762-48f4-8a56-c28882374273': File(uuid='24789051-6762-48f4-8a56-c28882374273', name='favicon.ico', health_status=<FileSystemItemHealthStatus.GOOD: 1>, visible_health_status=<FileSystemItemHealthStatus.GOOD: 1>, previous_hash=None, revealed_to_red=False, sys_log=<primaite.simulator.system.core.sys_log.SysLog object at 0x000002923D79AC50>, deleted=False, folder_id='7a86576b-607f-468b-826f-4834cf2b3511', folder_name='root', file_type=<FileType.UNKNOWN: 0>, sim_size=0, real=False, sim_path=None, sim_root=WindowsPath('C:/Projects/PrimAITE/simulation_output/2024-04-08_12-19-36/google_server/fs'), num_access=0, folder=Folder(uuid='7a86576b-607f-468b-826f-4834cf2b3511', name='root', health_status=<FileSystemItemHealthStatus.GOOD: 1>, visible_health_status=<FileSystemItemHealthStatus.GOOD: 1>, previous_hash=None, revealed_to_red=False, sys_log=<primaite.simulator.system.core.sys_log.SysLog object at 0x000002923D79AC50>, deleted=False, files={...}, deleted_files={}, scan_duration=3, scan_countdown=0, red_scan_duration=3, red_scan_countdown=0, restore_duration=3, restore_countdown=0))}, deleted_files={}, scan_duration=3, scan_countdown=0, red_scan_duration=3, red_scan_countdown=0, restore_duration=3, restore_countdown=0))"
]
},
"execution_count": 127,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_server_folder = my_server.file_system.create_folder(\"static\")\n",
"my_server.file_system.create_file(\"favicon.ico\", file_type=FileType.PNG)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add applications to nodes"
]
},
{
"cell_type": "code",
"execution_count": 128,
"metadata": {},
"outputs": [],
"source": [
"from primaite.simulator.system.applications.application import Application, ApplicationOperatingState\n",
"from primaite.simulator.system.software import SoftwareHealthState, SoftwareCriticality\n",
"from primaite.simulator.network.transmission.transport_layer import Port\n",
"from primaite.simulator.network.transmission.network_layer import IPProtocol\n",
"from primaite.simulator.file_system.file_system import FileSystem\n",
"from pathlib import Path\n",
"\n",
2023-08-20 18:43:21 +01:00
"# no applications exist yet so we will create our own.\n",
"class MSPaint(Application):\n",
" def describe_state(self):\n",
" return super().describe_state()"
]
},
{
"cell_type": "code",
"execution_count": 129,
"metadata": {},
"outputs": [],
"source": [
"mspaint = MSPaint(name = \"mspaint\", health_state_actual=SoftwareHealthState.GOOD, health_state_visible=SoftwareHealthState.GOOD, criticality=SoftwareCriticality.MEDIUM, port=Port.HTTP, protocol = IPProtocol.NONE,operating_state=ApplicationOperatingState.RUNNING,execution_control_status='manual', file_system=FileSystem(sys_log=SysLog(hostname=\"Test\"), sim_root=Path(__name__).parent),)"
]
},
{
"cell_type": "code",
"execution_count": 130,
"metadata": {},
"outputs": [],
"source": [
"my_pc.applications[mspaint.uuid] = mspaint"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create a domain account"
]
},
{
"cell_type": "code",
"execution_count": 131,
"metadata": {},
"outputs": [],
"source": [
"from primaite.simulator.domain.account import Account, AccountType\n"
]
},
{
"cell_type": "code",
"execution_count": 132,
"metadata": {},
"outputs": [],
"source": [
"acct = Account(username=\"admin\", password=\"admin12\", account_type=AccountType.USER)\n",
"my_sim.domain.accounts[acct.uuid] = acct"
]
},
2023-08-20 18:43:21 +01:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Verify that the state dictionary contains no non-serialisable objects."
]
},
{
"cell_type": "code",
"execution_count": 133,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'uuid': '42d005b2-4dc8-4aec-be54-3493242eee32',\n",
" 'network': {'uuid': '069f61a4-ac40-431f-ad13-2fc9b26dc091',\n",
" 'nodes': {'primaite_pc': {'uuid': '52246eed-9a3f-4b19-ad0c-48fc3bbb998d',\n",
" 'hostname': 'primaite_pc',\n",
" 'operating_state': 2,\n",
" 'NICs': {1: {'uuid': '73dcb42e-7db4-45cf-b439-9b8066c8e32e',\n",
" 'mac_address': 'c9:84:ec:48:87:77',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {},\n",
" 'ip_address': '192.168.1.10',\n",
" 'subnet_mask': '255.255.255.0',\n",
" 'wake_on_lan': False},\n",
" 2: {'uuid': 'e0fbda66-afcb-4a79-b696-aad0778279a2',\n",
" 'mac_address': 'cb:66:8b:b2:dc:51',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {},\n",
" 'ip_address': '130.1.1.1',\n",
" 'subnet_mask': '255.255.255.0',\n",
" 'wake_on_lan': False}},\n",
" 'file_system': {'uuid': '8a857927-dd5e-40e9-86fd-1df8b3a2b463',\n",
" 'folders': {'root': {'uuid': 'acb725c9-461e-40c5-b2c0-ed198865e1f2',\n",
" 'name': 'root',\n",
" 'health_status': 1,\n",
" 'visible_status': 1,\n",
" 'previous_hash': None,\n",
" 'revealed_to_red': False,\n",
" 'files': {},\n",
" 'deleted_files': {}},\n",
" 'downloads': {'uuid': '484f7bcf-b8da-4995-8538-82b2a4d059c7',\n",
" 'name': 'downloads',\n",
" 'health_status': 1,\n",
" 'visible_status': 1,\n",
" 'previous_hash': None,\n",
" 'revealed_to_red': False,\n",
" 'files': {'firefox_installer.zip': {'uuid': '5e1e5bec-a984-4ae1-9799-78083bd2e3c2',\n",
" 'name': 'firefox_installer.zip',\n",
" 'health_status': 1,\n",
" 'visible_status': 1,\n",
" 'previous_hash': None,\n",
" 'revealed_to_red': False,\n",
" 'size': 1024000,\n",
" 'file_type': 'ZIP',\n",
" 'num_access': 0}},\n",
" 'deleted_files': {}}},\n",
" 'deleted_folders': {},\n",
" 'num_file_creations': 0,\n",
" 'num_file_deletions': 0},\n",
" 'applications': {'WebBrowser': {'uuid': '5987fc38-686d-439f-b513-23166884596e',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 80,\n",
" 'operating_state': 2,\n",
" 'execution_control_status': 'manual',\n",
" 'num_executions': 0,\n",
" 'groups': [],\n",
" 'history': []},\n",
" 'mspaint': {'uuid': '88eb36c5-dba4-4f79-ad95-5957f7de3fa2',\n",
" 'health_state_actual': 1,\n",
" 'health_state_visible': 1,\n",
" 'criticality': 3,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 80,\n",
" 'operating_state': 1,\n",
" 'execution_control_status': 'manual',\n",
" 'num_executions': 0,\n",
" 'groups': []}},\n",
" 'services': {'ARP': {'uuid': 'e220dde6-88d5-4e24-a2de-5bce0cd4a916',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 219,\n",
" 'operating_state': 2},\n",
" 'ICMP': {'uuid': 'ef728c73-97b7-480f-bedb-04dc3d5efd57',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 0,\n",
" 'operating_state': 2},\n",
" 'DNSClient': {'uuid': '30b159f1-a4e8-41f5-923b-c692d104f385',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 53,\n",
" 'operating_state': 2},\n",
" 'FTPClient': {'uuid': '5f267d5f-6bb8-4e97-b6b9-855ee2d50c25',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 21,\n",
" 'operating_state': 2},\n",
" 'NTPClient': {'uuid': '1ea99f1e-dc04-4548-a384-913851a7e4fd',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 123,\n",
" 'operating_state': 2}},\n",
" 'process': {},\n",
" 'revealed_to_red': False},\n",
" 'google_server': {'uuid': 'b9a41d9c-6642-441b-8049-8302ddafd3b1',\n",
" 'hostname': 'google_server',\n",
" 'operating_state': 2,\n",
" 'NICs': {1: {'uuid': 'd0736beb-085a-4754-8b44-de73e6a8c80f',\n",
" 'mac_address': '45:27:ed:64:ac:09',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {},\n",
" 'ip_address': '192.168.1.11',\n",
" 'subnet_mask': '255.255.255.0',\n",
" 'wake_on_lan': False},\n",
" 2: {'uuid': '53993d8f-216e-4c00-9b03-c6bb9e2437b5',\n",
" 'mac_address': '17:9d:82:db:ca:c8',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {},\n",
" 'ip_address': '130.1.1.2',\n",
" 'subnet_mask': '255.255.255.0',\n",
" 'wake_on_lan': False}},\n",
" 'file_system': {'uuid': '8d4ded3a-56bb-46f0-ad7f-40d65b523581',\n",
" 'folders': {'root': {'uuid': '7a86576b-607f-468b-826f-4834cf2b3511',\n",
" 'name': 'root',\n",
" 'health_status': 1,\n",
" 'visible_status': 1,\n",
" 'previous_hash': None,\n",
" 'revealed_to_red': False,\n",
" 'files': {'favicon.ico': {'uuid': '24789051-6762-48f4-8a56-c28882374273',\n",
" 'name': 'favicon.ico',\n",
" 'health_status': 1,\n",
" 'visible_status': 1,\n",
" 'previous_hash': None,\n",
" 'revealed_to_red': False,\n",
" 'size': 0,\n",
" 'file_type': 'UNKNOWN',\n",
" 'num_access': 0}},\n",
" 'deleted_files': {}},\n",
" 'static': {'uuid': '154b2ad3-e43d-4924-b758-e11db0e176de',\n",
" 'name': 'static',\n",
" 'health_status': 1,\n",
" 'visible_status': 1,\n",
" 'previous_hash': None,\n",
" 'revealed_to_red': False,\n",
" 'files': {},\n",
" 'deleted_files': {}}},\n",
" 'deleted_folders': {},\n",
" 'num_file_creations': 1,\n",
" 'num_file_deletions': 0},\n",
" 'applications': {'WebBrowser': {'uuid': '9b368321-e22d-4e35-9395-80632492c20a',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 80,\n",
" 'operating_state': 2,\n",
" 'execution_control_status': 'manual',\n",
" 'num_executions': 0,\n",
" 'groups': [],\n",
" 'history': []}},\n",
" 'services': {'ARP': {'uuid': '30df82c0-5823-4464-8c23-5b99922f98f7',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 219,\n",
" 'operating_state': 2},\n",
" 'ICMP': {'uuid': '2d02a2de-7ec8-4da1-9538-c85eb397d4e3',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 0,\n",
" 'operating_state': 2},\n",
" 'DNSClient': {'uuid': 'db979263-ff81-4a04-95e8-d94442e9ddfa',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 53,\n",
" 'operating_state': 2},\n",
" 'FTPClient': {'uuid': 'd9d6417b-d1e0-416b-a711-3478fa248194',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 21,\n",
" 'operating_state': 2},\n",
" 'NTPClient': {'uuid': 'b23a1032-a817-492b-bdd6-2ecc6fb4591c',\n",
" 'health_state_actual': 0,\n",
" 'health_state_visible': 0,\n",
" 'criticality': 1,\n",
" 'fixing_count': 0,\n",
" 'scanning_count': 0,\n",
" 'revealed_to_red': False,\n",
" 'installing_count': 0,\n",
" 'max_sessions': 100,\n",
" 'tcp': True,\n",
" 'udp': True,\n",
" 'port': 123,\n",
" 'operating_state': 2}},\n",
" 'process': {},\n",
" 'revealed_to_red': False},\n",
" 'switch1': {'uuid': 'e658eac3-c4b8-4768-bf27-e2d90b7f57c0',\n",
" 'hostname': 'switch1',\n",
" 'operating_state': 2,\n",
" 'NICs': {1: {'uuid': '7ebc80f5-902f-4253-8ea6-0cafa3d1cccd',\n",
" 'mac_address': 'df:d2:c7:2a:a1:52',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 2: {'uuid': 'c03d4d22-f309-49b6-a1ad-45a04c40d25e',\n",
" 'mac_address': '84:01:f3:bb:47:1c',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 3: {'uuid': '4207353c-e0cd-456d-89fe-13ddfc605cff',\n",
" 'mac_address': '8b:31:ac:cc:05:c9',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 4: {'uuid': '8aa1395f-e360-48a7-be97-ed1a5ca191ae',\n",
" 'mac_address': '75:3c:ae:bd:3a:b5',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 5: {'uuid': '8b5d575c-ab0c-43ac-abfc-fa5ae75183e5',\n",
" 'mac_address': 'e7:7f:c4:af:8e:5b',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 6: {'uuid': '9d3cd584-f684-4f2e-9c8a-423d859fe3d3',\n",
" 'mac_address': '48:cf:18:8d:92:80',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 7: {'uuid': 'd42338bb-d579-483d-9e05-0318e17e574a',\n",
" 'mac_address': 'c6:99:5c:41:13:d7',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 8: {'uuid': '55bbd70b-491d-4452-8326-390ec3fadc28',\n",
" 'mac_address': '81:ab:39:0c:a2:dd',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 9: {'uuid': '0755d768-79c7-48cf-9220-d2dad32e574b',\n",
" 'mac_address': '62:35:0c:5e:cc:5d',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 10: {'uuid': 'deaecc57-ec76-4e27-a37e-f66964901b03',\n",
" 'mac_address': '51:26:00:c6:7e:ac',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 11: {'uuid': '53fe318c-4969-42fe-920b-37a491f54d84',\n",
" 'mac_address': '35:59:c7:13:ab:a5',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 12: {'uuid': '5a81caa0-9d91-4a86-9bd4-4ecb589c70ae',\n",
" 'mac_address': '7a:6b:ec:15:1e:de',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}}},\n",
" 'file_system': {'uuid': '289bea1e-69bf-44d5-80fe-212dad8afcd5',\n",
" 'folders': {'root': {'uuid': '3b588b3c-bc4a-4c06-a688-eced0128b128',\n",
" 'name': 'root',\n",
" 'health_status': 1,\n",
" 'visible_status': 1,\n",
" 'previous_hash': None,\n",
" 'revealed_to_red': False,\n",
" 'files': {},\n",
" 'deleted_files': {}}},\n",
" 'deleted_folders': {},\n",
" 'num_file_creations': 0,\n",
" 'num_file_deletions': 0},\n",
" 'applications': {},\n",
" 'services': {},\n",
" 'process': {},\n",
" 'revealed_to_red': False,\n",
" 'ports': {1: {'uuid': '7ebc80f5-902f-4253-8ea6-0cafa3d1cccd',\n",
" 'mac_address': 'df:d2:c7:2a:a1:52',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 2: {'uuid': 'c03d4d22-f309-49b6-a1ad-45a04c40d25e',\n",
" 'mac_address': '84:01:f3:bb:47:1c',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 3: {'uuid': '4207353c-e0cd-456d-89fe-13ddfc605cff',\n",
" 'mac_address': '8b:31:ac:cc:05:c9',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 4: {'uuid': '8aa1395f-e360-48a7-be97-ed1a5ca191ae',\n",
" 'mac_address': '75:3c:ae:bd:3a:b5',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 5: {'uuid': '8b5d575c-ab0c-43ac-abfc-fa5ae75183e5',\n",
" 'mac_address': 'e7:7f:c4:af:8e:5b',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 6: {'uuid': '9d3cd584-f684-4f2e-9c8a-423d859fe3d3',\n",
" 'mac_address': '48:cf:18:8d:92:80',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 7: {'uuid': 'd42338bb-d579-483d-9e05-0318e17e574a',\n",
" 'mac_address': 'c6:99:5c:41:13:d7',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 8: {'uuid': '55bbd70b-491d-4452-8326-390ec3fadc28',\n",
" 'mac_address': '81:ab:39:0c:a2:dd',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 9: {'uuid': '0755d768-79c7-48cf-9220-d2dad32e574b',\n",
" 'mac_address': '62:35:0c:5e:cc:5d',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 10: {'uuid': 'deaecc57-ec76-4e27-a37e-f66964901b03',\n",
" 'mac_address': '51:26:00:c6:7e:ac',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 11: {'uuid': '53fe318c-4969-42fe-920b-37a491f54d84',\n",
" 'mac_address': '35:59:c7:13:ab:a5',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}},\n",
" 12: {'uuid': '5a81caa0-9d91-4a86-9bd4-4ecb589c70ae',\n",
" 'mac_address': '7a:6b:ec:15:1e:de',\n",
" 'speed': 100,\n",
" 'mtu': 1500,\n",
" 'enabled': False,\n",
" 'nmne': {}}},\n",
" 'num_ports': 12,\n",
" 'mac_address_table': {}}},\n",
" 'links': {'primaite_pc:eth-2<->switch1:eth-1': {'uuid': '3d053257-7473-4a66-afbc-ee33a18f2e39',\n",
" 'endpoint_a': 'e0fbda66-afcb-4a79-b696-aad0778279a2',\n",
" 'endpoint_b': '7ebc80f5-902f-4253-8ea6-0cafa3d1cccd',\n",
" 'bandwidth': 100.0,\n",
" 'current_load': 0.0,\n",
" 'hostname_a': 'primaite_pc',\n",
" 'hostname_b': 'switch1',\n",
" 'port_a': 2,\n",
" 'port_b': 1},\n",
" 'google_server:eth-2<->switch1:eth-2': {'uuid': '42b8f911-3640-4ccb-b277-b48b294a1fc8',\n",
" 'endpoint_a': '53993d8f-216e-4c00-9b03-c6bb9e2437b5',\n",
" 'endpoint_b': 'c03d4d22-f309-49b6-a1ad-45a04c40d25e',\n",
" 'bandwidth': 100.0,\n",
" 'current_load': 0.0,\n",
" 'hostname_a': 'google_server',\n",
" 'hostname_b': 'switch1',\n",
" 'port_a': 2,\n",
" 'port_b': 2}}},\n",
" 'domain': {'uuid': 'f0629156-e9af-493d-b098-f47d73126122',\n",
" 'accounts': {'admin': {'uuid': 'b76653a9-d40e-483b-85a3-1b44628a11d0',\n",
" 'num_logons': 0,\n",
" 'num_logoffs': 0,\n",
" 'num_group_changes': 0,\n",
" 'username': 'admin',\n",
" 'password': 'admin12',\n",
" 'account_type': 2,\n",
" 'enabled': True}}}}"
]
},
"execution_count": 133,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2023-08-17 15:32:12 +01:00
"my_sim.describe_state()"
]
},
{
"cell_type": "code",
"execution_count": 134,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'{\"uuid\": \"42d005b2-4dc8-4aec-be54-3493242eee32\", \"network\": {\"uuid\": \"069f61a4-ac40-431f-ad13-2fc9b26dc091\", \"nodes\": {\"primaite_pc\": {\"uuid\": \"52246eed-9a3f-4b19-ad0c-48fc3bbb998d\", \"hostname\": \"primaite_pc\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"73dcb42e-7db4-45cf-b439-9b8066c8e32e\", \"mac_address\": \"c9:84:ec:48:87:77\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"192.168.1.10\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}, \"2\": {\"uuid\": \"e0fbda66-afcb-4a79-b696-aad0778279a2\", \"mac_address\": \"cb:66:8b:b2:dc:51\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}}, \"file_system\": {\"uuid\": \"8a857927-dd5e-40e9-86fd-1df8b3a2b463\", \"folders\": {\"root\": {\"uuid\": \"acb725c9-461e-40c5-b2c0-ed198865e1f2\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}, \"downloads\": {\"uuid\": \"484f7bcf-b8da-4995-8538-82b2a4d059c7\", \"name\": \"downloads\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {\"firefox_installer.zip\": {\"uuid\": \"5e1e5bec-a984-4ae1-9799-78083bd2e3c2\", \"name\": \"firefox_installer.zip\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"size\": 1024000, \"file_type\": \"ZIP\", \"num_access\": 0}}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 0, \"num_file_deletions\": 0}, \"applications\": {\"WebBrowser\": {\"uuid\": \"5987fc38-686d-439f-b513-23166884596e\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 2, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": [], \"history\": []}, \"mspaint\": {\"uuid\": \"88eb36c5-dba4-4f79-ad95-5957f7de3fa2\", \"health_state_actual\": 1, \"health_state_visible\": 1, \"criticality\": 3, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 1, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {\"ARP\": {\"uuid\": \"e220dde6-88d5-4e24-a2de-5bce0cd4a916\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 219, \"operating_state\": 2}, \"ICMP\": {\"uuid\": \"ef728c73-97b7-480f-bedb-04dc3d5efd57\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 0, \"operating_state\": 2}, \"DNSClient\": {\"uuid\": \"30b159f1-a4e8-41f5-923b-c692d104f385\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 53, \"operating_state\": 2}, \"FTPClient\": {\"uuid\": \"5f267d5f-6bb8-4e97-b6b9-855ee2d50c25\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 21, \"operating_state\": 2}, \"NTPClient\": {\"uuid\": \"1ea99f1e-dc04-4548-a384-913851a7e4fd\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_r
]
},
"execution_count": 134,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2023-08-20 18:43:21 +01:00
"import json\n",
"json.dumps(my_sim.describe_state())"
]
2023-08-17 15:32:12 +01:00
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
2023-08-17 15:32:12 +01:00
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}