Query Details

S02 Route53 Dns 5m Summary

Query

// REVIEW ONLY - Summary Rule KQL Spec: S02 -> Target Table: AWS_Route53_5m_CL
// Schedule: Every 5m over AWSRoute53Resolver. Pre-computes parent domain, subdomain label length,
// NXDOMAIN counts, and distinct subdomain fan-out to keep DNS visuals and baselines fast and cheap.
AWSRoute53Resolver
| where TimeGenerated > ago(15m)
| extend CleanQname = trim_end(@"\.", tolower(QueryName))
| where isnotempty(CleanQname)
| extend Labels = split(CleanQname, ".")
| extend LabelCount = array_length(Labels)
| extend ParentDomain = iff(LabelCount >= 2, strcat(tostring(Labels[LabelCount - 2]), ".", tostring(Labels[LabelCount - 1])), CleanQname),
    LeftmostLabel = tostring(Labels[0]),
    InstanceId = tostring(SrcIds.instance)
| extend LeftmostLen = strlen(LeftmostLabel),
    DigitHexChars = countof(LeftmostLabel, @"[0-9a-f\-]", "regex")
| summarize
    TotalQueries = count(),
    NxDomainCount = countif(Rcode =~ "NXDOMAIN"),
    ServFailCount = countif(Rcode =~ "SERVFAIL"),
    FirewallBlocks = countif(FirewallRuleAction =~ "BLOCK"),
    DistinctSubdomains = dcount(CleanQname),
    MaxLabelLength = max(LeftmostLen),
    AvgLabelLength = round(avg(todouble(LeftmostLen)), 1),
    LongLabelQueries = countif(LeftmostLen >= 32),
    TxtOrNullQueries = countif(QueryType in~ ("TXT", "NULL", "CNAME", "MX")),
    QueryTypes = make_set(QueryType, 10)
    by WindowStart=bin(TimeGenerated, 5m), AccountId, Region, VpcId, SrcAddr, InstanceId, ParentDomain
| take 10000

Explanation

This query is designed to analyze DNS query data from AWS Route 53 Resolver logs. It runs every 5 minutes and processes data from the last 15 minutes. Here's a simplified breakdown of what it does:

  1. Data Preparation:

    • It cleans and normalizes the domain names in the queries by converting them to lowercase and removing trailing dots.
    • It splits the domain names into their individual labels (parts separated by dots).
  2. Domain Analysis:

    • It calculates the number of labels in each domain name.
    • It identifies the parent domain (the last two labels) and the leftmost label (the first part of the domain).
    • It measures the length of the leftmost label and counts any hexadecimal or digit characters in it.
  3. Summarization:

    • It counts the total number of queries.
    • It counts how many queries resulted in NXDOMAIN (non-existent domain) and SERVFAIL (server failure) responses.
    • It counts how many queries were blocked by a firewall.
    • It calculates the number of distinct subdomains queried.
    • It finds the maximum and average length of the leftmost label.
    • It counts queries with a leftmost label length of 32 or more.
    • It counts queries of specific types (TXT, NULL, CNAME, MX).
    • It creates a set of up to 10 different query types observed.
  4. Grouping and Limiting:

    • The data is grouped by 5-minute intervals, account ID, region, VPC ID, source address, instance ID, and parent domain.
    • It limits the output to 10,000 records.

This query is used to pre-compute data for DNS visualizations and baselines, making them faster and more cost-effective.