mal-simulator 2.2.0__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. {mal_simulator-2.2.0/mal_simulator.egg-info → mal_simulator-2.3.0}/PKG-INFO +1 -1
  2. {mal_simulator-2.2.0 → mal_simulator-2.3.0/mal_simulator.egg-info}/PKG-INFO +1 -1
  3. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/__init__.py +2 -2
  4. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/base_classes.py +5 -2
  5. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/attack_surface.py +3 -1
  6. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/attacker_state_factories.py +37 -15
  7. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/simulator.py +30 -37
  8. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/pyproject.toml +1 -1
  9. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/tests/test_mal_simulator.py +92 -3
  10. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/AUTHORS +0 -0
  11. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/LICENSE +0 -0
  12. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/README.md +0 -0
  13. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/mal_simulator.egg-info/SOURCES.txt +0 -0
  14. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/mal_simulator.egg-info/dependency_links.txt +0 -0
  15. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/mal_simulator.egg-info/entry_points.txt +0 -0
  16. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/mal_simulator.egg-info/requires.txt +0 -0
  17. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/mal_simulator.egg-info/top_level.txt +0 -0
  18. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/__main__.py +0 -0
  19. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/config/__init__.py +0 -0
  20. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/config/agent_settings.py +0 -0
  21. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/config/agent_settings_factories.py +0 -0
  22. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/config/node_property_rule.py +0 -0
  23. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/config/sim_settings.py +0 -0
  24. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/__init__.py +0 -0
  25. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/graph/__init__.py +0 -0
  26. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/graph/graph_env.py +0 -0
  27. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/graph/mal_spaces.py +0 -0
  28. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/graph/serialization.py +0 -0
  29. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/graph/utils.py +0 -0
  30. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/graph/wrapper.py +0 -0
  31. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/legacy/__init__.py +0 -0
  32. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/legacy/gym_envs.py +0 -0
  33. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/envs/legacy/malsim_vectorized_obs_env.py +0 -0
  34. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/__init__.py +0 -0
  35. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/agent_state.py +0 -0
  36. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/attacker_state.py +0 -0
  37. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/attacker_step.py +0 -0
  38. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/defender_state.py +0 -0
  39. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/defender_state_factories.py +0 -0
  40. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/defender_step.py +0 -0
  41. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/defense_surface.py +0 -0
  42. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/false_alerts.py +0 -0
  43. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/graph_processing.py +0 -0
  44. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/graph_state.py +0 -0
  45. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/graph_utils.py +0 -0
  46. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/node_getters.py +0 -0
  47. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/observability.py +0 -0
  48. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/register_agent.py +0 -0
  49. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/reset_agent.py +0 -0
  50. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/rewards.py +0 -0
  51. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/run_simulation.py +0 -0
  52. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/simulator_state.py +0 -0
  53. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/state_query.py +0 -0
  54. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/mal_simulator/ttc_utils.py +0 -0
  55. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/__init__.py +0 -0
  56. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/attackers/__init__.py +0 -0
  57. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/attackers/searchers.py +0 -0
  58. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/attackers/shortest_path.py +0 -0
  59. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/attackers/ttc_soft_min.py +0 -0
  60. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/decision_agent.py +0 -0
  61. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/defenders/__init__.py +0 -0
  62. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/defenders/heuristic_agent.py +0 -0
  63. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/keyboard_input.py +0 -0
  64. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/passive_agent.py +0 -0
  65. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/random_agent.py +0 -0
  66. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/policies/utils/path_finding.py +0 -0
  67. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/scenario/__init__.py +0 -0
  68. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/scenario/scenario.py +0 -0
  69. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/types.py +0 -0
  70. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/malsim/visualization/malsim_gui_client.py +0 -0
  71. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/setup.cfg +0 -0
  72. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/tests/test_graph_processing.py +0 -0
  73. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/tests/test_main.py +0 -0
  74. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/tests/test_scenario.py +0 -0
  75. {mal_simulator-2.2.0 → mal_simulator-2.3.0}/tests/test_ttc_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mal-simulator
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: A MAL compliant simulator.
5
5
  Author-email: Andrei Buhaiu <buhaiu@kth.se>, Joakim Loxdal <loxdal@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Sandor Berglund <sandorb@kth.se>
6
6
  License: Apache Software License
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mal-simulator
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: A MAL compliant simulator.
5
5
  Author-email: Andrei Buhaiu <buhaiu@kth.se>, Joakim Loxdal <loxdal@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Sandor Berglund <sandorb@kth.se>
6
6
  License: Apache Software License
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # MAL Simulator v2.2.0
2
+ # MAL Simulator v2.3.0
3
3
  # Copyright 2025, Andrei Buhaiu.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,7 +27,7 @@ from malsim.scenario import Scenario
27
27
  from malsim.config import AttackerSettings, DefenderSettings
28
28
 
29
29
  __title__ = 'malsim'
30
- __version__ = '2.2.0'
30
+ __version__ = '2.3.0'
31
31
  __authors__ = [
32
32
  'Andrei Buhaiu',
33
33
  'Joakim Loxdal',
@@ -2,6 +2,9 @@ from abc import ABC, abstractmethod
2
2
  from typing import Any, Optional
3
3
 
4
4
  from maltoolbox.attackgraph import AttackGraphNode
5
+
6
+ from ..mal_simulator.defender_state import MalSimDefenderState
7
+ from ..mal_simulator.attacker_state import MalSimAttackerState
5
8
  from ..mal_simulator import MalSimulator, MalSimAgentState
6
9
 
7
10
 
@@ -14,10 +17,10 @@ class MalSimEnv(ABC):
14
17
 
15
18
  def reset(
16
19
  self, seed: Optional[int] = None, options: Optional[dict[str, Any]] = None
17
- ) -> None:
20
+ ) -> dict[str, MalSimAttackerState | MalSimDefenderState]:
18
21
  if seed is not None:
19
22
  self.sim.sim_settings.seed = seed
20
- self.sim.reset()
23
+ return self.sim.reset()
21
24
 
22
25
  def register_attacker(
23
26
  self, attacker_name: str, entry_points: set[AttackGraphNode]
@@ -31,7 +31,9 @@ def get_effects_of_attack_step(
31
31
  while potential_effects:
32
32
  effect = potential_effects.popleft()
33
33
  has_visited = performed | set(effects)
34
- if node_is_traversable(sim_state, has_visited, effect):
34
+ if effect not in has_visited and node_is_traversable(
35
+ sim_state, has_visited, effect
36
+ ):
35
37
  effects.add(effect)
36
38
  potential_effects += (
37
39
  n for n in effect.children if n.causal_mode == 'effect'
@@ -6,7 +6,10 @@ from types import MappingProxyType
6
6
  from typing import Optional, TYPE_CHECKING
7
7
 
8
8
  from malsim.config.node_property_rule import NodePropertyRule
9
- from malsim.mal_simulator.attack_surface import get_attack_surface
9
+ from malsim.mal_simulator.attack_surface import (
10
+ get_attack_surface,
11
+ get_effects_of_attack_step,
12
+ )
10
13
  from malsim.mal_simulator.attacker_state import MalSimAttackerState
11
14
  from malsim.mal_simulator.node_getters import (
12
15
  full_name_dict_to_node_dict,
@@ -31,8 +34,8 @@ def create_attacker_state(
31
34
  sim_state: MalSimulatorState,
32
35
  name: str,
33
36
  entry_points: Set[AttackGraphNode],
37
+ step_compromised_nodes: Set[AttackGraphNode],
34
38
  goals: Set[AttackGraphNode] = frozenset(),
35
- step_compromised_nodes: Set[AttackGraphNode] = frozenset(),
36
39
  step_attempted_nodes: Set[AttackGraphNode] = frozenset(),
37
40
  step_nodes_made_unviable: Set[AttackGraphNode] = frozenset(),
38
41
  ttc_overrides: Mapping[AttackGraphNode, TTCDist] = MappingProxyType({}),
@@ -48,9 +51,7 @@ def create_attacker_state(
48
51
  """
49
52
 
50
53
  if previous_state is None:
51
- # Initial compromised nodes
52
- if sim_state.settings.compromise_entrypoints_at_start:
53
- step_compromised_nodes |= entry_points
54
+ # Initial compromised nodes are just the step compromised nodes
54
55
  compromised_nodes = step_compromised_nodes
55
56
 
56
57
  # Create an initial attack surface
@@ -141,6 +142,21 @@ def create_attacker_state(
141
142
  )
142
143
 
143
144
 
145
+ def get_entrypoint_compromises(
146
+ sim_state: MalSimulatorState,
147
+ entry_points: set[AttackGraphNode],
148
+ ) -> set[AttackGraphNode]:
149
+ """Compromise entry points and return compromised nodes including effects"""
150
+ step_compromised_nodes: set[AttackGraphNode] = set()
151
+ for entry_point in entry_points:
152
+ step_compromised_nodes.add(entry_point)
153
+ # Perform effects of entry point compromises
154
+ step_compromised_nodes |= get_effects_of_attack_step(
155
+ sim_state, entry_point, step_compromised_nodes
156
+ )
157
+ return step_compromised_nodes
158
+
159
+
144
160
  def initial_attacker_state(
145
161
  sim_state: MalSimulatorState,
146
162
  attacker_settings: AttackerSettings,
@@ -148,24 +164,30 @@ def initial_attacker_state(
148
164
  rng: np.random.Generator,
149
165
  ) -> MalSimAttackerState:
150
166
  """Create an attacker state from attacker settings"""
167
+
151
168
  ttc_overrides, ttc_value_overrides, impossible_steps = (
152
169
  attacker_overriding_ttc_settings(
153
170
  sim_state.attack_graph, attacker_settings, ttc_mode, rng
154
171
  )
155
172
  )
173
+ entry_points = set(
174
+ full_names_or_nodes_to_nodes(
175
+ sim_state.attack_graph, attacker_settings.entry_points
176
+ )
177
+ )
178
+ goals = set(
179
+ full_names_or_nodes_to_nodes(sim_state.attack_graph, attacker_settings.goals)
180
+ )
181
+ step_compromised_nodes: Set[AttackGraphNode] = set()
182
+ if sim_state.settings.compromise_entrypoints_at_start:
183
+ step_compromised_nodes = get_entrypoint_compromises(sim_state, entry_points)
184
+
156
185
  return create_attacker_state(
157
186
  sim_state=sim_state,
158
187
  name=attacker_settings.name,
159
- entry_points=set(
160
- full_names_or_nodes_to_nodes(
161
- sim_state.attack_graph, attacker_settings.entry_points
162
- )
163
- ),
164
- goals=set(
165
- full_names_or_nodes_to_nodes(
166
- sim_state.attack_graph, attacker_settings.goals
167
- )
168
- ),
188
+ entry_points=entry_points,
189
+ goals=goals,
190
+ step_compromised_nodes=step_compromised_nodes,
169
191
  ttc_overrides=ttc_overrides,
170
192
  ttc_value_overrides=ttc_value_overrides,
171
193
  impossible_step_overrides=impossible_steps,
@@ -474,7 +474,6 @@ class MalSimulator:
474
474
  self._agent_states,
475
475
  self._alive_agents,
476
476
  self.rng,
477
- self._alive_agents,
478
477
  self._agent_rewards,
479
478
  self.performed_attacks_func,
480
479
  self.enabled_defenses_func,
@@ -629,7 +628,7 @@ def _pre_step_check(
629
628
  print(msg)
630
629
 
631
630
  if done(alive_agents):
632
- msg = 'Simulation is done, step has no effect'
631
+ msg = 'Simulation is done but you can still step'
633
632
  logger.warning(msg)
634
633
  print(msg)
635
634
 
@@ -644,7 +643,6 @@ def step(
644
643
  agent_states: AgentStates,
645
644
  alive_agents: set[str],
646
645
  rng: np.random.Generator,
647
- live_agents: set[str],
648
646
  agent_rewards: dict[str, float],
649
647
  performed_attacks_func: Callable[[MalSimAttackerState], frozenset[AttackGraphNode]],
650
648
  enabled_defenses_func: Callable[[MalSimDefenderState], frozenset[AttackGraphNode]],
@@ -662,7 +660,7 @@ def step(
662
660
  - A dictionary containing the agent state views keyed by agent names
663
661
  """
664
662
 
665
- _pre_step_check(agent_states, live_agents, actions)
663
+ _pre_step_check(agent_states, alive_agents, actions)
666
664
 
667
665
  # Populate these from the results for all agents' actions.
668
666
  step_compromised_nodes: list[AttackGraphNode] = []
@@ -671,9 +669,7 @@ def step(
671
669
  current_iteration = 0
672
670
 
673
671
  # Perform defender actions first
674
- for defender_state in get_defender_agents(
675
- agent_states, live_agents, only_alive=True
676
- ):
672
+ for defender_state in get_defender_agents(agent_states, alive_agents):
677
673
  agent_actions = list(
678
674
  full_names_or_nodes_to_nodes(
679
675
  sim_state.attack_graph, actions.get(defender_state.name, [])
@@ -687,9 +683,7 @@ def step(
687
683
  step_nodes_made_unviable |= unviable
688
684
 
689
685
  # Perform attacker actions afterwards
690
- for attacker_state in get_attacker_agents(
691
- agent_states, live_agents, only_alive=True
692
- ):
686
+ for attacker_state in get_attacker_agents(agent_states, alive_agents):
693
687
  agent_actions = list(
694
688
  full_names_or_nodes_to_nodes(
695
689
  sim_state.attack_graph, actions.get(attacker_state.name, [])
@@ -724,35 +718,34 @@ def step(
724
718
  sim_state.settings.ttc_mode,
725
719
  )
726
720
 
727
- # Update defender states and remove 'dead' agents of any type
728
- for agent_name in live_agents.copy():
729
- agent_state = agent_states[agent_name]
730
-
731
- if isinstance(agent_state, MalSimDefenderState):
732
- current_iteration = agent_state.iteration
733
- # Update defender state
734
- updated_defender_state = create_defender_state(
735
- sim_state=sim_state,
736
- name=agent_name,
737
- step_compromised_nodes=set(step_compromised_nodes),
738
- step_enabled_defenses=set(step_enabled_defenses),
739
- step_nodes_made_unviable=step_nodes_made_unviable,
740
- previous_state=agent_state,
741
- rng=rng,
742
- )
743
- agent_states[agent_name] = updated_defender_state
721
+ # Update defender states and rewards
722
+ for defender_state in get_defender_agents(agent_states, alive_agents):
723
+ current_iteration = defender_state.iteration
724
+ # Update defender state
725
+ updated_defender_state = create_defender_state(
726
+ sim_state=sim_state,
727
+ name=defender_state.name,
728
+ step_compromised_nodes=set(step_compromised_nodes),
729
+ step_enabled_defenses=set(step_enabled_defenses),
730
+ step_nodes_made_unviable=step_nodes_made_unviable,
731
+ previous_state=defender_state,
732
+ rng=rng,
733
+ )
734
+ agent_states[defender_state.name] = updated_defender_state
744
735
 
745
- # Update defender reward
746
- agent_rewards[agent_state.name] = defender_step_reward(
747
- enabled_defenses_func,
748
- enabled_attacks_func,
749
- updated_defender_state,
750
- )
736
+ # Update defender reward
737
+ agent_rewards[defender_state.name] = defender_step_reward(
738
+ enabled_defenses_func,
739
+ enabled_attacks_func,
740
+ updated_defender_state,
741
+ )
751
742
 
743
+ # Mark terminated agents as dead
744
+ for agent_name in alive_agents.copy():
752
745
  # Remove agents that are terminated
753
- if agent_is_terminated(agent_states, alive_agents, agent_state.name):
754
- logger.info('Agent %s terminated', agent_state.name)
755
- live_agents.remove(agent_state.name)
746
+ if agent_is_terminated(agent_states, alive_agents, agent_name):
747
+ logger.info('Agent %s terminated', agent_name)
748
+ alive_agents.remove(agent_name)
756
749
 
757
750
  # the way current_iteration is used here is flawed.
758
751
  if rest_api_client:
@@ -761,4 +754,4 @@ def step(
761
754
  current_iteration,
762
755
  )
763
756
 
764
- return agent_states, recording, sim_state, agent_rewards, live_agents
757
+ return agent_states, recording, sim_state, agent_rewards, alive_agents
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mal-simulator"
3
- version = "2.2.0"
3
+ version = "2.3.0"
4
4
  authors = [
5
5
  { name="Andrei Buhaiu", email="buhaiu@kth.se" },
6
6
  { name="Joakim Loxdal", email="loxdal@kth.se" },
@@ -985,6 +985,29 @@ def test_simulator_false_positives() -> None:
985
985
  assert len(defender_state.observed_nodes) > len(defender_state.compromised_nodes)
986
986
 
987
987
 
988
+ def test_simulator_false_positives_after_done() -> None:
989
+ """Create a simulator with false positives"""
990
+
991
+ scenario = Scenario.load_from_file(
992
+ 'tests/testdata/scenarios/traininglang_fp_fn_scenario.yml'
993
+ )
994
+
995
+ scenario.false_negative_rates = None
996
+ sim = MalSimulator.from_scenario(scenario, MalSimulatorSettings(seed=100))
997
+ run_simulation(sim, scenario.agent_settings)
998
+ assert sim.done()
999
+
1000
+ # Simulation is done, but we can still observe false positives
1001
+ false_positives: set[AttackGraphNode] = set()
1002
+ for _ in range(100):
1003
+ states = sim.step({})
1004
+ defender_state = states['defender']
1005
+ assert isinstance(defender_state, MalSimDefenderState)
1006
+ false_positives |= defender_state.observed_nodes
1007
+
1008
+ assert false_positives
1009
+
1010
+
988
1011
  def test_simulator_false_positives_reset() -> None:
989
1012
  """Create a simulator with false positives"""
990
1013
 
@@ -1144,8 +1167,16 @@ def test_simulator_multiple_attackers() -> None:
1144
1167
  sim.get_node('Host:1:connect'),
1145
1168
  ],
1146
1169
  },
1147
- 2: {'Defender1': [], 'Attacker1': [sim.get_node('Host:0:authenticate')]},
1148
- 3: {'Defender1': [], 'Attacker1': [sim.get_node('Host:0:access')]},
1170
+ 2: {
1171
+ 'Defender1': [],
1172
+ 'Attacker1': [sim.get_node('Host:0:authenticate')],
1173
+ 'Attacker2': [],
1174
+ },
1175
+ 3: {
1176
+ 'Defender1': [],
1177
+ 'Attacker1': [sim.get_node('Host:0:access')],
1178
+ 'Attacker2': [],
1179
+ },
1149
1180
  4: {
1150
1181
  'Defender1': [],
1151
1182
  'Attacker1': [
@@ -1153,8 +1184,13 @@ def test_simulator_multiple_attackers() -> None:
1153
1184
  sim.get_node('Data:2:modify'),
1154
1185
  sim.get_node('Network:3:access'),
1155
1186
  ],
1187
+ 'Attacker2': [],
1188
+ },
1189
+ 5: {
1190
+ 'Defender1': [],
1191
+ 'Attacker1': [sim.get_node('Host:1:connect')],
1192
+ 'Attacker2': [],
1156
1193
  },
1157
- 5: {'Defender1': [], 'Attacker1': [sim.get_node('Host:1:connect')]},
1158
1194
  }
1159
1195
 
1160
1196
 
@@ -1571,6 +1607,59 @@ def test_actions_effects() -> None:
1571
1607
  'SecretData:attemptRead',
1572
1608
  }
1573
1609
 
1610
+ # But in the recording each step performs an action and an effect
1611
+ expected_recording = {
1612
+ 1: {'Attacker': ['Net1:attemptScan', 'Net1:scan']},
1613
+ 2: {'Attacker': ['ComputerA:attemptConnect', 'ComputerA:connect']},
1614
+ 3: {'Attacker': ['Net2:attemptScan', 'Net2:scan']},
1615
+ 4: {'Attacker': ['ComputerA:attemptAccess']},
1616
+ 5: {'Attacker': ['Net3:attemptScan', 'Net3:scan']},
1617
+ 6: {'Attacker': ['ComputerD:attemptConnect', 'ComputerD:connect']},
1618
+ 7: {'Attacker': ['ComputerD:attemptAccess', 'ComputerD:access']},
1619
+ 8: {'Attacker': ['SecretData:attemptRead', 'SecretData:read']},
1620
+ }
1621
+
1622
+ # Convert recording nodes to full names for comparison
1623
+ for i in sim.recording:
1624
+ assert len(sim.recording[i]['Attacker']) == len(
1625
+ expected_recording[i]['Attacker']
1626
+ )
1627
+ for j, node in enumerate(sim.recording[i]['Attacker']):
1628
+ assert node.full_name == expected_recording[i]['Attacker'][j]
1629
+
1630
+
1631
+ def test_actions_effects_entrypoints() -> None:
1632
+ """Verify actions and effects works as intended with entrypoints"""
1633
+
1634
+ scenario = Scenario.load_from_file(
1635
+ 'tests/testdata/scenarios/actions_effects_scenario_entrypoint_with_effects.yml'
1636
+ )
1637
+ sim = MalSimulator.from_scenario(
1638
+ scenario,
1639
+ sim_settings=MalSimulatorSettings(
1640
+ ttc_mode=TTCMode.DISABLED,
1641
+ run_defense_step_bernoullis=False,
1642
+ run_attack_step_bernoullis=False,
1643
+ attack_surface_skip_unnecessary=False,
1644
+ compromise_entrypoints_at_start=True,
1645
+ attacker_reward_mode=RewardMode.SAMPLE_TTC,
1646
+ seed=1,
1647
+ ),
1648
+ )
1649
+ selected_actions = run_simulation(sim, scenario.agent_settings)
1650
+
1651
+ # Attacker only selects steps starting with 'attempt'
1652
+ assert {n.full_name for n in selected_actions['Attacker']} == {
1653
+ 'Net1:attemptScan',
1654
+ 'Net2:attemptScan',
1655
+ 'Net3:attemptScan',
1656
+ 'ComputerD:attemptConnect',
1657
+ 'ComputerA:attemptConnect',
1658
+ 'ComputerD:attemptAccess',
1659
+ 'ComputerC:attemptConnect',
1660
+ 'SecretData:attemptRead',
1661
+ }
1662
+
1574
1663
  # But in the recording each step performs an action and an effect
1575
1664
  for i in sim.recording:
1576
1665
  action = sim.recording[i]['Attacker'][0]
File without changes
File without changes
File without changes
File without changes