Committed the v1.1.0 code provided by James Short. Had to add setuptools==66 to setup.py as older versions of Gym are uninstallable with setuptools>=67
This commit is contained in:
@@ -11,7 +11,7 @@ class ActiveNode(Node):
|
||||
Active Node class
|
||||
"""
|
||||
|
||||
def __init__(self, _id, _name, _type, _priority, _state, _ip_address, _os_state, _config_values):
|
||||
def __init__(self, _id, _name, _type, _priority, _state, _ip_address, _os_state, _file_system_state, _config_values):
|
||||
"""
|
||||
Init
|
||||
|
||||
@@ -23,12 +23,22 @@ class ActiveNode(Node):
|
||||
_state: The node state (enum)
|
||||
_ip_address: The node IP address
|
||||
_os_state: The node Operating System state
|
||||
_file_system_state: The node file system state
|
||||
_config_values: The config values
|
||||
"""
|
||||
|
||||
super().__init__(_id, _name, _type, _priority, _state, _config_values)
|
||||
self.ip_address = _ip_address
|
||||
# Related to O/S
|
||||
self.os_state = _os_state
|
||||
self.patching_count = 0
|
||||
# Related to File System
|
||||
self.file_system_state_actual = _file_system_state
|
||||
self.file_system_state_observed = _file_system_state
|
||||
self.file_system_scanning = False
|
||||
self.file_system_scanning_count = 0
|
||||
self.file_system_action_count = 0
|
||||
|
||||
|
||||
def set_ip_address(self, _ip_address):
|
||||
"""
|
||||
@@ -93,3 +103,103 @@ class ActiveNode(Node):
|
||||
if self.patching_count <= 0:
|
||||
self.patching_count = 0
|
||||
self.os_state = SOFTWARE_STATE.GOOD
|
||||
|
||||
def set_file_system_state(self, _file_system_state):
|
||||
"""
|
||||
Sets the file system state (actual and observed)
|
||||
|
||||
Args:
|
||||
_file_system_state: File system state
|
||||
"""
|
||||
|
||||
self.file_system_state_actual = _file_system_state
|
||||
|
||||
if _file_system_state == FILE_SYSTEM_STATE.REPAIRING:
|
||||
self.file_system_action_count = self.config_values.file_system_repairing_limit
|
||||
self.file_system_state_observed = FILE_SYSTEM_STATE.REPAIRING
|
||||
elif _file_system_state == FILE_SYSTEM_STATE.RESTORING:
|
||||
self.file_system_action_count = self.config_values.file_system_restoring_limit
|
||||
self.file_system_state_observed = FILE_SYSTEM_STATE.RESTORING
|
||||
elif _file_system_state == FILE_SYSTEM_STATE.GOOD:
|
||||
self.file_system_state_observed = FILE_SYSTEM_STATE.GOOD
|
||||
|
||||
def set_file_system_state_if_not_compromised(self, _file_system_state):
|
||||
"""
|
||||
Sets the file system state (actual and observed) if not in a compromised state
|
||||
Use for green PoL to prevent it overturning a compromised state
|
||||
|
||||
Args:
|
||||
_file_system_state: File system state
|
||||
"""
|
||||
|
||||
if self.file_system_state_actual != FILE_SYSTEM_STATE.CORRUPT and self.file_system_state_actual != FILE_SYSTEM_STATE.DESTROYED:
|
||||
self.file_system_state_actual = _file_system_state
|
||||
|
||||
if _file_system_state == FILE_SYSTEM_STATE.REPAIRING:
|
||||
self.file_system_action_count = self.config_values.file_system_repairing_limit
|
||||
self.file_system_state_observed = FILE_SYSTEM_STATE.REPAIRING
|
||||
elif _file_system_state == FILE_SYSTEM_STATE.RESTORING:
|
||||
self.file_system_action_count = self.config_values.file_system_restoring_limit
|
||||
self.file_system_state_observed = FILE_SYSTEM_STATE.RESTORING
|
||||
elif _file_system_state == FILE_SYSTEM_STATE.GOOD:
|
||||
self.file_system_state_observed = FILE_SYSTEM_STATE.GOOD
|
||||
|
||||
def get_file_system_state_actual(self):
|
||||
"""
|
||||
Gets file system state (actual)
|
||||
|
||||
Returns:
|
||||
File system state (actual)
|
||||
"""
|
||||
|
||||
return self.file_system_state_actual
|
||||
|
||||
def get_file_system_state_observed(self):
|
||||
"""
|
||||
Gets file system state (observed)
|
||||
|
||||
Returns:
|
||||
File system state (observed)
|
||||
"""
|
||||
|
||||
return self.file_system_state_observed
|
||||
|
||||
def start_file_system_scan(self):
|
||||
"""
|
||||
Starts a file system scan
|
||||
"""
|
||||
|
||||
self.file_system_scanning = True
|
||||
self.file_system_scanning_count = self.config_values.file_system_scanning_limit
|
||||
|
||||
def is_scanning_file_system(self):
|
||||
"""
|
||||
Gets true/false on whether file system is being scanned
|
||||
|
||||
Returns:
|
||||
True if file system is being scanned
|
||||
"""
|
||||
|
||||
return self.file_system_scanning
|
||||
|
||||
def update_file_system_state(self):
|
||||
"""
|
||||
Updates file system status based on scanning / restore / repair cycle
|
||||
"""
|
||||
|
||||
# Deprecate both the action count (for restoring or reparing) and the scanning count
|
||||
self.file_system_action_count -= 1
|
||||
self.file_system_scanning_count -= 1
|
||||
|
||||
# Reparing / Restoring updates
|
||||
if self.file_system_action_count <= 0:
|
||||
self.file_system_action_count = 0
|
||||
if self.file_system_state_actual == FILE_SYSTEM_STATE.REPAIRING or self.file_system_state_actual == FILE_SYSTEM_STATE.RESTORING:
|
||||
self.file_system_state_actual = FILE_SYSTEM_STATE.GOOD
|
||||
self.file_system_state_observed = FILE_SYSTEM_STATE.GOOD
|
||||
|
||||
# Scanning updates
|
||||
if self.file_system_scanning == True and self.file_system_scanning_count < 0:
|
||||
self.file_system_state_observed = self.file_system_state_actual
|
||||
self.file_system_scanning = False
|
||||
self.file_system_scanning_count = 0
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
# Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence.
|
||||
"""
|
||||
Defines node behaviour for PoL
|
||||
Defines node behaviour for Green PoL
|
||||
"""
|
||||
|
||||
class NodeStateInstruction(object):
|
||||
class NodeStateInstructionGreen(object):
|
||||
"""
|
||||
The Node State Instruction class
|
||||
"""
|
||||
|
||||
def __init__(self, _id, _start_step, _end_step, _node_id, _node_pol_type, _service_name, _state, _is_entry_node=False):
|
||||
def __init__(self, _id, _start_step, _end_step, _node_id, _node_pol_type, _service_name, _state):
|
||||
"""
|
||||
Init
|
||||
|
||||
@@ -20,7 +20,6 @@ class NodeStateInstruction(object):
|
||||
_node_pol_type: The pattern of life type
|
||||
_service_name: The service name
|
||||
_state: The state (node or service)
|
||||
_is_entry_node: Indicator for entry node (default = False)
|
||||
"""
|
||||
|
||||
self.id = _id
|
||||
@@ -30,7 +29,6 @@ class NodeStateInstruction(object):
|
||||
self.node_pol_type = _node_pol_type
|
||||
self.service_name = _service_name # Not used when not a service instruction
|
||||
self.state = _state
|
||||
self.is_entry_node = _is_entry_node
|
||||
|
||||
def get_start_step(self):
|
||||
"""
|
||||
@@ -91,14 +89,4 @@ class NodeStateInstruction(object):
|
||||
"""
|
||||
|
||||
return self.state
|
||||
|
||||
def get_is_entry_node(self):
|
||||
"""
|
||||
Informs of entry node
|
||||
|
||||
Returns:
|
||||
True if entry node
|
||||
"""
|
||||
|
||||
return self.is_entry_node
|
||||
|
||||
140
PRIMAITE/nodes/node_state_instruction_red.py
Normal file
140
PRIMAITE/nodes/node_state_instruction_red.py
Normal file
@@ -0,0 +1,140 @@
|
||||
# Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence.
|
||||
"""
|
||||
Defines node behaviour for Green PoL
|
||||
"""
|
||||
|
||||
class NodeStateInstructionRed(object):
|
||||
"""
|
||||
The Node State Instruction class
|
||||
"""
|
||||
|
||||
def __init__(self, _id, _start_step, _end_step, _target_node_id, _pol_initiator, _pol_type, pol_protocol, _pol_state, _pol_source_node_id, _pol_source_node_service, _pol_source_node_service_state):
|
||||
"""
|
||||
Init
|
||||
|
||||
Args:
|
||||
_id: The node state instruction id
|
||||
_start_step: The start step of the instruction
|
||||
_end_step: The end step of the instruction
|
||||
_target_node_id: The id of the associated node
|
||||
-pol_initiator: The way the PoL is applied (DIRECT, IER or SERVICE)
|
||||
_pol_type: The pattern of life type
|
||||
-pol_protocol: The pattern of life protocol/service affected
|
||||
_pol_state: The state (node or service)
|
||||
_pol_source_node_id: The source node Id (used for initiator type SERVICE)
|
||||
_pol_source_node_service: The source node service (used for initiator type SERVICE)
|
||||
_pol_source_node_service_state: The source node service state (used for initiator type SERVICE)
|
||||
"""
|
||||
|
||||
self.id = _id
|
||||
self.start_step = _start_step
|
||||
self.end_step = _end_step
|
||||
self.target_node_id = _target_node_id
|
||||
self.initiator = _pol_initiator
|
||||
self.pol_type = _pol_type
|
||||
self.service_name = pol_protocol # Not used when not a service instruction
|
||||
self.state = _pol_state
|
||||
self.source_node_id = _pol_source_node_id
|
||||
self.source_node_service = _pol_source_node_service
|
||||
self.source_node_service_state = _pol_source_node_service_state
|
||||
|
||||
def get_start_step(self):
|
||||
"""
|
||||
Gets the start step
|
||||
|
||||
Returns:
|
||||
The start step
|
||||
"""
|
||||
|
||||
return self.start_step
|
||||
|
||||
def get_end_step(self):
|
||||
"""
|
||||
Gets the end step
|
||||
|
||||
Returns:
|
||||
The end step
|
||||
"""
|
||||
|
||||
return self.end_step
|
||||
|
||||
def get_target_node_id(self):
|
||||
"""
|
||||
Gets the node ID
|
||||
|
||||
Returns:
|
||||
The node ID
|
||||
"""
|
||||
|
||||
return self.target_node_id
|
||||
|
||||
def get_initiator(self):
|
||||
"""
|
||||
Gets the initiator
|
||||
|
||||
Returns:
|
||||
The initiator
|
||||
"""
|
||||
|
||||
return self.initiator
|
||||
|
||||
def get_pol_type(self):
|
||||
"""
|
||||
Gets the node pattern of life type (enum)
|
||||
|
||||
Returns:
|
||||
The node pattern of life type (enum)
|
||||
"""
|
||||
|
||||
return self.pol_type
|
||||
|
||||
def get_service_name(self):
|
||||
"""
|
||||
Gets the service name
|
||||
|
||||
Returns:
|
||||
The service name
|
||||
"""
|
||||
|
||||
return self.service_name
|
||||
|
||||
def get_state(self):
|
||||
"""
|
||||
Gets the state (node or service)
|
||||
|
||||
Returns:
|
||||
The state (node or service)
|
||||
"""
|
||||
|
||||
return self.state
|
||||
|
||||
def get_source_node_id(self):
|
||||
"""
|
||||
Gets the source node id (used for initiator type SERVICE)
|
||||
|
||||
Returns:
|
||||
The source node id
|
||||
"""
|
||||
|
||||
return self.source_node_id
|
||||
|
||||
def get_source_node_service(self):
|
||||
"""
|
||||
Gets the source node service (used for initiator type SERVICE)
|
||||
|
||||
Returns:
|
||||
The source node service
|
||||
"""
|
||||
|
||||
return self.source_node_service
|
||||
|
||||
def get_source_node_service_state(self):
|
||||
"""
|
||||
Gets the source node service state (used for initiator type SERVICE)
|
||||
|
||||
Returns:
|
||||
The source node service state
|
||||
"""
|
||||
|
||||
return self.source_node_service_state
|
||||
|
||||
@@ -11,7 +11,7 @@ class ServiceNode(ActiveNode):
|
||||
ServiceNode class
|
||||
"""
|
||||
|
||||
def __init__(self, _id, _name, _type, _priority, _state, _ip_address, _os_state, _config_values):
|
||||
def __init__(self, _id, _name, _type, _priority, _state, _ip_address, _os_state, _file_system_state, _config_values):
|
||||
"""
|
||||
Init
|
||||
|
||||
@@ -23,9 +23,10 @@ class ServiceNode(ActiveNode):
|
||||
_state: The state of the node
|
||||
_ipAddress: The IP address of the node
|
||||
_osState: The operating system state of the node
|
||||
_file_system_state: The file system state of the node
|
||||
"""
|
||||
|
||||
super().__init__(_id, _name, _type, _priority, _state, _ip_address, _os_state, _config_values)
|
||||
super().__init__(_id, _name, _type, _priority, _state, _ip_address, _os_state, _file_system_state, _config_values)
|
||||
self.services = {}
|
||||
|
||||
def add_service(self, _service):
|
||||
|
||||
Reference in New Issue
Block a user