mal-toolbox 0.3.3__py3-none-any.whl → 0.3.5__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.3
3
+ Version: 0.3.5
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,29 +1,29 @@
1
- maltoolbox/__init__.py,sha256=KOtf1beGjcKq7VUvCHLBIam5toxmKjgI6EuEpGpk_aA,2088
1
+ maltoolbox/__init__.py,sha256=k-H51l_Zc67HUyRK7pqhKe9LQ_IGX79UtA-eqrZrJI0,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=Gozh0sT7HXCgaQ0PMDdwP9CH_rgXjnmYweo1ei66xvQ,23799
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
- maltoolbox/attackgraph/query.py,sha256=s66EQcHlldn7XLCWxZ2FRjZTgk8o3V0mD4LnRaImdCw,6836
10
+ maltoolbox/attackgraph/query.py,sha256=TPr0yDK_ZpRWO4BVTZ64_ATNjLnrglU3Jh1QGkhLeE0,7441
11
11
  maltoolbox/attackgraph/analyzers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  maltoolbox/attackgraph/analyzers/apriori.py,sha256=pLTZBJDOMbmMQpHQ7V-hocvaNvtFnjklr3TJ0sdEakc,8986
13
13
  maltoolbox/ingestors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  maltoolbox/ingestors/neo4j.py,sha256=W3AH3nymRQHI9N65HsSyyeQKcETPXmY_SLKc-iB4sBI,8328
15
15
  maltoolbox/language/__init__.py,sha256=9p5nvVqDCKEhXbDMIz1MtwZ9GN7x1jmUUXbpjEwuqnw,269
16
- maltoolbox/language/languagegraph.py,sha256=npP1lX1EE1rqqKNr9qTb4Jylvdn5JYApNyJhjwSebJs,67785
16
+ maltoolbox/language/languagegraph.py,sha256=eBPTyoDpfc01ONEj321-RmIJV3DfVenYfHdVu0TiITo,67856
17
17
  maltoolbox/language/compiler/__init__.py,sha256=JQyAgDwJh1pU7AmuOhd1-d2b2PYXpgMVPtxnav8QHVc,15872
18
18
  maltoolbox/language/compiler/mal_lexer.py,sha256=BeifykDAt4PloRASOaLzBgWF35ev_zgD8lXMIsSHykc,12063
19
19
  maltoolbox/language/compiler/mal_parser.py,sha256=sUoaE43l2VKg-Dou30mk2wlVS1FvdOREwHNIyFe4IkY,114699
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.3.dist-info/AUTHORS,sha256=zxLrLe8EY39WtRKlAY4Oorx4Z2_LHV2ApRvDGZgY7xY,127
24
- mal_toolbox-0.3.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
- mal_toolbox-0.3.3.dist-info/METADATA,sha256=dZnRcj2VHu_oL87Zu4aA8XwG8lygJck0ulYHSV6NvAQ,6158
26
- mal_toolbox-0.3.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
27
- mal_toolbox-0.3.3.dist-info/entry_points.txt,sha256=oqby5O6cUP_OHCm70k_iYPA6UlbTBf7se1i3XwdK3uU,56
28
- mal_toolbox-0.3.3.dist-info/top_level.txt,sha256=phqRVLRKGdSUgRY03mcpi2cmbbDo5YGjkV4gkqHFFcM,11
29
- mal_toolbox-0.3.3.dist-info/RECORD,,
23
+ mal_toolbox-0.3.5.dist-info/AUTHORS,sha256=zxLrLe8EY39WtRKlAY4Oorx4Z2_LHV2ApRvDGZgY7xY,127
24
+ mal_toolbox-0.3.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
+ mal_toolbox-0.3.5.dist-info/METADATA,sha256=GEueck0b9oEH59bosSJlO5lYi5nUQUhKfP3Fc4rVycY,6158
26
+ mal_toolbox-0.3.5.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
27
+ mal_toolbox-0.3.5.dist-info/entry_points.txt,sha256=oqby5O6cUP_OHCm70k_iYPA6UlbTBf7se1i3XwdK3uU,56
28
+ mal_toolbox-0.3.5.dist-info/top_level.txt,sha256=phqRVLRKGdSUgRY03mcpi2cmbbDo5YGjkV4gkqHFFcM,11
29
+ mal_toolbox-0.3.5.dist-info/RECORD,,
maltoolbox/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # MAL Toolbox v0.3.3
3
- # Copyright 2024, Andrei Buhaiu.
2
+ # MAL Toolbox v0.3.5
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.3"
24
+ __version__ = "0.3.5"
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 = {
@@ -46,13 +46,26 @@ def is_node_traversable_by_attacker(
46
46
 
47
47
  match(node.type):
48
48
  case 'or':
49
+ for parent in node.parents:
50
+ if parent.is_compromised_by(attacker):
51
+ logger.debug(
52
+ '"%s"(%d) is traversable because it is viable, and '
53
+ 'of type "or", and its parent "%s(%d)" has already '
54
+ 'been compromised.',
55
+ node.full_name,
56
+ node.id,
57
+ parent.full_name,
58
+ parent.id
59
+ )
60
+ return True
49
61
  logger.debug(
50
- '"%s"(%d) is traversable because it is viable and '
51
- 'of type "or".',
62
+ '"%s"(%d) is not traversable because while it is '
63
+ 'viable, and of type "or", none of its parents '
64
+ 'have been compromised.',
52
65
  node.full_name,
53
66
  node.id
54
67
  )
55
- return True
68
+ return False
56
69
 
57
70
  case 'and':
58
71
  for parent in node.parents:
@@ -34,8 +34,8 @@ def disaggregate_attack_step_full_name(
34
34
 
35
35
  @dataclass
36
36
  class Detector:
37
- context: Context
38
37
  name: Optional[str]
38
+ context: Context
39
39
  type: Optional[str]
40
40
  tprate: Optional[dict]
41
41
 
@@ -61,6 +61,8 @@ class Context(dict):
61
61
  def __str__(self) -> str:
62
62
  return str({label: asset.name for label, asset in self._context_dict.items()})
63
63
 
64
+ def __repr__(self) -> str:
65
+ return f"Context({str(self)}))"
64
66
 
65
67
  @dataclass
66
68
  class LanguageGraphAsset:
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