Query Details

29 Ueba Layer Readiness

Query

// REVIEW ONLY workbook query: 9.1 AWS UEBA, Behaviors Layer & Anomalies Onboarding Status
let Start = {TimeRange:start};
let End = {TimeRange:end};
let ExpectedLayers = datatable(Order:int, LayerName:string, BackingTables:string, PortalSetting:string)[
    1, "Classic UEBA — AWS CloudTrail", "BehaviorAnalytics", "Sentinel -> UEBA -> Connect data sources -> AWS Cloud Trail",
    2, "Classic UEBA — AWS GuardDuty", "BehaviorAnalytics", "Sentinel -> UEBA -> Connect data sources -> AWS Guard Duty",
    3, "UEBA & ML Anomalies — AWS CloudTrail & GuardDuty", "Anomalies", "Sentinel -> Analytics -> Anomaly rules (Production / Flighting)",
    4, "New! UEBA Behaviors Layer — AWS CloudTrail (184 Behaviors)", "SentinelBehaviorInfo / BehaviorInfo", "Sentinel -> UEBA -> New! Behaviors layer -> Enable + AWS Cloud Trail",
    5, "New! UEBA Behaviors Entities — Amazon Web Services", "SentinelBehaviorEntities / BehaviorEntities", "Populated automatically when UEBA Behaviors layer processes AWSCloudTrail"
];
let Observed = union isfuzzy=true
    (datatable(LayerName:string, TimeGenerated:datetime, Signal:string)[]),
    (BehaviorAnalytics | where TimeGenerated between (Start .. End)
     | where NativeTableName == "AWSCloudTrail" or EventSource has "CloudTrail" or (EventVendor has_any ("AWS", "Amazon") and ActivityType has_any ("LogOn", "SignIn", "ConsoleLogin"))
     | project LayerName="Classic UEBA — AWS CloudTrail", TimeGenerated, Signal=coalesce(ActivityType, ActionType)),
    (BehaviorAnalytics | where TimeGenerated between (Start .. End)
     | where NativeTableName == "AWSGuardDuty" or EventSource has "GuardDuty"
     | project LayerName="Classic UEBA — AWS GuardDuty", TimeGenerated, Signal=coalesce(ActivityType, ActionType)),
    (Anomalies | where TimeGenerated between (Start .. End)
     | where AnomalyTemplateName has_any ("AwsCloudTrail", "AWS", "GuardDuty") or RuleName has_any ("AwsCloudTrail", "AWS", "GuardDuty")
     | project LayerName="UEBA & ML Anomalies — AWS CloudTrail & GuardDuty", TimeGenerated, Signal=coalesce(AnomalyTemplateName, RuleName)),
    (SentinelBehaviorInfo | where TimeGenerated between (Start .. End)
     | where DataSources has_any ("AWS", "CloudTrail", "Amazon") or AdditionalFields has "AWSCloudTrail"
     | project LayerName="New! UEBA Behaviors Layer — AWS CloudTrail (184 Behaviors)", TimeGenerated, Signal=ActionType),
    (BehaviorInfo | where TimeGenerated between (Start .. End)
     | where ServiceSource == "Microsoft Sentinel" and (DataSources has_any ("AWS", "CloudTrail", "Amazon") or AdditionalFields has "AWSCloudTrail")
     | project LayerName="New! UEBA Behaviors Layer — AWS CloudTrail (184 Behaviors)", TimeGenerated, Signal=ActionType),
    (SentinelBehaviorEntities | where TimeGenerated between (Start .. End)
     | where CloudPlatform =~ "Amazon Web Services" or DataSources has_any ("AWS", "CloudTrail")
     | project LayerName="New! UEBA Behaviors Entities — Amazon Web Services", TimeGenerated, Signal=coalesce(CloudResourceType, EntityType))
| summarize AwsRows=count(), DistinctPatterns=dcount(Signal), LastEventUtc=max(TimeGenerated), SamplePatterns=make_set(Signal, 8)
    by LayerName;
ExpectedLayers
| join kind=leftouter Observed on LayerName
| extend LayerStatus = iff(coalesce(AwsRows, 0) > 0, "🟢 ACTIVE: AWS behavioral records observed", "🟡 NO_ROWS_IN_WINDOW: Enable toggle in UEBA settings or widen TimeRange"),
    FreshnessMin = iff(isnull(LastEventUtc), -1.0, round(datetime_diff('second', now(), LastEventUtc) / 60.0, 1))
| order by Order asc
| project LayerName, LayerStatus, AwsRows=coalesce(AwsRows, long(0)), DistinctPatterns=coalesce(DistinctPatterns, long(0)),
    LastEventUtc, FreshnessMin, BackingTables, PortalSetting, SamplePatterns
| take 50

Explanation

This KQL query is designed to monitor and report on the status of various AWS User and Entity Behavior Analytics (UEBA) layers and anomalies within a specified time range. Here's a simplified breakdown of what the query does:

  1. Define Time Range: The query starts by setting a time range (Start and End) for the data analysis.

  2. Expected Layers: It defines a list of expected UEBA layers and their details, such as order, name, backing tables, and portal settings.

  3. Observed Data: The query then collects observed data from different sources (like BehaviorAnalytics, Anomalies, SentinelBehaviorInfo, etc.) within the specified time range. It checks for specific AWS-related activities and anomalies, categorizing them into predefined layers.

  4. Summarize Observations: For each layer, it summarizes the number of AWS records (AwsRows), distinct patterns (DistinctPatterns), the time of the last event (LastEventUtc), and a sample of patterns observed.

  5. Join and Extend: The query joins the expected layers with the observed data to determine the status of each layer:

    • Active: If there are AWS records observed.
    • No Rows in Window: If no records are observed, suggesting to enable settings or adjust the time range.
  6. Calculate Freshness: It calculates how fresh the data is by determining the time difference between now and the last observed event.

  7. Order and Project: Finally, it orders the results by the predefined order and selects specific columns to display, such as layer name, status, number of rows, distinct patterns, last event time, freshness, backing tables, portal settings, and sample patterns.

  8. Limit Results: The query limits the output to the first 50 results.

In essence, this query helps in understanding the onboarding status and activity of AWS-related UEBA layers in Microsoft Sentinel, providing insights into whether these layers are actively receiving data or need configuration adjustments.