Query Details

P0 08 Aws Telemetry Blindspot And Health

Query

// Standalone KQL for Analytic Rule: AWS SecOps P0-08 - AWS Connector Failure, Ingestion Lag and Per-Source Blind Spot
// Rule File: analytics/P0-08-aws-telemetry-blindspot-and-health.yaml | Rule ID: REPLACE_WITH_RULE_GUID | Severity: High
// Schedule: 1h / Lookback: 7d | REVIEW ONLY - Do not deploy/schedule without approval.
// REVIEW ONLY. Validate enabled AWS tables via discovery/D01 first and populate AWS_SourceSlaConfig
// ONLY for sources expected in this workspace.
let SlaConfig = _GetWatchlist('AWS_SourceSlaConfig')
| where tolower(tostring(column_ifexists("Enabled", ""))) == "true"
| project SourceTable=tostring(column_ifexists("SourceTable", "")), ConnectorPattern=tolower(tostring(column_ifexists("ConnectorNamePattern", ""))),
    ExpectedAccountId=tostring(column_ifexists("AWSAccountId", "")), ExpectedFreshnessMin=todouble(column_ifexists("ExpectedFreshnessMinutes", "")),
    ZeroVolumeMin=todouble(column_ifexists("ZeroVolumeAlertMinutes", "")), DropPctThreshold=todouble(column_ifexists("VolumeDropPctThreshold", ""));
let SourceStats = union
    (AWSCloudTrail | where TimeGenerated > ago(7d) | project SourceTable="AWSCloudTrail", TimeGenerated, Ingest=ingestion_time(), AWSAccountId=RecipientAccountId),
    (AWSGuardDuty | where TimeGenerated > ago(7d) | project SourceTable="AWSGuardDuty", TimeGenerated, Ingest=ingestion_time(), AWSAccountId=AccountId),
    (AWSVPCFlow | where TimeGenerated > ago(7d) | project SourceTable="AWSVPCFlow", TimeGenerated, Ingest=ingestion_time(), AWSAccountId=AccountId),
    (AWSRoute53Resolver | where TimeGenerated > ago(7d) | project SourceTable="AWSRoute53Resolver", TimeGenerated, Ingest=ingestion_time(), AWSAccountId=AccountId),
    (AWSWAF | where TimeGenerated > ago(7d) | project SourceTable="AWSWAF", TimeGenerated, Ingest=ingestion_time(), AWSAccountId="*"),
    (AWSNetworkFirewallAlert | where TimeGenerated > ago(7d) | project SourceTable="AWSNetworkFirewallAlert", TimeGenerated, Ingest=ingestion_time(), AWSAccountId="*")
| summarize
    LastEventUtc = max(TimeGenerated),
    LastIngestUtc = max(Ingest),
    Last24hEvents = countif(TimeGenerated > ago(24h)),
    BaselineDailyAvg = todouble(countif(TimeGenerated between (ago(7d) .. ago(1d)))) / 6.0,
    P95LagMin = round(percentile(datetime_diff('second', Ingest, TimeGenerated), 95) / 60.0, 1)
    by SourceTable, AWSAccountId;
let HealthIssues = SentinelHealth
| where TimeGenerated > ago(2h) and SentinelResourceType == "DataConnector"
| where Status in ("Failure", "Warning", "Partial Success")
| where SentinelResourceKind has_any ("AmazonWebServices", "AWS") or SentinelResourceName has_any ("AWS", "Amazon")
| summarize HealthErrorCount=count(), LatestHealthStatus=take_any(Status), HealthReasons=make_set(Reason, 10)
    by ConnectorLower=tolower(SentinelResourceName), SentinelResourceId;
SlaConfig
| join kind=leftouter SourceStats on SourceTable
| where ExpectedAccountId == "*" or isempty(AWSAccountId) or AWSAccountId == ExpectedAccountId
| extend FreshnessMin = iff(isnull(LastEventUtc), 999999.0, round(datetime_diff('second', now(), LastEventUtc) / 60.0, 1)),
    VolumeDropPct = iff(coalesce(BaselineDailyAvg, 0.0) >= 100.0, round(100.0 * (BaselineDailyAvg - todouble(coalesce(Last24hEvents, 0))) / BaselineDailyAvg, 1), 0.0)
| join kind=leftouter HealthIssues on $left.ConnectorPattern == $right.ConnectorLower
| extend BlindSpotClassification = case(
    coalesce(HealthErrorCount, 0) > 0 and FreshnessMin > ExpectedFreshnessMin, "SentinelConnectorFailureWithDataGap",
    coalesce(HealthErrorCount, 0) > 0, "SentinelConnectorDegradedWarning",
    FreshnessMin > ZeroVolumeMin, "ZeroVolumeOrDisconnectedBlindSpot",
    P95LagMin > ExpectedFreshnessMin and FreshnessMin > ExpectedFreshnessMin, "UpstreamAWSDeliveryDelay",
    VolumeDropPct >= coalesce(DropPctThreshold, 75.0), "SharpVolumeDropOrSchemaDrift",
    "")
| where isnotempty(BlindSpotClassification)
| extend TimeGenerated = now(),
    EffectiveAccount = coalesce(AWSAccountId, ExpectedAccountId),
    FreshnessMinStr = tostring(FreshnessMin),
    P95LagMinStr = tostring(coalesce(P95LagMin, 0.0)),
    VolumeDropPctStr = tostring(VolumeDropPct),
    HealthReasonsStr = tostring(coalesce(HealthReasons, dynamic([])))
| project TimeGenerated, SourceTable, AWSAccountId=EffectiveAccount, BlindSpotClassification,
    FreshnessMinStr, P95LagMinStr, VolumeDropPctStr, LastEventUtc, LastIngestUtc,
    ConnectorName=ConnectorPattern, SentinelResourceId=coalesce(SentinelResourceId, ""), HealthReasonsStr

Explanation

This KQL query is designed to identify and classify potential issues with AWS data ingestion and telemetry in a security operations context. Here's a simplified breakdown of what the query does:

  1. Configuration Setup:

    • It retrieves a list of AWS source configurations from a watchlist named AWS_SourceSlaConfig. This list includes details like the source table, expected AWS account ID, and thresholds for data freshness and volume drops.
  2. Data Collection:

    • It gathers data from various AWS services (like AWS CloudTrail, AWS GuardDuty, etc.) over the past 7 days. For each service, it calculates statistics such as the time of the last event, the time of the last data ingestion, the number of events in the last 24 hours, and the average daily event count over the past 6 days.
  3. Health Check:

    • It checks for any recent health issues related to AWS data connectors in the SentinelHealth table, focusing on failures, warnings, or partial successes.
  4. Data Analysis and Classification:

    • It joins the configuration data with the collected statistics and health check results.
    • It calculates metrics like data freshness (how recent the last event is), volume drop percentage, and data ingestion lag.
    • Based on these metrics and health check results, it classifies potential issues into categories such as:
      • "SentinelConnectorFailureWithDataGap": Connector failure with a data gap.
      • "SentinelConnectorDegradedWarning": Connector is degraded.
      • "ZeroVolumeOrDisconnectedBlindSpot": No data or disconnected source.
      • "UpstreamAWSDeliveryDelay": Delay in data delivery from AWS.
      • "SharpVolumeDropOrSchemaDrift": Significant drop in data volume or schema changes.
  5. Output:

    • It outputs a list of potential issues with details like the source table, AWS account ID, classification of the issue, and relevant metrics (e.g., freshness, lag, volume drop).

This query is intended for review and validation purposes only and should not be deployed without approval. It helps identify blind spots and health issues in AWS data ingestion, which are critical for maintaining effective security monitoring.