mal-toolbox 0.0.39__tar.gz → 0.1.0__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 (43) hide show
  1. {mal_toolbox-0.0.39/mal_toolbox.egg-info → mal_toolbox-0.1.0}/PKG-INFO +45 -24
  2. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/README.md +43 -23
  3. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0/mal_toolbox.egg-info}/PKG-INFO +45 -24
  4. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/mal_toolbox.egg-info/SOURCES.txt +9 -1
  5. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/mal_toolbox.egg-info/requires.txt +1 -0
  6. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/__init__.py +10 -9
  7. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/__main__.py +24 -42
  8. mal_toolbox-0.1.0/maltoolbox/attackgraph/analyzers/__init__.py +0 -0
  9. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/attackgraph/analyzers/apriori.py +39 -22
  10. mal_toolbox-0.1.0/maltoolbox/attackgraph/attacker.py +102 -0
  11. mal_toolbox-0.1.0/maltoolbox/attackgraph/attackgraph.py +667 -0
  12. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/attackgraph/node.py +46 -30
  13. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/attackgraph/query.py +62 -28
  14. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/default.conf +3 -3
  15. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/exceptions.py +13 -0
  16. mal_toolbox-0.1.0/maltoolbox/file_utils.py +66 -0
  17. mal_toolbox-0.1.0/maltoolbox/ingestors/__init__.py +0 -0
  18. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/ingestors/neo4j.py +68 -70
  19. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/language/classes_factory.py +40 -24
  20. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/language/compiler/__init__.py +5 -4
  21. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/language/compiler/mal_lexer.py +1 -1
  22. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/language/compiler/mal_parser.py +1 -1
  23. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/language/compiler/mal_visitor.py +4 -5
  24. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/language/languagegraph.py +320 -186
  25. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/language/specification.py +19 -18
  26. mal_toolbox-0.1.0/maltoolbox/model.py +687 -0
  27. mal_toolbox-0.1.0/maltoolbox/translators/__init__.py +0 -0
  28. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/translators/securicad.py +49 -33
  29. mal_toolbox-0.1.0/maltoolbox/translators/updater.py +132 -0
  30. mal_toolbox-0.1.0/maltoolbox/wrappers.py +62 -0
  31. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/pyproject.toml +15 -1
  32. mal_toolbox-0.1.0/tests/test_model.py +743 -0
  33. mal_toolbox-0.1.0/tests/test_wrappers.py +10 -0
  34. mal_toolbox-0.0.39/maltoolbox/attackgraph/attacker.py +0 -70
  35. mal_toolbox-0.0.39/maltoolbox/attackgraph/attackgraph.py +0 -470
  36. mal_toolbox-0.0.39/maltoolbox/model.py +0 -524
  37. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/AUTHORS +0 -0
  38. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/LICENSE +0 -0
  39. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/mal_toolbox.egg-info/dependency_links.txt +0 -0
  40. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/mal_toolbox.egg-info/top_level.txt +0 -0
  41. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/attackgraph/__init__.py +0 -0
  42. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/maltoolbox/language/__init__.py +0 -0
  43. {mal_toolbox-0.0.39 → mal_toolbox-0.1.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mal-toolbox
3
- Version: 0.0.39
3
+ Version: 0.1.0
4
4
  Summary: A collection of tools used to create MAL models and attack graphs.
5
5
  Author-email: Andrei Buhaiu <buhaiu@kth.se>, Giuseppe Nebbione <nebbione@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Joakim Loxdal <loxdal@kth.se>
6
6
  License: Apache Software License
@@ -23,17 +23,21 @@ Requires-Dist: python-jsonschema-objects>=0.4.1
23
23
  Requires-Dist: antlr4-tools
24
24
  Requires-Dist: antlr4-python3-runtime
25
25
  Requires-Dist: docopt
26
+ Requires-Dist: PyYAML
26
27
 
27
- # Overview
28
+ # MAL Toolbox overview
28
29
 
29
- A collection of python modules to help developers create and work with MAL
30
- models and attack graphs.
30
+ MAL Toolbox is a collection of python modules to help developers create and work with
31
+ MAL ([Meta Attack Language](https://mal-lang.org/)) models and attack graphs.
31
32
 
32
- # The Language Module
33
+ Attack graphs can be used to run simulations (see MAL Simulator) or analysis.
34
+ MAL Toolbox also gives the ability to view the AttackGraph/Model graphically in neo4j.
35
+
36
+ ## The Language Module
33
37
 
34
38
  The language module provides various tools to process MAL languages.
35
39
 
36
- ## The Language Specification Submodule
40
+ ### The Language Specification Submodule
37
41
 
38
42
  The language specification submodule provides functions to load the
39
43
  specification from a .mar archive(`load_language_specification_from_mar`) or a
@@ -42,7 +46,7 @@ then be used to generate python classes representing the assets and
42
46
  associations of the language and to determine the attack steps for each asset
43
47
  when generating the attack graph.
44
48
 
45
- ## The Language Classes Factory Submodule
49
+ ### The Language Classes Factory Submodule
46
50
 
47
51
  The language classes factory submodule is used to generate python classes
48
52
  using the `python_jsonschema_objects` package from a language specification.
@@ -53,19 +57,23 @@ using JSON Schema validators they will enforce their restrictions when using
53
57
  the python objects created. These classes are typically used in conjunction
54
58
  with model module to create instance models.
55
59
 
56
- # The Model Module
60
+ ## The Model Module
61
+
62
+ With a MAL language a Model (a MAL instance model) can be created either
63
+ from a model file or empty.
64
+
65
+ The model class will store all of the relevant information to the MAL
66
+ instance model, most importantly the assets and associations that make it up.
67
+
68
+ Assets and associations are objects of classes created using the language
69
+ classes factory submodule in runtime. It also allows for `Attacker` objects
70
+ to be created and associated with attack steps on assets in the model.
71
+ The most relevant methods of the Model are the ones used to add different
72
+ elements to the model, `add_asset`, `add_association`, and `add_attacker`.
57
73
 
58
- The model module is used to create MAL instance models. The model class will
59
- store all of the relevant information to the MAL instance model, most
60
- importantly the assets and associations that make it up. These assets and
61
- associations should be objects created using the language classes factory
62
- submodule. It also allows for `Attacker` objects to be created and associated
63
- with attack steps on assets in the model. The most relevant functions here are
64
- the ones used to add different elements to the model, `add_asset`,
65
- `add_association`, and `add_attacker`. Model objects can be used to generate
66
- attack graphs using the attack graph module.
74
+ Model objects can be used to generate attack graphs with the AttackGraph module.
67
75
 
68
- # The Attack Graph Module
76
+ ## The Attack Graph Module
69
77
 
70
78
  The attack graph module contains tools used to generate attack graphs from
71
79
  existing MAL instance models and analyse MAL attack graphs. The function used
@@ -83,14 +91,21 @@ resulting attack graph with the instance model given as a parameter in order
83
91
  to create attack step nodes that represent the entry points of the attackers
84
92
  and attach them to the attack steps specified in the instance model.
85
93
 
86
- # Ingestors Module
94
+ ## Ingestors Module
87
95
 
88
96
  The ingestors module contains various tools that can make use of the instance
89
97
  model or attack graph. Currently the Neo4J ingestor is the only one available
90
98
  and it can be used to visualise the instance model and the attack graph.
91
99
 
92
- # Command Line Client
93
100
 
101
+ # Usage
102
+
103
+ ## Configuration
104
+ A default configuration file `default.conf` can be found in the package
105
+ directory. This contains the default values to use for logging and can also be
106
+ used to store the information needed to access the local Neo4J instance.
107
+
108
+ ## Command Line Client
94
109
  In addition to the modules that make up the MAL-Toolbox package it also
95
110
  provides a simple command line client that can be used to easily generate
96
111
  attack graphs from a .mar language specification file and a JSON instance
@@ -102,7 +117,13 @@ The usage is: `maltoolbox gen_ag [--neo4j] <model_json_file>
102
117
  If the `--neo4j` flag is specified the model and attack graph will be loaded
103
118
  into a local Neo4J instance.
104
119
 
105
- # Configuration
106
- A default configuration file `default.conf` can be found in the package
107
- directory. This contains the default values to use for logging and can also be
108
- used to store the information needed to access the local Neo4J instance.
120
+ ## Code examples / Tutorial
121
+
122
+ To find code examples and tutorials, visit the
123
+ [MAL Toolbox Tutorial](https://github.com/mal-lang/mal-toolbox-tutorial/tree/main) repository.
124
+
125
+ # Tests
126
+ There are unit tests inside of ./tests.
127
+ Before running the tests, make sure to install the requirements in ./tests/requirements.txt with `python -m pip install -r ./tests/requirements.txt`.
128
+
129
+ To run all tests, use the `pytest` command. To run just a specific file or test function use `pytest tests/<filename>` or `pytest -k <function_name>`.
@@ -1,13 +1,16 @@
1
- # Overview
1
+ # MAL Toolbox overview
2
2
 
3
- A collection of python modules to help developers create and work with MAL
4
- models and attack graphs.
3
+ MAL Toolbox is a collection of python modules to help developers create and work with
4
+ MAL ([Meta Attack Language](https://mal-lang.org/)) models and attack graphs.
5
5
 
6
- # The Language Module
6
+ Attack graphs can be used to run simulations (see MAL Simulator) or analysis.
7
+ MAL Toolbox also gives the ability to view the AttackGraph/Model graphically in neo4j.
8
+
9
+ ## The Language Module
7
10
 
8
11
  The language module provides various tools to process MAL languages.
9
12
 
10
- ## The Language Specification Submodule
13
+ ### The Language Specification Submodule
11
14
 
12
15
  The language specification submodule provides functions to load the
13
16
  specification from a .mar archive(`load_language_specification_from_mar`) or a
@@ -16,7 +19,7 @@ then be used to generate python classes representing the assets and
16
19
  associations of the language and to determine the attack steps for each asset
17
20
  when generating the attack graph.
18
21
 
19
- ## The Language Classes Factory Submodule
22
+ ### The Language Classes Factory Submodule
20
23
 
21
24
  The language classes factory submodule is used to generate python classes
22
25
  using the `python_jsonschema_objects` package from a language specification.
@@ -27,19 +30,23 @@ using JSON Schema validators they will enforce their restrictions when using
27
30
  the python objects created. These classes are typically used in conjunction
28
31
  with model module to create instance models.
29
32
 
30
- # The Model Module
33
+ ## The Model Module
34
+
35
+ With a MAL language a Model (a MAL instance model) can be created either
36
+ from a model file or empty.
37
+
38
+ The model class will store all of the relevant information to the MAL
39
+ instance model, most importantly the assets and associations that make it up.
40
+
41
+ Assets and associations are objects of classes created using the language
42
+ classes factory submodule in runtime. It also allows for `Attacker` objects
43
+ to be created and associated with attack steps on assets in the model.
44
+ The most relevant methods of the Model are the ones used to add different
45
+ elements to the model, `add_asset`, `add_association`, and `add_attacker`.
31
46
 
32
- The model module is used to create MAL instance models. The model class will
33
- store all of the relevant information to the MAL instance model, most
34
- importantly the assets and associations that make it up. These assets and
35
- associations should be objects created using the language classes factory
36
- submodule. It also allows for `Attacker` objects to be created and associated
37
- with attack steps on assets in the model. The most relevant functions here are
38
- the ones used to add different elements to the model, `add_asset`,
39
- `add_association`, and `add_attacker`. Model objects can be used to generate
40
- attack graphs using the attack graph module.
47
+ Model objects can be used to generate attack graphs with the AttackGraph module.
41
48
 
42
- # The Attack Graph Module
49
+ ## The Attack Graph Module
43
50
 
44
51
  The attack graph module contains tools used to generate attack graphs from
45
52
  existing MAL instance models and analyse MAL attack graphs. The function used
@@ -57,14 +64,21 @@ resulting attack graph with the instance model given as a parameter in order
57
64
  to create attack step nodes that represent the entry points of the attackers
58
65
  and attach them to the attack steps specified in the instance model.
59
66
 
60
- # Ingestors Module
67
+ ## Ingestors Module
61
68
 
62
69
  The ingestors module contains various tools that can make use of the instance
63
70
  model or attack graph. Currently the Neo4J ingestor is the only one available
64
71
  and it can be used to visualise the instance model and the attack graph.
65
72
 
66
- # Command Line Client
67
73
 
74
+ # Usage
75
+
76
+ ## Configuration
77
+ A default configuration file `default.conf` can be found in the package
78
+ directory. This contains the default values to use for logging and can also be
79
+ used to store the information needed to access the local Neo4J instance.
80
+
81
+ ## Command Line Client
68
82
  In addition to the modules that make up the MAL-Toolbox package it also
69
83
  provides a simple command line client that can be used to easily generate
70
84
  attack graphs from a .mar language specification file and a JSON instance
@@ -76,7 +90,13 @@ The usage is: `maltoolbox gen_ag [--neo4j] <model_json_file>
76
90
  If the `--neo4j` flag is specified the model and attack graph will be loaded
77
91
  into a local Neo4J instance.
78
92
 
79
- # Configuration
80
- A default configuration file `default.conf` can be found in the package
81
- directory. This contains the default values to use for logging and can also be
82
- used to store the information needed to access the local Neo4J instance.
93
+ ## Code examples / Tutorial
94
+
95
+ To find code examples and tutorials, visit the
96
+ [MAL Toolbox Tutorial](https://github.com/mal-lang/mal-toolbox-tutorial/tree/main) repository.
97
+
98
+ # Tests
99
+ There are unit tests inside of ./tests.
100
+ Before running the tests, make sure to install the requirements in ./tests/requirements.txt with `python -m pip install -r ./tests/requirements.txt`.
101
+
102
+ To run all tests, use the `pytest` command. To run just a specific file or test function use `pytest tests/<filename>` or `pytest -k <function_name>`.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mal-toolbox
3
- Version: 0.0.39
3
+ Version: 0.1.0
4
4
  Summary: A collection of tools used to create MAL models and attack graphs.
5
5
  Author-email: Andrei Buhaiu <buhaiu@kth.se>, Giuseppe Nebbione <nebbione@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Joakim Loxdal <loxdal@kth.se>
6
6
  License: Apache Software License
@@ -23,17 +23,21 @@ Requires-Dist: python-jsonschema-objects>=0.4.1
23
23
  Requires-Dist: antlr4-tools
24
24
  Requires-Dist: antlr4-python3-runtime
25
25
  Requires-Dist: docopt
26
+ Requires-Dist: PyYAML
26
27
 
27
- # Overview
28
+ # MAL Toolbox overview
28
29
 
29
- A collection of python modules to help developers create and work with MAL
30
- models and attack graphs.
30
+ MAL Toolbox is a collection of python modules to help developers create and work with
31
+ MAL ([Meta Attack Language](https://mal-lang.org/)) models and attack graphs.
31
32
 
32
- # The Language Module
33
+ Attack graphs can be used to run simulations (see MAL Simulator) or analysis.
34
+ MAL Toolbox also gives the ability to view the AttackGraph/Model graphically in neo4j.
35
+
36
+ ## The Language Module
33
37
 
34
38
  The language module provides various tools to process MAL languages.
35
39
 
36
- ## The Language Specification Submodule
40
+ ### The Language Specification Submodule
37
41
 
38
42
  The language specification submodule provides functions to load the
39
43
  specification from a .mar archive(`load_language_specification_from_mar`) or a
@@ -42,7 +46,7 @@ then be used to generate python classes representing the assets and
42
46
  associations of the language and to determine the attack steps for each asset
43
47
  when generating the attack graph.
44
48
 
45
- ## The Language Classes Factory Submodule
49
+ ### The Language Classes Factory Submodule
46
50
 
47
51
  The language classes factory submodule is used to generate python classes
48
52
  using the `python_jsonschema_objects` package from a language specification.
@@ -53,19 +57,23 @@ using JSON Schema validators they will enforce their restrictions when using
53
57
  the python objects created. These classes are typically used in conjunction
54
58
  with model module to create instance models.
55
59
 
56
- # The Model Module
60
+ ## The Model Module
61
+
62
+ With a MAL language a Model (a MAL instance model) can be created either
63
+ from a model file or empty.
64
+
65
+ The model class will store all of the relevant information to the MAL
66
+ instance model, most importantly the assets and associations that make it up.
67
+
68
+ Assets and associations are objects of classes created using the language
69
+ classes factory submodule in runtime. It also allows for `Attacker` objects
70
+ to be created and associated with attack steps on assets in the model.
71
+ The most relevant methods of the Model are the ones used to add different
72
+ elements to the model, `add_asset`, `add_association`, and `add_attacker`.
57
73
 
58
- The model module is used to create MAL instance models. The model class will
59
- store all of the relevant information to the MAL instance model, most
60
- importantly the assets and associations that make it up. These assets and
61
- associations should be objects created using the language classes factory
62
- submodule. It also allows for `Attacker` objects to be created and associated
63
- with attack steps on assets in the model. The most relevant functions here are
64
- the ones used to add different elements to the model, `add_asset`,
65
- `add_association`, and `add_attacker`. Model objects can be used to generate
66
- attack graphs using the attack graph module.
74
+ Model objects can be used to generate attack graphs with the AttackGraph module.
67
75
 
68
- # The Attack Graph Module
76
+ ## The Attack Graph Module
69
77
 
70
78
  The attack graph module contains tools used to generate attack graphs from
71
79
  existing MAL instance models and analyse MAL attack graphs. The function used
@@ -83,14 +91,21 @@ resulting attack graph with the instance model given as a parameter in order
83
91
  to create attack step nodes that represent the entry points of the attackers
84
92
  and attach them to the attack steps specified in the instance model.
85
93
 
86
- # Ingestors Module
94
+ ## Ingestors Module
87
95
 
88
96
  The ingestors module contains various tools that can make use of the instance
89
97
  model or attack graph. Currently the Neo4J ingestor is the only one available
90
98
  and it can be used to visualise the instance model and the attack graph.
91
99
 
92
- # Command Line Client
93
100
 
101
+ # Usage
102
+
103
+ ## Configuration
104
+ A default configuration file `default.conf` can be found in the package
105
+ directory. This contains the default values to use for logging and can also be
106
+ used to store the information needed to access the local Neo4J instance.
107
+
108
+ ## Command Line Client
94
109
  In addition to the modules that make up the MAL-Toolbox package it also
95
110
  provides a simple command line client that can be used to easily generate
96
111
  attack graphs from a .mar language specification file and a JSON instance
@@ -102,7 +117,13 @@ The usage is: `maltoolbox gen_ag [--neo4j] <model_json_file>
102
117
  If the `--neo4j` flag is specified the model and attack graph will be loaded
103
118
  into a local Neo4J instance.
104
119
 
105
- # Configuration
106
- A default configuration file `default.conf` can be found in the package
107
- directory. This contains the default values to use for logging and can also be
108
- used to store the information needed to access the local Neo4J instance.
120
+ ## Code examples / Tutorial
121
+
122
+ To find code examples and tutorials, visit the
123
+ [MAL Toolbox Tutorial](https://github.com/mal-lang/mal-toolbox-tutorial/tree/main) repository.
124
+
125
+ # Tests
126
+ There are unit tests inside of ./tests.
127
+ Before running the tests, make sure to install the requirements in ./tests/requirements.txt with `python -m pip install -r ./tests/requirements.txt`.
128
+
129
+ To run all tests, use the `pytest` command. To run just a specific file or test function use `pytest tests/<filename>` or `pytest -k <function_name>`.
@@ -11,13 +11,17 @@ maltoolbox/__init__.py
11
11
  maltoolbox/__main__.py
12
12
  maltoolbox/default.conf
13
13
  maltoolbox/exceptions.py
14
+ maltoolbox/file_utils.py
14
15
  maltoolbox/model.py
16
+ maltoolbox/wrappers.py
15
17
  maltoolbox/attackgraph/__init__.py
16
18
  maltoolbox/attackgraph/attacker.py
17
19
  maltoolbox/attackgraph/attackgraph.py
18
20
  maltoolbox/attackgraph/node.py
19
21
  maltoolbox/attackgraph/query.py
22
+ maltoolbox/attackgraph/analyzers/__init__.py
20
23
  maltoolbox/attackgraph/analyzers/apriori.py
24
+ maltoolbox/ingestors/__init__.py
21
25
  maltoolbox/ingestors/neo4j.py
22
26
  maltoolbox/language/__init__.py
23
27
  maltoolbox/language/classes_factory.py
@@ -27,4 +31,8 @@ maltoolbox/language/compiler/__init__.py
27
31
  maltoolbox/language/compiler/mal_lexer.py
28
32
  maltoolbox/language/compiler/mal_parser.py
29
33
  maltoolbox/language/compiler/mal_visitor.py
30
- maltoolbox/translators/securicad.py
34
+ maltoolbox/translators/__init__.py
35
+ maltoolbox/translators/securicad.py
36
+ maltoolbox/translators/updater.py
37
+ tests/test_model.py
38
+ tests/test_wrappers.py
@@ -3,3 +3,4 @@ python-jsonschema-objects>=0.4.1
3
3
  antlr4-tools
4
4
  antlr4-python3-runtime
5
5
  docopt
6
+ PyYAML
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # MAL Toolbox v0.0.39
2
+ # MAL Toolbox v0.1.0
3
3
  # Copyright 2024, Andrei Buhaiu.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,7 @@ MAL-Toolbox Framework
21
21
  """
22
22
 
23
23
  __title__ = 'maltoolbox'
24
- __version__ = '0.0.39'
24
+ __version__ = '0.1.0'
25
25
  __authors__ = ['Andrei Buhaiu',
26
26
  'Giuseppe Nebbione',
27
27
  'Nikolaos Kakouros',
@@ -33,7 +33,6 @@ __docformat__ = 'restructuredtext en'
33
33
  __all__ = ()
34
34
 
35
35
  import os
36
- import sys
37
36
  import configparser
38
37
  import logging
39
38
 
@@ -74,15 +73,18 @@ log_level = log_configs['log_level']
74
73
  if log_level != '':
75
74
  level = logging.getLevelName(log_level)
76
75
  logger.setLevel(level)
77
- logger.info(f'Set loggin level of {__name__} to {log_level}.')
76
+ logger.info('Set loggin level of %s to %s.', __name__, log_level)
78
77
 
79
78
  if 'neo4j' in config:
80
79
  for term in ['uri', 'username', 'password', 'dbname']:
81
80
  if term not in config['neo4j']:
82
- logger.critical('Config file is missing essential '\
83
- f'Neo4J information: {term}, cannot proceed.')
84
- raise ValueError('Config file is missing essential '\
85
- f'Neo4J information: {term}, cannot proceed.')
81
+
82
+ msg = (
83
+ 'Config file is missing essential Neo4J '
84
+ f'information: {term}, cannot proceed.'
85
+ )
86
+ logger.critical(msg)
87
+ raise ValueError(msg)
86
88
 
87
89
  neo4j_configs = {
88
90
  'uri': config['neo4j']['uri'],
@@ -90,4 +92,3 @@ if 'neo4j' in config:
90
92
  'password': config['neo4j']['password'],
91
93
  'dbname': config['neo4j']['dbname'],
92
94
  }
93
-
@@ -21,74 +21,56 @@ Notes:
21
21
  parameters required for this app to reach the Neo4j instance should be
22
22
  defined in the default.conf file.
23
23
  """
24
- import docopt
24
+
25
25
  import logging
26
26
  import json
27
- import sys
28
- import zipfile
27
+ import docopt
29
28
 
29
+ from maltoolbox.wrappers import create_attack_graph
30
30
  from . import log_configs, neo4j_configs
31
- from .language import LanguageClassesFactory, LanguageGraph
32
31
  from .language.compiler import MalCompiler
33
- from .model import Model
34
- from .attackgraph import AttackGraph
35
- from .attackgraph.analyzers.apriori import calculate_viability_and_necessity
36
32
  from .ingestors import neo4j
37
- from .exceptions import AttackGraphStepExpressionError
38
33
 
39
34
  logger = logging.getLogger(__name__)
40
35
 
41
-
42
- def generate_attack_graph(model_file: str, lang_file: str, send_to_neo4j: bool) -> None:
43
- try:
44
- lang_graph = LanguageGraph.from_mar_archive(lang_file)
45
- except zipfile.BadZipFile:
46
- lang_graph = LanguageGraph.from_mal_spec(lang_file)
47
-
48
- if log_configs['langspec_file']:
49
- lang_graph.save_language_specification_to_json(log_configs['langspec_file'])
50
-
51
- lang_classes_factory = LanguageClassesFactory(lang_graph)
52
-
53
- instance_model = Model.load_from_file(model_file, lang_classes_factory)
54
-
55
- if log_configs['model_file']:
56
- instance_model.save_to_file(log_configs['model_file'])
57
-
58
- try:
59
- graph = AttackGraph(lang_graph, instance_model)
60
- except AttackGraphStepExpressionError:
61
- logger.error('Attack graph generation failed when attempting ' \
62
- 'to resolve attack step expression!')
63
- sys.exit(1)
64
-
65
- calculate_viability_and_necessity(graph)
66
-
67
- graph.attach_attackers()
68
-
36
+ def generate_attack_graph(
37
+ model_file: str,
38
+ lang_file: str,
39
+ send_to_neo4j: bool
40
+ ) -> None:
41
+ """Create an attack graph and optionally send to neo4j
42
+
43
+ Args:
44
+ model_file - path to the model file
45
+ lang_file - path to the language file
46
+ send_to_neo4j - whether to ingest into neo4j or not
47
+ """
48
+ attack_graph = create_attack_graph(lang_file, model_file)
69
49
  if log_configs['attackgraph_file']:
70
- graph.save_to_file(
71
- log_configs['attackgraph_file'])
50
+ attack_graph.save_to_file(
51
+ log_configs['attackgraph_file']
52
+ )
72
53
 
73
54
  if send_to_neo4j:
74
55
  logger.debug('Ingest model graph into Neo4J database.')
75
- neo4j.ingest_model(instance_model,
56
+ neo4j.ingest_model(attack_graph.model,
76
57
  neo4j_configs['uri'],
77
58
  neo4j_configs['username'],
78
59
  neo4j_configs['password'],
79
60
  neo4j_configs['dbname'],
80
61
  delete=True)
81
62
  logger.debug('Ingest attack graph into Neo4J database.')
82
- neo4j.ingest_attack_graph(graph,
63
+ neo4j.ingest_attack_graph(attack_graph,
83
64
  neo4j_configs['uri'],
84
65
  neo4j_configs['username'],
85
66
  neo4j_configs['password'],
86
67
  neo4j_configs['dbname'],
87
68
  delete=False)
88
69
 
89
- def compile(lang_file, output_file):
90
- compiler = MalCompiler()
91
70
 
71
+ def compile(lang_file: str, output_file: str) -> None:
72
+ """Compile language and dump into output file"""
73
+ compiler = MalCompiler()
92
74
  with open(output_file, "w") as f:
93
75
  json.dump(compiler.compile(lang_file), f, indent=2)
94
76