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 200Explanation
This query is designed to analyze AWS GuardDuty data over the past week. Here's a simple breakdown of what it does:
-
Data Filtering: It looks at GuardDuty records generated in the last 7 days.
-
Key Extraction: It extracts key information from the
ResourceDetailsandServiceDetailsfields, such as:ResKeys: Keys fromResourceDetails.SvcKeys: Keys fromServiceDetails.ActionKeys: Keys fromServiceDetails.action.ArchivedFlag: Whether the finding is archived.ResourceType: Type of resource involved.
-
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.
- Counting the total number of records (
-
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.