mal-toolbox 0.3.4__py3-none-any.whl → 0.3.6__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mal-toolbox
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Summary: A collection of tools used to create MAL models and attack graphs.
5
5
  Author-email: Andrei Buhaiu <buhaiu@kth.se>, Joakim Loxdal <loxdal@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Giuseppe Nebbione <nebbione@kth.se>
6
6
  License: Apache Software License
@@ -1,10 +1,10 @@
1
- maltoolbox/__init__.py,sha256=hZCoM58rmBiJvbjPRpzNVFgNlhml32Pq7NB0fb0kIKs,2088
1
+ maltoolbox/__init__.py,sha256=IPS2eQ4uAhZ4Axdc_vu-lHK7nXXT_peN_nMQn5Ci_qY,2088
2
2
  maltoolbox/__main__.py,sha256=PSg8vFS8X-klJBJdSzrg0aLh9ykZgbcoSSEy3DTQoQQ,3499
3
3
  maltoolbox/exceptions.py,sha256=0YjPx2v1yYumZ2o7pVZ1s_jS-GAb3Ng979KEFhROSNY,1399
4
4
  maltoolbox/file_utils.py,sha256=tBR8Kjl8IoFzAtYaLNHNALuQrdMT3pD1ZpczHm1pu2g,1875
5
- maltoolbox/model.py,sha256=XCneM5Hdl2GQhtgXYq0SUAlHBksXn7okevIsSKMSwVY,24084
5
+ maltoolbox/model.py,sha256=H7hmnTQVz6Uublih2bPfoQGNLvUjBWRnXUQ6SW6jJc8,24051
6
6
  maltoolbox/attackgraph/__init__.py,sha256=AHDyX6dAkx3mDic2K56v1xche9N6ofDfbaHkKbdJ2qQ,230
7
- maltoolbox/attackgraph/attacker.py,sha256=dKMAcOwlNM3LL8qh1tBJuzjFxlTNG-QI2st1LzP8Ofc,4030
7
+ maltoolbox/attackgraph/attacker.py,sha256=EwlzVinscBKO84QrCvy2W1jxXqTHrrufOovO3t6Xi2A,4113
8
8
  maltoolbox/attackgraph/attackgraph.py,sha256=5ejaqeTF6QNc_75p_jgvC9-33-4J0PaaHUFBi_oQy20,32663
9
9
  maltoolbox/attackgraph/node.py,sha256=Ec67_u_8qf_MgCHaUg4wIbZFC013GWxbIsC8EjoguzE,6465
10
10
  maltoolbox/attackgraph/query.py,sha256=TPr0yDK_ZpRWO4BVTZ64_ATNjLnrglU3Jh1QGkhLeE0,7441
@@ -20,10 +20,10 @@ maltoolbox/language/compiler/mal_parser.py,sha256=sUoaE43l2VKg-Dou30mk2wlVS1FvdO
20
20
  maltoolbox/translators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  maltoolbox/translators/securicad.py,sha256=PJYjieioWN5tE_oKm83dtgV5UkC8EUH9Vsy3-FxBtUo,7017
22
22
  maltoolbox/translators/updater.py,sha256=8bisZnzMWjGaG5tu8jdF-Oq6bPwIjXkVO-_yZDGc6cA,8652
23
- mal_toolbox-0.3.4.dist-info/AUTHORS,sha256=zxLrLe8EY39WtRKlAY4Oorx4Z2_LHV2ApRvDGZgY7xY,127
24
- mal_toolbox-0.3.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
- mal_toolbox-0.3.4.dist-info/METADATA,sha256=bP52aB2aNCsIIBk6J4_tPhUI0B5q_xm44sNI-TSaUtU,6158
26
- mal_toolbox-0.3.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
27
- mal_toolbox-0.3.4.dist-info/entry_points.txt,sha256=oqby5O6cUP_OHCm70k_iYPA6UlbTBf7se1i3XwdK3uU,56
28
- mal_toolbox-0.3.4.dist-info/top_level.txt,sha256=phqRVLRKGdSUgRY03mcpi2cmbbDo5YGjkV4gkqHFFcM,11
29
- mal_toolbox-0.3.4.dist-info/RECORD,,
23
+ mal_toolbox-0.3.6.dist-info/AUTHORS,sha256=zxLrLe8EY39WtRKlAY4Oorx4Z2_LHV2ApRvDGZgY7xY,127
24
+ mal_toolbox-0.3.6.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
+ mal_toolbox-0.3.6.dist-info/METADATA,sha256=lJ1tUZbqDf4d808Y4w_WPZcL0jyrgxpi9i4Ljsijipc,6158
26
+ mal_toolbox-0.3.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
27
+ mal_toolbox-0.3.6.dist-info/entry_points.txt,sha256=oqby5O6cUP_OHCm70k_iYPA6UlbTBf7se1i3XwdK3uU,56
28
+ mal_toolbox-0.3.6.dist-info/top_level.txt,sha256=phqRVLRKGdSUgRY03mcpi2cmbbDo5YGjkV4gkqHFFcM,11
29
+ mal_toolbox-0.3.6.dist-info/RECORD,,
maltoolbox/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # MAL Toolbox v0.3.4
3
- # Copyright 2024, Andrei Buhaiu.
2
+ # MAL Toolbox v0.3.6
3
+ # Copyright 2025, Andrei Buhaiu.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ MAL-Toolbox Framework
21
21
  """
22
22
 
23
23
  __title__ = "maltoolbox"
24
- __version__ = "0.3.4"
24
+ __version__ = "0.3.6"
25
25
  __authors__ = [
26
26
  "Andrei Buhaiu",
27
27
  "Giuseppe Nebbione",
@@ -23,9 +23,11 @@ class Attacker:
23
23
  attacker_id: Optional[int] = None
24
24
  ):
25
25
  self.name = name
26
- self.entry_points = entry_points
27
- self.reached_attack_steps = reached_attack_steps
28
26
  self.id = attacker_id
27
+ self.entry_points = entry_points
28
+ self.reached_attack_steps: set[AttackGraphNode] = set()
29
+ for node in reached_attack_steps:
30
+ self.compromise(node)
29
31
 
30
32
  def to_dict(self) -> dict:
31
33
  attacker_dict: dict = {
maltoolbox/model.py CHANGED
@@ -152,11 +152,6 @@ class Model():
152
152
  self.lang_graph = lang_graph
153
153
  self.maltoolbox_version: str = mt_version
154
154
 
155
- # Below sets used to check for duplicate names or ids,
156
- # better for optimization than iterating over all assets
157
- self.asset_ids: set[int] = set()
158
- self.asset_names: set[str] = set()
159
-
160
155
 
161
156
  def add_asset(
162
157
  self,
@@ -192,16 +187,15 @@ class Model():
192
187
 
193
188
  # Set asset ID and check for duplicates
194
189
  asset_id = asset_id or self.next_id
195
- if asset_id in self.asset_ids:
190
+ if asset_id in self.assets:
196
191
  raise ValueError(f'Asset index {asset_id} already in use.')
197
- self.asset_ids.add(asset_id)
198
192
 
199
193
  self.next_id = max(asset_id + 1, self.next_id)
200
194
 
201
195
  if not name:
202
196
  name = asset_type + ':' + str(asset_id)
203
197
  else:
204
- if name in self.asset_names:
198
+ if name in self._name_to_asset:
205
199
  if allow_duplicate_names:
206
200
  name = name + ':' + str(asset_id)
207
201
  else:
@@ -209,7 +203,6 @@ class Model():
209
203
  f'Asset name {name} is a duplicate'
210
204
  ' and we do not allow duplicates.'
211
205
  )
212
- self.asset_names.add(name)
213
206
 
214
207
  lg_asset = self.lang_graph.assets[asset_type]
215
208
 
@@ -252,7 +245,10 @@ class Model():
252
245
  )
253
246
 
254
247
  # First remove all of the associated assets
255
- for fieldname, assoc_assets in asset.associated_assets.items():
248
+ # We can not remove from the dict while iterating over it
249
+ # so we first have to copy the keys and then remove those assets
250
+ associated_fieldnames = dict(asset.associated_assets)
251
+ for fieldname, assoc_assets in associated_fieldnames.items():
256
252
  asset.remove_associated_assets(fieldname, assoc_assets)
257
253
 
258
254
  # Also remove all of the entry points
@@ -656,17 +652,13 @@ class ModelAsset:
656
652
  other_fieldname, set()
657
653
  ).add(self)
658
654
 
659
- def remove_associated_assets(self, fieldname: str,
660
- assets: set[ModelAsset]):
655
+ def remove_associated_assets(
656
+ self, fieldname: str, assets: set[ModelAsset]):
661
657
  """ Remove the assets provided as a parameter from the set of
662
658
  associated assets dictionary entry corresponding to the fieldname
663
659
  parameter.
664
660
  """
665
- self._associated_assets[fieldname] -= set(assets)
666
- if len(self._associated_assets[fieldname]) == 0:
667
- del self._associated_assets[fieldname]
668
-
669
- # Also remove this asset to the associated assets' dictionaries
661
+ # Remove this asset from its associated assets' dictionaries
670
662
  lg_assoc = self.lg_asset.associations[fieldname]
671
663
  other_fieldname = lg_assoc.get_opposite_fieldname(fieldname)
672
664
  for asset in assets:
@@ -674,6 +666,11 @@ class ModelAsset:
674
666
  if len(asset._associated_assets[other_fieldname]) == 0:
675
667
  del asset._associated_assets[other_fieldname]
676
668
 
669
+ # Remove associated assets from this asset
670
+ self._associated_assets[fieldname] -= set(assets)
671
+ if len(self._associated_assets[fieldname]) == 0:
672
+ del self._associated_assets[fieldname]
673
+
677
674
 
678
675
  @property
679
676
  def associated_assets(self):