15 Guard Duty Identity Linked Guardduty Findings
Query
// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: GuardDuty | Panel: identity-linked-guardduty-findings | Visualization: table | Mode: Analyst
// Security Question: What concrete CloudTrail API mutations did the GuardDuty-flagged AccessKeyId execute?
// Drill-Through: Copy AccessKeyId into Cross-Cloud Investigation Workbook (AccessKeyId parameter) to pivot into Entra ID and Defender XDR.
// Empty/No-Data Contract: No IAM/AccessKey-linked GuardDuty findings observed in window.
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}");
let GdIam = union isfuzzy=true
(datatable(TimeGenerated:datetime, Id:string, AccountId:string, Region:string, Severity:real, ActivityType:string, ServiceDetails:dynamic, ResourceDetails:dynamic)[]),
(AWSGuardDuty | where TimeGenerated between (Start .. End)
| project TimeGenerated, Id, AccountId, Region, Severity=todouble(Severity), ActivityType, ServiceDetails=todynamic(ServiceDetails), ResourceDetails=todynamic(ResourceDetails))
| where (AccountFilter == "*" or AccountId == AccountFilter)
| summarize arg_max(TimeGenerated, *) by Id
| where tobool(ServiceDetails.archived) != true
| extend AccessKeyId = tostring(ResourceDetails.accessKeyDetails.accessKeyId),
UserName = tostring(ResourceDetails.accessKeyDetails.userName)
| where isnotempty(AccessKeyId)
| project FindingId=Id, AccountId, Region, Severity, ActivityType, UserName, AccessKeyId, FindingTime=TimeGenerated;
let TrailByKey = union isfuzzy=true
(datatable(TimeGenerated:datetime, UserIdentityAccountId:string, UserIdentityAccessKeyId:string, EventName:string, ReadOnly:bool, SourceIpAddress:string)[]),
(AWSCloudTrail | where TimeGenerated between (Start .. End)
| project TimeGenerated, UserIdentityAccountId, UserIdentityAccessKeyId, EventName, ReadOnly, SourceIpAddress)
| summarize CtCalls=count(), MutatingApis=make_set_if(EventName, ReadOnly == false, 15), SourceIps=make_set(SourceIpAddress, 10)
by AccountId=UserIdentityAccountId, AccessKeyId=UserIdentityAccessKeyId;
GdIam
| join kind=leftouter TrailByKey on AccountId, AccessKeyId
| order by Severity desc, CtCalls desc
| take 5000Explanation
This query is designed to analyze AWS security operations, specifically focusing on identifying CloudTrail API actions executed by AccessKeyIds flagged by GuardDuty. Here's a simplified breakdown of what the query does:
-
Setup and Filters:
- The query starts by setting up time range filters (
StartandEnd) and various other filters like organization, account, region, environment, workload, severity, source, principal, and IP. These filters are decoded from base64 strings.
- The query starts by setting up time range filters (
-
GuardDuty Findings:
- It retrieves GuardDuty findings within the specified time range.
- Filters the findings based on the account filter and ensures they are not archived.
- Extracts details such as AccessKeyId and UserName from the findings.
- Projects relevant information like FindingId, AccountId, Region, Severity, ActivityType, UserName, AccessKeyId, and FindingTime.
-
CloudTrail Events:
- It retrieves CloudTrail events within the specified time range.
- Summarizes the events by counting the number of calls (
CtCalls), identifying mutating API calls (those that change state), and recording source IP addresses.
-
Join and Output:
- The query performs a left outer join between the GuardDuty findings and CloudTrail events based on AccountId and AccessKeyId.
- It orders the results by severity of the findings and the number of CloudTrail calls, in descending order.
- Finally, it limits the output to 5000 records.
The purpose of this query is to provide a table view that helps analysts understand which specific CloudTrail API actions were executed by AccessKeyIds that have been flagged by GuardDuty, allowing for further investigation into potential security incidents. If no relevant findings are observed, it indicates that there are no IAM/AccessKey-linked GuardDuty findings within the specified time window.