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

MAPEX-203 Fix search engine 404 errors #98

Merged
merged 2 commits into from
Jul 31, 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
33 changes: 26 additions & 7 deletions src/mappings_explorer/site_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ def parse_techniques(
return techniques


def parse_non_mappable_techniques(attack_data: dict, techniques: list):
def parse_unmapped_techniques(attack_data: dict, techniques: list):
"""Create a list of non-mappable objects for all ATT&CK techniques in each version
Adds all technique objects that do not have mappings associated with them
Args:
Expand All @@ -1237,16 +1237,16 @@ def parse_non_mappable_techniques(attack_data: dict, techniques: list):
Returns:
List of technique objects
"""
non_mappables = []
unmapped = []
for technique in attack_data:
if technique["id"] not in [t.id for t in techniques]:
if technique.get("id")[:2] != "TA":
t = Technique()
t.id = technique["id"]
t.label = technique["name"]
t.description = technique["description"]
non_mappables.append(t)
return non_mappables
unmapped.append(t)
return unmapped


def parse_tactics(
Expand Down Expand Up @@ -1322,7 +1322,7 @@ def build_attack_pages(projects: list, url_prefix: str, breadcrumbs: list):
for attack_domain in list(attack_domains.keys()):
all_techniques = []
all_tactics = []
non_mappables = []
unmapped = []
for attack_version in attack_domains[attack_domain]:
logger.info(
f"Creating pages for ATT&CK {attack_version} {attack_domain}..."
Expand All @@ -1343,7 +1343,7 @@ def build_attack_pages(projects: list, url_prefix: str, breadcrumbs: list):
)
# non_mappable attack technique tables not currently shown
# in the website. Waiting for better solution to be worked out
non_mappables = parse_non_mappable_techniques(
unmapped = parse_unmapped_techniques(
attack_data=attack_data,
techniques=all_techniques,
)
Expand All @@ -1362,8 +1362,27 @@ def build_attack_pages(projects: list, url_prefix: str, breadcrumbs: list):
techniques=all_techniques,
tactics=all_tactics,
breadcrumbs=breadcrumbs,
non_mappables=non_mappables,
non_mappables=unmapped,
)
# Build technique pages that don't have mappings to fix any linking errors
for technique in unmapped:
external_dir = (
PUBLIC_DIR
/ "attack"
/ ("attack-" + attack_version)
/ ("domain-" + attack_domain.lower())
/ "techniques"
)

if technique.id:
build_technique_page(
url_prefix=url_prefix,
parent_dir=external_dir,
attack_version=attack_version,
attack_domain=attack_domain,
technique=technique,
breadcrumbs=breadcrumbs,
)

for technique in all_techniques:
external_dir = (
Expand Down
11 changes: 10 additions & 1 deletion src/mappings_explorer/templates/macros.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</a>
{% endmacro %}

{% macro table(headers, mappings, url_prefix, table_max_count, full_link, full_size) %}
{% macro table(headers, mappings, url_prefix, table_max_count, full_link, full_size, attack_version, attack_domain, previous_link) %}
<div class="table-responsive table-outer">
{% if mappings | length > table_max_count %}
<p class="notice">
Expand All @@ -29,6 +29,7 @@
</tr>
</thead>
<tbody>
{% if mappings | length > 0 %}
{%- for mapping in mappings[:table_max_count] %}
<tr>
{% for header in headers -%}
Expand All @@ -44,6 +45,14 @@
{% endfor -%}
</tr>
{% endfor -%}
{% else %}
<tr>
<td class="text-center" colspan="{{headers | length}}">
No mappings found for this technique in ATT&CK {{attack_domain}} version {{attack_version}}. <a href={{previous_link}}>Change versions
of ATT&CK</a> or check out a different technique with <a href="{{url_prefix}}attack/matrix/">Matrix View</a>.
</td>
</tr>
{% endif%}
</tbody>
</table>
<script>
Expand Down
2 changes: 1 addition & 1 deletion src/mappings_explorer/templates/technique.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
</div>
<div class="col-12">
{{ macros.table(headers, mappings, url_prefix, table_max_count, full_link, full_size) }}
{{ macros.table(headers, mappings, url_prefix, table_max_count, full_link, full_size, attack_version, attack_domain, previous_link) }}
</div>
</div>
</div>
Expand Down
Loading