Fn AWS Guard Duty Normalized
Query
// REVIEW ONLY - Reusable Workspace Function Spec: fn_AWS_GuardDutyNormalized
// Purpose: Deduplicates GuardDuty findings by Finding ID (Id) + latest TimeGenerated, filters archived findings,
// and normalizes affected resource, principal, access key, and network attributes across finding schemas.
let Lookback = 24h;
AWSGuardDuty
| where TimeGenerated > ago(Lookback)
| summarize arg_max(TimeGenerated, *) by Id
| extend Archived = tobool(ServiceDetails.archived)
| where Archived != true
| extend Tokens = split(ActivityType, ":")
| extend ThreatPurpose = tostring(Tokens[0]),
SubTokens = split(tostring(Tokens[1]), "/")
| extend ResourceTypeAffected = tostring(SubTokens[0]),
ThreatFamilyName = tostring(split(tostring(SubTokens[1]), ".")[0]),
ResourceTypeDetail = tostring(ResourceDetails.resourceType),
AccessKeyId = tostring(ResourceDetails.accessKeyDetails.accessKeyId),
PrincipalName = coalesce(
tostring(ResourceDetails.accessKeyDetails.userName),
tostring(ResourceDetails.kubernetesDetails.kubernetesUserDetails.username),
tostring(ResourceDetails.rdsDbUserDetails.user),
""),
InstanceId = tostring(ResourceDetails.instanceDetails.instanceId),
S3BucketName = tostring(ResourceDetails.s3BucketDetails[0].name),
EksClusterName = tostring(ResourceDetails.eksClusterDetails.name),
ActionBlock = ServiceDetails.action
| extend RemoteIp = coalesce(
tostring(ActionBlock.awsApiCallAction.remoteIpDetails.ipAddressV4),
tostring(ActionBlock.networkConnectionAction.remoteIpDetails.ipAddressV4),
tostring(ActionBlock.kubernetesApiCallAction.remoteIpDetails.ipAddressV4),
tostring(ActionBlock.rdsLoginAttemptAction.remoteIpDetails.ipAddressV4),
""),
LocalIp = tostring(ActionBlock.networkConnectionAction.localIpDetails.ipAddressV4),
SeverityBand = case(Severity >= 7, "High", Severity >= 4, "Medium", "Low"),
IsRepeatOccurrence = (TimeGenerated > TimeCreated),
FindingAgeHours = round(datetime_diff('minute', now(), TimeCreated) / 60.0, 1),
FindingUrl = iff(isnotempty(Region) and isnotempty(Id), strcat("https://", Region, ".console.aws.amazon.com/guardduty/home?region=", Region, "#/findings?fId=", Id), "")
| project TimeGenerated, TimeCreated, IngestTime=ingestion_time(), FindingId=Id, FindingArn=Arn, AccountId, Region,
Severity, SeverityBand, ActivityType, Title, Description, ThreatPurpose, ResourceTypeAffected, ThreatFamilyName,
ResourceTypeDetail, PrincipalName, AccessKeyId, InstanceId, S3BucketName, EksClusterName, RemoteIp, LocalIp,
IsRepeatOccurrence, FindingAgeHours, FindingUrl
| take 2000Explanation
This query is designed to process and normalize AWS GuardDuty findings. Here's a simplified breakdown of what it does:
-
Time Filtering: It looks at GuardDuty findings generated in the last 24 hours.
-
Deduplication: It keeps only the latest finding for each unique Finding ID.
-
Exclusion of Archived Findings: It filters out any findings that have been marked as archived.
-
Attribute Normalization: It extracts and organizes various attributes from the findings, such as:
- Threat Information: Breaks down the activity type to identify the threat purpose and family name.
- Resource Details: Identifies the type of resource affected and details like instance ID, S3 bucket name, and EKS cluster name.
- Principal and Access Information: Extracts details about the principal involved, such as the username and access key ID.
- Network Details: Retrieves remote and local IP addresses involved in the finding.
-
Severity Classification: It categorizes the severity of findings into "High," "Medium," or "Low."
-
Occurrence Tracking: Determines if the finding is a repeat occurrence and calculates how old the finding is in hours.
-
Finding URL Generation: Constructs a URL for each finding that links to its detailed view in the AWS GuardDuty console.
-
Output: Selects and organizes relevant fields for output, limiting the result to the first 2000 findings.
Overall, this query helps in efficiently managing and analyzing GuardDuty findings by deduplicating, filtering, and normalizing the data for easier interpretation and action.