maltoolbox.model module
MAL-Toolbox Model Module
- class maltoolbox.model.AttackerAttachment(id: Optional[int] = None, name: Optional[str] = None, entry_points: list[tuple[ModelAsset, list[str]]] = <factory>)[source]
Bases:
object
Used to attach attackers to attack step entry points of assets
- add_entry_point(asset: ModelAsset, attackstep_name: str)[source]
Add an entry point to an AttackerAttachment
self.entry_points contain tuples, first element of each tuple is an asset, second element is a list of attack step names that are entry points for the attacker.
Arguments: asset - the asset to add the entry point to attackstep_name - the name of the attack step to add as an entry point
- entry_points: list[tuple[ModelAsset, list[str]]]
- get_entry_point_tuple(asset: ModelAsset) tuple[ModelAsset, list[str]] | None [source]
Return an entry point tuple of an AttackerAttachment matching the asset provided.
Arguments: asset - the asset to add entry point to
Return: The entry point tuple containing the asset and the list of attack steps if the asset has any entry points defined for this attacker attachemnt. None, otherwise.
- id: int | None = None
- name: str | None = None
- remove_entry_point(asset: ModelAsset, attackstep_name: str)[source]
Remove an entry point from an AttackerAttachment if it exists
Arguments: asset - the asset to remove the entry point from
- class maltoolbox.model.Model(name: str, lang_graph: LanguageGraph, mt_version: str = '0.3.11')[source]
Bases:
object
An implementation of a MAL language model containing assets
- add_asset(asset_type: str, name: str | None = None, asset_id: int | None = None, defenses: dict[str, float] | None = None, extras: dict | None = None, allow_duplicate_names: bool = True) ModelAsset [source]
Create an asset based on the provided parameters and add it to the model.
Arguments: asset_type - string containing the asset type name name - string containing the asset name. If not
provided the concatenated asset type and id will be used as a name.
- asset_id - id to assign to this asset, usually from an
instance model file. If not provided the id will be set to the next highest id available.
defeses - dictionary of defense values extras - dictionary of extras allow_duplicate_name - allow duplicate names to be used. If allowed
and a duplicate is encountered the name will be appended with the id.
Return: The newly created asset.
- add_attacker(attacker: AttackerAttachment, attacker_id: int | None = None) None [source]
Add an attacker to the model.
Arguments: attacker - the attacker to add attacker_id - optional id for the attacker
- attacker_to_dict(attacker: AttackerAttachment) tuple[int | None, dict] [source]
Get dictionary representation of the attacker.
Arguments: attacker - attacker to get dictionary representation of
- get_asset_by_id(asset_id: int) ModelAsset | None [source]
Find an asset in the model based on its id.
Arguments: asset_id - the id of the asset we are looking for
Return: An asset matching the id if it exists in the model.
- get_asset_by_name(asset_name: str) ModelAsset | None [source]
Find an asset in the model based on its name.
Arguments: asset_name - the name of the asset we are looking for
Return: An asset matching the name if it exists in the model.
- get_attacker_by_id(attacker_id: int) AttackerAttachment | None [source]
Find an attacker in the model based on its id.
Arguments: attacker_id - the id of the attacker we are looking for
Return: An attacker matching the id if it exists in the model.
- classmethod load_from_file(filename: str, lang_graph: LanguageGraph) Model [source]
Create from json or yaml file depending on file extension
- next_id: int = 0
- remove_asset(asset: ModelAsset) None [source]
Remove an asset from the model.
Arguments: asset - the asset to remove
- remove_attacker(attacker: AttackerAttachment) None [source]
Remove attacker
- class maltoolbox.model.ModelAsset(name: str, asset_id: int, lg_asset: LanguageGraphAsset, defenses: dict[str, float] | None = None, extras: dict | None = None)[source]
Bases:
object
- add_associated_assets(fieldname: str, assets: set[ModelAsset])[source]
Add the assets provided as a parameter to the set of associated assets dictionary entry corresponding to the given fieldname.
- property associated_assets
- property id
- remove_associated_assets(fieldname: str, assets: set[ModelAsset])[source]
Remove the assets provided as a parameter from the set of associated assets dictionary entry corresponding to the fieldname parameter.
- validate_associated_assets(fieldname: str, assets_to_add: set[ModelAsset])[source]
Validate an association we want to add (through fieldname) is valid with the assets given in param assets_to_add: - fieldname is valid for the asset type of this ModelAsset - type of assets_to_add is valid for the association - no more assets than ‘field.maximum’ are added to the field
- Raises:
LookupError - fieldname can not be found for this ModelAsset –
ValueError - there will be too many assets in the field – if we add this association
TypeError - if the asset type of assets_to_add is not valid –