Skip to content

Commit 5fe460e

Browse files
committed
Fix Excel parsing for x-data-components
1 parent a510e28 commit 5fe460e

4 files changed

Lines changed: 31 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# v1.5.6 4/24/2022
2+
3+
## Fixes
4+
5+
- Fix Excel parsing for x-data-components
6+
17
# v1.5.5 4/23/2022
28

39
## Fixes

mitreattack/attackToExcel/attackToExcel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def write_excel(dataframes: Dict, domain: str, version: str = None, outputDir: s
157157

158158
# add citations to master citations list
159159
if "citations" in dataframes[objType]:
160-
citations = citations.append(dataframes[objType]["citations"])
160+
citations = pd.concat([citations, dataframes[objType]["citations"]])
161161

162162
# add main df to master dataset
163163
dataframes[objType][objType].to_excel(master_writer, sheet_name=objType, index=False)

mitreattack/attackToExcel/stixToDf.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77
import pandas as pd
8+
from loguru import logger
89
from stix2 import Filter, MemoryStore
910
from tqdm import tqdm
1011

@@ -104,13 +105,14 @@ def parseBaseStix(sdo):
104105
"""Given an SDO, return a dict of field names:values that are common across all ATT&CK STIX types."""
105106
row = {}
106107
url = None
107-
if "external_references" in sdo and sdo["external_references"][0]["source_name"] in [
108-
"mitre-attack",
109-
"mitre-mobile-attack",
110-
"mitre-ics-attack",
111-
]:
112-
row["ID"] = sdo["external_references"][0]["external_id"]
113-
url = sdo["external_references"][0]["url"]
108+
if sdo.get("external_references"):
109+
if sdo["external_references"][0]["source_name"] in [
110+
"mitre-attack",
111+
"mitre-mobile-attack",
112+
"mitre-ics-attack",
113+
]:
114+
row["ID"] = sdo["external_references"][0]["external_id"]
115+
url = sdo["external_references"][0]["url"]
114116
if "name" in sdo:
115117
row["name"] = sdo["name"]
116118
if "description" in sdo:
@@ -237,7 +239,7 @@ def techniquesToDf(src, domain):
237239
# add/merge citations
238240
if not citations.empty:
239241
if "citations" in dataframes: # append to existing citations from references
240-
dataframes["citations"] = dataframes["citations"].append(citations)
242+
dataframes["citations"] = pd.concat([dataframes["citations"], citations])
241243
else: # add citations
242244
dataframes["citations"] = citations
243245

@@ -336,7 +338,7 @@ def sourcesToDf(src, domain):
336338
# add/merge citations
337339
if not citations.empty:
338340
if "citations" in dataframes: # append to existing citations from references
339-
dataframes["citations"] = dataframes["citations"].append(citations)
341+
dataframes["citations"] = pd.concat([dataframes["citations"], citations])
340342
else: # add citations
341343
dataframes["citations"] = citations
342344

@@ -385,7 +387,7 @@ def softwareToDf(src, domain):
385387
# add/merge citations
386388
if not citations.empty:
387389
if "citations" in dataframes: # append to existing citations from references
388-
dataframes["citations"] = dataframes["citations"].append(citations)
390+
dataframes["citations"] = pd.concat([dataframes["citations"], citations])
389391
else: # add citations
390392
dataframes["citations"] = citations
391393

@@ -435,7 +437,7 @@ def groupsToDf(src, domain):
435437
# add/merge citations
436438
if not citations.empty:
437439
if "citations" in dataframes: # append to existing citations from references
438-
dataframes["citations"] = dataframes["citations"].append(citations)
440+
dataframes["citations"] = pd.concat([dataframes["citations"], citations])
439441
else: # add citations
440442
dataframes["citations"] = citations
441443

@@ -469,7 +471,7 @@ def mitigationsToDf(src, domain):
469471
# add/merge citations
470472
if not citations.empty:
471473
if "citations" in dataframes: # append to existing citations from references
472-
dataframes["citations"] = dataframes["citations"].append(citations)
474+
dataframes["citations"] = pd.concat([dataframes["citations"], citations])
473475
else: # add citations
474476
dataframes["citations"] = citations
475477

@@ -804,12 +806,15 @@ def relationshipsToDf(src, relatedType=None):
804806
row = {}
805807

806808
def add_side(label, sdo):
807-
"""add data for one side of the mapping"""
808-
if "external_references" in sdo and sdo["external_references"][0]["source_name"] in [
809-
"mitre-attack",
810-
"mitre-mobile-attack",
811-
]:
812-
row[f"{label} ID"] = sdo["external_references"][0]["external_id"] # "source ID" or "target ID"
809+
"""Add data for one side of the mapping."""
810+
# logger.debug(sdo)
811+
if sdo.get("external_references"):
812+
if sdo["external_references"][0]["source_name"] in [
813+
"mitre-attack",
814+
"mitre-mobile-attack",
815+
"mitre-ics-attack",
816+
]:
817+
row[f"{label} ID"] = sdo["external_references"][0]["external_id"] # "source ID" or "target ID"
813818
if "name" in sdo:
814819
row[f"{label} name"] = sdo["name"] # "source name" or "target name"
815820
row[f"{label} type"] = stixToAttackTerm[sdo["type"]] # "source type" or "target type"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="mitreattack-python",
8-
version="1.5.5",
8+
version="1.5.6",
99
author="MITRE ATT&CK, MITRE Corporation",
1010
author_email="attack@mitre.org",
1111
description="MITRE ATT&CK python library",

0 commit comments

Comments
 (0)