Query Details

AWS SecOps P0-06a - GuardDuty High Severity Prioritized Baseline (Single-Source)

P0 06a Guardduty High Dedup Baseline

Query

// REVIEW ONLY. Validate AWSGuardDuty schema first via discovery/D03-awsguardduty-schema-check.kql
let CriticalAssets = _GetWatchlist('AWS_CriticalAssets')
| where tolower(tostring(column_ifexists("Verified", ""))) == "true"
| project AssetAccountId=tostring(column_ifexists("AWSAccountId", "")), ResourceKey=tolower(tostring(column_ifexists("ResourceIdOrName", ""))),
    AssetCriticality=tostring(column_ifexists("Criticality", "")), Environment=tostring(column_ifexists("Environment", "")), Workload=tostring(column_ifexists("Workload", ""));
AWSGuardDuty
| where TimeGenerated > ago(30m)
| summarize arg_max(TimeGenerated, *) by Id
| where ingestion_time() > ago(5m)
| where tobool(ServiceDetails.archived) != true
| where Severity >= 7
| extend ActionBlock = ServiceDetails.action,
    AccessKeyId = tostring(ResourceDetails.accessKeyDetails.accessKeyId),
    PrincipalName = coalesce(
        tostring(ResourceDetails.accessKeyDetails.userName),
        tostring(ResourceDetails.kubernetesDetails.kubernetesUserDetails.username),
        tostring(ResourceDetails.rdsDbUserDetails.user), ""),
    AffectedResource = coalesce(
        tostring(ResourceDetails.instanceDetails.instanceId),
        tostring(ResourceDetails.s3BucketDetails[0].name),
        tostring(ResourceDetails.eksClusterDetails.name),
        tostring(ResourceDetails.accessKeyDetails.principalId), "")
| extend RemoteIpAddress = coalesce(
        tostring(ActionBlock.awsApiCallAction.remoteIpDetails.ipAddressV4),
        tostring(ActionBlock.networkConnectionAction.remoteIpDetails.ipAddressV4),
        tostring(ActionBlock.kubernetesApiCallAction.remoteIpDetails.ipAddressV4), "")
| extend ResourceKey = tolower(AffectedResource)
| join kind=leftouter CriticalAssets on $left.AccountId == $right.AssetAccountId and $left.ResourceKey == $right.ResourceKey
| extend DynamicSeverity = iff(Severity >= 8 or AssetCriticality =~ "Critical", "High", "High"),
    FindingUrl = iff(isnotempty(Region) and isnotempty(Id), strcat("https://", Region, ".console.aws.amazon.com/guardduty/home?region=", Region, "#/findings?fId=", Id), ""),
    IsRepeatUpdate = tostring(TimeGenerated > TimeCreated)
| project TimeGenerated, TimeCreated, FindingId=Id, AWSAccountId=AccountId, AWSRegion=Region,
    Severity, DynamicSeverity, ActivityType, Title, Description, PrincipalName, AccessKeyId,
    AffectedResource, AssetCriticality=coalesce(AssetCriticality, "Unclassified"),
    Environment=coalesce(Environment, "Unclassified"), Workload=coalesce(Workload, "Unclassified"),
    RemoteIpAddress, IsRepeatUpdate, FindingUrl

Explanation

This query is designed to monitor AWS GuardDuty for high-severity security findings and create alerts for them. Here's a simplified breakdown:

  1. Purpose: The query identifies and processes high-severity security alerts from AWS GuardDuty, focusing on findings with a severity of 7 or higher. It aims to reduce noise by deduplicating findings based on their ID and timestamp, and it suppresses archived findings and approved scanner tests.

  2. Data Source: It uses data from AWS GuardDuty, accessed via an AWS S3 data connector.

  3. Frequency: The query runs every 5 minutes and looks at data from the last 30 minutes.

  4. Filtering and Processing:

    • It checks for findings that are not archived and have a severity of 7 or higher.
    • It deduplicates findings by their ID and the latest update timestamp.
    • It enriches the findings with additional information like the principal name, access key ID, affected resource, and remote IP address.
    • It joins the findings with a list of critical assets to determine if any critical assets are affected.
  5. Output: The query projects relevant details such as the time of the finding, AWS account and region, severity, principal name, affected resource, and more. It also constructs a URL for each finding for easy access in the AWS console.

  6. Alerting and Incident Management:

    • Alerts are generated for each finding, with a custom display name and description.
    • Incidents are created for these alerts, and findings are grouped into incidents based on their ID and AWS account.
    • The configuration allows for incidents to be reopened if new related findings are detected within a 7-day lookback period.
  7. Entity Mapping: The query maps certain fields to entities like accounts and IP addresses for better integration with security tools.

Overall, this query is part of a security operations process to monitor and respond to high-severity security threats detected by AWS GuardDuty.