Query Details

H11 Route53 Rare Domains And Periodic Dns

Query

// REVIEW ONLY - Hunting Query H11: Route 53 Rare Parent Domains & Inter-Arrival Periodic DNS Beaconing
// Separates first-seen parent domains from low-jitter periodic DNS callback intervals per workload IP.
let BaselineStart = ago(7d);
let RecentStart = ago(6h);
let KnownParentDomains = AWSRoute53Resolver
| where TimeGenerated between (BaselineStart .. RecentStart)
| extend Labels = split(trim_end(@"\.", tolower(QueryName)), ".")
| where array_length(Labels) >= 2
| extend ParentDomain = strcat(tostring(Labels[-2]), ".", tostring(Labels[-1]))
| distinct VpcId, ParentDomain;
AWSRoute53Resolver
| where TimeGenerated > RecentStart
| extend CleanQname = trim_end(@"\.", tolower(QueryName))
| extend Labels = split(CleanQname, ".")
| where array_length(Labels) >= 2
| extend ParentDomain = strcat(tostring(Labels[-2]), ".", tostring(Labels[-1])),
    InstanceId = tostring(SrcIds.instance)
| where not(ParentDomain endswith "amazonaws.com")
| join kind=leftanti KnownParentDomains on VpcId, ParentDomain
| summarize FirstSeen=min(TimeGenerated), LastSeen=max(TimeGenerated), Queries=count(),
    DistinctSubdomains=dcount(CleanQname), Active5mBins=dcount(bin(TimeGenerated, 5m)),
    NxDomains=countif(Rcode =~ "NXDOMAIN"), QueryTypes=make_set(QueryType, 10)
    by AccountId, Region, VpcId, SrcAddr, InstanceId, ParentDomain
| where Queries >= 15 or Active5mBins >= 6
| order by Active5mBins desc, DistinctSubdomains desc
| take 1000

Explanation

This query is designed to identify unusual DNS activity in AWS Route 53 by focusing on rare parent domains and periodic DNS beaconing patterns. Here's a simplified breakdown:

  1. Baseline Establishment: The query first establishes a baseline of known parent domains by examining DNS queries from the past week up to 6 hours ago. It extracts and records the parent domains (the last two segments of a domain name) for each VPC (Virtual Private Cloud).

  2. Recent Activity Analysis: It then looks at DNS queries from the last 6 hours, focusing on parent domains that are not part of the baseline and do not end with "amazonaws.com".

  3. Filtering and Joining: The query filters out known parent domains by performing a left anti-join with the baseline data, leaving only the new or rare parent domains.

  4. Summarization: For these rare domains, it summarizes data such as the first and last time they were seen, the total number of queries, the number of distinct subdomains, the number of active 5-minute intervals, the count of NXDOMAIN responses (indicating failed DNS queries), and the types of DNS queries made.

  5. Significance Criteria: It filters the results to include only those with at least 15 queries or activity in at least 6 different 5-minute intervals, indicating potential periodic beaconing.

  6. Ordering and Limiting: Finally, it orders the results by the number of active intervals and distinct subdomains, taking the top 1000 entries.

This query helps in identifying potentially suspicious DNS activity that may indicate malicious behavior, such as DNS tunneling or beaconing, by highlighting rare and periodic DNS patterns.