fix type hints and describe state functions
This commit is contained in:
@@ -40,11 +40,11 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'uuid': '8d5cbb1b-aa9b-4f66-8b23-80d47755df69',\n",
|
||||
" 'network': {'uuid': 'd3569bc4-eeed-40b1-9c3c-0fe80b9bb11c',\n",
|
||||
"{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n",
|
||||
" 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n",
|
||||
" 'nodes': {},\n",
|
||||
" 'links': {}},\n",
|
||||
" 'domain': {'uuid': '4d4024ae-5948-4f07-aed9-d2315891cddc', 'accounts': {}}}"
|
||||
" 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912', 'accounts': {}}}"
|
||||
]
|
||||
},
|
||||
"execution_count": 2,
|
||||
@@ -81,19 +81,28 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'uuid': '8d5cbb1b-aa9b-4f66-8b23-80d47755df69',\n",
|
||||
" 'network': {'uuid': 'd3569bc4-eeed-40b1-9c3c-0fe80b9bb11c',\n",
|
||||
" 'nodes': {'5f596f4f-4d34-4d1c-9688-9a105e489444': {'uuid': '5f596f4f-4d34-4d1c-9688-9a105e489444',\n",
|
||||
"{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n",
|
||||
" 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n",
|
||||
" 'nodes': {'c7c91f06-f128-4891-84a2-83beceea3908': {'uuid': 'c7c91f06-f128-4891-84a2-83beceea3908',\n",
|
||||
" 'hostname': 'primaite_pc',\n",
|
||||
" 'operating_state': 0,\n",
|
||||
" 'NICs': {},\n",
|
||||
" 'file_system': {'uuid': 'dc1e7032-7dba-44d5-aedb-5da75ab1eccc',\n",
|
||||
" 'file_system': {'uuid': '04ffd1e8-dea7-47ad-a088-4856df055ed1',\n",
|
||||
" 'folders': {}},\n",
|
||||
" 'applications': {},\n",
|
||||
" 'services': {},\n",
|
||||
" 'process': {}},\n",
|
||||
" 'dfcc395a-93ff-4dd5-9684-c80c5885d827': {'uuid': 'dfcc395a-93ff-4dd5-9684-c80c5885d827',\n",
|
||||
" 'hostname': 'google_server',\n",
|
||||
" 'operating_state': 0,\n",
|
||||
" 'NICs': {},\n",
|
||||
" 'file_system': {'uuid': 'aea8f406-05de-4a02-b65f-972aa1fed70e',\n",
|
||||
" 'folders': {}},\n",
|
||||
" 'applications': {},\n",
|
||||
" 'services': {},\n",
|
||||
" 'process': {}}},\n",
|
||||
" 'links': {}},\n",
|
||||
" 'domain': {'uuid': '4d4024ae-5948-4f07-aed9-d2315891cddc', 'accounts': {}}}"
|
||||
" 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912', 'accounts': {}}}"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
@@ -103,16 +112,387 @@
|
||||
],
|
||||
"source": [
|
||||
"my_pc = Node(hostname=\"primaite_pc\",)\n",
|
||||
"my_server = Node(hostname=\"google_server\")\n",
|
||||
"\n",
|
||||
"# TODO: when there is a proper function for adding nodes, use it instead of manually adding.\n",
|
||||
"\n",
|
||||
"my_sim.network.nodes[my_pc.uuid] = my_pc\n",
|
||||
"my_sim.network.nodes[my_server.uuid] = my_server\n",
|
||||
"\n",
|
||||
"my_sim.describe_state()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Connect the nodes"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from primaite.simulator.network.hardware.base import NIC, Link, Switch\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2023-08-20 18:34:59,328: NIC c3:08:90:23:29:cb/130.1.1.1 connected to Link c3:08:90:23:29:cb/130.1.1.1<-->40:4a:3f:2e:ee:2e\n",
|
||||
"2023-08-20 18:34:59,329: SwitchPort 40:4a:3f:2e:ee:2e connected to Link c3:08:90:23:29:cb/130.1.1.1<-->40:4a:3f:2e:ee:2e\n",
|
||||
"2023-08-20 18:34:59,331: NIC 69:50:cb:76:22:10/130.1.1.2 connected to Link 69:50:cb:76:22:10/130.1.1.2<-->18:5e:49:ed:21:55\n",
|
||||
"2023-08-20 18:34:59,331: SwitchPort 18:5e:49:ed:21:55 connected to Link 69:50:cb:76:22:10/130.1.1.2<-->18:5e:49:ed:21:55\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"my_swtich = Switch(hostname=\"switch1\", num_ports=12)\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",
|
||||
"\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",
|
||||
"\n",
|
||||
"pc_to_switch = Link(endpoint_a=pc_nic, endpoint_b=my_swtich.switch_ports[1])\n",
|
||||
"server_to_swtich = Link(endpoint_a=server_nic, endpoint_b=my_swtich.switch_ports[2])\n",
|
||||
"\n",
|
||||
"my_sim.network.links[pc_to_switch.uuid] = pc_to_switch\n",
|
||||
"my_sim.network.links[server_to_swtich.uuid] = server_to_swtich"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n",
|
||||
" 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n",
|
||||
" 'nodes': {'c7c91f06-f128-4891-84a2-83beceea3908': {'uuid': 'c7c91f06-f128-4891-84a2-83beceea3908',\n",
|
||||
" 'hostname': 'primaite_pc',\n",
|
||||
" 'operating_state': 0,\n",
|
||||
" 'NICs': {'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2': {'uuid': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n",
|
||||
" 'ip_adress': '130.1.1.1',\n",
|
||||
" 'subnet_mask': '255.255.255.0',\n",
|
||||
" 'gateway': '130.1.1.255',\n",
|
||||
" 'mac_address': 'c3:08:90:23:29:cb',\n",
|
||||
" 'speed': 100,\n",
|
||||
" 'mtu': 1500,\n",
|
||||
" 'wake_on_lan': False,\n",
|
||||
" 'dns_servers': [],\n",
|
||||
" 'enabled': False}},\n",
|
||||
" 'file_system': {'uuid': '04ffd1e8-dea7-47ad-a088-4856df055ed1',\n",
|
||||
" 'folders': {}},\n",
|
||||
" 'applications': {},\n",
|
||||
" 'services': {},\n",
|
||||
" 'process': {}},\n",
|
||||
" 'dfcc395a-93ff-4dd5-9684-c80c5885d827': {'uuid': 'dfcc395a-93ff-4dd5-9684-c80c5885d827',\n",
|
||||
" 'hostname': 'google_server',\n",
|
||||
" 'operating_state': 0,\n",
|
||||
" 'NICs': {'1fd281a0-83ae-49d9-9b40-6aae7b465cab': {'uuid': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n",
|
||||
" 'ip_adress': '130.1.1.2',\n",
|
||||
" 'subnet_mask': '255.255.255.0',\n",
|
||||
" 'gateway': '130.1.1.255',\n",
|
||||
" 'mac_address': '69:50:cb:76:22:10',\n",
|
||||
" 'speed': 100,\n",
|
||||
" 'mtu': 1500,\n",
|
||||
" 'wake_on_lan': False,\n",
|
||||
" 'dns_servers': [],\n",
|
||||
" 'enabled': False}},\n",
|
||||
" 'file_system': {'uuid': 'aea8f406-05de-4a02-b65f-972aa1fed70e',\n",
|
||||
" 'folders': {}},\n",
|
||||
" 'applications': {},\n",
|
||||
" 'services': {},\n",
|
||||
" 'process': {}}},\n",
|
||||
" 'links': {'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9': {'uuid': 'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9',\n",
|
||||
" 'endpoint_a': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n",
|
||||
" 'endpoint_b': '4e6abc87-b4b9-4f95-a9a9-59cac130c6ff',\n",
|
||||
" 'bandwidth': 100.0,\n",
|
||||
" 'current_load': 0.0},\n",
|
||||
" '2dab7fc3-470d-44d2-8593-feb8e96d71ae': {'uuid': '2dab7fc3-470d-44d2-8593-feb8e96d71ae',\n",
|
||||
" 'endpoint_a': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n",
|
||||
" 'endpoint_b': 'e136553f-333e-4abf-b1f3-ce352ffa4630',\n",
|
||||
" 'bandwidth': 100.0,\n",
|
||||
" 'current_load': 0.0}}},\n",
|
||||
" 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912', 'accounts': {}}}"
|
||||
]
|
||||
},
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"my_sim.describe_state()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Add files and folders to nodes\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from primaite.simulator.file_system.file_system_file_type import FileSystemFileType\n",
|
||||
"from primaite.simulator.file_system.file_system_file import FileSystemFile"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"my_pc_downloads_folder = my_pc.file_system.create_folder(\"downloads\")\n",
|
||||
"my_pc_downloads_folder.add_file(FileSystemFile(name=\"firefox_installer.zip\",file_type=FileSystemFileType.ZIP))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"FileSystemFile(uuid='3ecf7223-dafd-4973-8c3b-b85af4e177da', name='favicon.ico', size=40.0, file_type=<FileSystemFileType.PNG: '11'>, action_manager=None)"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"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=FileSystemFileType.PNG)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Add applications to nodes"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"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",
|
||||
"\n",
|
||||
"class MSPaint(Application):\n",
|
||||
" def describe_state(self):\n",
|
||||
" return super().describe_state()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"mspaint = MSPaint(name = \"mspaint\", health_state_actual=SoftwareHealthState.GOOD, health_state_visible=SoftwareHealthState.GOOD, criticality=SoftwareCriticality.MEDIUM, ports={Port.HTTP}, operating_state=ApplicationOperatingState.RUNNING,execution_control_status='manual')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"my_pc.applications[mspaint.uuid] = mspaint"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Create a domain account"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from primaite.simulator.domain.account import Account, AccountType\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"acct = Account(username=\"admin\", password=\"admin12\", account_type=AccountType.USER)\n",
|
||||
"my_sim.domain.accounts[acct.uuid] = acct"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n",
|
||||
" 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n",
|
||||
" 'nodes': {'c7c91f06-f128-4891-84a2-83beceea3908': {'uuid': 'c7c91f06-f128-4891-84a2-83beceea3908',\n",
|
||||
" 'hostname': 'primaite_pc',\n",
|
||||
" 'operating_state': 0,\n",
|
||||
" 'NICs': {'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2': {'uuid': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n",
|
||||
" 'ip_adress': '130.1.1.1',\n",
|
||||
" 'subnet_mask': '255.255.255.0',\n",
|
||||
" 'gateway': '130.1.1.255',\n",
|
||||
" 'mac_address': 'c3:08:90:23:29:cb',\n",
|
||||
" 'speed': 100,\n",
|
||||
" 'mtu': 1500,\n",
|
||||
" 'wake_on_lan': False,\n",
|
||||
" 'dns_servers': [],\n",
|
||||
" 'enabled': False}},\n",
|
||||
" 'file_system': {'uuid': '04ffd1e8-dea7-47ad-a088-4856df055ed1',\n",
|
||||
" 'folders': {'f1fdf2ae-6377-4417-a28a-3edb4058712d': {'uuid': 'f1fdf2ae-6377-4417-a28a-3edb4058712d',\n",
|
||||
" 'name': 'downloads',\n",
|
||||
" 'size': 1000.0,\n",
|
||||
" 'files': {'409b09a3-0d98-4c03-adf2-09190539be45': {'uuid': '409b09a3-0d98-4c03-adf2-09190539be45',\n",
|
||||
" 'name': 'firefox_installer.zip',\n",
|
||||
" 'size': 1000.0,\n",
|
||||
" 'file_type': 'ZIP'}},\n",
|
||||
" 'is_quarantined': False}}},\n",
|
||||
" 'applications': {'cddee888-d1b9-4289-8512-bc0a6672c880': {'uuid': 'cddee888-d1b9-4289-8512-bc0a6672c880',\n",
|
||||
" 'health_state': 'GOOD',\n",
|
||||
" 'health_state_red_view': 'GOOD',\n",
|
||||
" 'criticality': 'MEDIUM',\n",
|
||||
" 'patching_count': 0,\n",
|
||||
" 'scanning_count': 0,\n",
|
||||
" 'revealed_to_red': False,\n",
|
||||
" 'installing_count': 0,\n",
|
||||
" 'max_sessions': 1,\n",
|
||||
" 'tcp': True,\n",
|
||||
" 'udp': True,\n",
|
||||
" 'ports': ['HTTP'],\n",
|
||||
" 'opearting_state': 'RUNNING',\n",
|
||||
" 'execution_control_status': 'manual',\n",
|
||||
" 'num_executions': 0,\n",
|
||||
" 'groups': []}},\n",
|
||||
" 'services': {},\n",
|
||||
" 'process': {}},\n",
|
||||
" 'dfcc395a-93ff-4dd5-9684-c80c5885d827': {'uuid': 'dfcc395a-93ff-4dd5-9684-c80c5885d827',\n",
|
||||
" 'hostname': 'google_server',\n",
|
||||
" 'operating_state': 0,\n",
|
||||
" 'NICs': {'1fd281a0-83ae-49d9-9b40-6aae7b465cab': {'uuid': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n",
|
||||
" 'ip_adress': '130.1.1.2',\n",
|
||||
" 'subnet_mask': '255.255.255.0',\n",
|
||||
" 'gateway': '130.1.1.255',\n",
|
||||
" 'mac_address': '69:50:cb:76:22:10',\n",
|
||||
" 'speed': 100,\n",
|
||||
" 'mtu': 1500,\n",
|
||||
" 'wake_on_lan': False,\n",
|
||||
" 'dns_servers': [],\n",
|
||||
" 'enabled': False}},\n",
|
||||
" 'file_system': {'uuid': 'aea8f406-05de-4a02-b65f-972aa1fed70e',\n",
|
||||
" 'folders': {'beb5b535-cf6c-431d-94f6-d1097910130d': {'uuid': 'beb5b535-cf6c-431d-94f6-d1097910130d',\n",
|
||||
" 'name': 'static',\n",
|
||||
" 'size': 0,\n",
|
||||
" 'files': {},\n",
|
||||
" 'is_quarantined': False},\n",
|
||||
" '6644cd6c-1eca-4fe4-9313-e3481abb895e': {'uuid': '6644cd6c-1eca-4fe4-9313-e3481abb895e',\n",
|
||||
" 'name': 'root',\n",
|
||||
" 'size': 40.0,\n",
|
||||
" 'files': {'3ecf7223-dafd-4973-8c3b-b85af4e177da': {'uuid': '3ecf7223-dafd-4973-8c3b-b85af4e177da',\n",
|
||||
" 'name': 'favicon.ico',\n",
|
||||
" 'size': 40.0,\n",
|
||||
" 'file_type': 'PNG'}},\n",
|
||||
" 'is_quarantined': False}}},\n",
|
||||
" 'applications': {},\n",
|
||||
" 'services': {},\n",
|
||||
" 'process': {}}},\n",
|
||||
" 'links': {'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9': {'uuid': 'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9',\n",
|
||||
" 'endpoint_a': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n",
|
||||
" 'endpoint_b': '4e6abc87-b4b9-4f95-a9a9-59cac130c6ff',\n",
|
||||
" 'bandwidth': 100.0,\n",
|
||||
" 'current_load': 0.0},\n",
|
||||
" '2dab7fc3-470d-44d2-8593-feb8e96d71ae': {'uuid': '2dab7fc3-470d-44d2-8593-feb8e96d71ae',\n",
|
||||
" 'endpoint_a': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n",
|
||||
" 'endpoint_b': 'e136553f-333e-4abf-b1f3-ce352ffa4630',\n",
|
||||
" 'bandwidth': 100.0,\n",
|
||||
" 'current_load': 0.0}}},\n",
|
||||
" 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912',\n",
|
||||
" 'accounts': {'563a1805-0b32-4ba6-9551-e127e5eb57a8': {'uuid': '563a1805-0b32-4ba6-9551-e127e5eb57a8',\n",
|
||||
" 'num_logons': 0,\n",
|
||||
" 'num_logoffs': 0,\n",
|
||||
" 'num_group_changes': 0,\n",
|
||||
" 'username': 'admin',\n",
|
||||
" 'password': 'admin12',\n",
|
||||
" 'account_type': 'USER',\n",
|
||||
" 'enabled': True}}}}"
|
||||
]
|
||||
},
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"my_sim.describe_state()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"import json"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'{\"uuid\": \"f0c06262-1bd9-49ee-81f8-793fb4a5e58e\", \"network\": {\"uuid\": \"455d6a1a-ca23-4135-b326-3ebf75022a45\", \"nodes\": {\"c7c91f06-f128-4891-84a2-83beceea3908\": {\"uuid\": \"c7c91f06-f128-4891-84a2-83beceea3908\", \"hostname\": \"primaite_pc\", \"operating_state\": 0, \"NICs\": {\"f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2\": {\"uuid\": \"f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2\", \"ip_adress\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"c3:08:90:23:29:cb\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"04ffd1e8-dea7-47ad-a088-4856df055ed1\", \"folders\": {\"f1fdf2ae-6377-4417-a28a-3edb4058712d\": {\"uuid\": \"f1fdf2ae-6377-4417-a28a-3edb4058712d\", \"name\": \"downloads\", \"size\": 1000.0, \"files\": {\"409b09a3-0d98-4c03-adf2-09190539be45\": {\"uuid\": \"409b09a3-0d98-4c03-adf2-09190539be45\", \"name\": \"firefox_installer.zip\", \"size\": 1000.0, \"file_type\": \"ZIP\"}}, \"is_quarantined\": false}}}, \"applications\": {\"cddee888-d1b9-4289-8512-bc0a6672c880\": {\"uuid\": \"cddee888-d1b9-4289-8512-bc0a6672c880\", \"health_state\": \"GOOD\", \"health_state_red_view\": \"GOOD\", \"criticality\": \"MEDIUM\", \"patching_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 1, \"tcp\": true, \"udp\": true, \"ports\": [\"HTTP\"], \"opearting_state\": \"RUNNING\", \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {}, \"process\": {}}, \"dfcc395a-93ff-4dd5-9684-c80c5885d827\": {\"uuid\": \"dfcc395a-93ff-4dd5-9684-c80c5885d827\", \"hostname\": \"google_server\", \"operating_state\": 0, \"NICs\": {\"1fd281a0-83ae-49d9-9b40-6aae7b465cab\": {\"uuid\": \"1fd281a0-83ae-49d9-9b40-6aae7b465cab\", \"ip_adress\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"69:50:cb:76:22:10\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"aea8f406-05de-4a02-b65f-972aa1fed70e\", \"folders\": {\"beb5b535-cf6c-431d-94f6-d1097910130d\": {\"uuid\": \"beb5b535-cf6c-431d-94f6-d1097910130d\", \"name\": \"static\", \"size\": 0, \"files\": {}, \"is_quarantined\": false}, \"6644cd6c-1eca-4fe4-9313-e3481abb895e\": {\"uuid\": \"6644cd6c-1eca-4fe4-9313-e3481abb895e\", \"name\": \"root\", \"size\": 40.0, \"files\": {\"3ecf7223-dafd-4973-8c3b-b85af4e177da\": {\"uuid\": \"3ecf7223-dafd-4973-8c3b-b85af4e177da\", \"name\": \"favicon.ico\", \"size\": 40.0, \"file_type\": \"PNG\"}}, \"is_quarantined\": false}}}, \"applications\": {}, \"services\": {}, \"process\": {}}}, \"links\": {\"cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9\": {\"uuid\": \"cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9\", \"endpoint_a\": \"f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2\", \"endpoint_b\": \"4e6abc87-b4b9-4f95-a9a9-59cac130c6ff\", \"bandwidth\": 100.0, \"current_load\": 0.0}, \"2dab7fc3-470d-44d2-8593-feb8e96d71ae\": {\"uuid\": \"2dab7fc3-470d-44d2-8593-feb8e96d71ae\", \"endpoint_a\": \"1fd281a0-83ae-49d9-9b40-6aae7b465cab\", \"endpoint_b\": \"e136553f-333e-4abf-b1f3-ce352ffa4630\", \"bandwidth\": 100.0, \"current_load\": 0.0}}}, \"domain\": {\"uuid\": \"9da912d5-4c07-4df6-94c2-b3630e178912\", \"accounts\": {\"563a1805-0b32-4ba6-9551-e127e5eb57a8\": {\"uuid\": \"563a1805-0b32-4ba6-9551-e127e5eb57a8\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": \"USER\", \"enabled\": true}}}}'"
|
||||
]
|
||||
},
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"d = my_sim.describe_state()\n",
|
||||
"json.dumps(d)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
@@ -59,7 +59,7 @@ class Account(SimComponent):
|
||||
"num_group_changes": self.num_group_changes,
|
||||
"username": self.username,
|
||||
"password": self.password,
|
||||
"account_type": self.account_type,
|
||||
"account_type": self.account_type.name,
|
||||
"enabled": self.enabled,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -13,7 +13,7 @@ _LOGGER = getLogger(__name__)
|
||||
class FileSystem(SimComponent):
|
||||
"""Class that contains all the simulation File System."""
|
||||
|
||||
folders: Dict = {}
|
||||
folders: Dict[str, FileSystemFolder] = {}
|
||||
"""List containing all the folders in the file system."""
|
||||
|
||||
def describe_state(self) -> Dict:
|
||||
@@ -26,7 +26,7 @@ class FileSystem(SimComponent):
|
||||
:rtype: Dict
|
||||
"""
|
||||
state = super().describe_state()
|
||||
state.update({"folders": {uuid: folder for uuid, folder in self.folders.items()}})
|
||||
state.update({"folders": {uuid: folder.describe_state() for uuid, folder in self.folders.items()}})
|
||||
return state
|
||||
|
||||
def get_folders(self) -> Dict:
|
||||
|
||||
@@ -45,9 +45,11 @@ class FileSystemFile(FileSystemItem):
|
||||
:return: Current state of this object and child objects.
|
||||
:rtype: Dict
|
||||
"""
|
||||
return {
|
||||
"uuid": self.uuid,
|
||||
"name": self.name,
|
||||
"size": self.size,
|
||||
"file_type": self.file_type,
|
||||
}
|
||||
state = super().describe_state()
|
||||
state.update(
|
||||
{
|
||||
"uuid": self.uuid,
|
||||
"file_type": self.file_type.name,
|
||||
}
|
||||
)
|
||||
return state
|
||||
|
||||
@@ -10,7 +10,7 @@ _LOGGER = getLogger(__name__)
|
||||
class FileSystemFolder(FileSystemItem):
|
||||
"""Simulation FileSystemFolder."""
|
||||
|
||||
files: Dict = {}
|
||||
files: Dict[str, FileSystemFile] = {}
|
||||
"""List of files stored in the folder."""
|
||||
|
||||
is_quarantined: bool = False
|
||||
@@ -25,13 +25,14 @@ class FileSystemFolder(FileSystemItem):
|
||||
:return: Current state of this object and child objects.
|
||||
:rtype: Dict
|
||||
"""
|
||||
return {
|
||||
"uuid": self.uuid,
|
||||
"name": self.name,
|
||||
"size": self.size,
|
||||
"files": {uuid: file for uuid, file in self.files.items()},
|
||||
"is_quarantined": self.is_quarantined,
|
||||
}
|
||||
state = super().describe_state()
|
||||
state.update(
|
||||
{
|
||||
"files": {uuid: file.describe_state() for uuid, file in self.files.items()},
|
||||
"is_quarantined": self.is_quarantined,
|
||||
}
|
||||
)
|
||||
return state
|
||||
|
||||
def get_file_by_id(self, file_id: str) -> FileSystemFile:
|
||||
"""Return a FileSystemFile with the matching id."""
|
||||
|
||||
@@ -11,15 +11,19 @@ from prettytable import PrettyTable
|
||||
from primaite import getLogger
|
||||
from primaite.exceptions import NetworkError
|
||||
from primaite.simulator.core import SimComponent
|
||||
from primaite.simulator.domain.account import Account
|
||||
from primaite.simulator.file_system.file_system import FileSystem
|
||||
from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket
|
||||
from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame
|
||||
from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol
|
||||
from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader
|
||||
from primaite.simulator.system.applications.application import Application
|
||||
from primaite.simulator.system.core.packet_capture import PacketCapture
|
||||
from primaite.simulator.system.core.session_manager import SessionManager
|
||||
from primaite.simulator.system.core.software_manager import SoftwareManager
|
||||
from primaite.simulator.system.core.sys_log import SysLog
|
||||
from primaite.simulator.system.processes.process import Process
|
||||
from primaite.simulator.system.services.service import Service
|
||||
|
||||
_LOGGER = getLogger(__name__)
|
||||
|
||||
@@ -137,9 +141,9 @@ class NIC(SimComponent):
|
||||
state = super().describe_state()
|
||||
state.update(
|
||||
{
|
||||
"ip_adress": self.ip_address,
|
||||
"subnet_mask": self.subnet_mask,
|
||||
"gateway": self.gateway,
|
||||
"ip_adress": str(self.ip_address),
|
||||
"subnet_mask": str(self.subnet_mask),
|
||||
"gateway": str(self.gateway),
|
||||
"mac_address": self.mac_address,
|
||||
"speed": self.speed,
|
||||
"mtu": self.mtu,
|
||||
@@ -319,6 +323,7 @@ class SwitchPort(SimComponent):
|
||||
"enabled": self.enabled,
|
||||
}
|
||||
)
|
||||
return state
|
||||
|
||||
def enable(self):
|
||||
"""Attempt to enable the SwitchPort."""
|
||||
@@ -802,13 +807,13 @@ class Node(SimComponent):
|
||||
nics: Dict[str, NIC] = {}
|
||||
"The NICs on the node."
|
||||
|
||||
accounts: Dict = {}
|
||||
accounts: Dict[str, Account] = {}
|
||||
"All accounts on the node."
|
||||
applications: Dict = {}
|
||||
applications: Dict[str, Application] = {}
|
||||
"All applications on the node."
|
||||
services: Dict = {}
|
||||
services: Dict[str, Service] = {}
|
||||
"All services on the node."
|
||||
processes: Dict = {}
|
||||
processes: Dict[str, Process] = {}
|
||||
"All processes on the node."
|
||||
file_system: FileSystem
|
||||
"The nodes file system."
|
||||
@@ -862,9 +867,9 @@ class Node(SimComponent):
|
||||
"NICs": {uuid: nic.describe_state() for uuid, nic in self.nics.items()},
|
||||
# "switch_ports": {uuid, sp for uuid, sp in self.switch_ports.items()},
|
||||
"file_system": self.file_system.describe_state(),
|
||||
"applications": {uuid: app for uuid, app in self.applications.items()},
|
||||
"services": {uuid: svc for uuid, svc in self.services.items()},
|
||||
"process": {uuid: proc for uuid, proc in self.processes.items()},
|
||||
"applications": {uuid: app.describe_state() for uuid, app in self.applications.items()},
|
||||
"services": {uuid: svc.describe_state() for uuid, svc in self.services.items()},
|
||||
"process": {uuid: proc.describe_state() for uuid, proc in self.processes.items()},
|
||||
}
|
||||
)
|
||||
return state
|
||||
@@ -1026,7 +1031,7 @@ class Switch(Node):
|
||||
return {
|
||||
"uuid": self.uuid,
|
||||
"num_ports": self.num_ports, # redundant?
|
||||
"ports": {port_num: port for port_num, port in self.switch_ports.items()},
|
||||
"ports": {port_num: port.describe_state() for port_num, port in self.switch_ports.items()},
|
||||
"mac_address_table": {mac: port for mac, port in self.mac_address_table.items()},
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,12 @@ from primaite.simulator.system.software import IOSoftware
|
||||
class ApplicationOperatingState(Enum):
|
||||
"""Enumeration of Application Operating States."""
|
||||
|
||||
|
||||
RUNNING = 1
|
||||
"The application is running."
|
||||
CLOSED = 2
|
||||
"The application is closed or not running."
|
||||
INSTALLING = 3
|
||||
"The application is being installed or updated."
|
||||
RUNNING = 1
|
||||
"The application is running."
|
||||
CLOSED = 2
|
||||
"The application is closed or not running."
|
||||
INSTALLING = 3
|
||||
"The application is being installed or updated."
|
||||
|
||||
|
||||
class Application(IOSoftware):
|
||||
@@ -43,7 +42,16 @@ class Application(IOSoftware):
|
||||
:return: Current state of this object and child objects.
|
||||
:rtype: Dict
|
||||
"""
|
||||
pass
|
||||
state = super().describe_state()
|
||||
state.update(
|
||||
{
|
||||
"opearting_state": self.operating_state.name,
|
||||
"execution_control_status": self.execution_control_status,
|
||||
"num_executions": self.num_executions,
|
||||
"groups": list(self.groups),
|
||||
}
|
||||
)
|
||||
return state
|
||||
|
||||
def apply_action(self, action: List[str]) -> None:
|
||||
"""
|
||||
|
||||
@@ -34,4 +34,6 @@ class Process(Software):
|
||||
:return: Current state of this object and child objects.
|
||||
:rtype: Dict
|
||||
"""
|
||||
pass
|
||||
state = super().describe_state()
|
||||
state.update({"operating_state": self.operating_state.name})
|
||||
return state
|
||||
|
||||
@@ -42,7 +42,9 @@ class Service(IOSoftware):
|
||||
:return: Current state of this object and child objects.
|
||||
:rtype: Dict
|
||||
"""
|
||||
pass
|
||||
state = super().describe_state()
|
||||
state.update({"operating_state": self.operating_state.name})
|
||||
return state
|
||||
|
||||
def apply_action(self, action: List[str]) -> None:
|
||||
"""
|
||||
|
||||
@@ -151,7 +151,17 @@ class IOSoftware(Software):
|
||||
:return: Current state of this object and child objects.
|
||||
:rtype: Dict
|
||||
"""
|
||||
pass
|
||||
state = super().describe_state()
|
||||
state.update(
|
||||
{
|
||||
"installing_count": self.installing_count,
|
||||
"max_sessions": self.max_sessions,
|
||||
"tcp": self.tcp,
|
||||
"udp": self.udp,
|
||||
"ports": [port.name for port in self.ports], # TODO: not sure if this should be port.name or port.value
|
||||
}
|
||||
)
|
||||
return state
|
||||
|
||||
def send(self, payload: Any, session_id: str, **kwargs) -> bool:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user