Query Details

H08 Xdr Identity To Authenticated S3 Reads

Query

// REVIEW ONLY. Requires S3 OBJECT DATA events, not just management events or Security Hub findings.
// Exact threshold: >=50 DISTINCT bucket/key objects in a fixed 15-minute window.
// The impacted user had a high-severity XDR alert in the preceding day; not proof of compromise or exfiltration.
let Start = ago(4h);
let End = now();
let SeedAWSAccountId = "REPLACE_WITH_12_DIGIT_ACCOUNT";
let XdrEntraTenantId = "REPLACE_WITH_XDR_ENTRA_TENANT_GUID";
let InputsValid = assert(SeedAWSAccountId matches regex @"^[0-9]{12}$"
    and isnotnull(toguid(XdrEntraTenantId)), "Set AWS identity account and XDR Entra tenant.");
let IdentityMap = _GetWatchlist('AWS_EntraIdentityMap')
| where tolower(tostring(column_ifexists("Verified", ""))) == "true" and isnotempty(tostring(column_ifexists("MappingEvidence", "")))
| 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", "")),
    ValidFrom=todatetime(column_ifexists("ValidFromUtc", "")), ValidTo=todatetime(column_ifexists("ValidToUtc", ""))
| summarize MappingRows=count(), take_any(*) by AwsAccessKeyId, AwsPrincipalArn, AWSAccountId
| where MappingRows == 1 and IdentityType == "User" and EntraTenantId == tolower(XdrEntraTenantId)
    and isnotempty(EntraObjectId);
let BulkReads = AWSCloudTrail
| where InputsValid and TimeGenerated between (Start .. End) and UserIdentityAccountId == SeedAWSAccountId
| where EventSource == "s3.amazonaws.com" and EventName == "GetObject"
| where isempty(ErrorCode) and isempty(ErrorMessage) and isnotempty(AwsEventId)
| extend Request=parse_json(RequestParameters)
| project AwsTime=TimeGenerated, AwsEventId, AwsAccessKeyId=UserIdentityAccessKeyId,
    AwsPrincipalArn=UserIdentityArn, AWSAccountId=UserIdentityAccountId, SourceIpAddress,
    Bucket=tostring(Request.bucketName), ObjectKey=tostring(Request.key)
| where isnotempty(AwsAccessKeyId) and isnotempty(AwsPrincipalArn) and isnotempty(Bucket) and isnotempty(ObjectKey)
| join kind=inner IdentityMap on AwsAccessKeyId, AwsPrincipalArn, AWSAccountId
| where AwsTime between (ValidFrom .. ValidTo)
| summarize FirstAws=min(AwsTime), LastAws=max(AwsTime),
    DistinctObjects=count_distinct(strcat(Bucket, "/", ObjectKey)), DistinctEvents=count_distinct(AwsEventId),
    Buckets=make_set(Bucket, 20), Sources=make_set(SourceIpAddress, 20), ExampleEvents=make_set(AwsEventId, 20)
    by Window=bin(AwsTime, 15m), AWSAccountId, AwsAccessKeyId, AwsPrincipalArn, EntraTenantId, EntraObjectId
| where DistinctObjects >= 50;
let ImpactedUsers = AlertEvidence
| where Timestamp between ((Start - 1d) .. End)
| where EntityType == "User" and EvidenceRole == "Impacted" and isnotempty(AccountObjectId)
| project AlertId, EntraObjectId=tolower(AccountObjectId)
| distinct AlertId, EntraObjectId;
BulkReads
| join kind=inner ImpactedUsers on EntraObjectId
| join kind=inner (
    AlertInfo
    | where Timestamp between ((Start - 1d) .. End)
    | summarize arg_max(Timestamp, *) by AlertId
    | where Severity =~ "High"
    | project AlertId, AlertTime=Timestamp, Title, ServiceSource
) on AlertId
| where FirstAws between (AlertTime .. (AlertTime + 1d))
| extend DefenderAlertUrl=strcat("https://security.microsoft.com/alerts/", AlertId),
    CorrelationBasis="Verified user/session + impacted-user XDR evidence + authenticated object reads",
    NextStep="Inspect objects and business purpose; CloudTrail GetObject alone does not establish data transfer volume"
| project FirstAws, LastAws, Window, AWSAccountId, AwsAccessKeyId, AwsPrincipalArn,
    EntraTenantId, EntraObjectId, DistinctObjects, DistinctEvents, Buckets, Sources,
    ExampleEvents, AlertId, AlertTime, Title, ServiceSource, DefenderAlertUrl, CorrelationBasis, NextStep
| order by LastAws desc
| take 2000

Explanation

This query is designed to identify potential suspicious activity in AWS S3 by analyzing object access patterns and correlating them with security alerts. Here's a simplified breakdown of what the query does:

  1. Setup and Validation:

    • It defines a time window from 4 hours ago to now.
    • It checks if the AWS account ID and XDR Entra tenant ID are valid.
  2. Identity Mapping:

    • It retrieves a list of verified AWS identities mapped to Entra identities from a watchlist.
    • It filters for user identities that are valid within the specified time window.
  3. Detecting Bulk Reads:

    • It searches AWS CloudTrail logs for "GetObject" events from S3 within the specified time window.
    • It filters out events with errors and ensures necessary fields are not empty.
    • It joins these events with the identity map to ensure they are from verified users.
    • It summarizes the data to find instances where 50 or more distinct objects were accessed within any 15-minute window.
  4. Correlating with Security Alerts:

    • It identifies users who had high-severity XDR alerts in the past day.
    • It correlates the bulk read events with these impacted users and their alerts.
    • It checks if the bulk read events occurred within a day of the alert.
  5. Output:

    • It provides details of the suspicious activity, including the time of access, AWS account details, number of distinct objects accessed, and related security alerts.
    • It suggests further investigation steps, as the detected activity alone does not confirm data exfiltration.

The query is designed to help security analysts identify and investigate potential unauthorized access to S3 objects, especially when correlated with recent security alerts.