Query Details

H10 Guardduty Repeat Actor And Aging Audit

Query

// REVIEW ONLY - Hunting Query H10: GuardDuty Repeat-Actor Clustering & Unarchived Finding Aging
// Deduplicates by Finding ID (Id) so repeated GuardDuty exports do not inflate counts.
AWSGuardDuty
| where TimeGenerated > ago(14d)
| summarize arg_max(TimeGenerated, *) by Id
| where tobool(ServiceDetails.archived) != true
| extend PrincipalName = coalesce(tostring(ResourceDetails.accessKeyDetails.userName), tostring(ResourceDetails.instanceDetails.instanceId), "UnattributedResource"),
    RemoteIp = coalesce(
        tostring(ServiceDetails.action.awsApiCallAction.remoteIpDetails.ipAddressV4),
        tostring(ServiceDetails.action.networkConnectionAction.remoteIpDetails.ipAddressV4), ""),
    AgeHours = round(datetime_diff('minute', now(), TimeCreated) / 60.0, 1),
    IsRecurring = (TimeGenerated > TimeCreated)
| summarize
    DistinctFindings = count(),
    MaxSeverity = max(Severity),
    RecurringFindings = countif(IsRecurring),
    OldestOpenHours = max(AgeHours),
    FindingTypes = make_set(ActivityType, 20),
    RemoteIps = make_set(RemoteIp, 15),
    SampleFindingIds = make_set(Id, 10)
    by AccountId, Region, PrincipalName
| where MaxSeverity >= 4 or DistinctFindings >= 3
| order by MaxSeverity desc, DistinctFindings desc
| take 1000

Explanation

This query is designed to analyze AWS GuardDuty findings over the past 14 days, focusing on repeated actors and unarchived findings. Here's a simplified breakdown of what it does:

  1. Data Filtering: It starts by selecting GuardDuty findings generated in the last 14 days.

  2. Deduplication: It ensures that each finding is unique by using the Finding ID, preventing duplicate entries from inflating the counts.

  3. Unarchived Findings: It filters out findings that have been archived, focusing only on active issues.

  4. Data Enrichment: It adds additional information to each finding, such as:

    • PrincipalName: The user or resource associated with the finding.
    • RemoteIp: The IP address involved in the finding.
    • AgeHours: How many hours have passed since the finding was created.
    • IsRecurring: A flag indicating if the finding has occurred more than once.
  5. Aggregation: It summarizes the data by account, region, and principal name, calculating:

    • DistinctFindings: The number of unique findings.
    • MaxSeverity: The highest severity level among the findings.
    • RecurringFindings: The count of findings that have recurred.
    • OldestOpenHours: The age of the oldest open finding in hours.
    • FindingTypes: A set of different types of activities detected.
    • RemoteIps: A set of distinct remote IPs involved.
    • SampleFindingIds: A sample set of finding IDs.
  6. Severity and Count Filtering: It filters the results to include only those with a maximum severity of 4 or higher, or with at least 3 distinct findings.

  7. Sorting and Limiting: The results are ordered by severity and the number of distinct findings, and the top 1000 results are selected.

In essence, this query helps identify and prioritize significant security issues by focusing on repeated and severe findings that have not been archived.