Sub topic 5
Enabling GuardDuty and generating sample findings
This chapter assumes you know AWS accounts, Regions, and IAM basics, and that you can run the AWS CLI with credentials that allow guardduty:*. You will enable GuardDuty, create sample findings, and query them.
The detector
GuardDuty is enabled per Region, per account. The resource that represents it is a detector. A detector holds the service settings for that Region, such as which protection plans are on and how often findings are published. Each account can have one detector per Region.
Enabling GuardDuty does not require agents or log configuration. It reads CloudTrail events, VPC Flow Logs, and DNS logs on its own, independent of whether you have turned those logs on in your account.
Create the detector
Run this in the Region you want to protect:
aws guardduty create-detector --enable --finding-publishing-frequency FIFTEEN_MINUTESThe command returns a DetectorId. The publishing frequency controls how often updates to existing findings go to EventBridge. New findings are always sent right away. The allowed values are FIFTEEN_MINUTES, ONE_HOUR, and SIX_HOURS, and the default is six hours.
If a detector already exists, the call fails with a BadRequestException. Look up the existing ID instead.
Generate sample findings
Sample findings let you see real finding structure without a real attack. They are also useful for testing EventBridge rules later in this tutorial.
DETECTOR_ID=$(aws guardduty list-detectors --query 'DetectorIds[0]' --output text)
aws guardduty create-sample-findings --detector-id "$DETECTOR_ID" --finding-types Recon:EC2/PortProbeUnprotectedPort UnauthorizedAccess:EC2/SSHBruteForceIf you leave out --finding-types, GuardDuty creates one sample of every type. That is a large batch, so name the types you need.
Sample findings carry a [SAMPLE] prefix in their title. Their details are fabricated, such as example IP addresses and instance IDs.
Query findings by severity
list-findings returns finding IDs, not the findings themselves. This query returns only findings with severity 7 or higher, which GuardDuty classes as high:
aws guardduty list-findings --detector-id "$DETECTOR_ID" --finding-criteria '{"Criterion":{"severity":{"Gte":7}}}'To read the contents, pass the IDs to get-findings. Check the Type, Severity, Resource, and Service fields, which the previous chapter covered.
Suppress known-benign findings
Once you know a finding type is noise in your environment, a filter with the ARCHIVE action archives new matches automatically. Archived findings are kept and stay searchable. They are just hidden from the active list.
aws guardduty create-filter --detector-id "$DETECTOR_ID" --name suppress-port-probe-sample --action ARCHIVE --rank 1 --finding-criteria '{"Criterion":{"type":{"Eq":["Recon:EC2/PortProbeUnprotectedPort"]}}}'The next chapter covers suppression rules and IP lists in more depth.
Common errors
- Empty results. You are in the wrong Region. Detectors and findings are Region-specific, so check
--regionor your profile default. AccessDeniedException. The caller lacks GuardDuty permissions. The managed policyAmazonGuardDutyFullAccessis a starting point for a lab account.- Sample findings missing after a few seconds. Retry
list-findings. Creation is not always instant. - Real findings buried under samples. Archive the samples when you finish testing, or use a filter like the one above.
Exercise
You ran create-sample-findings in us-east-1, but list-findings in eu-west-1 returns nothing. Why, and what do you do?
Show answer
Detectors and findings are Region-specific. The detector and its sample findings exist only in us-east-1. Rerun list-findings with --region us-east-1, or create a detector in eu-west-1 and generate samples there.
Exercise
What does --finding-publishing-frequency change, and what does it not change?
Show answer
It sets how often updates to existing findings are published to EventBridge (15 minutes, 1 hour, or 6 hours). It does not delay new findings, which are sent right away, and it does not change how quickly GuardDuty detects threats.