-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eva
committed
Sep 29, 2023
1 parent
3e7d76f
commit cff4769
Showing
3 changed files
with
99 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import csv | ||
import json | ||
|
||
import pandas as pd | ||
import yaml | ||
|
||
|
||
def read_csv_file(filepath): | ||
cve_mappings = open(filepath, "r", encoding="UTF-8") | ||
datareader = csv.reader(cve_mappings, delimiter=",", quotechar='"') | ||
return datareader | ||
|
||
|
||
def read_excel_file(filepath): | ||
df = pd.read_excel(filepath) | ||
return df | ||
|
||
|
||
def read_json_file(filepath): | ||
with open(filepath, encoding="UTF-8") as user_file: | ||
veris_mappings = user_file.read() | ||
return json.loads(veris_mappings) | ||
|
||
|
||
def read_yaml(filepath): | ||
with open(filepath, encoding="UTF-8") as file: | ||
return yaml.safe_load(file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import json | ||
|
||
import pandas as pd | ||
import yaml | ||
|
||
|
||
def write_parsed_mappings_yaml(parsed_mappings, filepath): | ||
parsed_mappings_yaml = yaml.dump(parsed_mappings) | ||
result_yaml_file = open( | ||
f"{filepath}.yaml", | ||
"w", | ||
encoding="UTF-8", | ||
) | ||
result_yaml_file.write(parsed_mappings_yaml) | ||
|
||
|
||
def write_parsed_mappings_json(parsed_mappings, filepath): | ||
result_json_file = open( | ||
f"{filepath}.json", | ||
"w", | ||
encoding="UTF-8", | ||
) | ||
json.dump(parsed_mappings, fp=result_json_file) | ||
|
||
|
||
def write_parsed_mappings_csv(parsed_mappings, filepath): | ||
metatdata_objects = [] | ||
attack_objects = [] | ||
mapping_platform_objects = [] | ||
for index, mapping in enumerate(parsed_mappings): | ||
# metadata object | ||
metadata_object = mapping["metadata"] | ||
metadata_object["key"] = index | ||
metatdata_objects.append(metadata_object) | ||
|
||
# attack object | ||
attack_object = mapping["attack-object"] | ||
attack_object["metadata-key"] = index | ||
attack_object["key"] = index | ||
# mapping platform will be its own table and will not be | ||
# part of attack_object | ||
exclude_keys = ["mapping-platform"] | ||
attack_object = { | ||
k: attack_object[k] | ||
for k in set(list(attack_object.keys())) - set(exclude_keys) | ||
} | ||
attack_objects.append(attack_object) | ||
|
||
# mapping platform object | ||
mapping_platform_object = mapping["attack-object"]["mapping-platform"] | ||
mapping_platform_object["attack-object-key"] = index | ||
mapping_platform_objects.append(mapping_platform_object) | ||
|
||
metadata_df = pd.DataFrame(metatdata_objects) | ||
metadata_df.to_csv(f"{filepath}_metadata.csv") | ||
|
||
attack_object_df = pd.DataFrame(attack_objects) | ||
attack_object_df.to_csv(f"{filepath}_attack-objects.csv") | ||
|
||
mapping_platform_df = pd.DataFrame(mapping_platform_objects) | ||
mapping_platform_df.to_csv(f"{filepath}_mapping-platforms.csv") |