mal-simulator 0.2.2__tar.gz → 0.2.3__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 (28) hide show
  1. {mal_simulator-0.2.2/mal_simulator.egg-info → mal_simulator-0.2.3}/PKG-INFO +1 -1
  2. {mal_simulator-0.2.2 → mal_simulator-0.2.3/mal_simulator.egg-info}/PKG-INFO +1 -1
  3. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/__init__.py +2 -2
  4. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/agents/searchers.py +26 -16
  5. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/pyproject.toml +1 -1
  6. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/AUTHORS +0 -0
  7. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/LICENSE +0 -0
  8. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/README.md +0 -0
  9. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/mal_simulator.egg-info/SOURCES.txt +0 -0
  10. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/mal_simulator.egg-info/dependency_links.txt +0 -0
  11. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/mal_simulator.egg-info/entry_points.txt +0 -0
  12. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/mal_simulator.egg-info/requires.txt +0 -0
  13. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/mal_simulator.egg-info/top_level.txt +0 -0
  14. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/__main__.py +0 -0
  15. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/agents/__init__.py +0 -0
  16. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/agents/decision_agent.py +0 -0
  17. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/agents/keyboard_input.py +0 -0
  18. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/agents/passive_agent.py +0 -0
  19. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/envs/__init__.py +0 -0
  20. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/envs/base_classes.py +0 -0
  21. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/envs/gym_envs.py +0 -0
  22. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/envs/malsim_vectorized_obs_env.py +0 -0
  23. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/mal_simulator.py +0 -0
  24. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/malsim/scenario.py +0 -0
  25. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/setup.cfg +0 -0
  26. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/tests/test_main.py +0 -0
  27. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/tests/test_mal_simulator.py +0 -0
  28. {mal_simulator-0.2.2 → mal_simulator-0.2.3}/tests/test_scenario.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mal-simulator
3
- Version: 0.2.2
3
+ Version: 0.2.3
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>
6
6
  License: Apache Software License
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mal-simulator
3
- Version: 0.2.2
3
+ Version: 0.2.3
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>
6
6
  License: Apache Software License
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # MAL Simulator v0.2.2
2
+ # MAL Simulator v0.2.3
3
3
  # Copyright 2025, Andrei Buhaiu.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@ MAL Simulator
24
24
  """
25
25
 
26
26
  __title__ = "malsim"
27
- __version__ = "0.2.2"
27
+ __version__ = "0.2.3"
28
28
  __authors__ = ["Andrei Buhaiu", "Joakim Loxdal", "Jakob Nyberg", "Nikolaos Kakouros"]
29
29
  __license__ = "Apache 2.0"
30
30
  __docformat__ = "restructuredtext en"
@@ -4,8 +4,7 @@ import random
4
4
  import re
5
5
 
6
6
  from collections import deque
7
- from collections.abc import Iterable
8
- from typing import Optional, TYPE_CHECKING
7
+ from typing import Optional, TYPE_CHECKING, Any
9
8
 
10
9
  from .decision_agent import DecisionAgent
11
10
  from ..mal_simulator import MalSimAgentStateView
@@ -27,7 +26,7 @@ class BreadthFirstAttacker(DecisionAgent):
27
26
  name = ' '.join(re.findall(r'[A-Z][^A-Z]*', __qualname__))
28
27
  # A human-friendly name for the agent.
29
28
 
30
- default_settings = {
29
+ default_settings: dict[str, Any] = {
31
30
  'randomize': False,
32
31
  # Whether to randomize next target selection, still respecting the
33
32
  # policy of the agent (e.g. BFS or DFS).
@@ -48,28 +47,38 @@ class BreadthFirstAttacker(DecisionAgent):
48
47
  self.settings = self.default_settings | agent_config
49
48
 
50
49
  self.rng = random.Random(self.settings.get('seed'))
50
+ self.started = False
51
51
 
52
52
  def get_next_action(
53
53
  self, agent_state: MalSimAgentStateView, **kwargs
54
54
  ) -> Optional[AttackGraphNode]:
55
- self._update_targets(agent_state.action_surface)
56
- self._select_next_target()
57
-
55
+ self._update_targets(
56
+ agent_state.step_action_surface_additions
57
+ if self.started
58
+ else agent_state.action_surface,
59
+ agent_state.step_action_surface_removals,
60
+ **kwargs,
61
+ )
62
+ self._select_next_target(**kwargs)
63
+
64
+ self.started = True
58
65
  return self.current_target
59
66
 
60
- def _update_targets(self, action_surface: Iterable[AttackGraphNode]):
67
+ def _update_targets(
68
+ self,
69
+ new_targets_set: set[AttackGraphNode],
70
+ disabled_nodes_set: set[AttackGraphNode],
71
+ **kwargs: Any,
72
+ ):
61
73
  if self.settings['seed']:
62
74
  # If a seed is set, we assume the user wants determinism in the
63
75
  # simulation. Thus, we sort to an ordered list to make sure the
64
76
  # non-deterministic ordering of the action_surface set does not
65
77
  # break simulation determinism.
66
- action_surface = sorted(list(action_surface), key=lambda n: n.id)
67
-
68
- new_targets = [
69
- step
70
- for step in action_surface
71
- if step not in self.targets and not step.is_compromised()
72
- ]
78
+ new_targets = sorted(new_targets_set, key=lambda n: n.id)
79
+ else:
80
+ # sorted above returns a list already
81
+ new_targets = list(new_targets_set)
73
82
 
74
83
  if self.settings['randomize']:
75
84
  self.rng.shuffle(new_targets)
@@ -81,11 +90,12 @@ class BreadthFirstAttacker(DecisionAgent):
81
90
  new_targets.append(self.current_target)
82
91
 
83
92
  # Enabled defenses may remove previously possible attack steps.
84
- self.targets = deque(filter(lambda n: n.is_viable, self.targets))
93
+ if disabled_nodes_set:
94
+ self.targets = deque(n for n in self.targets if n.is_viable)
85
95
 
86
96
  getattr(self.targets, self._extend_method)(new_targets)
87
97
 
88
- def _select_next_target(self) -> None:
98
+ def _select_next_target(self, **kwargs: Any) -> None:
89
99
  """
90
100
  Implement the actual next target selection logic.
91
101
  """
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mal-simulator"
3
- version = "0.2.2"
3
+ version = "0.2.3"
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