Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 216261b

Browse files
author
clittle
committed
Working first version
1 parent 889644b commit 216261b

9,117 files changed

Lines changed: 509153 additions & 339 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

layers/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ This folder contains modules and scripts for working with ATT&CK Navigator layer
1818
|:-------|:------------|
1919
| [layerops](manipulators/layerops.py) | Provides a means by which to combine multiple ATT&CK layer objects in customized ways. A further breakdown can be found in the corresponding section below. |
2020

21+
#### Exporter Scripts
22+
| script | description |
23+
|:-------|:------------|
24+
| [matrix_gen](exporters/matrix_gen.py) | Provides a means by which to generate a matrix from raw data, either cached or from the ATT&CK TAXII server. |
25+
| [excel_templates](exporters/excel_templates.py) | Provides a means by which to convert a matrix into a base excel template. |
26+
| [to_excel](exporters/to_excel.py) | Provides a means by which to export an ATT&CK Layer to an excel file. A further breakdown can be found in the corresponding section below. |
27+
2128
## Layer
2229
The Layer class provides format validation and read/write capabilities to aid in working with ATT&CK Navigator Layers in python. It is the primary interface through which other Layer-related classes defined in the core module should be used. The Layer class API and a usage example are below.
2330

@@ -119,3 +126,19 @@ lo4 = LayerOps(score=lambda x: '; '.join(x),
119126
out_layer6 = lo4.process([demo2, demo3]) # Trigger processing on a list of demo2 and demo0
120127
out_layer6.to_file("C:\demo_layer6.json") # Save combined comment layer to file
121128
```
129+
130+
## to_excel.py
131+
to_excel.py provides the ToExcel class, which is a way to export an existing layer file as an Excel spreadsheet. The ToExcel class has an optional parameter for the export function, `to_file()`, that tells the exporter to build the output matrix based on live data from cti-taxii.mitre.org. Otherwise, it will use the cached subtechniques data. If matrix template lacks elements included in a layer's technique listing, those elements will not be visible in the output file.
132+
#### Example Usage
133+
```python
134+
from layers import Layer
135+
from layers import ToExcel
136+
137+
lay = Layer()
138+
lay.from_file("path/to/layer/file.json")
139+
t = ToExcel(lay)
140+
# Using cached data for template
141+
t.to_file("demo.xlsx")
142+
# Using live data for templates
143+
t.to_file("demo2.xlsx", fresh=True)
144+
```

layers/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .core import *
2+
from .exporters import *
3+
from .manipulators import *

layers/core/gradient.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import colour
2+
import math
13
try:
24
from ..core.exceptions import typeChecker, typeCheckerArray
35
except ValueError:
@@ -13,6 +15,8 @@ def __init__(self, colors, minValue, maxValue):
1315
:param minValue: The minValue for this gradient
1416
:param maxValue: The maxValue for this gradient
1517
"""
18+
self.__minValue = None
19+
self.__maxValue = None
1620
self.colors = colors
1721
self.minValue = minValue
1822
self.maxValue = maxValue
@@ -27,6 +31,7 @@ def colors(self, colors):
2731
self.__colors = []
2832
for entry in colors:
2933
self.__colors.append(entry)
34+
self._compute_curve()
3035

3136
@property
3237
def minValue(self):
@@ -36,6 +41,7 @@ def minValue(self):
3641
def minValue(self, minValue):
3742
typeChecker(type(self).__name__, minValue, int, "minValue")
3843
self.__minValue = minValue
44+
self._compute_curve()
3945

4046
@property
4147
def maxValue(self):
@@ -45,6 +51,39 @@ def maxValue(self):
4551
def maxValue(self, maxValue):
4652
typeChecker(type(self).__name__, maxValue, int, "maxValue")
4753
self.__maxValue = maxValue
54+
self._compute_curve()
55+
56+
def _compute_curve(self):
57+
"""
58+
Computes the gradient color curve
59+
"""
60+
if self.maxValue is not None and self.minValue is not None and self.colors is not None:
61+
if len(self.colors) == 2:
62+
s_c = colour.Color(self.colors[0])
63+
e_c = colour.Color(self.colors[1])
64+
self.curve = list(s_c.range_to(e_c, self.maxValue - self.minValue))
65+
else:
66+
s_c = colour.Color(self.colors[0])
67+
m_c = colour.Color(self.colors[1])
68+
e_c = colour.Color(self.colors[2])
69+
self.curve = list(s_c.range_to(m_c, int(math.floor(self.maxValue - self.minValue)/2)))
70+
curve_2 = list(m_c.range_to(e_c, int(math.ceil(self.maxValue - self.minValue)/2)))
71+
self.curve.extend(curve_2)
72+
73+
def compute_color(self, score):
74+
"""
75+
Computes a specific color based on the score value provided
76+
:returns: A hexadecimal color representation of the score on
77+
the gradient
78+
"""
79+
if score <= self.minValue:
80+
return self.colors[0]
81+
if score >= self.maxValue:
82+
return self.colors[-1]
83+
84+
target = self.curve[score - self.minValue]
85+
return target.hex_l
86+
4887

4988
def get_dict(self):
5089
"""

layers/core/technique.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def tactic(self, tactic):
5050

5151
@property
5252
def comment(self):
53-
if self.__tactic != UNSETVALUE:
53+
if self.__comment != UNSETVALUE:
5454
return self.__comment
5555

5656
@comment.setter

layers/exporters/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .excel_templates import ExcelTemplates
2+
from .matrix_gen import MatrixGen
3+
from .to_excel import ToExcel

0 commit comments

Comments
 (0)