Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure navigator layer comments are easy to read #89

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions src/mapex/write_parsed_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
def get_techniques_dict(mapping_objects):
techniques_dict = {}
for mapping in mapping_objects:
tehchnique_id = mapping["attack_object_id"]
technique_id = mapping["attack_object_id"]
capability_id = mapping["capability_id"]

# define metadata
Expand All @@ -380,25 +380,30 @@
if mapping.get("comments"):
metadata.append({"name": "comment", "value": mapping["comments"]})

if techniques_dict.get(tehchnique_id):
# add capability information to technique it is mapped to
techniques_dict[tehchnique_id]["capability_ids"].append(capability_id)
metadata_info = [{"name": "control", "value": mapping["capability_id"]}]
if techniques_dict.get(technique_id) is None:
techniques_dict[technique_id] = {
"capability_ids": {capability_id},
"metadata": [],
}

technique = techniques_dict[technique_id]

# Add Capability ID
technique["capability_ids"].add(capability_id)

# Add Metadata
metadata_info = []
if len(metadata) > 0:
metadata_info.extend(

Check warning on line 397 in src/mapex/write_parsed_mappings.py

View check run for this annotation

Codecov / codecov/patch

src/mapex/write_parsed_mappings.py#L397

Added line #L397 was not covered by tests
[
{"divider": True},
{"name": "control", "value": mapping["capability_id"]},
]
)
metadata_info.extend(metadata)
metadata_info.append({"divider": True})

if "metadata" in techniques_dict[tehchnique_id]:
techniques_dict[tehchnique_id]["metadata"].extend(metadata_info)
else:
techniques_dict[tehchnique_id]["metadata"] = metadata_info
else:
# add capability information to technique it is mapped to
techniques_dict[tehchnique_id] = {"capability_ids": [capability_id]}
techniques_dict[tehchnique_id]["metadata"] = [
{"name": "control", "value": mapping["capability_id"]}
]
techniques_dict[tehchnique_id]["metadata"].extend(metadata)
techniques_dict[tehchnique_id]["metadata"].append({"divider": True})
# No need to check if metadata_info is empty
technique["metadata"].extend(metadata_info)

return techniques_dict

Expand Down Expand Up @@ -434,13 +439,14 @@

related_controls_string = ""
if len(capability_ids):
related_controls_string = ", ".join(capability_ids)
# formats ids in a bulleted list
related_controls_string = "\u2022" + "\n\u2022".join(capability_ids)

layer["techniques"].append(
{
"techniqueID": technique,
"score": len(techniques_dict[technique]["capability_ids"]),
"comment": f"Related to {related_controls_string}",
"comment": f" Related to: \n {related_controls_string}",
"metadata": techniques_dict[technique].get("metadata", []),
}
)
Expand Down
8 changes: 4 additions & 4 deletions tests/expected_results/expected_results_navigator_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
{
"techniqueID": "T1137",
"score": 1,
"comment": "Related to AC-10",
"metadata": [{"name": "control", "value": "AC-10"}, {"divider": True}],
"comment": " Related to: \n •AC-10",
"metadata": [],
},
{
"techniqueID": "T1137.002",
"score": 1,
"comment": "Related to AC-10",
"metadata": [{"name": "control", "value": "AC-10"}, {"divider": True}],
"comment": " Related to: \n •AC-10",
"metadata": [],
},
],
"gradient": {"colors": ["#ffe766", "#ffaf66"], "minValue": 1, "maxValue": 1},
Expand Down
Loading