|
| 1 | +import datetime |
| 2 | + |
| 3 | +from dojo.models import Finding |
| 4 | + |
| 5 | + |
| 6 | +class SecurityHub: |
| 7 | + def get_item(self, finding: dict, test): |
| 8 | + finding_id = finding.get("Id", "") |
| 9 | + title = finding.get("Title", "") |
| 10 | + severity = finding.get("Severity", {}).get("Label", "INFORMATIONAL").title() |
| 11 | + mitigation = "" |
| 12 | + impact = [] |
| 13 | + references = [] |
| 14 | + unsaved_vulnerability_ids = [] |
| 15 | + epss_score = None |
| 16 | + mitigations = finding.get("FindingProviderFields", {}).get("Types") |
| 17 | + for mitigate in mitigations: |
| 18 | + mitigation += mitigate + "\n" |
| 19 | + active = True |
| 20 | + if finding.get("RecordState") == "ACTIVE": |
| 21 | + is_Mitigated = False |
| 22 | + mitigated = None |
| 23 | + else: |
| 24 | + is_Mitigated = True |
| 25 | + if finding.get("LastObservedAt"): |
| 26 | + try: |
| 27 | + mitigated = datetime.datetime.strptime(finding.get("LastObservedAt"), "%Y-%m-%dT%H:%M:%S.%fZ") |
| 28 | + except Exception: |
| 29 | + mitigated = datetime.datetime.strptime(finding.get("LastObservedAt"), "%Y-%m-%dT%H:%M:%fZ") |
| 30 | + else: |
| 31 | + mitigated = datetime.datetime.now(datetime.UTC) |
| 32 | + description = f"This is a Security Hub Finding\n{finding.get('Description', '')}" + "\n" |
| 33 | + description += f"**AWS Finding ARN:** {finding_id}\n" |
| 34 | + description += f"**AwsAccountId:** {finding.get('AwsAccountId', '')}\n" |
| 35 | + description += f"**Region:** {finding.get('Region', '')}\n" |
| 36 | + description += f"**Generator ID:** {finding.get('GeneratorId', '')}\n" |
| 37 | + title_suffix = "" |
| 38 | + hosts = [] |
| 39 | + for resource in finding.get("Resources", []): |
| 40 | + component_name = resource.get("Type") |
| 41 | + resource_id = resource["Id"].split(":")[-1] |
| 42 | + impact.append(f"Resource: {resource_id}") |
| 43 | + title_suffix = f" - Resource: {resource_id}" |
| 44 | + if remediation_rec_url := finding.get("Remediation", {}).get("Recommendation", {}).get("Url"): |
| 45 | + references.append(remediation_rec_url) |
| 46 | + false_p = False |
| 47 | + result = Finding( |
| 48 | + title=f"{title}{title_suffix}", |
| 49 | + test=test, |
| 50 | + description=description, |
| 51 | + mitigation=mitigation, |
| 52 | + references="\n".join(references), |
| 53 | + severity=severity, |
| 54 | + impact="\n".join(impact), |
| 55 | + active=active, |
| 56 | + verified=False, |
| 57 | + false_p=false_p, |
| 58 | + unique_id_from_tool=finding_id, |
| 59 | + mitigated=mitigated, |
| 60 | + is_mitigated=is_Mitigated, |
| 61 | + static_finding=True, |
| 62 | + dynamic_finding=False, |
| 63 | + component_name=component_name, |
| 64 | + ) |
| 65 | + result.unsaved_endpoints = [] |
| 66 | + result.unsaved_endpoints.extend(hosts) |
| 67 | + if epss_score is not None: |
| 68 | + result.epss_score = epss_score |
| 69 | + # Add the unsaved vulnerability ids |
| 70 | + result.unsaved_vulnerability_ids = unsaved_vulnerability_ids |
| 71 | + return result |
0 commit comments