mal-toolbox 0.0.27__tar.gz → 0.1.12__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 (52) hide show
  1. {mal-toolbox-0.0.27/mal_toolbox.egg-info → mal_toolbox-0.1.12}/PKG-INFO +59 -27
  2. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/README.md +51 -23
  3. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12/mal_toolbox.egg-info}/PKG-INFO +59 -27
  4. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/mal_toolbox.egg-info/SOURCES.txt +17 -9
  5. mal_toolbox-0.1.12/mal_toolbox.egg-info/requires.txt +6 -0
  6. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/maltoolbox/__init__.py +31 -31
  7. mal_toolbox-0.1.12/maltoolbox/__main__.py +83 -0
  8. mal_toolbox-0.1.12/maltoolbox/attackgraph/__init__.py +8 -0
  9. mal_toolbox-0.1.12/maltoolbox/attackgraph/analyzers/__init__.py +0 -0
  10. mal_toolbox-0.1.12/maltoolbox/attackgraph/analyzers/apriori.py +232 -0
  11. mal_toolbox-0.1.12/maltoolbox/attackgraph/attacker.py +125 -0
  12. mal_toolbox-0.1.12/maltoolbox/attackgraph/attackgraph.py +742 -0
  13. mal_toolbox-0.1.12/maltoolbox/attackgraph/node.py +183 -0
  14. mal_toolbox-0.1.12/maltoolbox/attackgraph/query.py +200 -0
  15. mal_toolbox-0.1.12/maltoolbox/default.conf +17 -0
  16. mal_toolbox-0.1.12/maltoolbox/exceptions.py +45 -0
  17. mal_toolbox-0.1.12/maltoolbox/file_utils.py +66 -0
  18. mal_toolbox-0.1.12/maltoolbox/ingestors/__init__.py +0 -0
  19. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/maltoolbox/ingestors/neo4j.py +95 -84
  20. mal_toolbox-0.1.12/maltoolbox/language/__init__.py +4 -0
  21. mal_toolbox-0.1.12/maltoolbox/language/classes_factory.py +243 -0
  22. mal-toolbox-0.0.27/maltoolbox/language/lexer_parser/__main__.py → mal_toolbox-0.1.12/maltoolbox/language/compiler/__init__.py +5 -12
  23. {mal-toolbox-0.0.27/maltoolbox/language/lexer_parser → mal_toolbox-0.1.12/maltoolbox/language/compiler}/mal_lexer.py +1 -1
  24. {mal-toolbox-0.0.27/maltoolbox/language/lexer_parser → mal_toolbox-0.1.12/maltoolbox/language/compiler}/mal_parser.py +1 -1
  25. {mal-toolbox-0.0.27/maltoolbox/language/lexer_parser → mal_toolbox-0.1.12/maltoolbox/language/compiler}/mal_visitor.py +4 -5
  26. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/maltoolbox/language/languagegraph.py +569 -168
  27. mal_toolbox-0.1.12/maltoolbox/model.py +858 -0
  28. mal_toolbox-0.1.12/maltoolbox/translators/__init__.py +0 -0
  29. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/maltoolbox/translators/securicad.py +76 -52
  30. mal_toolbox-0.1.12/maltoolbox/translators/updater.py +132 -0
  31. mal_toolbox-0.1.12/maltoolbox/wrappers.py +62 -0
  32. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/pyproject.toml +20 -3
  33. mal_toolbox-0.1.12/tests/test_model.py +906 -0
  34. mal_toolbox-0.1.12/tests/test_wrappers.py +10 -0
  35. mal-toolbox-0.0.27/mal_toolbox.egg-info/requires.txt +0 -2
  36. mal-toolbox-0.0.27/maltoolbox/__main__.py +0 -7
  37. mal-toolbox-0.0.27/maltoolbox/attackgraph/analyzers/apriori.py +0 -86
  38. mal-toolbox-0.0.27/maltoolbox/attackgraph/attacker.py +0 -47
  39. mal-toolbox-0.0.27/maltoolbox/attackgraph/attackgraph.py +0 -452
  40. mal-toolbox-0.0.27/maltoolbox/attackgraph/node.py +0 -61
  41. mal-toolbox-0.0.27/maltoolbox/attackgraph/query.py +0 -98
  42. mal-toolbox-0.0.27/maltoolbox/cl_parser.py +0 -89
  43. mal-toolbox-0.0.27/maltoolbox/default.conf +0 -16
  44. mal-toolbox-0.0.27/maltoolbox/language/classes_factory.py +0 -162
  45. mal-toolbox-0.0.27/maltoolbox/language/specification.py +0 -265
  46. mal-toolbox-0.0.27/maltoolbox/main.py +0 -84
  47. mal-toolbox-0.0.27/maltoolbox/model/model.py +0 -279
  48. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/AUTHORS +0 -0
  49. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/LICENSE +0 -0
  50. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/mal_toolbox.egg-info/dependency_links.txt +0 -0
  51. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/mal_toolbox.egg-info/top_level.txt +0 -0
  52. {mal-toolbox-0.0.27 → mal_toolbox-0.1.12}/setup.cfg +0 -0
@@ -1,8 +1,8 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: mal-toolbox
3
- Version: 0.0.27
3
+ Version: 0.1.12
4
4
  Summary: A collection of tools used to create MAL models and attack graphs.
5
- Author-email: Andrei Buhaiu <buhaiu@kth.se>, Giuseppe Nebbione <nebbione@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Jakob Nyberg <jaknyb@kth.se>
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
7
7
  Project-URL: Homepage, https://github.com/mal-lang/mal-toolbox
8
8
  Project-URL: Bug Tracker, https://github.com/mal-lang/mal-toolbox/issues
@@ -19,18 +19,27 @@ Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
20
  License-File: AUTHORS
21
21
  Requires-Dist: py2neo>=2021.2.3
22
- Requires-Dist: python-jsonschema-objects>=0.4.1
22
+ Requires-Dist: python-jsonschema-objects>=0.5.5
23
+ Requires-Dist: antlr4-tools
24
+ Requires-Dist: antlr4-python3-runtime
25
+ Requires-Dist: docopt
26
+ Requires-Dist: PyYAML
23
27
 
24
- # Overview
28
+ # MAL Toolbox overview
25
29
 
26
- A collection of python modules to help developers create and work with MAL
27
- 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.
28
32
 
29
- # 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
+ [Documentation](https://mal-lang.org/mal-toolbox/index.html)(Work in progress)
37
+
38
+ ## The Language Module
30
39
 
31
40
  The language module provides various tools to process MAL languages.
32
41
 
33
- ## The Language Specification Submodule
42
+ ### The Language Specification Submodule
34
43
 
35
44
  The language specification submodule provides functions to load the
36
45
  specification from a .mar archive(`load_language_specification_from_mar`) or a
@@ -39,7 +48,7 @@ then be used to generate python classes representing the assets and
39
48
  associations of the language and to determine the attack steps for each asset
40
49
  when generating the attack graph.
41
50
 
42
- ## The Language Classes Factory Submodule
51
+ ### The Language Classes Factory Submodule
43
52
 
44
53
  The language classes factory submodule is used to generate python classes
45
54
  using the `python_jsonschema_objects` package from a language specification.
@@ -50,19 +59,23 @@ using JSON Schema validators they will enforce their restrictions when using
50
59
  the python objects created. These classes are typically used in conjunction
51
60
  with model module to create instance models.
52
61
 
53
- # The Model Module
62
+ ## The Model Module
63
+
64
+ With a MAL language a Model (a MAL instance model) can be created either
65
+ from a model file or empty.
66
+
67
+ The model class will store all of the relevant information to the MAL
68
+ instance model, most importantly the assets and associations that make it up.
69
+
70
+ Assets and associations are objects of classes created using the language
71
+ classes factory submodule in runtime. It also allows for `Attacker` objects
72
+ to be created and associated with attack steps on assets in the model.
73
+ The most relevant methods of the Model are the ones used to add different
74
+ elements to the model, `add_asset`, `add_association`, and `add_attacker`.
54
75
 
55
- The model module is used to create MAL instance models. The model class will
56
- store all of the relevant information to the MAL instance model, most
57
- importantly the assets and associations that make it up. These assets and
58
- associations should be objects created using the language classes factory
59
- submodule. It also allows for `Attacker` objects to be created and associated
60
- with attack steps on assets in the model. The most relevant functions here are
61
- the ones used to add different elements to the model, `add_asset`,
62
- `add_association`, and `add_attacker`. Model objects can be used to generate
63
- attack graphs using the attack graph module.
76
+ Model objects can be used to generate attack graphs with the AttackGraph module.
64
77
 
65
- # The Attack Graph Module
78
+ ## The Attack Graph Module
66
79
 
67
80
  The attack graph module contains tools used to generate attack graphs from
68
81
  existing MAL instance models and analyse MAL attack graphs. The function used
@@ -80,14 +93,27 @@ resulting attack graph with the instance model given as a parameter in order
80
93
  to create attack step nodes that represent the entry points of the attackers
81
94
  and attach them to the attack steps specified in the instance model.
82
95
 
83
- # Ingestors Module
96
+ ## Ingestors Module
84
97
 
85
98
  The ingestors module contains various tools that can make use of the instance
86
99
  model or attack graph. Currently the Neo4J ingestor is the only one available
87
100
  and it can be used to visualise the instance model and the attack graph.
88
101
 
89
- # Command Line Client
90
102
 
103
+ # Usage
104
+
105
+ ## Installation
106
+
107
+ ```
108
+ pip install mal-toolbox
109
+ ```
110
+
111
+ ## Configuration
112
+ A default configuration file `default.conf` can be found in the package
113
+ directory. This contains the default values to use for logging and can also be
114
+ used to store the information needed to access the local Neo4J instance.
115
+
116
+ ## Command Line Client
91
117
  In addition to the modules that make up the MAL-Toolbox package it also
92
118
  provides a simple command line client that can be used to easily generate
93
119
  attack graphs from a .mar language specification file and a JSON instance
@@ -99,7 +125,13 @@ The usage is: `maltoolbox gen_ag [--neo4j] <model_json_file>
99
125
  If the `--neo4j` flag is specified the model and attack graph will be loaded
100
126
  into a local Neo4J instance.
101
127
 
102
- # Configuration
103
- A default configuration file `default.conf` can be found in the package
104
- directory. This contains the default values to use for logging and can also be
105
- used to store the information needed to access the local Neo4J instance.
128
+ ## Code examples / Tutorial
129
+
130
+ To find code examples and tutorials, visit the
131
+ [MAL Toolbox Tutorial](https://github.com/mal-lang/mal-toolbox-tutorial/tree/main) repository.
132
+
133
+ # Tests
134
+ There are unit tests inside of ./tests.
135
+ Before running the tests, make sure to install the requirements in ./tests/requirements.txt with `python -m pip install -r ./tests/requirements.txt`.
136
+
137
+ 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,18 @@
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
+ [Documentation](https://mal-lang.org/mal-toolbox/index.html)(Work in progress)
10
+
11
+ ## The Language Module
7
12
 
8
13
  The language module provides various tools to process MAL languages.
9
14
 
10
- ## The Language Specification Submodule
15
+ ### The Language Specification Submodule
11
16
 
12
17
  The language specification submodule provides functions to load the
13
18
  specification from a .mar archive(`load_language_specification_from_mar`) or a
@@ -16,7 +21,7 @@ then be used to generate python classes representing the assets and
16
21
  associations of the language and to determine the attack steps for each asset
17
22
  when generating the attack graph.
18
23
 
19
- ## The Language Classes Factory Submodule
24
+ ### The Language Classes Factory Submodule
20
25
 
21
26
  The language classes factory submodule is used to generate python classes
22
27
  using the `python_jsonschema_objects` package from a language specification.
@@ -27,19 +32,23 @@ using JSON Schema validators they will enforce their restrictions when using
27
32
  the python objects created. These classes are typically used in conjunction
28
33
  with model module to create instance models.
29
34
 
30
- # The Model Module
35
+ ## The Model Module
36
+
37
+ With a MAL language a Model (a MAL instance model) can be created either
38
+ from a model file or empty.
39
+
40
+ The model class will store all of the relevant information to the MAL
41
+ instance model, most importantly the assets and associations that make it up.
42
+
43
+ Assets and associations are objects of classes created using the language
44
+ classes factory submodule in runtime. It also allows for `Attacker` objects
45
+ to be created and associated with attack steps on assets in the model.
46
+ The most relevant methods of the Model are the ones used to add different
47
+ elements to the model, `add_asset`, `add_association`, and `add_attacker`.
31
48
 
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.
49
+ Model objects can be used to generate attack graphs with the AttackGraph module.
41
50
 
42
- # The Attack Graph Module
51
+ ## The Attack Graph Module
43
52
 
44
53
  The attack graph module contains tools used to generate attack graphs from
45
54
  existing MAL instance models and analyse MAL attack graphs. The function used
@@ -57,14 +66,27 @@ resulting attack graph with the instance model given as a parameter in order
57
66
  to create attack step nodes that represent the entry points of the attackers
58
67
  and attach them to the attack steps specified in the instance model.
59
68
 
60
- # Ingestors Module
69
+ ## Ingestors Module
61
70
 
62
71
  The ingestors module contains various tools that can make use of the instance
63
72
  model or attack graph. Currently the Neo4J ingestor is the only one available
64
73
  and it can be used to visualise the instance model and the attack graph.
65
74
 
66
- # Command Line Client
67
75
 
76
+ # Usage
77
+
78
+ ## Installation
79
+
80
+ ```
81
+ pip install mal-toolbox
82
+ ```
83
+
84
+ ## Configuration
85
+ A default configuration file `default.conf` can be found in the package
86
+ directory. This contains the default values to use for logging and can also be
87
+ used to store the information needed to access the local Neo4J instance.
88
+
89
+ ## Command Line Client
68
90
  In addition to the modules that make up the MAL-Toolbox package it also
69
91
  provides a simple command line client that can be used to easily generate
70
92
  attack graphs from a .mar language specification file and a JSON instance
@@ -76,7 +98,13 @@ The usage is: `maltoolbox gen_ag [--neo4j] <model_json_file>
76
98
  If the `--neo4j` flag is specified the model and attack graph will be loaded
77
99
  into a local Neo4J instance.
78
100
 
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.
101
+ ## Code examples / Tutorial
102
+
103
+ To find code examples and tutorials, visit the
104
+ [MAL Toolbox Tutorial](https://github.com/mal-lang/mal-toolbox-tutorial/tree/main) repository.
105
+
106
+ # Tests
107
+ There are unit tests inside of ./tests.
108
+ Before running the tests, make sure to install the requirements in ./tests/requirements.txt with `python -m pip install -r ./tests/requirements.txt`.
109
+
110
+ 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,8 +1,8 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: mal-toolbox
3
- Version: 0.0.27
3
+ Version: 0.1.12
4
4
  Summary: A collection of tools used to create MAL models and attack graphs.
5
- Author-email: Andrei Buhaiu <buhaiu@kth.se>, Giuseppe Nebbione <nebbione@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Jakob Nyberg <jaknyb@kth.se>
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
7
7
  Project-URL: Homepage, https://github.com/mal-lang/mal-toolbox
8
8
  Project-URL: Bug Tracker, https://github.com/mal-lang/mal-toolbox/issues
@@ -19,18 +19,27 @@ Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
20
  License-File: AUTHORS
21
21
  Requires-Dist: py2neo>=2021.2.3
22
- Requires-Dist: python-jsonschema-objects>=0.4.1
22
+ Requires-Dist: python-jsonschema-objects>=0.5.5
23
+ Requires-Dist: antlr4-tools
24
+ Requires-Dist: antlr4-python3-runtime
25
+ Requires-Dist: docopt
26
+ Requires-Dist: PyYAML
23
27
 
24
- # Overview
28
+ # MAL Toolbox overview
25
29
 
26
- A collection of python modules to help developers create and work with MAL
27
- 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.
28
32
 
29
- # 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
+ [Documentation](https://mal-lang.org/mal-toolbox/index.html)(Work in progress)
37
+
38
+ ## The Language Module
30
39
 
31
40
  The language module provides various tools to process MAL languages.
32
41
 
33
- ## The Language Specification Submodule
42
+ ### The Language Specification Submodule
34
43
 
35
44
  The language specification submodule provides functions to load the
36
45
  specification from a .mar archive(`load_language_specification_from_mar`) or a
@@ -39,7 +48,7 @@ then be used to generate python classes representing the assets and
39
48
  associations of the language and to determine the attack steps for each asset
40
49
  when generating the attack graph.
41
50
 
42
- ## The Language Classes Factory Submodule
51
+ ### The Language Classes Factory Submodule
43
52
 
44
53
  The language classes factory submodule is used to generate python classes
45
54
  using the `python_jsonschema_objects` package from a language specification.
@@ -50,19 +59,23 @@ using JSON Schema validators they will enforce their restrictions when using
50
59
  the python objects created. These classes are typically used in conjunction
51
60
  with model module to create instance models.
52
61
 
53
- # The Model Module
62
+ ## The Model Module
63
+
64
+ With a MAL language a Model (a MAL instance model) can be created either
65
+ from a model file or empty.
66
+
67
+ The model class will store all of the relevant information to the MAL
68
+ instance model, most importantly the assets and associations that make it up.
69
+
70
+ Assets and associations are objects of classes created using the language
71
+ classes factory submodule in runtime. It also allows for `Attacker` objects
72
+ to be created and associated with attack steps on assets in the model.
73
+ The most relevant methods of the Model are the ones used to add different
74
+ elements to the model, `add_asset`, `add_association`, and `add_attacker`.
54
75
 
55
- The model module is used to create MAL instance models. The model class will
56
- store all of the relevant information to the MAL instance model, most
57
- importantly the assets and associations that make it up. These assets and
58
- associations should be objects created using the language classes factory
59
- submodule. It also allows for `Attacker` objects to be created and associated
60
- with attack steps on assets in the model. The most relevant functions here are
61
- the ones used to add different elements to the model, `add_asset`,
62
- `add_association`, and `add_attacker`. Model objects can be used to generate
63
- attack graphs using the attack graph module.
76
+ Model objects can be used to generate attack graphs with the AttackGraph module.
64
77
 
65
- # The Attack Graph Module
78
+ ## The Attack Graph Module
66
79
 
67
80
  The attack graph module contains tools used to generate attack graphs from
68
81
  existing MAL instance models and analyse MAL attack graphs. The function used
@@ -80,14 +93,27 @@ resulting attack graph with the instance model given as a parameter in order
80
93
  to create attack step nodes that represent the entry points of the attackers
81
94
  and attach them to the attack steps specified in the instance model.
82
95
 
83
- # Ingestors Module
96
+ ## Ingestors Module
84
97
 
85
98
  The ingestors module contains various tools that can make use of the instance
86
99
  model or attack graph. Currently the Neo4J ingestor is the only one available
87
100
  and it can be used to visualise the instance model and the attack graph.
88
101
 
89
- # Command Line Client
90
102
 
103
+ # Usage
104
+
105
+ ## Installation
106
+
107
+ ```
108
+ pip install mal-toolbox
109
+ ```
110
+
111
+ ## Configuration
112
+ A default configuration file `default.conf` can be found in the package
113
+ directory. This contains the default values to use for logging and can also be
114
+ used to store the information needed to access the local Neo4J instance.
115
+
116
+ ## Command Line Client
91
117
  In addition to the modules that make up the MAL-Toolbox package it also
92
118
  provides a simple command line client that can be used to easily generate
93
119
  attack graphs from a .mar language specification file and a JSON instance
@@ -99,7 +125,13 @@ The usage is: `maltoolbox gen_ag [--neo4j] <model_json_file>
99
125
  If the `--neo4j` flag is specified the model and attack graph will be loaded
100
126
  into a local Neo4J instance.
101
127
 
102
- # Configuration
103
- A default configuration file `default.conf` can be found in the package
104
- directory. This contains the default values to use for logging and can also be
105
- used to store the information needed to access the local Neo4J instance.
128
+ ## Code examples / Tutorial
129
+
130
+ To find code examples and tutorials, visit the
131
+ [MAL Toolbox Tutorial](https://github.com/mal-lang/mal-toolbox-tutorial/tree/main) repository.
132
+
133
+ # Tests
134
+ There are unit tests inside of ./tests.
135
+ Before running the tests, make sure to install the requirements in ./tests/requirements.txt with `python -m pip install -r ./tests/requirements.txt`.
136
+
137
+ 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>`.
@@ -9,21 +9,29 @@ mal_toolbox.egg-info/requires.txt
9
9
  mal_toolbox.egg-info/top_level.txt
10
10
  maltoolbox/__init__.py
11
11
  maltoolbox/__main__.py
12
- maltoolbox/cl_parser.py
13
12
  maltoolbox/default.conf
14
- maltoolbox/main.py
13
+ maltoolbox/exceptions.py
14
+ maltoolbox/file_utils.py
15
+ maltoolbox/model.py
16
+ maltoolbox/wrappers.py
17
+ maltoolbox/attackgraph/__init__.py
15
18
  maltoolbox/attackgraph/attacker.py
16
19
  maltoolbox/attackgraph/attackgraph.py
17
20
  maltoolbox/attackgraph/node.py
18
21
  maltoolbox/attackgraph/query.py
22
+ maltoolbox/attackgraph/analyzers/__init__.py
19
23
  maltoolbox/attackgraph/analyzers/apriori.py
24
+ maltoolbox/ingestors/__init__.py
20
25
  maltoolbox/ingestors/neo4j.py
26
+ maltoolbox/language/__init__.py
21
27
  maltoolbox/language/classes_factory.py
22
28
  maltoolbox/language/languagegraph.py
23
- maltoolbox/language/specification.py
24
- maltoolbox/language/lexer_parser/__main__.py
25
- maltoolbox/language/lexer_parser/mal_lexer.py
26
- maltoolbox/language/lexer_parser/mal_parser.py
27
- maltoolbox/language/lexer_parser/mal_visitor.py
28
- maltoolbox/model/model.py
29
- maltoolbox/translators/securicad.py
29
+ maltoolbox/language/compiler/__init__.py
30
+ maltoolbox/language/compiler/mal_lexer.py
31
+ maltoolbox/language/compiler/mal_parser.py
32
+ maltoolbox/language/compiler/mal_visitor.py
33
+ maltoolbox/translators/__init__.py
34
+ maltoolbox/translators/securicad.py
35
+ maltoolbox/translators/updater.py
36
+ tests/test_model.py
37
+ tests/test_wrappers.py
@@ -0,0 +1,6 @@
1
+ py2neo>=2021.2.3
2
+ python-jsonschema-objects>=0.5.5
3
+ antlr4-tools
4
+ antlr4-python3-runtime
5
+ docopt
6
+ PyYAML
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # MAL Toolbox v0.0.27
2
+ # MAL Toolbox v0.1.12
3
3
  # Copyright 2024, Andrei Buhaiu.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,69 +21,70 @@ MAL-Toolbox Framework
21
21
  """
22
22
 
23
23
  __title__ = 'maltoolbox'
24
- __version__ = '0.0.27'
24
+ __version__ = '0.1.12'
25
25
  __authors__ = ['Andrei Buhaiu',
26
26
  'Giuseppe Nebbione',
27
27
  'Nikolaos Kakouros',
28
- 'Jakob Nyberg']
28
+ 'Jakob Nyberg',
29
+ 'Joakim Loxdal']
29
30
  __license__ = 'Apache 2.0'
30
31
  __docformat__ = 'restructuredtext en'
31
32
 
32
33
  __all__ = ()
33
34
 
34
35
  import os
35
- import sys
36
36
  import configparser
37
37
  import logging
38
38
 
39
- from pkg_resources import Requirement, resource_filename
40
-
41
39
  ERROR_INCORRECT_CONFIG = 1
42
40
 
43
- CONFIGFILE = resource_filename(Requirement.parse("mal-toolbox"),
44
- "maltoolbox/default.conf")
41
+ CONFIGFILE = os.path.join(
42
+ os.path.dirname(os.path.abspath(__file__)),
43
+ "default.conf"
44
+ )
45
45
 
46
46
  config = configparser.ConfigParser()
47
47
  config.read(CONFIGFILE)
48
48
 
49
49
  if 'logging' not in config:
50
- print('Config file is missing essential information, cannot proceed.')
51
- sys.exit(ERROR_INCORRECT_CONFIG)
50
+ raise ValueError('Config file is missing essential information, cannot proceed.')
52
51
 
53
- for term in ['output_dir', 'log_file']:
54
- if term not in config['logging']:
55
- logger.critical('Config file is missing essential '\
56
- 'information, cannot proceed.')
57
- print('Config file is missing essential information, cannot '\
58
- 'proceed.')
59
- sys.exit(ERROR_INCORRECT_CONFIG)
52
+ if 'log_file' not in config['logging']:
53
+ raise ValueError('Config file is missing a log_file location, cannot proceed.')
60
54
 
61
55
  log_configs = {
62
- 'output_dir': config['logging']['output_dir'],
63
56
  'log_file': config['logging']['log_file'],
57
+ 'log_level': config['logging']['log_level'],
64
58
  'attackgraph_file': config['logging']['attackgraph_file'],
65
59
  'model_file': config['logging']['model_file'],
66
60
  'langspec_file': config['logging']['langspec_file'],
67
61
  }
68
62
 
69
- os.makedirs(log_configs['output_dir'], exist_ok = True)
70
- logging.basicConfig(level=logging.DEBUG,
71
- format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
72
- datefmt='%m-%d %H:%M',
73
- filename=log_configs["log_file"],
74
- filemode='w')
75
- logging.getLogger('python_jsonschema_objects').setLevel(logging.WARNING)
63
+ os.makedirs(os.path.dirname(log_configs['log_file']), exist_ok = True)
64
+
65
+ formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s', datefmt='%m-%d %H:%M')
66
+ file_handler = logging.FileHandler(log_configs['log_file'], mode='w')
67
+ file_handler.setFormatter(formatter)
76
68
 
77
69
  logger = logging.getLogger(__name__)
70
+ logger.addHandler(file_handler)
71
+
72
+ log_level = log_configs['log_level']
73
+ if log_level != '':
74
+ level = logging.getLevelName(log_level)
75
+ logger.setLevel(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
- print('Config file is missing essential '\
85
- f'Neo4J information: {term}, cannot proceed.')
86
- sys.exit(ERROR_INCORRECT_CONFIG)
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)
87
88
 
88
89
  neo4j_configs = {
89
90
  'uri': config['neo4j']['uri'],
@@ -91,4 +92,3 @@ if 'neo4j' in config:
91
92
  'password': config['neo4j']['password'],
92
93
  'dbname': config['neo4j']['dbname'],
93
94
  }
94
-
@@ -0,0 +1,83 @@
1
+ """
2
+ Command-line interface for MAL toolbox operations
3
+
4
+ Usage:
5
+ maltoolbox attack-graph generate [options] <model> <lang_file>
6
+ maltoolbox compile <lang_file> <output_file>
7
+
8
+ Arguments:
9
+ <model> Path to JSON instance model file.
10
+ <lang_file> Path to .mar or .mal file containing MAL spec.
11
+ <output_file> Path to write the JSON result of the compilation.
12
+
13
+ Options:
14
+ --neo4j Ingest attack graph and instance model into a Neo4j instance
15
+
16
+ Notes:
17
+ - <lang_file> can be either a .mar file (generated by the older MAL
18
+ compiler) or a .mal file containing the DSL written in MAL.
19
+
20
+ - If --neo4j is used, the Neo4j instance should be running. The connection
21
+ parameters required for this app to reach the Neo4j instance should be
22
+ defined in the default.conf file.
23
+ """
24
+
25
+ import logging
26
+ import json
27
+ import docopt
28
+
29
+ from maltoolbox.wrappers import create_attack_graph
30
+ from . import log_configs, neo4j_configs
31
+ from .language.compiler import MalCompiler
32
+ from .ingestors import neo4j
33
+
34
+ logger = logging.getLogger(__name__)
35
+
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)
49
+ if log_configs['attackgraph_file']:
50
+ attack_graph.save_to_file(
51
+ log_configs['attackgraph_file']
52
+ )
53
+
54
+ if send_to_neo4j:
55
+ logger.debug('Ingest model graph into Neo4J database.')
56
+ neo4j.ingest_model(attack_graph.model,
57
+ neo4j_configs['uri'],
58
+ neo4j_configs['username'],
59
+ neo4j_configs['password'],
60
+ neo4j_configs['dbname'],
61
+ delete=True)
62
+ logger.debug('Ingest attack graph into Neo4J database.')
63
+ neo4j.ingest_attack_graph(attack_graph,
64
+ neo4j_configs['uri'],
65
+ neo4j_configs['username'],
66
+ neo4j_configs['password'],
67
+ neo4j_configs['dbname'],
68
+ delete=False)
69
+
70
+
71
+ def compile(lang_file: str, output_file: str) -> None:
72
+ """Compile language and dump into output file"""
73
+ compiler = MalCompiler()
74
+ with open(output_file, "w") as f:
75
+ json.dump(compiler.compile(lang_file), f, indent=2)
76
+
77
+
78
+ args = docopt.docopt(__doc__)
79
+
80
+ if args['attack-graph'] and args['generate']:
81
+ generate_attack_graph(args['<model>'], args['<lang_file>'], args['--neo4j'])
82
+ elif args['compile']:
83
+ compile(args['<lang_file>'], args['<output_file>'])
@@ -0,0 +1,8 @@
1
+ """
2
+ Contains tools used to generate attack graphs from MAL instance
3
+ models and analyze attack graphs.
4
+ """
5
+
6
+ from .attacker import Attacker
7
+ from .attackgraph import AttackGraph
8
+ from .node import AttackGraphNode