22 H08 Xdr S3
Query
// REVIEW ONLY workbook query: 7.3 H08 — Defender XDR Impacted Users Performing Authenticated S3 Bulk Object Reads (≥50 Objects / 15m)
let Start = {TimeRange:start};
let End = {TimeRange:end};
let AccountFilter = trim(" ", base64_decode_tostring("{AwsAccount:base64}"));
let UseAllAccounts = AccountFilter in ("", "*");
let TargetXdrTenant = tolower(trim(" ", base64_decode_tostring("{XdrTenantId:base64}")));
let SafeCloudTrail = union isfuzzy=true
(datatable(TimeGenerated:datetime, AwsEventId:string, EventSource:string, EventName:string, AWSRegion:string,
RecipientAccountId:string, UserIdentityAccountId:string, UserIdentityType:string, UserIdentityArn:string,
UserIdentityAccessKeyId:string, SourceIpAddress:string, UserAgent:string,
ErrorCode:string, ErrorMessage:string, RequestParameters:string, ResponseElements:string, Resources:string,
ManagementEvent:bool, ReadOnly:bool, SessionMfaAuthenticated:string)[]),
(AWSCloudTrail
| where TimeGenerated between (Start .. End)
| project TimeGenerated, AwsEventId, EventSource, EventName, AWSRegion, RecipientAccountId,
UserIdentityAccountId, UserIdentityType, UserIdentityArn,
UserIdentityAccessKeyId, SourceIpAddress, UserAgent, ErrorCode, ErrorMessage,
RequestParameters, ResponseElements, Resources, ManagementEvent, ReadOnly, SessionMfaAuthenticated);
let IdentityMap = union isfuzzy=true
(datatable(SearchKey:string)[]),
(_GetWatchlist('AWS_EntraIdentityMap'))
| where isnotempty(tostring(column_ifexists("SearchKey", "")))
| extend VerifiedVal = tolower(tostring(column_ifexists("Verified", ""))),
MappingEvidenceVal = tostring(column_ifexists("MappingEvidence", ""))
| where VerifiedVal == "true" and isnotempty(MappingEvidenceVal)
| project AwsAccessKeyId=tostring(column_ifexists("AwsAccessKeyId", "")),
AwsPrincipalArn=tostring(column_ifexists("AwsPrincipalArn", "")),
AWSAccountId=tostring(column_ifexists("AWSAccountId", "")),
EntraTenantId=tolower(tostring(column_ifexists("EntraTenantId", ""))),
EntraObjectId=tolower(tostring(column_ifexists("EntraObjectId", ""))),
IdentityType=tostring(column_ifexists("IdentityType", "")),
AppClientId=tolower(tostring(column_ifexists("AppClientId", ""))),
ValidFrom=todatetime(column_ifexists("ValidFromUtc", "")),
ValidTo=todatetime(column_ifexists("ValidToUtc", ""))
| summarize MappingRows=count(), take_any(*) by AwsAccessKeyId, AwsPrincipalArn, AWSAccountId
| where MappingRows == 1 and isnotempty(EntraTenantId) and isnotempty(EntraObjectId);
let ScopedUsers = IdentityMap | where IdentityType == "User" and (isempty(TargetXdrTenant) or EntraTenantId == TargetXdrTenant);
let ImpactedUsers = union isfuzzy=true
(datatable(AlertTime:datetime, AlertId:string, AccountObjectId:string, EvidenceRole:string)[]),
(AlertEvidence
| where Timestamp between (Start .. End)
| where EntityType == "User" and EvidenceRole == "Impacted" and isnotempty(AccountObjectId)
| project AlertTime=Timestamp, AlertId, AccountObjectId=tolower(AccountObjectId), EvidenceRole)
| summarize XdrAlertCount=count_distinct(AlertId), XdrAlertIds=make_set(AlertId, 10), FirstXdrAlert=min(AlertTime)
by EntraObjectId=AccountObjectId;
let S3Bulk = SafeCloudTrail
| where EventSource == "s3.amazonaws.com" and EventName == "GetObject" and ManagementEvent == false
| where isempty(ErrorCode) and isempty(ErrorMessage)
| where UseAllAccounts or UserIdentityAccountId == AccountFilter or RecipientAccountId == AccountFilter
| extend Req = parse_json(RequestParameters)
| extend Bucket = tostring(Req.bucketName), ObjectKey = tostring(Req.key)
| where isnotempty(Bucket) and isnotempty(ObjectKey)
| summarize TotalGetObjects=count(), DistinctObjects=count_distinct(strcat(Bucket, "/", ObjectKey)),
Buckets=make_set(Bucket, 20), SourceIps=make_set(SourceIpAddress, 10)
by Window15m=bin(TimeGenerated, 15m), AWSAccountId=UserIdentityAccountId,
RecipientAccountId, AwsAccessKeyId=UserIdentityAccessKeyId, AwsPrincipalArn=UserIdentityArn
| where DistinctObjects >= 50;
S3Bulk
| join kind=inner ScopedUsers on AWSAccountId, AwsAccessKeyId, AwsPrincipalArn
| where Window15m between (ValidFrom .. ValidTo)
| join kind=inner ImpactedUsers on EntraObjectId
| project Window15m, AWSAccountId, RecipientAccountId, AwsPrincipalArn, AwsAccessKeyId,
DistinctObjects, TotalGetObjects, Buckets, SourceIps, EntraTenantId, EntraObjectId,
XdrAlertCount, FirstXdrAlert, XdrAlertIds
| order by DistinctObjects desc
| take 5000Explanation
This query is designed to identify and analyze users who have performed a significant number of authenticated S3 object reads within a short time frame, specifically 50 or more objects within 15 minutes. Here's a simplified breakdown of what the query does:
-
Time and Account Filters: It sets a time range and filters for specific AWS accounts based on input parameters.
-
Data Collection:
- CloudTrail Data: It gathers AWS CloudTrail logs for S3 "GetObject" events, filtering out management events and errors, and focusing on events within the specified time range and account filters.
- Identity Mapping: It retrieves a mapping of AWS access keys to Entra (Azure AD) identities, ensuring the mappings are verified and valid.
- Impacted Users: It collects information on users flagged as "Impacted" in security alerts within the specified time range.
-
Analysis:
- S3 Bulk Reads: It identifies instances where a user has read 50 or more distinct S3 objects within a 15-minute window, summarizing the data by account and user identity.
- User Scope: It filters the users to those mapped to a specific Entra tenant (if specified) and identified as "User" type.
-
Joining Data:
- It combines the S3 bulk read data with the scoped users and impacted users data to find overlaps, ensuring the events occurred within the valid time range for the identity mappings.
-
Output:
- The query outputs a list of these events, including details such as the number of distinct objects accessed, the AWS account and user details, the associated Entra tenant and object IDs, and any related security alerts. The results are ordered by the number of distinct objects accessed and limited to 5000 entries.
In essence, this query helps security analysts identify potentially suspicious activity involving large-scale S3 data access by authenticated users, correlating it with known impacted users and identity mappings.