mal-simulator 3.2.0__tar.gz → 3.2.1__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 (78) hide show
  1. {mal_simulator-3.2.0/mal_simulator.egg-info → mal_simulator-3.2.1}/PKG-INFO +1 -1
  2. {mal_simulator-3.2.0 → mal_simulator-3.2.1/mal_simulator.egg-info}/PKG-INFO +1 -1
  3. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/__init__.py +2 -2
  4. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/envs/graph/mal_spaces.py +1 -1
  5. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/attack_surface.py +3 -7
  6. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/attacker_state_factories.py +6 -6
  7. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/graph_utils.py +7 -18
  8. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/run_simulation.py +10 -2
  9. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/simulator.py +3 -0
  10. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/pyproject.toml +1 -1
  11. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/AUTHORS +0 -0
  12. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/LICENSE +0 -0
  13. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/README.md +0 -0
  14. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/mal_simulator.egg-info/SOURCES.txt +0 -0
  15. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/mal_simulator.egg-info/dependency_links.txt +0 -0
  16. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/mal_simulator.egg-info/entry_points.txt +0 -0
  17. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/mal_simulator.egg-info/requires.txt +0 -0
  18. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/mal_simulator.egg-info/top_level.txt +0 -0
  19. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/__main__.py +0 -0
  20. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/config/__init__.py +0 -0
  21. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/config/agent_settings.py +0 -0
  22. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/config/agent_settings_factories.py +0 -0
  23. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/config/node_property_rule.py +0 -0
  24. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/config/sim_settings.py +0 -0
  25. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/envs/__init__.py +0 -0
  26. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/envs/base_classes.py +0 -0
  27. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/envs/graph/__init__.py +0 -0
  28. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/envs/graph/graph_env.py +0 -0
  29. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/envs/graph/serialization.py +0 -0
  30. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/envs/graph/utils.py +0 -0
  31. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/envs/graph/wrapper.py +0 -0
  32. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/__init__.py +0 -0
  33. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/agent_state.py +0 -0
  34. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/agent_states.py +0 -0
  35. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/attacker_state.py +0 -0
  36. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/attacker_step.py +0 -0
  37. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/defender_state.py +0 -0
  38. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/defender_state_factories.py +0 -0
  39. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/defender_step.py +0 -0
  40. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/defense_surface.py +0 -0
  41. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/event_logger.py +0 -0
  42. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/false_alerts.py +0 -0
  43. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/graph_processing.py +0 -0
  44. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/graph_state.py +0 -0
  45. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/node_getters.py +0 -0
  46. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/observability.py +0 -0
  47. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/reset_agent.py +0 -0
  48. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/rewards.py +0 -0
  49. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/simulator_state.py +0 -0
  50. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/simulator_static_data.py +0 -0
  51. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/state_query.py +0 -0
  52. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/mal_simulator/ttc_utils.py +0 -0
  53. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/__init__.py +0 -0
  54. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/attackers/__init__.py +0 -0
  55. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/attackers/searchers.py +0 -0
  56. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/attackers/shortest_path.py +0 -0
  57. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/attackers/ttc_soft_min.py +0 -0
  58. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/decision_agent.py +0 -0
  59. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/defenders/__init__.py +0 -0
  60. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/defenders/heuristic_agent.py +0 -0
  61. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/keyboard_input.py +0 -0
  62. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/passive_agent.py +0 -0
  63. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/random_agent.py +0 -0
  64. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/policies/utils/path_finding.py +0 -0
  65. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/scenario/__init__.py +0 -0
  66. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/scenario/scenario.py +0 -0
  67. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/types.py +0 -0
  68. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/malsim/visualization/malsim_gui_client.py +0 -0
  69. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/setup.cfg +0 -0
  70. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/tests/test_attacker.py +0 -0
  71. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/tests/test_attacker_settings.py +0 -0
  72. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/tests/test_defender.py +0 -0
  73. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/tests/test_event_logger.py +0 -0
  74. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/tests/test_graph_processing.py +0 -0
  75. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/tests/test_main.py +0 -0
  76. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/tests/test_mal_simulator.py +0 -0
  77. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/tests/test_scenario.py +0 -0
  78. {mal_simulator-3.2.0 → mal_simulator-3.2.1}/tests/test_ttc_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mal-simulator
3
- Version: 3.2.0
3
+ Version: 3.2.1
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: 3.2.0
3
+ Version: 3.2.1
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,4 +1,4 @@
1
- # MAL Simulator v3.2.0
1
+ # MAL Simulator v3.2.1
2
2
  # Copyright 2025, Andrei Buhaiu.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +26,7 @@ from malsim.scenario import Scenario
26
26
  from malsim.config import AttackerSettings, DefenderSettings
27
27
 
28
28
  __title__ = 'malsim'
29
- __version__ = '3.2.0'
29
+ __version__ = '3.2.1'
30
30
  __authors__ = [
31
31
  'Andrei Buhaiu',
32
32
  'Joakim Loxdal',
@@ -176,7 +176,7 @@ class MALObs(Space[MALObsInstance]):
176
176
  return False
177
177
 
178
178
  def _generate_sample_space(
179
- self, base_space: None | Box | Discrete, num: int
179
+ self, base_space: Box | Discrete | None, num: int
180
180
  ) -> Box | MultiDiscrete | None:
181
181
  raise NotImplementedError(
182
182
  'Sample space generation is not implemented for MALObs'
@@ -66,7 +66,7 @@ def get_attack_surface(
66
66
  skip_unnecessary = settings.skip_unnecessary
67
67
 
68
68
  def uncompromised(node: AttackGraphNode) -> bool:
69
- return not (skip_compromised and node in performed_nodes)
69
+ return node not in performed_nodes
70
70
 
71
71
  def necessary(node: AttackGraphNode) -> bool:
72
72
  return node_is_necessary(sim_state, node)
@@ -88,9 +88,5 @@ def get_attack_surface(
88
88
  and traversable(node)
89
89
  )
90
90
 
91
- return frozenset(
92
- node
93
- for parent in from_nodes
94
- for node in parent.children
95
- if in_attack_surface(node)
96
- )
91
+ from_node_children = {node for parent in from_nodes for node in parent.children}
92
+ return frozenset(filter(in_attack_surface, from_node_children))
@@ -72,10 +72,10 @@ def create_attacker_state(
72
72
  num_attempts[node] += 1
73
73
 
74
74
  action_surface = get_attack_surface(
75
- attack_surface_settings,
76
- sim_state,
77
- attacker_settings.actionable_steps,
78
- previous_performed_nodes | new_performed_nodes,
75
+ settings=attack_surface_settings,
76
+ sim_state=sim_state,
77
+ actionability=attacker_settings.actionable_steps,
78
+ performed_nodes=performed_nodes,
79
79
  )
80
80
 
81
81
  if not previous_state and not sim_state.settings.compromise_entrypoints_at_start:
@@ -137,9 +137,9 @@ def get_entry_points(
137
137
  else:
138
138
  # Multiple potential entry point sets given
139
139
  # - sample one set of entry points from the options
140
- chosen_entry_points = rng.choice(list(attacker_settings.entry_points)) # type: ignore
140
+ chosen_entry_points = rng.choice(list(attacker_settings.entry_points))
141
141
  return set(
142
- full_names_or_nodes_to_nodes(sim_state.attack_graph, chosen_entry_points)
142
+ full_names_or_nodes_to_nodes(sim_state.attack_graph, chosen_entry_points) # type: ignore
143
143
  )
144
144
 
145
145
 
@@ -5,11 +5,10 @@ from collections.abc import Set
5
5
 
6
6
  from maltoolbox.attackgraph import AttackGraphNode
7
7
  from malsim.config.node_property_rule import NodePropertyRule
8
- from malsim.mal_simulator.node_getters import full_name_or_node_to_node
9
8
  from malsim.mal_simulator.simulator_state import MalSimulatorState
10
9
 
11
10
 
12
- def node_is_blocked(sim_state: MalSimulatorState, node: AttackGraphNode | str) -> bool:
11
+ def node_is_blocked(sim_state: MalSimulatorState, node: AttackGraphNode) -> bool:
13
12
  """Get blocked status of a node"""
14
13
 
15
14
  def _node_blocks_children(node: AttackGraphNode) -> bool:
@@ -25,7 +24,6 @@ def node_is_blocked(sim_state: MalSimulatorState, node: AttackGraphNode | str) -
25
24
  case _:
26
25
  return False
27
26
 
28
- node = full_name_or_node_to_node(sim_state.attack_graph, node)
29
27
  if node.type == 'and':
30
28
  return node in sim_state.graph_state.impossible_attack_steps or any(
31
29
  _node_blocks_children(parent) for parent in node.parents
@@ -38,11 +36,8 @@ def node_is_blocked(sim_state: MalSimulatorState, node: AttackGraphNode | str) -
38
36
  return False
39
37
 
40
38
 
41
- def node_is_necessary(
42
- sim_state: MalSimulatorState, node: AttackGraphNode | str
43
- ) -> bool:
39
+ def node_is_necessary(sim_state: MalSimulatorState, node: AttackGraphNode) -> bool:
44
40
  """Get necessity of a node"""
45
- node = full_name_or_node_to_node(sim_state.attack_graph, node)
46
41
  return sim_state.graph_state.necessity_per_node[node]
47
42
 
48
43
 
@@ -70,13 +65,6 @@ def node_is_traversable(
70
65
  node - the node we wish to evalute traversability for
71
66
  """
72
67
 
73
- def parents_reached(node: AttackGraphNode) -> bool:
74
- # If no parent is reached, the node can not be traversable
75
- return (node.parents & performed_nodes) != set()
76
-
77
- def or_traversable(node: AttackGraphNode) -> bool:
78
- return any(parent in performed_nodes for parent in node.parents)
79
-
80
68
  def and_traversable(node: AttackGraphNode) -> bool:
81
69
  return all(
82
70
  parent in performed_nodes
@@ -84,9 +72,9 @@ def node_is_traversable(
84
72
  if node_is_necessary(sim_state, parent)
85
73
  )
86
74
 
87
- def is_and_or_traversable(node: AttackGraphNode) -> bool:
75
+ def is_and_or_traversable(node: AttackGraphNode, parents_reached: bool) -> bool:
88
76
  if node.type == 'or':
89
- return or_traversable(node)
77
+ return parents_reached
90
78
  elif node.type == 'and':
91
79
  return and_traversable(node)
92
80
  else:
@@ -97,8 +85,9 @@ def node_is_traversable(
97
85
  return (
98
86
  is_attack_step(node)
99
87
  and not node_is_blocked(sim_state, node)
100
- and parents_reached(node)
101
- and is_and_or_traversable(node)
88
+ # If no parent is reached, the node can not be traversable
89
+ and (parents_reached := (node.parents & performed_nodes) != set())
90
+ and is_and_or_traversable(node, parents_reached)
102
91
  )
103
92
 
104
93
 
@@ -5,11 +5,19 @@ from malsim.policies.decision_agent import DecisionAgent
5
5
  from malsim.mal_simulator.simulator import MalSimulator
6
6
 
7
7
 
8
- def run_simulation(sim: MalSimulator) -> dict[str, list[AttackGraphNode]]:
8
+ def run_simulation(
9
+ sim: MalSimulator, max_steps: int | float | None = None
10
+ ) -> dict[str, list[AttackGraphNode]]:
9
11
  """Run a simulation with agents
10
12
 
13
+ Args:
14
+ sim: the simulator to run
15
+ max_steps: if set, stop after this many steps even if not sim.done()
16
+
11
17
  Return selected actions by each agent in each step
12
18
  """
19
+ if max_steps is None:
20
+ max_steps = float('inf')
13
21
  agents = sim.agent_settings
14
22
  agent_actions: dict[str, list[AttackGraphNode]] = {}
15
23
  total_rewards = dict.fromkeys(agents, 0.0)
@@ -17,7 +25,7 @@ def run_simulation(sim: MalSimulator) -> dict[str, list[AttackGraphNode]]:
17
25
  logger.info('Starting CLI env simulator.')
18
26
  states = sim.reset()
19
27
  iteration = 0
20
- while not sim.done():
28
+ while not sim.done() and (iteration < max_steps):
21
29
  print(f'Iteration {iteration}')
22
30
  actions: dict[str, list[AttackGraphNode]] = {}
23
31
 
@@ -28,6 +28,7 @@ from malsim.mal_simulator.defender_step import (
28
28
  )
29
29
  from malsim.mal_simulator.graph_state import compute_initial_graph_state
30
30
  from malsim.mal_simulator.node_getters import (
31
+ full_name_or_node_to_node,
31
32
  full_names_or_nodes_to_nodes,
32
33
  get_node,
33
34
  )
@@ -284,9 +285,11 @@ class MalSimulator:
284
285
  return node_false_negative_rate(node, false_negative_rates_rule)
285
286
 
286
287
  def node_is_blocked(self, node: AttackGraphNode | str) -> bool:
288
+ node = full_name_or_node_to_node(self.sim_state.attack_graph, node)
287
289
  return node_is_blocked(self.sim_state, node)
288
290
 
289
291
  def node_is_necessary(self, node: AttackGraphNode | str) -> bool:
292
+ node = full_name_or_node_to_node(self.sim_state.attack_graph, node)
290
293
  return node_is_necessary(self.sim_state, node)
291
294
 
292
295
  def node_is_enabled_defense(self, node: AttackGraphNode | str) -> bool:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mal-simulator"
3
- version = "3.2.0"
3
+ version = "3.2.1"
4
4
  authors = [
5
5
  { name="Andrei Buhaiu", email="buhaiu@kth.se" },
6
6
  { name="Joakim Loxdal", email="loxdal@kth.se" },
File without changes
File without changes
File without changes
File without changes