Sub topic 10
Viewing and querying GuardDuty findings in Security Hub
This chapter assumes you have enabled GuardDuty with a detector, can read a GuardDuty finding, and are comfortable with the AWS CLI and JSON. You also need to know the basics of AWS Security Hub from earlier chapters. By the end you will be able to confirm that GuardDuty findings reach Security Hub, filter them from the CLI and from Python, and track triage state without leaving Security Hub.
How findings get from GuardDuty to Security Hub
When both services are enabled in the same account and Region, GuardDuty sends its findings to Security Hub automatically. You don't create a rule or a subscription. In Security Hub terms, GuardDuty is a product integration that is on by default.
Each finding is converted into the AWS Security Finding Format (ASFF), the JSON schema Security Hub uses for findings from every source. A single GuardDuty finding becomes one Security Hub finding. When GuardDuty updates the finding, for example when it sees more activity, the Security Hub copy is updated in place.
Three properties of this integration cause most surprises:
- It is Regional. A Security Hub finding appears in the same Region as the GuardDuty finding. To see several Regions in one place, use Security Hub cross-Region aggregation (covered in the multi-account chapter).
- It is not instant. There is a short delay between GuardDuty creating a finding and Security Hub showing it. Don't treat a missing finding as a failure until a few minutes have passed.
- Suppressed findings stay out. Findings that match an active GuardDuty suppression rule are archived at creation. Archived findings are not a good source for alerting, so check
RecordStatein your queries.
Confirming the integration
Enable Security Hub if you haven't, then pull a few GuardDuty findings. This is the same pair of commands you will use as a smoke test.
aws securityhub enable-security-hub --enable-default-standards
aws securityhub get-findings --filters '{"ProductName":[{"Value":"GuardDuty","Comparison":"EQUALS"}],"RecordState":[{"Value":"ACTIVE","Comparison":"EQUALS"}]}' --max-items 5If you generated sample findings earlier, they should appear here. Samples are marked as samples in their details, so you can tell them from real detections.
Anatomy of a GuardDuty finding in ASFF
The ASFF version differs from the native GuardDuty JSON. These top-level fields matter most for querying.
| ASFF field | What it holds for a GuardDuty finding |
|---|---|
| `ProductName` | `GuardDuty`. The best first filter. |
| `ProductArn` | The GuardDuty product ARN for the Region. Needed when you update findings. |
| `Id` | A unique ARN-style identifier for the finding. |
| `Types` | The finding type in ASFF taxonomy form, such as `TTPs/Initial Access/UnauthorizedAccess:EC2-SSHBruteForce`. The GuardDuty type's `/` becomes `-`. |
| `Severity.Original` | The GuardDuty severity value. |
| `Severity.Label` | The normalized label: `INFORMATIONAL`, `LOW`, `MEDIUM`, `HIGH`, or `CRITICAL`. |
| `Severity.Normalized` | A 0 to 100 value Security Hub uses to compare severity across products. |
| `Resources` | The affected resources, each with a `Type` such as `AwsEc2Instance` and an `Id`. |
| `RecordState` | `ACTIVE` or `ARCHIVED`. Set by the source product. |
| `Workflow.Status` | `NEW`, `NOTIFIED`, `SUPPRESSED`, or `RESOLVED`. Set by you or your automation. |
RecordState and Workflow.Status are easy to confuse. RecordState describes whether the source still considers the finding relevant. Workflow.Status is your own triage progress, and Security Hub never changes it for you.
Because GuardDuty severity (0 to 10 scale) differs from Security Hub's normalized scale, filter on SeverityLabel or SeverityNormalized in Security Hub, not on the raw GuardDuty number. In GuardDuty itself you filter with severity greater than or equal to 7, as in the earlier list-findings example. In Security Hub, the equivalent is the label. Check the Severity.Label of one of your own findings before relying on any mapping.
Querying with filters
The --filters argument of get-findings takes a JSON object. Each key is an ASFF field name. Each value is a list of conditions, and conditions in the same list are combined with OR. Different keys are combined with AND.
String conditions have a Value and a Comparison. The comparisons are EQUALS, NOT_EQUALS, PREFIX, PREFIX_NOT_EQUALS, CONTAINS, and NOT_CONTAINS. Numeric conditions use Gte, Lte, or Eq. Date conditions use Start and End, or a relative DateRange.
Active, high-severity GuardDuty findings from the last day:
aws securityhub get-findings \
--filters '{
"ProductName": [{"Value": "GuardDuty", "Comparison": "EQUALS"}],
"RecordState": [{"Value": "ACTIVE", "Comparison": "EQUALS"}],
"SeverityLabel": [{"Value": "HIGH", "Comparison": "EQUALS"}],
"CreatedAt": [{"DateRange": {"Value": 1, "Unit": "DAYS"}}]
}' \
--max-items 20All brute-force findings, whatever the resource, using a prefix match on the type:
aws securityhub get-findings \
--filters '{
"ProductName": [{"Value": "GuardDuty", "Comparison": "EQUALS"}],
"Type": [{"Value": "TTPs/Initial Access/UnauthorizedAccess", "Comparison": "PREFIX"}]
}' \
--max-items 20The raw output is large. Use the CLI's --query option, which is JMESPath, to project only what you need:
aws securityhub get-findings \
--filters '{"ProductName":[{"Value":"GuardDuty","Comparison":"EQUALS"}],"RecordState":[{"Value":"ACTIVE","Comparison":"EQUALS"}]}' \
--query 'Findings[].{Title:Title,Label:Severity.Label,Resource:Resources[0].Id,Status:Workflow.Status}' \
--output tableQuerying from Python
For scripts and reports, boto3's paginator handles NextToken for you. This example lists active high-severity GuardDuty findings and prints one line for each.
import boto3
securityhub = boto3.client("securityhub")
filters = {
"ProductName": [{"Value": "GuardDuty", "Comparison": "EQUALS"}],
"RecordState": [{"Value": "ACTIVE", "Comparison": "EQUALS"}],
"SeverityLabel": [{"Value": "HIGH", "Comparison": "EQUALS"}],
}
paginator = securityhub.get_paginator("get_findings")
for page in paginator.paginate(Filters=filters, PaginationConfig={"PageSize": 100}):
for finding in page["Findings"]:
resource = finding["Resources"][0]
print(
finding["Severity"]["Label"],
finding["Types"][0],
resource["Type"],
resource["Id"],
)Recording triage with workflow status
Querying is half the job. Once someone looks at a finding, record it, so the next query can exclude it. batch-update-findings changes Workflow.Status and adds a note. It identifies each finding by both Id and ProductArn, so copy both values from the get-findings output.
aws securityhub batch-update-findings \
--finding-identifiers Id="<finding-id>",ProductArn="<product-arn>" \
--workflow Status=NOTIFIED \
--note Text="Paged on-call",UpdatedBy="triage-script"Then exclude resolved work from your dashboards:
aws securityhub get-findings \
--filters '{"ProductName":[{"Value":"GuardDuty","Comparison":"EQUALS"}],"WorkflowStatus":[{"Value":"NEW","Comparison":"EQUALS"}]}'Common problems
- No findings appear. Check that you are in the right Region, that both services are enabled there, and that the GuardDuty findings are not already archived by a suppression rule.
- A filter returns nothing that should match. ASFF field names are case-sensitive, and
Typesvalues use the ASFF taxonomy form, not the GuardDuty form. A filter onRecon:EC2/PortProbeUnprotectedPortwill not match. Look at one real finding and copy itsTypesvalue. - Counts differ between GuardDuty and Security Hub. Security Hub keeps a finding for 90 days after its last update, and your queries may include different record states. Compare like with like.
- A format change breaks scripts. Security Hub is moving toward the Open Cybersecurity Schema Framework (OCSF) as a finding format. The ASFF queries in this chapter apply to the ASFF-based APIs. Check which format your Security Hub configuration returns before you reuse field names.
Exercise
You want a daily report of GuardDuty findings that are still active, are rated HIGH, and have not yet been triaged. Which three filter keys do you need beyond ProductName, and which Workflow.Status value marks untriaged findings?
Show answer
Use RecordState equal to ACTIVE, SeverityLabel equal to HIGH, and WorkflowStatus equal to NEW. NEW is the status of findings nobody has triaged yet. Use a paginator or the CLI's default pagination so you don't stop at the first page.
Exercise
A teammate's get-findings filter uses "Type" with the value "Recon:EC2/PortProbeUnprotectedPort" and returns nothing, even though the finding exists in GuardDuty. What is wrong, and how do you fix the filter?
Show answer
Security Hub stores the type in ASFF taxonomy form, such as "TTPs/Discovery/Recon:EC2-PortProbeUnprotectedPort". The GuardDuty-style string does not match it. Fetch one real finding, copy its Types value, and use it with EQUALS, or use PREFIX or CONTAINS on a shorter part such as "PortProbeUnprotectedPort".