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

Commit 5632998

Browse files
committed
add gitignore, genericify exceptions, misc cleanup
1 parent 7bcf436 commit 5632998

5 files changed

Lines changed: 178 additions & 30 deletions

File tree

.gitignore

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/python,macos
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=python,macos
3+
4+
### macOS ###
5+
# General
6+
.DS_Store
7+
.AppleDouble
8+
.LSOverride
9+
10+
# Icon must end with two \r
11+
Icon
12+
13+
# Thumbnails
14+
._*
15+
16+
# Files that might appear in the root of a volume
17+
.DocumentRevisions-V100
18+
.fseventsd
19+
.Spotlight-V100
20+
.TemporaryItems
21+
.Trashes
22+
.VolumeIcon.icns
23+
.com.apple.timemachine.donotpresent
24+
25+
# Directories potentially created on remote AFP share
26+
.AppleDB
27+
.AppleDesktop
28+
Network Trash Folder
29+
Temporary Items
30+
.apdisk
31+
32+
### Python ###
33+
# Byte-compiled / optimized / DLL files
34+
__pycache__/
35+
*.py[cod]
36+
*$py.class
37+
38+
# C extensions
39+
*.so
40+
41+
# Distribution / packaging
42+
.Python
43+
build/
44+
develop-eggs/
45+
dist/
46+
downloads/
47+
eggs/
48+
.eggs/
49+
lib/
50+
lib64/
51+
parts/
52+
sdist/
53+
var/
54+
wheels/
55+
pip-wheel-metadata/
56+
share/python-wheels/
57+
*.egg-info/
58+
.installed.cfg
59+
*.egg
60+
MANIFEST
61+
62+
# PyInstaller
63+
# Usually these files are written by a python script from a template
64+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
65+
*.manifest
66+
*.spec
67+
68+
# Installer logs
69+
pip-log.txt
70+
pip-delete-this-directory.txt
71+
72+
# Unit test / coverage reports
73+
htmlcov/
74+
.tox/
75+
.nox/
76+
.coverage
77+
.coverage.*
78+
.cache
79+
nosetests.xml
80+
coverage.xml
81+
*.cover
82+
*.py,cover
83+
.hypothesis/
84+
.pytest_cache/
85+
86+
# Translations
87+
*.mo
88+
*.pot
89+
90+
# Django stuff:
91+
*.log
92+
local_settings.py
93+
db.sqlite3
94+
db.sqlite3-journal
95+
96+
# Flask stuff:
97+
instance/
98+
.webassets-cache
99+
100+
# Scrapy stuff:
101+
.scrapy
102+
103+
# Sphinx documentation
104+
docs/_build/
105+
106+
# PyBuilder
107+
target/
108+
109+
# Jupyter Notebook
110+
.ipynb_checkpoints
111+
112+
# IPython
113+
profile_default/
114+
ipython_config.py
115+
116+
# pyenv
117+
.python-version
118+
119+
# pipenv
120+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
121+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
122+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
123+
# install all needed dependencies.
124+
#Pipfile.lock
125+
126+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
127+
__pypackages__/
128+
129+
# Celery stuff
130+
celerybeat-schedule
131+
celerybeat.pid
132+
133+
# SageMath parsed files
134+
*.sage.py
135+
136+
# Environments
137+
.env
138+
.venv
139+
env/
140+
venv/
141+
ENV/
142+
env.bak/
143+
venv.bak/
144+
145+
# Spyder project settings
146+
.spyderproject
147+
.spyproject
148+
149+
# Rope project settings
150+
.ropeproject
151+
152+
# mkdocs documentation
153+
/site
154+
155+
# mypy
156+
.mypy_cache/
157+
.dmypy.json
158+
dmypy.json
159+
160+
# Pyre type checker
161+
.pyre/
162+
163+
# pytype static type analyzer
164+
.pytype/
165+
166+
# End of https://www.toptal.com/developers/gitignore/api/python,macos

layers/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This folder contains modules and scripts for working with ATT&CK Navigator layer
2626
| script | description |
2727
|:-------|:------------|
2828
| [excel_templates](exporters/excel_templates.py) | Provides a means by which to convert a matrix into a clean excel matrix template. |
29-
| [matrix_gen](exporters/matrix_gen.py) | Provides a means by which to generate a matrix from raw data, either from the ATT&CK TAXII server or from a local collection. |
29+
| [matrix_gen](exporters/matrix_gen.py) | Provides a means by which to generate a matrix from raw data, either from the ATT&CK TAXII server or from a local STIX Bundle. |
3030

3131
## Layer
3232
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.
@@ -133,14 +133,14 @@ out_layer6.to_file("C:\demo_layer6.json") # Save combined co
133133
## to_excel.py
134134
to_excel.py provides the ToExcel class, which is a way to export an existing layer file as an Excel
135135
spreadsheet. The ToExcel class has an optional parameter for the initialization function, that
136-
tells the exporter what data source to use when building the output matrix. Valid options include using live data from cti-taxii.mitre.org or using a local collection.
136+
tells the exporter what data source to use when building the output matrix. Valid options include using live data from cti-taxii.mitre.org or using a local STIX bundle.
137137

138138
##### ToExcel()
139139
```python
140140
x = ToExcel(domain='enterprise', source='taxii', local=None)
141141
```
142142
The ToExcel constructor takes domain, server, and local arguments during instantiation. The domain can
143-
be either `enterprise` or `mobile`, and can be pulled directly from a layer file as `layer.domain`. The source argument tells the matrix generation tool which data source to use when building the matrix. `taxii` indicates that the tool should utilize the `cti-taxii` server when building the matrix, while the `local` option indicates that it should use a local collection respectively. The local argument is only required if the source is set to `local`, in which case it should be a path to a local stix collection.
143+
be either `enterprise` or `mobile`, and can be pulled directly from a layer file as `layer.domain`. The source argument tells the matrix generation tool which data source to use when building the matrix. `taxii` indicates that the tool should utilize the `cti-taxii` server when building the matrix, while the `local` option indicates that it should use a local bundle respectively. The local argument is only required if the source is set to `local`, in which case it should be a path to a local stix bundle.
144144

145145
##### .to_file() Method
146146
```python

layers/exporters/excel_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, source='taxii', local=None, domain='enterprise'):
1616
Initialization - Creates a ExcelTemplate object
1717
1818
:param source: Source to use when compiling the matrix
19-
:param local: Optional path to local stix data
19+
:param local: Optional path to local stix data, required if source == "local"
2020
:param domain: The domain to utilize
2121
"""
2222
muse = domain

layers/exporters/matrix_gen.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ def subtechniques(self):
7171
def subtechniques(self, subtechniques):
7272
self.__subtechniques = subtechniques
7373

74-
class BadSource(Exception):
75-
pass
76-
77-
class BadLocation(Exception):
78-
pass
79-
8074
class MatrixGen:
8175
def __init__(self, source='taxii', local=None):
8276
"""
@@ -88,7 +82,7 @@ def __init__(self, source='taxii', local=None):
8882
self.convert_data = {}
8983
if source.lower() not in ['taxii', 'local']:
9084
print('[MatrixGen] - Unable to generate matrix, source {} is not one of "taxii" or "local"'.format(source))
91-
raise BadSource
85+
raise ValueError
9286

9387
if source.lower() == 'taxii':
9488
self.server = Server('https://cti-taxii.mitre.org/taxii')
@@ -100,14 +94,11 @@ def __init__(self, source='taxii', local=None):
10094
self.collections[collection.title.split(' ')[0].lower()] = TAXIICollectionSource(tc)
10195
elif source.lower() == 'local':
10296
if local is not None:
103-
try:
104-
self.collections['enterprise'] = FileSystemSource(local)
105-
self.collections['mobile'] = FileSystemSource(local)
106-
except:
107-
raise BadLocation
97+
self.collections['enterprise'] = FileSystemSource(local)
98+
self.collections['mobile'] = FileSystemSource(local)
10899
else:
109100
print('[MatrixGen] - "local" source specified, but path to local source not provided')
110-
raise BadSource
101+
raise ValueError
111102
self.matrix = {}
112103
self._build_matrix()
113104

layers/exporters/to_excel.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
from ..core import Layer
99
from ..exporters import ExcelTemplates
1010

11-
class NoLayer(Exception):
12-
pass
13-
14-
class MisMatchDomain(Exception):
15-
pass
16-
1711
class ToExcel:
1812
def __init__(self, domain='enterprise', source='taxii', local=None):
1913
"""
@@ -33,15 +27,12 @@ def to_xlsx(self, layer, filepath="layer.xlsx"):
3327
:param layer: A layer to initialize the instance with
3428
:param filepath: The location to write the excel file to
3529
"""
36-
if layer is not None:
37-
if not isinstance(layer, Layer):
38-
raise TypeError
39-
40-
if layer is None:
41-
raise NoLayer
4230

31+
if not isinstance(layer, Layer):
32+
raise TypeError
33+
4334
if self.domain not in layer.layer.domain:
44-
raise MisMatchDomain
35+
raise ValueError(f"layer domain ({layer.layer.domain}) does not match exporter domain ({self.domain})")
4536

4637
included_subs = []
4738
if layer.layer.techniques:

0 commit comments

Comments
 (0)