Skip to content

Commit

Permalink
Reformat code for easier reading.
Browse files Browse the repository at this point in the history
  • Loading branch information
reuteras committed May 17, 2024
1 parent d856e28 commit ef819fb
Show file tree
Hide file tree
Showing 3 changed files with 829 additions and 200 deletions.
35 changes: 29 additions & 6 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
from src.stix_parser import StixParser

if __name__ == '__main__':
domains = ['enterprise-attack', 'mobile-attack', 'ics-attack']
parser = argparse.ArgumentParser(description='Download MITRE ATT&CK STIX data and parse it to Obsidian markdown notes')
domains = [
'enterprise-attack',
'mobile-attack',
'ics-attack'
]
parser = argparse.ArgumentParser(
description='Download MITRE ATT&CK STIX data and parse it to Obsidian markdown notes'
)

parser.add_argument('--path', help="Filepath to the markdown note file")
parser.add_argument('-o', '--output', help="Output directory in which the notes will be saved. It should be placed inside a Obsidian vault.")
parser.add_argument('-o', '--output',
help="Output directory in which the notes will be saved."
)

args = parser.parse_args()

Expand All @@ -24,7 +32,11 @@
# Main functionality
os.chdir(os.path.dirname(os.path.abspath(__file__)))

stix_data = StixParser(config['repository_url'], version=config['version'], verbose=config['verbose'])
stix_data = StixParser(
config['repository_url'],
version=config['version'],
verbose=config['verbose']
)

output_dir = args.output
if not os.path.exists(output_dir):
Expand All @@ -34,7 +46,17 @@
stix_data.get_domain_data(domain)

stix_data.get_cti_data()
markdown_generator = MarkdownGenerator(output_dir, stix_data.techniques, stix_data.groups, stix_data.tactics, stix_data.mitigations, stix_data.software, stix_data.campaigns, stix_data.assets, stix_data.data_sources)
markdown_generator = MarkdownGenerator(
output_dir,
stix_data.techniques,
stix_data.groups,
stix_data.tactics,
stix_data.mitigations,
stix_data.software,
stix_data.campaigns,
stix_data.assets,
stix_data.data_sources
)

for domain in domains:
markdown_generator.create_tactic_notes(domain)
Expand All @@ -59,7 +81,8 @@

content += "# MITRE ATT&CK®\n\n"
content += "This is a collection of of the MITRE ATT&CK®[^mitre] framework for Obsidian.\n\n"
content += "Generated by obsidian-mitre-attack[^obsidian-mitre-attack] on " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + ".\n\n"
current_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
content += "Generated by obsidian-mitre-attack[^obsidian-mitre-attack] on " + current_date + ".\n\n"
content += "This collection is based on the following ATT&CK domains:\n\n"
for domain in domains:
content += "- " + domain + " version " + str(config['version']) + ".\n"
Expand Down
12 changes: 11 additions & 1 deletion src/markdown_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ class MarkdownGenerator():
"""
Class to generate markdown notes for MITRE ATT&CK data
"""
def __init__(self, output_dir=None, techniques=[], groups=[], tactics=[], mitigations=[], software=[], campaigns=[], assets=[], data_sources=[]):
def __init__(self,
output_dir=None,
techniques=[],
groups=[],
tactics=[],
mitigations=[],
software=[],
campaigns=[],
assets=[],
data_sources=[]
):
if output_dir:
self.output_dir = os.path.join(ROOT, output_dir)
self.tactics = tactics
Expand Down
Loading

0 comments on commit ef819fb

Please sign in to comment.