Query Details

34 Coverage Operations Analyst Crosscloud Entra Xdr Pivot

Query

// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: CoverageOperations | Panel: analyst-crosscloud-entra-xdr-pivot | Visualization: table | Mode: Analyst
// Security Question: When investigating an AWS principal or IP, what correlated Entra sign-ins, service-principal activity, audit changes, or Defender XDR alerts exist?
// Drill-Through: Click any principal or IP row in Tabs 1, 3, 4, 5, 6, 7, 8, or 9 to populate SelectedPrincipal / SelectedIp.
// Empty/No-Data Contract: Click a principal or IP row in an upstream tab (or populate AWS_EntraIdentityMap) to view correlated Entra & Defender XDR events.
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 MappedIds = union isfuzzy=true
    (datatable(SearchKey:string)[]),
    (_GetWatchlist('AWS_EntraIdentityMap'))
| where isnotempty(tostring(column_ifexists("SearchKey", "")))
| where tolower(tostring(column_ifexists("Verified", ""))) == "true"
| extend AwsArn=tostring(column_ifexists("AwsPrincipalArn", "")),
    AwsKey=tostring(column_ifexists("AwsAccessKeyId", "")),
    Upn=tostring(column_ifexists("EntraUPN", "")),
    ObjId=tolower(tostring(column_ifexists("EntraObjectId", "")))
| where isnotempty(ObjId) and (SelectedPrincipalFilter == "*" or AwsArn has SelectedPrincipalFilter or AwsKey == SelectedPrincipalFilter or Upn has SelectedPrincipalFilter)
| project EntraObjectId=ObjId;
let HasMapped = toscalar(MappedIds | summarize count() > 0);
union isfuzzy=true
    (datatable(TimeGenerated:datetime, Workload:string, Actor:string, ObjectId:string, Action:string, Result:string, Ip:string)[]),
    (SigninLogs | where TimeGenerated between (Start .. End)
        | where (SelectedIpFilter != "*" and IPAddress == SelectedIpFilter)
            or (SelectedPrincipalFilter != "*" and (tolower(UserId) in (MappedIds) or UserPrincipalName has SelectedPrincipalFilter))
            or (SelectedIpFilter == "*" and SelectedPrincipalFilter == "*" and HasMapped and tolower(UserId) in (MappedIds))
        | project TimeGenerated, Workload="Entra:SigninLogs", Actor=UserPrincipalName, ObjectId=UserId, Action=AppDisplayName, Result=ResultType, Ip=IPAddress),
    (AADServicePrincipalSignInLogs | where TimeGenerated between (Start .. End)
        | where (SelectedIpFilter != "*" and IPAddress == SelectedIpFilter)
            or (SelectedPrincipalFilter != "*" and (tolower(ServicePrincipalId) in (MappedIds) or ServicePrincipalName has SelectedPrincipalFilter))
            or (SelectedIpFilter == "*" and SelectedPrincipalFilter == "*" and HasMapped and tolower(ServicePrincipalId) in (MappedIds))
        | project TimeGenerated, Workload="Entra:ServicePrincipalSignIn", Actor=ServicePrincipalName, ObjectId=ServicePrincipalId, Action=ResourceDisplayName, Result=ResultType, Ip=IPAddress),
    (AuditLogs | where TimeGenerated between (Start .. End)
        | extend InitUser = tostring(parse_json(tostring(InitiatedBy.user)).userPrincipalName),
            InitUserId = tolower(tostring(parse_json(tostring(InitiatedBy.user)).id)),
            InitSpId = tolower(tostring(parse_json(tostring(InitiatedBy.app)).servicePrincipalId)),
            InitIp = coalesce(iff(isnotempty(tostring(parse_json(tostring(InitiatedBy.user)).ipAddress)), tostring(parse_json(tostring(InitiatedBy.user)).ipAddress), ""), tostring(parse_json(tostring(InitiatedBy.app)).ipAddress))
        | where (SelectedIpFilter != "*" and InitIp == SelectedIpFilter)
            or (SelectedPrincipalFilter != "*" and (InitUserId in (MappedIds) or InitSpId in (MappedIds) or InitUser has SelectedPrincipalFilter))
            or (SelectedIpFilter == "*" and SelectedPrincipalFilter == "*" and HasMapped and (InitUserId in (MappedIds) or InitSpId in (MappedIds)))
        | project TimeGenerated, Workload="Entra:AuditLogs", Actor=coalesce(iff(isnotempty(InitUser), InitUser, ""), InitSpId), ObjectId=coalesce(iff(isnotempty(InitUserId), InitUserId, ""), InitSpId), Action=OperationName, Result, Ip=InitIp),
    (AlertEvidence | where Timestamp between (Start .. End)
        | where (SelectedIpFilter != "*" and RemoteIP == SelectedIpFilter)
            or (SelectedPrincipalFilter != "*" and (tolower(AccountObjectId) in (MappedIds) or AccountUpn has SelectedPrincipalFilter))
            or (SelectedIpFilter == "*" and SelectedPrincipalFilter == "*" and HasMapped and tolower(AccountObjectId) in (MappedIds))
        | project TimeGenerated=Timestamp, Workload=strcat("DefenderXDR:", ServiceSource), Actor=coalesce(iff(isnotempty(AccountUpn), AccountUpn, ""), DeviceName), ObjectId=coalesce(iff(isnotempty(AccountObjectId), AccountObjectId, ""), DeviceId), Action=Title, Result=Severity, Ip=RemoteIP)
| where isnotempty(Workload)
| order by TimeGenerated desc
| take 5000

Explanation

This query is designed to help security analysts investigate activities related to an AWS principal or IP address by finding correlated events in Entra sign-ins, service principal activities, audit changes, and Defender XDR alerts. Here's a simplified breakdown of what the query does:

  1. Time and Filters Setup: The query begins by setting up time filters (Start and End) and various other filters (like organization, account, region, environment, workload, severity, source, and selected principal/IP) using base64-decoded values.

  2. Mapping Identities: It creates a list of mapped identities by combining a watchlist (AWS_EntraIdentityMap) with any existing data, ensuring that only verified entries are considered. This list is used to identify AWS principals that have corresponding Entra identities.

  3. Data Collection: The query collects data from several sources:

    • SigninLogs: Logs of sign-ins to Entra services.
    • AADServicePrincipalSignInLogs: Logs of service principal sign-ins.
    • AuditLogs: Logs of audit events, including user and service principal actions.
    • AlertEvidence: Logs of alerts from Defender XDR.
  4. Filtering and Projection: For each data source, it filters events based on the selected principal or IP address. It checks if the principal or IP matches the selected filters or if there are any mapped identities. It then projects relevant fields like time, workload, actor, object ID, action, result, and IP.

  5. Result Compilation: The query compiles all the filtered and projected data, orders it by the time the events were generated (most recent first), and limits the results to 5000 entries.

  6. Output: The final output is a table visualization that provides a comprehensive view of correlated security events related to the specified AWS principal or IP, helping analysts in their investigation.

Overall, this query is a tool for cross-cloud security operations, allowing analysts to quickly find and analyze related security events across AWS and Entra environments.