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

add test description for AWS SecurityHub Scan #9904

Merged
merged 5 commits into from
May 2, 2024
Merged
Changes from 3 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
21 changes: 21 additions & 0 deletions dojo/tools/awssecurityhub/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from dojo.tools.awssecurityhub.inspector import Inspector
from dojo.tools.awssecurityhub.guardduty import GuardDuty
from dojo.tools.awssecurityhub.compliance import Compliance
from dojo.tools.parser_test import ParserTest


class AwsSecurityHubParser:
ID = "AWS Security Hub"

def get_scan_types(self):
return ["AWS Security Hub Scan"]
Expand All @@ -15,6 +17,25 @@ def get_label_for_scan_types(self, scan_type):
def get_description_for_scan_types(self, scan_type):
return "AWS Security Hub exports in JSON format."

def get_tests(self, scan_type, scan):
data = json.load(scan)
findings = data.get("Findings", data.get("findings", None))
if not isinstance(findings, list):
raise TypeError("Incorrect Security Hub report format")
prod = list()
aws_acc = list()
for finding in findings:
prod.append(finding.get("ProductName", "AWS Security Hub Ruleset"))
aws_acc.append(finding.get("AwsAccountId"))
report_date = data.get("createdAt")
test = ParserTest(
name=self.ID, type=self.ID, version=""
)
test.description = "**AWS Accounts:** " + ', '.join(set(aws_acc)) + "\n"
test.description += "**Finding Origins:** " + ', '.join(set(prod)) + "\n"
test.findings = self.get_items(data, report_date)
return [test]

def get_findings(self, filehandle, test):
tree = json.load(filehandle)
if not isinstance(tree, dict):
Expand Down
Loading