Skip to content

Commit

Permalink
Merge pull request #155 from mitre-attack/98-update-layer-version
Browse files Browse the repository at this point in the history
98 update layer version to 4.5
  • Loading branch information
jondricek authored Oct 27, 2023
2 parents 2b10b19 + 2fdab4c commit 85a11b6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 18 deletions.
7 changes: 6 additions & 1 deletion mitreattack/navlayers/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ layer_example.layer.layout = dict(layout="side",
showName=True,
showAggregateScores=True,
countUnscored=True,
aggregateFunction="sum") # average, sum, max, min
aggregateFunction="sum", # average, sum, max, min
expandedSubtechniques="annotated") # all, annotated, none

# configure whether or not to hide disabled techniques
layer_example.layer.hideDisabled = True
Expand Down Expand Up @@ -102,6 +103,7 @@ layout_obj.layout = "side"
layout_obj.showID = True
layout_obj.showName = True
layout_obj.showAggregateScores = True
layout_obj.expandedSubtechniques = "annotated"
layout_obj.countUnscored = True
layout_obj.aggregateFunction = "sum" # average, sum, max, min
layer_build.layout = layout_obj
Expand Down Expand Up @@ -171,6 +173,7 @@ in the source code for them.
_LayerObj().tacticRowBackground # Color code for tactic background
_LayerObj().selectTechniquesAcrossTactics # Bool determining whether or not to select cross-tactic
_LayerObj().selectSubtechniquesWithParent # Bool determining whether or not to select subtechniques
_LayerObj().selectVisibleTechniques # Bool determining whether or not to select only visible techniques
_LayerObj().metadata # List of links to Metadata items
_LayerObj().get_dict() # Export Layer as a dictionary object
```
Expand Down Expand Up @@ -198,6 +201,8 @@ for backwards compatibility reasons.
Layout().countUnscored # Bool denoting whether ot not to count unscored techniques as 0s for Aggregates
Layout().aggregateFunction # A enum integer denoting which aggregate function to utilize
# 1 - Average, 2 - min, 3 - max, 4 - sum
Layout().expandedSubtechniques # String denoting how to display sub-techniques in the layer
# "all" - expand all sub-techniques, "annotated" - expand only annotated sub-techniques, "none" - collapse all sub-techniques
Layout().get_dict() # Export Layout data as a dictionary object
Layout().compute_aggregate() # Compute the aggregate score for a technique and it's subtechniques
```
Expand Down
20 changes: 20 additions & 0 deletions mitreattack/navlayers/core/layerobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, name, domain):
self.__tacticRowBackground = UNSETVALUE
self.__selectTechniquesAcrossTactics = UNSETVALUE
self.__selectSubtechniquesWithParent = UNSETVALUE
self.__selectVisibleTechniques = UNSETVALUE
self.__metadata = UNSETVALUE
self.__links = UNSETVALUE

Expand Down Expand Up @@ -179,6 +180,8 @@ def layout(self, layout):
temp.countUnscored = layout["countUnscored"]
if "aggregateFunction" in layout:
temp.aggregateFunction = layout["aggregateFunction"]
if "expandedSubtechniques" in layout:
temp.expandedSubtechniques = layout["expandedSubtechniques"]
self.__layout = temp

@property
Expand Down Expand Up @@ -300,6 +303,17 @@ def selectSubtechniquesWithParent(self, selectSubtechniquesWithParent):
typeChecker(type(self).__name__, selectSubtechniquesWithParent, bool, "selectSubtechniquesWithParent")
self.__selectSubtechniquesWithParent = selectSubtechniquesWithParent

@property
def selectVisibleTechniques(self):
"""Getter for selectVisibleTechniques."""
if self.__selectVisibleTechniques != UNSETVALUE:
return self.__selectVisibleTechniques

@selectVisibleTechniques.setter
def selectVisibleTechniques(self, selectVisibleTechniques):
typeChecker(type(self).__name__, selectVisibleTechniques, bool, "selectVisibleTechniques")
self.__selectVisibleTechniques = selectVisibleTechniques

@property
def metadata(self):
"""Getter for metadata."""
Expand Down Expand Up @@ -389,6 +403,8 @@ def _enumerate(self):
temp.append("selectTechniquesAcrossTactics")
if self.selectSubtechniquesWithParent:
temp.append("selectSubtechniquesWithParent")
if self.selectVisibleTechniques:
temp.append("selectVisibleTechniques")
if self.metadata:
temp.append("metadata")
return temp
Expand Down Expand Up @@ -426,6 +442,8 @@ def get_dict(self):
temp["selectTechniquesAcrossTactics"] = self.selectTechniquesAcrossTactics
if self.selectSubtechniquesWithParent is not None:
temp["selectSubtechniquesWithParent"] = self.selectSubtechniquesWithParent
if self.selectVisibleTechniques is not None:
temp["selectVisibleTechniques"] = self.selectVisibleTechniques
if self.metadata:
temp["metadata"] = [x.get_dict() for x in self.metadata]
return temp
Expand Down Expand Up @@ -470,6 +488,8 @@ def _linker(self, field, data):
self.selectTechniquesAcrossTactics = data
elif field == "selectSubtechniquesWithParent":
self.selectSubtechniquesWithParent = data
elif field == "selectVisibleTechniques":
self.selectVisibleTechniques = data
elif field == "metadata":
self.metadata = data
elif field == "links":
Expand Down
12 changes: 12 additions & 0 deletions mitreattack/navlayers/core/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self):
self.__showAggregateScores = UNSETVALUE
self.__countUnscored = UNSETVALUE
self.__aggregateFunction = Aggregates.average
self.__expandedSubtechniques = UNSETVALUE

def compute_aggregate(self, technique, subtechniques):
"""Compute the aggregate score for a technique and any subtechniques.
Expand Down Expand Up @@ -111,6 +112,17 @@ def showName(self, showName):
typeChecker(type(self).__name__, showName, bool, "showName")
self.__showName = showName

@property
def expandedSubtechniques(self):
"""Getter for expandedSubtechniques."""
if self.__expandedSubtechniques != UNSETVALUE:
return self.__expandedSubtechniques

@expandedSubtechniques.setter
def expandedSubtechniques(self, expandedSubtechniques):
typeChecker(type(self).__name__, expandedSubtechniques, bool, "expandedSubtechniques")
self.__expandedSubtechniques = expandedSubtechniques

@property
def showAggregateScores(self):
"""Getter for showAggregateScores."""
Expand Down
12 changes: 6 additions & 6 deletions mitreattack/navlayers/core/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from mitreattack.navlayers.core.exceptions import typeChecker, categoryChecker, UNSETVALUE, BadInput

defaults = dict(layer="4.3", navigator="4.5.5")
defaults = dict(layer="4.5", navigator="4.9.0")


class Versions:
Expand Down Expand Up @@ -60,15 +60,15 @@ def layer(self, layer):
"""Setter for layer."""
typeChecker(type(self).__name__, layer, str, "layer")
try:
categoryChecker(type(self).__name__, layer, ["3.0", "4.0", "4.1", "4.2", "4.3", "4.4"], "layer version")
categoryChecker(type(self).__name__, layer, ["3.0", "4.0", "4.1", "4.2", "4.3", "4.4", "4.5"], "layer version")
except BadInput:
print(
f"[WARNING] - unrecognized layer version {layer}. Defaulting to the 4.4 schema, this may result in "
f"[WARNING] - unrecognized layer version {layer}. Defaulting to the 4.5 schema, this may result in "
f"unexpected behavior."
)
if layer in ["3.0", "4.0", "4.1", "4.2", "4.3"]:
print(f"[NOTICE] - Forcibly upgrading version from {layer} to 4.4.")
layer = "4.4"
if layer in ["3.0", "4.0", "4.1", "4.2", "4.3", "4.4"]:
print(f"[NOTICE] - Forcibly upgrading version from {layer} to 4.5.")
layer = "4.5"
self.__layer = layer

def get_dict(self):
Expand Down
41 changes: 30 additions & 11 deletions tests/resources/testing_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"showName": True,
"showAggregateScores": False,
"countUnscored": False,
"expandedSubtechniques": "annotated",
},
"hideDisabled": False,
"techniques": [],
Expand All @@ -39,6 +40,7 @@
"tacticRowBackground": "#dddddd",
"selectTechniquesAcrossTactics": True,
"selectSubtechniquesWithParent": False,
"selectVisibleTechniques": False,
}
agg_layer_1 = """
{
Expand All @@ -55,7 +57,8 @@
"layout": "side",
"showID": false,
"showName": true,
"showAggregateScores": true
"showAggregateScores": true,
"expandedSubtechniques": "annotated",
},
"techniques": [
{
Expand Down Expand Up @@ -103,7 +106,8 @@
"showID": false,
"showName": true,
"showAggregateScores": true,
"aggregateFunction": "min"
"aggregateFunction": "min",
"expandedSubtechniques": "annotated",
},
"techniques": [
{
Expand Down Expand Up @@ -152,7 +156,8 @@
"showID": false,
"showName": true,
"showAggregateScores": true,
"aggregateFunction": "min"
"aggregateFunction": "min",
"expandedSubtechniques": "annotated",
},
"techniques": [
{
Expand Down Expand Up @@ -216,7 +221,8 @@
"showID": false,
"showName": true,
"showAggregateScores": true,
"countUnscored": false
"countUnscored": false,
"expandedSubtechniques": "annotated",
},
"hideDisabled": false,
"techniques": [
Expand Down Expand Up @@ -257,7 +263,8 @@
"showTacticRowBackground": false,
"tacticRowBackground": "#dddddd",
"selectTechniquesAcrossTactics": true,
"selectSubtechniquesWithParent": false
"selectSubtechniquesWithParent": false,
"selectVisibleTechniques": false,
}"""

agg_layer_6 = """
Expand Down Expand Up @@ -292,7 +299,8 @@
"showID": false,
"showName": true,
"showAggregateScores": true,
"countUnscored": false
"countUnscored": false,
"expandedSubtechniques": "annotated",
},
"hideDisabled": false,
"techniques": [
Expand Down Expand Up @@ -343,7 +351,8 @@
"showTacticRowBackground": false,
"tacticRowBackground": "#dddddd",
"selectTechniquesAcrossTactics": true,
"selectSubtechniquesWithParent": false
"selectSubtechniquesWithParent": false,
"selectVisibleTechniques": false,
}
"""

Expand All @@ -363,7 +372,8 @@
"showID": false,
"showName": true,
"showAggregateScores": true,
"aggregateFunction": "average"
"aggregateFunction": "average",
"expandedSubtechniques": "annotated",
},
"techniques": [
{
Expand Down Expand Up @@ -472,6 +482,7 @@
"tacticRowBackground": "#dddddd",
"selectTechniquesAcrossTactics": false,
"selectSubtechniquesWithParent": false,
"selectVisibleTechniques": false,
"metadata": [
{
"name": "layer metadata 1",
Expand Down Expand Up @@ -821,7 +832,8 @@
"showTacticRowBackground": false,
"tacticRowBackground": "#4400ff",
"selectTechniquesAcrossTactics": false,
"selectSubtechniquesWithParent": false
"selectSubtechniquesWithParent": false,
"selectVisibleTechniques": false,
}
"""

Expand Down Expand Up @@ -7361,7 +7373,8 @@
"showTacticRowBackground": false,
"tacticRowBackground": "#dddddd",
"selectTechniquesAcrossTactics": true,
"selectSubtechniquesWithParent": false
"selectSubtechniquesWithParent": false,
"selectVisibleTechniques": false,
}"""

example_layer_v41 = """
Expand Down Expand Up @@ -7446,6 +7459,7 @@
"tacticRowBackground": "#dddddd",
"selectTechniquesAcrossTactics": false,
"selectSubtechniquesWithParent": false,
"selectVisibleTechniques": false,
"metadata": [
{
"name": "layer metadata 1",
Expand Down Expand Up @@ -7590,7 +7604,8 @@
"showTacticRowBackground": false,
"tacticRowBackground": "#dddddd",
"selectTechniquesAcrossTactics": true,
"selectSubtechniquesWithParent": false
"selectSubtechniquesWithParent": false,
"selectVisibleTechniques": false,
}"""

example_layer_v3_dict = {
Expand Down Expand Up @@ -7654,6 +7669,7 @@
"showAggregateScores": True,
"countUnscored": True,
"aggregateFunction": "average",
"expandedSubtechniques": "annotated",
},
"hideDisabled": False,
"techniques": [
Expand Down Expand Up @@ -7699,6 +7715,7 @@
"tacticRowBackground": "#dddddd",
"selectTechniquesAcrossTactics": False,
"selectSubtechniquesWithParent": False,
"selectVisibleTechniques": False,
"metadata": [
{"name": "layer metadata 1", "value": "layer metadata 1 value"},
{"divider": True},
Expand All @@ -7721,6 +7738,7 @@
"showAggregateScores": True,
"countUnscored": True,
"aggregateFunction": "average",
"expandedSubtechniques": "annotated",
},
"hideDisabled": False,
"techniques": [
Expand Down Expand Up @@ -7759,6 +7777,7 @@
"tacticRowBackground": "#dddddd",
"selectTechniquesAcrossTactics": False,
"selectSubtechniquesWithParent": False,
"selectVisibleTechniques": False,
"metadata": [
{"name": "layer metadata 1", "value": "layer metadata 1 value"},
{"name": "layer metadata 2", "value": "layer metadata 2 value"},
Expand Down

0 comments on commit 85a11b6

Please sign in to comment.