|
5 | 5 |
|
6 | 6 | import numpy as np |
7 | 7 | import pandas as pd |
| 8 | +from loguru import logger |
8 | 9 | from stix2 import Filter, MemoryStore |
9 | 10 | from tqdm import tqdm |
10 | 11 |
|
@@ -104,13 +105,14 @@ def parseBaseStix(sdo): |
104 | 105 | """Given an SDO, return a dict of field names:values that are common across all ATT&CK STIX types.""" |
105 | 106 | row = {} |
106 | 107 | 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"] |
114 | 116 | if "name" in sdo: |
115 | 117 | row["name"] = sdo["name"] |
116 | 118 | if "description" in sdo: |
@@ -237,7 +239,7 @@ def techniquesToDf(src, domain): |
237 | 239 | # add/merge citations |
238 | 240 | if not citations.empty: |
239 | 241 | 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]) |
241 | 243 | else: # add citations |
242 | 244 | dataframes["citations"] = citations |
243 | 245 |
|
@@ -336,7 +338,7 @@ def sourcesToDf(src, domain): |
336 | 338 | # add/merge citations |
337 | 339 | if not citations.empty: |
338 | 340 | 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]) |
340 | 342 | else: # add citations |
341 | 343 | dataframes["citations"] = citations |
342 | 344 |
|
@@ -385,7 +387,7 @@ def softwareToDf(src, domain): |
385 | 387 | # add/merge citations |
386 | 388 | if not citations.empty: |
387 | 389 | 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]) |
389 | 391 | else: # add citations |
390 | 392 | dataframes["citations"] = citations |
391 | 393 |
|
@@ -435,7 +437,7 @@ def groupsToDf(src, domain): |
435 | 437 | # add/merge citations |
436 | 438 | if not citations.empty: |
437 | 439 | 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]) |
439 | 441 | else: # add citations |
440 | 442 | dataframes["citations"] = citations |
441 | 443 |
|
@@ -469,7 +471,7 @@ def mitigationsToDf(src, domain): |
469 | 471 | # add/merge citations |
470 | 472 | if not citations.empty: |
471 | 473 | 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]) |
473 | 475 | else: # add citations |
474 | 476 | dataframes["citations"] = citations |
475 | 477 |
|
@@ -804,12 +806,15 @@ def relationshipsToDf(src, relatedType=None): |
804 | 806 | row = {} |
805 | 807 |
|
806 | 808 | 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" |
813 | 818 | if "name" in sdo: |
814 | 819 | row[f"{label} name"] = sdo["name"] # "source name" or "target name" |
815 | 820 | row[f"{label} type"] = stixToAttackTerm[sdo["type"]] # "source type" or "target type" |
|
0 commit comments