Query Details

D09 Aws Ueba Behaviors And Anomalies Check

Query

// REVIEW ONLY - Do not run against production without approval.
// Discovery D09: Validates Microsoft Sentinel UEBA (BehaviorAnalytics), ML/UEBA Anomalies (Anomalies),
// and the UEBA Behaviors Layer (SentinelBehaviorInfo / SentinelBehaviorEntities) for AWS CloudTrail & AWS GuardDuty.
let Lookback = 7d;
let ExpectedLayers = datatable(LayerTable:string, Capability:string)[
    "BehaviorAnalytics", "Classic UEBA Enrichment (AWS CloudTrail ConsoleLogin & AWS GuardDuty)",
    "Anomalies", "UEBA & 21-Day ML Anomaly Rules (AWS CloudTrail & AWS GuardDuty)",
    "SentinelBehaviorInfo", "UEBA Behaviors Layer (184 AWS CloudTrail Aggregated/Sequenced Behaviors + Network Layer)",
    "SentinelBehaviorEntities", "UEBA Behaviors Layer Entities (CloudPlatform == Amazon Web Services)"
];
let Observed = union isfuzzy=true
    (datatable(LayerTable:string, TimeGenerated:datetime, Detail:string)[]),
    (BehaviorAnalytics
     | where TimeGenerated > ago(Lookback)
     | where NativeTableName in ("AWSCloudTrail", "AWSGuardDuty") or EventSource has_any ("AWS", "CloudTrail", "GuardDuty") or EventVendor has_any ("AWS", "Amazon")
     | project LayerTable="BehaviorAnalytics", TimeGenerated, Detail=coalesce(NativeTableName, EventSource)),
    (Anomalies
     | where TimeGenerated > ago(Lookback)
     | where AnomalyTemplateName has_any ("AwsCloudTrail", "AWS", "GuardDuty") or RuleName has_any ("AwsCloudTrail", "AWS", "GuardDuty")
     | project LayerTable="Anomalies", TimeGenerated, Detail=coalesce(AnomalyTemplateName, RuleName)),
    (SentinelBehaviorInfo
     | where TimeGenerated > ago(Lookback)
     | where DataSources has_any ("AWS", "CloudTrail", "Amazon") or AdditionalFields has "AWSCloudTrail"
     | project LayerTable="SentinelBehaviorInfo", TimeGenerated, Detail=ActionType),
    (SentinelBehaviorEntities
     | where TimeGenerated > ago(Lookback)
     | where CloudPlatform =~ "Amazon Web Services" or DataSources has_any ("AWS", "CloudTrail")
     | project LayerTable="SentinelBehaviorEntities", TimeGenerated, Detail=coalesce(CloudResourceType, EntityType))
| summarize AwsRecords=count(), DistinctSignals=dcount(Detail), LastSeenUtc=max(TimeGenerated), SampleSignals=make_set(Detail, 10)
    by LayerTable;
ExpectedLayers
| join kind=leftouter Observed on LayerTable
| extend Status = iff(coalesce(AwsRecords, 0) > 0, "ACTIVE_AWS_DATA_OBSERVED", "NO_AWS_ROWS_OR_FEATURE_NOT_ENABLED")
| project LayerTable, Capability, Status, AwsRecords=coalesce(AwsRecords, 0), DistinctSignals=coalesce(DistinctSignals, 0), LastSeenUtc, SampleSignals
| order by LayerTable asc
| take 20

Explanation

This query is designed to validate and monitor the activity of Microsoft Sentinel's User and Entity Behavior Analytics (UEBA) features, specifically focusing on AWS CloudTrail and AWS GuardDuty data. Here's a simplified breakdown of what the query does:

  1. Lookback Period: It examines data from the past 7 days.

  2. Expected Layers: It defines a set of expected data layers and capabilities related to UEBA, including:

    • BehaviorAnalytics
    • Anomalies
    • SentinelBehaviorInfo
    • SentinelBehaviorEntities
  3. Data Collection: It gathers data from various sources (BehaviorAnalytics, Anomalies, SentinelBehaviorInfo, SentinelBehaviorEntities) related to AWS CloudTrail and AWS GuardDuty, filtering for relevant events and anomalies.

  4. Data Aggregation: It summarizes the collected data by counting the number of AWS records, distinct signals, and capturing the last seen timestamp and a sample of signals for each layer.

  5. Comparison and Status: It compares the observed data against the expected layers to determine if AWS data is actively being observed or if no data is present (indicating the feature might not be enabled).

  6. Output: The query outputs a table showing each layer, its capability, status (active or not), the number of AWS records, distinct signals, last seen time, and sample signals, ordered by layer name.

This query is meant for review purposes only and should not be run against a production environment without proper approval.