Query Details

14 Guard Duty Active Aging And Repeat Findings

Query

// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: GuardDuty | Panel: active-aging-and-repeat-findings | Visualization: table | Mode: All
// Security Question: Which unarchived GuardDuty findings are recurring (TimeGenerated > TimeCreated) or aging unaddressed?
// Drill-Through: Click a row to export RemoteIp into SelectedIp, then pivot to Tab 5 (Network) or Tab 10 (Cross-Cloud Pivot).
// Empty/No-Data Contract: Zero unarchived GuardDuty findings matched current filters.
let Start = {TimeRange:start};
let End = {TimeRange:end};
let OrgFilter = base64_decode_tostring("{Organization:base64}");
let AccountFilter = base64_decode_tostring("{AwsAccount:base64}");
let RegionFilter = base64_decode_tostring("{AwsRegion:base64}");
let EnvFilter = base64_decode_tostring("{Environment:base64}");
let WorkloadFilter = base64_decode_tostring("{Workload:base64}");
let SeverityFilter = base64_decode_tostring("{Severity:base64}");
let SourceFilter = base64_decode_tostring("{SourceTable:base64}");
let SummaryPref = base64_decode_tostring("{SummaryMode:base64}");
let SelectedPrincipalFilter = base64_decode_tostring("{SelectedPrincipal:base64}");
let SelectedIpFilter = base64_decode_tostring("{SelectedIp:base64}");
union isfuzzy=true
    (datatable(TimeGenerated:datetime, TimeCreated:datetime, Id:string, AccountId:string, Region:string, ActivityType:string, Severity:real, ServiceDetails:dynamic, ResourceDetails:dynamic)[]),
    (AWSGuardDuty | where TimeGenerated between (Start .. End)
     | project TimeGenerated, TimeCreated, Id, AccountId, Region, ActivityType, Severity=todouble(Severity), ServiceDetails=todynamic(ServiceDetails), ResourceDetails=todynamic(ResourceDetails))
| where (AccountFilter == "*" or AccountId == AccountFilter) and (RegionFilter == "*" or Region == RegionFilter)
| summarize arg_max(TimeGenerated, *) by Id
| where tobool(ServiceDetails.archived) != true
| extend SeverityBand = case(Severity >= 7.0, "High", Severity >= 4.0, "Medium", "Low")
| where SeverityFilter == "*" or SeverityBand =~ SeverityFilter
| extend AffectedResource = coalesce(
    iff(isnotempty(tostring(ResourceDetails.instanceDetails.instanceId)), tostring(ResourceDetails.instanceDetails.instanceId), ""),
    iff(isnotempty(tostring(ResourceDetails.s3BucketDetails[0].name)), tostring(ResourceDetails.s3BucketDetails[0].name), ""),
    iff(isnotempty(tostring(ResourceDetails.eksClusterDetails.name)), tostring(ResourceDetails.eksClusterDetails.name), ""),
    iff(isnotempty(tostring(ResourceDetails.accessKeyDetails.userName)), tostring(ResourceDetails.accessKeyDetails.userName), ""),
    "UnknownResource"),
    AccessKeyId = tostring(ResourceDetails.accessKeyDetails.accessKeyId),
    RemoteIp = coalesce(
        iff(isnotempty(tostring(ServiceDetails.action.awsApiCallAction.remoteIpDetails.ipAddressV4)), tostring(ServiceDetails.action.awsApiCallAction.remoteIpDetails.ipAddressV4), ""),
        tostring(ServiceDetails.action.networkConnectionAction.remoteIpDetails.ipAddressV4)),
    RepeatOngoing = (TimeGenerated > TimeCreated),
    AgeHours = round(datetime_diff('minute', now(), TimeCreated) / 60.0, 1)
| project LastUpdatedUtc=TimeGenerated, FirstCreatedUtc=TimeCreated, AgeHours, RepeatOngoing,
    Severity, SeverityBand, AccountId, Region, ActivityType, AffectedResource, AccessKeyId, RemoteIp, FindingId=Id
| order by Severity desc, RepeatOngoing desc, AgeHours desc
| take 5000

Explanation

This query is designed to analyze AWS GuardDuty findings to identify which ones are recurring or aging without being addressed. Here's a simplified breakdown of what the query does:

  1. Time Range and Filters: It sets a time range and applies various filters based on organization, account, region, environment, workload, severity, source, and selected principal or IP.

  2. Data Collection: It gathers data from AWS GuardDuty, focusing on findings generated within the specified time range.

  3. Filtering:

    • It filters out findings that are archived.
    • It applies additional filters based on account, region, and severity.
  4. Severity Categorization: It categorizes findings into "High," "Medium," or "Low" based on their severity score.

  5. Resource Identification: It identifies the affected resource, such as an instance ID, S3 bucket name, EKS cluster name, or access key username. If none of these are available, it labels it as "UnknownResource."

  6. IP Address Extraction: It extracts the remote IP address involved in the finding.

  7. Recurrence and Aging:

    • It checks if the finding is recurring by comparing the time it was generated with the time it was created.
    • It calculates how long the finding has been unaddressed in hours.
  8. Output: It outputs a table with details such as the last updated and first created times, age in hours, whether it's recurring, severity, account ID, region, activity type, affected resource, access key ID, remote IP, and finding ID.

  9. Sorting and Limiting: The results are sorted by severity, recurrence, and age, and the top 5000 findings are displayed.

  10. Drill-Through: Users can click on a row to export the remote IP and pivot to other tabs for further analysis.

In essence, this query helps security teams quickly identify and prioritize GuardDuty findings that need attention based on their recurrence and how long they have been unaddressed.