Skip to content

Commit da0321f

Browse files
🐛 fix broken AWS Endpoints (#11902)
* 🐛 fix for AWS Parser endpoints * ruff * resolve conflicts * added upgrade note --------- Co-authored-by: manuelsommer <47991713+manuel-sommer@users.noreply.github.com>
1 parent f30b1ef commit da0321f

File tree

7 files changed

+48
-7
lines changed

7 files changed

+48
-7
lines changed

docs/content/en/connecting_your_tools/parsers/file/awssecurityhub.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ AWS Security Hub integrates with multiple AWS Tools. Thus, you can retrieve find
1515
- AWS Security Hub GuardDuty: <br>`aws securityhub get-findings --filters ProductName="[{Value=GuardDuty,Comparison=EQUALS}]" | jq "." > output.json`
1616
- AWS Security Hub Inspector: <br>`aws securityhub get-findings --filters ProductName="[{Value=Inspector,Comparison=EQUALS}]" | jq "." > output.json`
1717

18+
### Important note
19+
AWS Security Hub Parser does import the affected service ARNs as hosts to DefectDojo. However, as ARNs contain invalid digits for hosts, the ARN is changed slightly. ":", " " & "/" are replaced by "_".
20+
1821
### Sample Scan Data
1922
Sample scan data for testing purposes can be found [here](https://github.com/DefectDojo/django-DefectDojo/tree/master/unittests/scans/awssecurityhub).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: 'Upgrading to DefectDojo Version 2.44.1'
3+
toc_hide: true
4+
weight: -20250203
5+
description: No special instructions.
6+
---
7+
8+
### AWS Parser Endpoint Migrations
9+
10+
The structure of AWS Endpoints changed slightly. In the past ARNs of Services were imported with invalid digits leading to broken Endpoints.
11+
The Endpoints thus changed slightly. ":", " " & "/" are replaced by "_".
12+
13+
An Migration is added as part of this release to avoid duplicates at the next import. It can take some time, depending on the amount of AWS Endpoints in the DB.
14+
15+
---
16+
17+
Check the [Release Notes](https://github.com/DefectDojo/django-DefectDojo/releases/tag/2.44.1) for the contents of the release.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 5.0.8 on 2024-09-12 18:22
2+
3+
from django.db import migrations
4+
5+
6+
def aws_sechub_update_endpoints(apps, schema_editor):
7+
endpoint_model = apps.get_model('dojo', 'Endpoint')
8+
endpoints = endpoint_model.objects.filter(finding__test__test_type__name__in=["AWS Security Hub Scan", "AWS Inspector2 Scan"])
9+
for endpoint in endpoints:
10+
endpoint.host = endpoint.host.replace(':', '_').replace("/", "_").replace(" ", "_")
11+
endpoint.save()
12+
13+
class Migration(migrations.Migration):
14+
15+
dependencies = [
16+
('dojo', '0222_clean_old_sessions'),
17+
]
18+
19+
operations = [
20+
migrations.RunPython(aws_sechub_update_endpoints, reverse_code=migrations.RunPython.noop),
21+
]

dojo/tools/aws_inspector2/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def process_endpoints(self, finding: Finding, raw_finding: dict) -> Finding:
188188
resource_type = resource_info.get("type", None)
189189
resource_id = resource_info.get("id", "N/A")
190190
resource_details = resource_info.get("details", {})
191-
endpoint_host = f"{resource_type} - {resource_id}"
191+
endpoint_host = f"{resource_type}_{resource_id}".replace(":", "_").replace("/", "_")
192192
if resource_type == "AWS_EC2_INSTANCE":
193193
aws_account = raw_finding.get("awsAccountId")
194194
resource_region = resource_info.get("region", "N/A")

dojo/tools/awssecurityhub/guardduty.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_item(self, finding: dict, test):
4343
for resource in finding.get("Resources", []):
4444
component_name = resource.get("Type")
4545
if component_name in {"AwsEcrContainerImage", "AwsEc2Instance"}:
46-
hosts.append(Endpoint(host=f"{component_name} {resource.get('Id')}"))
46+
hosts.append(Endpoint(host=f"{component_name}_{resource.get('Id')}".replace(":", "_").replace("/", "_")))
4747
if component_name == "AwsEcrContainerImage":
4848
details = resource.get("Details", {}).get("AwsEcrContainerImage")
4949
arn = resource.get("Id")

dojo/tools/awssecurityhub/inspector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_item(self, finding: dict, test):
5454
hosts = []
5555
for resource in finding.get("Resources", []):
5656
component_name = resource.get("Type")
57-
hosts.append(Endpoint(host=f"{component_name} {resource.get('Id')}"))
57+
hosts.append(Endpoint(host=f"{component_name}_{resource.get('Id')}".replace(":", "_").replace("/", "_")))
5858
if component_name == "AwsEcrContainerImage":
5959
details = resource.get("Details", {}).get("AwsEcrContainerImage")
6060
arn = resource.get("Id")

unittests/tools/test_awssecurityhub_parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_inspector_ec2(self):
6868
self.assertEqual("CVE-2022-3643", finding.unsaved_vulnerability_ids[0])
6969
self.assertEqual("- Update kernel-4.14.301\n\t- yum update kernel\n", finding.mitigation)
7070
endpoint = finding.unsaved_endpoints[0]
71-
self.assertEqual("AwsEc2Instance arn:aws:ec2:us-east-1:XXXXXXXXXXXX:i-11111111111111111", endpoint.host)
71+
self.assertEqual("AwsEc2Instance_arn_aws_ec2_us-east-1_XXXXXXXXXXXX_i-11111111111111111", endpoint.host)
7272

7373
def test_inspector_ec2_with_no_vulnerabilities(self):
7474
with open(sample_path("inspector_ec2_cve_no_vulnerabilities.json"), encoding="utf-8") as test_file:
@@ -91,7 +91,7 @@ def test_inspector_ec2_ghsa(self):
9191
self.assertSetEqual({"CVE-2023-34256", "GHSA-p98r-538v-jgw5"}, set(finding.unsaved_vulnerability_ids))
9292
self.assertEqual("https://github.com/bottlerocket-os/bottlerocket/security/advisories/GHSA-p98r-538v-jgw5", finding.references)
9393
endpoint = finding.unsaved_endpoints[0]
94-
self.assertEqual("AwsEc2Instance arn:aws:ec2:eu-central-1:012345678912:instance/i-07c11cc535d830123", endpoint.host)
94+
self.assertEqual("AwsEc2Instance_arn_aws_ec2_eu-central-1_012345678912_instance_i-07c11cc535d830123", endpoint.host)
9595

9696
def test_inspector_ecr(self):
9797
with open(sample_path("inspector_ecr.json"), encoding="utf-8") as test_file:
@@ -108,7 +108,7 @@ def test_inspector_ecr(self):
108108
self.assertIn("Repository: repo-os", finding.impact)
109109
self.assertEqual(0.0014, finding.epss_score)
110110
endpoint = finding.unsaved_endpoints[0]
111-
self.assertEqual("AwsEcrContainerImage arn:aws:ecr:eu-central-1:123456789012:repository/repo-os/sha256:af965ef68c78374a5f987fce98c0ddfa45801df2395bf012c50b863e65978d74", endpoint.host)
111+
self.assertEqual("AwsEcrContainerImage_arn_aws_ecr_eu-central-1_123456789012_repository_repo-os_sha256_af965ef68c78374a5f987fce98c0ddfa45801df2395bf012c50b863e65978d74", endpoint.host)
112112

113113
def test_guardduty(self):
114114
with open(sample_path("guardduty.json"), encoding="utf-8") as test_file:
@@ -124,7 +124,7 @@ def test_guardduty(self):
124124
self.assertEqual("User AssumedRole : 123123123 is anomalously invoking APIs commonly used in Discovery tactics. - Resource: 123123123", finding.title)
125125
self.assertEqual("TTPs/Discovery/IAMUser-AnomalousBehavior\n[https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_finding-types-active.html](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_finding-types-active.html)", finding.mitigation)
126126
endpoint = findings[0].unsaved_endpoints[0]
127-
self.assertEqual("AwsEc2Instance arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890", endpoint.host)
127+
self.assertEqual("AwsEc2Instance_arn_aws_ec2_us-east-1_123456789012_instance_i-1234567890", endpoint.host)
128128
self.assertEqual("This is a GuardDuty Finding\nAPIs commonly used in Discovery tactics were invoked by user AssumedRole : 123123123, under anomalous circumstances. Such activity is not typically seen from this user.\n**AWS Finding ARN:** arn:aws:guardduty:us-east-1:123456789012:detector/123456789/finding/2123123123123\n**SourceURL:** [https://us-east-1.console.aws.amazon.com/guardduty/home?region=us-east-1#/findings?macros=current&fId=2123123123123](https://us-east-1.console.aws.amazon.com/guardduty/home?region=us-east-1#/findings?macros=current&fId=2123123123123)\n**AwsAccountId:** 123456789012\n**Region:** us-east-1\n**Generator ID:** arn:aws:guardduty:us-east-1:123456789012:detector/123456789\n", finding.description)
129129

130130
def test_issue_10956(self):

0 commit comments

Comments
 (0)