Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #46 #58

Merged
merged 2 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cyberbattle/_env/cyberbattle_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ def validate_environment(self, environment: model.Environment):

if effective_maximum_credentials_per_action > self.__bounds.maximum_discoverable_credentials_per_action:
raise ValueError(
f"Some action in the environment returns {effective_maximum_credentials_per_action}"
f"credentials which exceeds the maximum number of discoverable credentials"
f"{self.__bounds.maximum_discoverable_credentials_per_action}")
f"Some action in the environment returns {effective_maximum_credentials_per_action} "
f"credentials which exceeds the maximum number of discoverable credentials "
f"of {self.__bounds.maximum_discoverable_credentials_per_action}")

refeerenced_ports = model.collect_ports_from_environment(environment)
undefined_ports = set(refeerenced_ports).difference(environment.identifiers.ports)
Expand Down
2 changes: 1 addition & 1 deletion cyberbattle/_env/cyberbattle_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class CyberBattleRandom(cyberbattle_env.CyberBattleEnv):

def __init__(self):
super().__init__(initial_environment=generate_network.new_environment(n_servers_per_protocol=15),
maximum_discoverable_credentials_per_action=15)
maximum_discoverable_credentials_per_action=32)
20 changes: 16 additions & 4 deletions cyberbattle/simulation/generate_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,13 @@ def create_cached_credential(node: NodeID, port: PortName) -> CredentialID:

def add_leak_neighbors_vulnerability(
node_id: m.NodeID,
library: m.VulnerabilityLibrary = {}) -> m.VulnerabilityLibrary:
library: Optional[m.VulnerabilityLibrary] = None) -> m.VulnerabilityLibrary:
"""Create random vulnerabilities
that reveals immediate traffic neighbors from a given node"""

if not library:
library = {}

rdp_neighbors = traffic_targets(node_id, 'RDP')

if len(rdp_neighbors) > 0:
Expand Down Expand Up @@ -246,22 +249,31 @@ def create_vulnerabilities_from_traffic_data(node_id: m.NodeID):
firewall=firewall_conf,
reimagable=False)})

def create_node_data(node_id: m.NodeID):
def create_node_data_without_vulnerabilities(node_id: m.NodeID):
return m.NodeInfo(
services=[m.ListeningService(name=port, allowedCredentials=assigned_passwords[(target_node, port)])
for (target_node, port) in assigned_passwords.keys()
if target_node == node_id
],
value=random.randint(0, 100),
vulnerabilities=create_vulnerabilities_from_traffic_data(node_id),
agent_installed=False,
firewall=firewall_conf
)

# Step 1: Create all the nodes with associated services and firewall configuration
for node in list(graph.nodes):
if node != entry_node_id:
graph.nodes[node].clear()
graph.nodes[node].update({'data': create_node_data(node)})
graph.nodes[node].update({'data': create_node_data_without_vulnerabilities(node)})

# Step 2: Assign vulnerabilities to each node.
# This must be a separate step because vulnerabilities definitions
# may depend on the passwords assigned to the nodes in Step 1.
for node in list(graph.nodes):
if node != entry_node_id:
node_data = graph.nodes[node]['data']
node_data.vulnerabilities = create_vulnerabilities_from_traffic_data(node)
graph.nodes[node].update({'data': node_data})

# remove all the edges inherited from the network graph
graph.clear_edges()
Expand Down
13,683 changes: 13,467 additions & 216 deletions notebooks/randomnetwork.ipynb

Large diffs are not rendered by default.