Skip to content

Code examples

Joakim Loxdal edited this page Jan 16, 2026 · 7 revisions

Creating a MAL Model using the mal-gui

  1. Install mal-gui.
  2. Launch mal-gui using the command malgui from command line and select your language.
  3. Drag and drop the assets you want and create associations between them by SHIFT+Left clicking and dragging from one asset to another.
  4. Export the model to either .yml or .json (you can export scenario files as well, this is for the mal-simulator)

Create a MAL Model programatically

  1. Load your language using maltoolbox.language.LanguageGraph.
  2. Use the maltoolbox.model.Model class to create a model and add assets.
  3. Add associations to your assets using asset.add_associated_assets.
"""Run the script from this directory"""

from maltoolbox.model import Model
from maltoolbox.language import LanguageGraph

# You can load language from .mar archives (created with 'malc')
# or directly from .mal-files
file_path = "org.mal-lang.coreLang-1.0.0.mar"
corelang_graph = LanguageGraph.load_from_file(file_path)

# Create an empty model from the language
model = Model("Test Model", corelang_graph)

# Add two assets to the model using the asset type name
# defined in your MAL Language
app1 = model.add_asset(asset_type = 'Application', name = 'Application 1')
app2 = model.add_asset(asset_type = 'Application', name = 'Application 2')

# Create an association between app1 and app2 using the field name of
# the association which was defined in your MAL Language
app1.add_associated_assets(fieldname='appExecutedApps', assets={app2})

# Save your model for later use
model.save_to_file('model.yml')

Generate attack graph from model

from maltoolbox.attackgraph import create_attack_graph

# The .mar archive created with `malc`
lang_file = "../resources/org.mal-lang.coreLang-1.0.0.mar" 

# The model file created by maltoolbox
model_file = "../resources/model.yml"

# Generate attack graph from language + model
attack_graph = create_attack_graph(lang_file, model_file)

# Save your attack graph for later use
attack_graph.save_to_file('attack_graph.yml')

Clone this wiki locally