Query Details

P0 06a Guardduty High Dedup Baseline

Query

// Standalone KQL for Analytic Rule: AWS SecOps P0-06a - GuardDuty High Severity Prioritized Baseline (Single-Source)
// Rule File: analytics/P0-06a-guardduty-high-dedup-baseline.yaml | Rule ID: REPLACE_WITH_RULE_GUID | Severity: High
// Schedule: 5m / Lookback: 30m | REVIEW ONLY - Do not deploy/schedule without approval.
// 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 KQL query is designed to analyze AWS GuardDuty findings with high severity and prioritize them based on certain criteria. Here's a simplified breakdown of what the query does:

  1. Critical Assets Identification: It first retrieves a list of critical AWS assets from a watchlist, filtering for those marked as "verified" and extracting relevant details like account ID, resource key, criticality, environment, and workload.

  2. GuardDuty Findings Filtering: It then queries the AWSGuardDuty data for findings generated in the last 30 minutes, ensuring they were ingested in the last 5 minutes and are not archived. It focuses on findings with a severity of 7 or higher.

  3. Data Enrichment: The query enriches the findings with additional details such as:

    • Action details from the service.
    • Access key ID and principal name involved.
    • Affected resource details.
    • Remote IP address involved in the action.
  4. Joining with Critical Assets: It attempts to match each finding with the critical assets list based on account ID and resource key.

  5. Dynamic Severity Assignment: It assigns a "High" dynamic severity to findings with a severity of 8 or higher or if the asset is marked as critical.

  6. Finding URL Generation: It generates a URL for each finding that links to the AWS GuardDuty console for further investigation.

  7. Repeat Update Check: It checks if the finding is a repeat update by comparing the generation time with the creation time.

  8. Projection of Results: Finally, it selects and organizes specific columns to display, including time generated, finding ID, AWS account and region, severity, dynamic severity, activity type, and other relevant details.

This query is intended for review and validation purposes only and should not be deployed or scheduled without proper approval. Additionally, it requires validation of the AWSGuardDuty schema before use.