Query Details

D03 Awsguardduty Schema Check

Query

// REVIEW ONLY - Mandatory Step 1: AWSGuardDuty Schema, Severity Type & Dynamic Payload Discovery
// Validates whether Severity is int vs real, whether archived findings are exported, and inspects
// ResourceDetails / ServiceDetails bag_keys() across finding families before enabling P0-06a / P0-06b.
AWSGuardDuty
| where TimeGenerated > ago(7d)
| extend ResKeys = bag_keys(ResourceDetails),
    SvcKeys = bag_keys(ServiceDetails),
    ActionKeys = bag_keys(ServiceDetails.action),
    ArchivedFlag = tostring(ServiceDetails.archived),
    ResourceType = tostring(ResourceDetails.resourceType)
| summarize
    Rows = count(),
    DistinctFindings = count_distinct(Id),
    DuplicateRatio = round(todouble(count()) / todouble(max_of(count_distinct(Id), 1)), 2),
    MinSeverity = min(Severity),
    MaxSeverity = max(Severity),
    ArchivedStates = make_set(ArchivedFlag, 10),
    ResourceTypes = make_set(ResourceType, 25),
    ObservedResKeys = make_set(ResKeys, 50),
    ObservedSvcKeys = make_set(SvcKeys, 50),
    ObservedActionKeys = make_set(ActionKeys, 25)
    by AccountId, Region
| order by Rows desc
| take 200

Explanation

This query is designed to analyze AWS GuardDuty data over the past week. Here's a simple breakdown of what it does:

  1. Data Filtering: It looks at GuardDuty records generated in the last 7 days.

  2. Key Extraction: It extracts key information from the ResourceDetails and ServiceDetails fields, such as:

    • ResKeys: Keys from ResourceDetails.
    • SvcKeys: Keys from ServiceDetails.
    • ActionKeys: Keys from ServiceDetails.action.
    • ArchivedFlag: Whether the finding is archived.
    • ResourceType: Type of resource involved.
  3. Data Summarization: For each AWS account and region, it summarizes the data by:

    • Counting the total number of records (Rows).
    • Counting distinct findings (DistinctFindings).
    • Calculating the ratio of duplicate findings (DuplicateRatio).
    • Finding the minimum and maximum severity levels (MinSeverity, MaxSeverity).
    • Listing unique archived states, resource types, and observed keys from the data.
  4. Sorting and Limiting: It orders the results by the number of records in descending order and limits the output to the top 200 entries.

This query helps in understanding the distribution and characteristics of GuardDuty findings, including severity levels, resource types, and whether findings are archived, across different AWS accounts and regions.