mal-simulator 0.2.0__tar.gz → 0.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 (28) hide show
  1. {mal_simulator-0.2.0/mal_simulator.egg-info → mal_simulator-0.2.1}/PKG-INFO +1 -1
  2. {mal_simulator-0.2.0 → mal_simulator-0.2.1/mal_simulator.egg-info}/PKG-INFO +1 -1
  3. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/__init__.py +2 -2
  4. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/mal_simulator.py +12 -5
  5. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/pyproject.toml +1 -1
  6. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/tests/test_mal_simulator.py +52 -33
  7. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/AUTHORS +0 -0
  8. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/LICENSE +0 -0
  9. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/README.md +0 -0
  10. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/mal_simulator.egg-info/SOURCES.txt +0 -0
  11. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/mal_simulator.egg-info/dependency_links.txt +0 -0
  12. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/mal_simulator.egg-info/entry_points.txt +0 -0
  13. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/mal_simulator.egg-info/requires.txt +0 -0
  14. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/mal_simulator.egg-info/top_level.txt +0 -0
  15. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/__main__.py +0 -0
  16. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/agents/__init__.py +0 -0
  17. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/agents/decision_agent.py +0 -0
  18. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/agents/keyboard_input.py +0 -0
  19. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/agents/passive_agent.py +0 -0
  20. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/agents/searchers.py +0 -0
  21. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/envs/__init__.py +0 -0
  22. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/envs/base_classes.py +0 -0
  23. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/envs/gym_envs.py +0 -0
  24. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/envs/malsim_vectorized_obs_env.py +0 -0
  25. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/malsim/scenario.py +0 -0
  26. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/setup.cfg +0 -0
  27. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/tests/test_main.py +0 -0
  28. {mal_simulator-0.2.0 → mal_simulator-0.2.1}/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.0
3
+ Version: 0.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>
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.0
3
+ Version: 0.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>
6
6
  License: Apache Software License
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # MAL Simulator v0.2.0
2
+ # MAL Simulator v0.2.1
3
3
  # Copyright 2024, 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.0"
27
+ __version__ = "0.2.1"
28
28
  __authors__ = ["Andrei Buhaiu", "Joakim Loxdal", "Jakob Nyberg", "Nikolaos Kakouros"]
29
29
  __license__ = "Apache 2.0"
30
30
  __docformat__ = "restructuredtext en"
@@ -211,7 +211,9 @@ class MalSimulator():
211
211
 
212
212
  if isinstance(agent, MalSimAttackerState):
213
213
  attacker = self.attack_graph.attackers[agent.attacker_id]
214
- agent.action_surface = query.calculate_attack_surface(attacker)
214
+ agent.action_surface = query.calculate_attack_surface(
215
+ attacker, skip_compromised = True
216
+ )
215
217
 
216
218
  elif isinstance(agent, MalSimDefenderState):
217
219
  agent.action_surface = \
@@ -310,14 +312,12 @@ class MalSimulator():
310
312
 
311
313
  def _attacker_step(
312
314
  self, agent: MalSimAttackerState, nodes: list[AttackGraphNode]
313
- ) -> set[AttackGraphNode]:
315
+ ):
314
316
  """Compromise attack step nodes with attacker
315
317
 
316
318
  Args:
317
319
  agent - the agent to compromise nodes with
318
320
  nodes - the nodes to compromise
319
-
320
- Returns: A set of attack steps nodes that were compromised
321
321
  """
322
322
 
323
323
  compromised_nodes = set()
@@ -352,9 +352,16 @@ class MalSimulator():
352
352
 
353
353
  # Update attacker action surface
354
354
  attack_surface_additions = query.calculate_attack_surface(
355
- attacker, from_nodes=compromised_nodes, skip_compromised=True
355
+ attacker, from_nodes = compromised_nodes, skip_compromised = True
356
356
  )
357
357
 
358
+ # Filter out nodes already in action surface, these are not additions.
359
+ attack_surface_additions -= agent.action_surface
360
+ # Also filter out nodes already compromised from the attack surface.
361
+ # TODO: Make this configurable in the future
362
+ agent.action_surface -= compromised_nodes
363
+ agent.step_action_surface_removals |= compromised_nodes
364
+
358
365
  agent.step_action_surface_additions = attack_surface_additions
359
366
  agent.action_surface |= attack_surface_additions
360
367
  agent.step_performed_nodes = compromised_nodes
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mal-simulator"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  authors = [
5
5
  { name="Andrei Buhaiu", email="buhaiu@kth.se" },
6
6
  { name="Joakim Loxdal", email="loxdal@kth.se" },
@@ -1,6 +1,6 @@
1
1
  """Test MalSimulator class"""
2
2
 
3
- from maltoolbox.attackgraph import AttackGraph, Attacker
3
+ from maltoolbox.attackgraph import AttackGraphNode, AttackGraph, Attacker
4
4
  from malsim.mal_simulator import MalSimulator
5
5
 
6
6
  from malsim.scenario import load_scenario
@@ -168,6 +168,12 @@ def test_defender_step(corelang_lang_graph, model):
168
168
 
169
169
 
170
170
  def test_agent_state_views_simple(corelang_lang_graph, model):
171
+
172
+ def get_node(full_name) -> AttackGraphNode:
173
+ node = sim.attack_graph.get_node_by_full_name(full_name)
174
+ assert node
175
+ return node
176
+
171
177
  attack_graph = AttackGraph(corelang_lang_graph, model)
172
178
  entry_point = attack_graph.get_node_by_full_name('OS App:fullAccess')
173
179
 
@@ -178,11 +184,12 @@ def test_agent_state_views_simple(corelang_lang_graph, model):
178
184
  attacker_id = 100
179
185
  )
180
186
  attack_graph.add_attacker(attacker, attacker.id)
187
+
188
+ # Create simulator and register agents
181
189
  sim = MalSimulator(attack_graph)
182
190
  attacker_name = 'attacker'
183
191
  defender_name = 'defender'
184
192
  sim.register_attacker(attacker_name, attacker.id)
185
-
186
193
  sim.register_defender(defender_name)
187
194
 
188
195
  # Evaluate the agent state views after reset
@@ -197,55 +204,67 @@ def test_agent_state_views_simple(corelang_lang_graph, model):
197
204
  assert asv.step_action_surface_removals == set()
198
205
  assert dsv.step_action_surface_removals == set()
199
206
 
207
+ # Save all relvant nodes in variables
208
+ program2_not_present = get_node('Program 2:notPresent')
209
+ os_app_attempt_deny = get_node('OS App:attemptDeny')
210
+ os_app_success_deny = get_node('OS App:successfulDeny')
211
+ os_app_not_present = get_node('OS App:notPresent')
212
+ os_app_access_netcon = get_node('OS App:accessNetworkAndConnections')
213
+ os_app_spec_access = get_node('OS App:specificAccess')
214
+
200
215
  # Evaluate the agent state views after stepping through an attack step and
201
216
  # a defense that will not impact it in any way
217
+
202
218
  state_views = sim.step({
203
- 'defender': {sim.attack_graph.get_node_by_full_name(
204
- 'Program 2:notPresent')},
205
- 'attacker': {sim.attack_graph.get_node_by_full_name(
206
- 'OS App:attemptDeny')}
219
+ 'defender': [program2_not_present],
220
+ 'attacker': [os_app_attempt_deny]
207
221
  })
208
222
  asv = state_views['attacker']
209
223
  dsv = state_views['defender']
210
- assert asv.step_performed_nodes == {
211
- sim.attack_graph.get_node_by_full_name('OS App:attemptDeny')}
212
- assert dsv.step_performed_nodes == {
213
- sim.attack_graph.get_node_by_full_name('Program 2:notPresent')}
214
- assert asv.step_action_surface_additions == {
215
- sim.attack_graph.get_node_by_full_name('OS App:successfulDeny')}
224
+ assert asv.step_performed_nodes == {os_app_attempt_deny}
225
+ assert dsv.step_performed_nodes == {program2_not_present}
226
+ assert asv.step_action_surface_additions == {os_app_success_deny}
216
227
  assert dsv.step_action_surface_additions == set()
217
- assert asv.step_action_surface_removals == set()
218
- assert dsv.step_action_surface_removals == {
219
- sim.attack_graph.get_node_by_full_name('Program 2:notPresent')}
220
- assert dsv.step_all_compromised_nodes == {
221
- sim.attack_graph.get_node_by_full_name('OS App:attemptDeny')}
228
+ assert asv.step_action_surface_removals == {os_app_attempt_deny}
229
+ assert os_app_attempt_deny not in asv.action_surface
230
+ assert dsv.step_action_surface_removals == {program2_not_present}
231
+ assert dsv.step_all_compromised_nodes == {os_app_attempt_deny}
222
232
  assert len(dsv.step_unviable_nodes) == 49
223
233
 
234
+ # Go through an attack step that already has some children in the attack
235
+ # surface(OS App:accessNetworkAndConnections in this case)
236
+ assert os_app_access_netcon in asv.action_surface
237
+ state_views = sim.step({
238
+ 'defender': [],
239
+ 'attacker': [os_app_spec_access]
240
+ })
241
+ asv = state_views['attacker']
242
+ dsv = state_views['defender']
243
+ assert asv.step_performed_nodes == {os_app_spec_access}
244
+ assert dsv.step_performed_nodes == set()
245
+ assert os_app_access_netcon in asv.action_surface
246
+ assert os_app_access_netcon not in asv.step_action_surface_additions
247
+ assert dsv.step_action_surface_additions == set()
248
+ assert asv.step_action_surface_removals == {os_app_spec_access}
249
+ assert os_app_spec_access not in asv.action_surface
250
+ assert dsv.step_action_surface_removals == set()
251
+ assert dsv.step_all_compromised_nodes == {os_app_spec_access}
252
+ assert len(dsv.step_unviable_nodes) == 0
253
+
224
254
  # Evaluate the agent state views after stepping through an attack step and
225
255
  # a defense that would prevent it from occurring
226
256
  state_views = sim.step({
227
- 'defender': {sim.attack_graph.get_node_by_full_name(
228
- 'OS App:notPresent')},
229
- 'attacker': {sim.attack_graph.get_node_by_full_name(
230
- 'OS App:successfulDeny')}
257
+ 'defender': [os_app_not_present],
258
+ 'attacker': [os_app_success_deny]
231
259
  })
232
260
  asv = state_views['attacker']
233
261
  dsv = state_views['defender']
234
262
  assert asv.step_performed_nodes == set()
235
- assert dsv.step_performed_nodes == {
236
- sim.attack_graph.get_node_by_full_name('OS App:notPresent')}
263
+ assert dsv.step_performed_nodes == {os_app_not_present}
237
264
  assert asv.step_action_surface_additions == set()
238
265
  assert dsv.step_action_surface_additions == set()
239
- assert asv.step_action_surface_removals == {
240
- sim.attack_graph.get_node_by_full_name('OS App:accessNetworkAndConnections'),
241
- sim.attack_graph.get_node_by_full_name('OS App:specificAccess'),
242
- sim.attack_graph.get_node_by_full_name('OS App:attemptApplicationRespondConnectThroughData'),
243
- sim.attack_graph.get_node_by_full_name('OS App:attemptRead'),
244
- sim.attack_graph.get_node_by_full_name('OS App:attemptModify'),
245
- sim.attack_graph.get_node_by_full_name('OS App:successfulDeny'),
246
- }
247
- assert dsv.step_action_surface_removals == {
248
- sim.attack_graph.get_node_by_full_name('OS App:notPresent')}
266
+ assert len(asv.step_action_surface_removals) == 12
267
+ assert dsv.step_action_surface_removals == {os_app_not_present}
249
268
  assert dsv.step_all_compromised_nodes == set()
250
269
  assert len(dsv.step_unviable_nodes) == 55
251
270
 
File without changes
File without changes
File without changes
File without changes