Sub topic 10
Viewing and querying GuardDuty findings in Security Hub
This chapter assumes you have GuardDuty enabled in at least one Region and can read a GuardDuty finding by type and severity. It also assumes you know the AWS CLI and basic JSON. Security Hub is the place where those findings sit next to results from other services, so you can filter and act on them in one view.
How findings arrive
When both services are enabled in the same account and Region, GuardDuty sends its findings to Security Hub automatically. The integration needs no extra rule or role from you. Security Hub converts each finding to its own format, so fields have different names than in GuardDuty. For example, the GuardDuty finding type appears in the Types field, and the GuardDuty severity is mapped onto Security Hub's severity labels.
Enable Security Hub and fetch findings
The first command turns on Security Hub with its default standards. The second retrieves up to five active findings that came from GuardDuty.
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 in GuardDuty earlier, they should appear here after a short delay. Allow a few minutes before you assume something is broken.
Reading the filter syntax
The --filters argument is a JSON object. Each key is a finding field, and each value is a list of conditions. Every condition has a Value and a Comparison.
| Part | Meaning | Example |
|---|---|---|
| Field name | The finding attribute to test | `ProductName` |
| `Value` | The text to compare against | `GuardDuty` |
| `Comparison` | How to compare | `EQUALS`, `PREFIX`, `NOT_EQUALS` |
Two rules explain most results:
- Several conditions on the same field are combined with OR, unless they use
NOT_EQUALS. - Conditions on different fields are combined with AND.
So the command above returns findings where the product is GuardDuty and the record state is active. Archived findings and findings from other products are excluded.
Filter by severity and type
Security Hub uses a severity label in addition to a number. To see only the serious GuardDuty findings, filter on the label:
aws securityhub get-findings --filters '{"ProductName":[{"Value":"GuardDuty","Comparison":"EQUALS"}],"SeverityLabel":[{"Value":"HIGH","Comparison":"EQUALS"},{"Value":"CRITICAL","Comparison":"EQUALS"}],"RecordState":[{"Value":"ACTIVE","Comparison":"EQUALS"}]}' --query 'Findings[].[Title,Severity.Label,Region]' --output tableThe --query option is a JMESPath expression that trims the output to a title, a label, and a Region. Without it, each finding is a long JSON document.
Common errors
- No findings returned. Check that Security Hub is enabled in the same Region as the detector. Findings do not cross Regions unless you set up aggregation.
- Archived findings missing. If you archive a finding in GuardDuty, or a suppression rule archives it, Security Hub reflects that in the record state. Filtering for
ACTIVEhides it. - Invalid filter JSON. Wrap the whole JSON in single quotes in a Unix shell, and keep double quotes inside it.
- Too many results.
--max-itemslimits how much the CLI prints. Narrow the filters instead of relying on it alone.
Exercise
You ran get-findings with ProductName equal to GuardDuty and got nothing, although GuardDuty shows findings in the console. Name two likely causes.
Show answer
Security Hub is not enabled in the Region where the detector lives, or the findings have not arrived yet because of the short delay. A third cause is a RecordState filter of ACTIVE when the findings are archived.
Exercise
How would you list only the titles and Regions of active GuardDuty findings with a severity label of HIGH?
Show answer
Use get-findings with filters on ProductName (GuardDuty), SeverityLabel (HIGH), and RecordState (ACTIVE), then add --query 'Findings[].[Title,Region]' to trim the output.