Query Details

22 DNS Dns Rcode And Firewall Trend

Query

// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: DNS | Panel: dns-rcode-and-firewall-trend | Visualization: timechart | Mode: All
// Security Question: Are NXDOMAIN bursts (DGA) or DNS Firewall blocks spiking in any VPC?
// Drill-Through: Review Panel 6.2 below to identify the exact originating SrcAddr and InstanceId.
// Empty/No-Data Contract: No AWS_Route53_5m_CL or AWSRoute53Resolver logs in window (verify AWSRoute53Resolver connector in Tab 2).
let Start = {TimeRange:start};
let End = {TimeRange:end};
let OrgFilter = base64_decode_tostring("{Organization:base64}");
let AccountFilter = base64_decode_tostring("{AwsAccount:base64}");
let RegionFilter = base64_decode_tostring("{AwsRegion:base64}");
let EnvFilter = base64_decode_tostring("{Environment:base64}");
let WorkloadFilter = base64_decode_tostring("{Workload:base64}");
let SeverityFilter = base64_decode_tostring("{Severity:base64}");
let SourceFilter = base64_decode_tostring("{SourceTable:base64}");
let SummaryPref = base64_decode_tostring("{SummaryMode:base64}");
let SelectedPrincipalFilter = base64_decode_tostring("{SelectedPrincipal:base64}");
let SelectedIpFilter = base64_decode_tostring("{SelectedIp:base64}");
let SummaryDns = union isfuzzy=true
    (datatable(WindowStart:datetime, AccountId:string, Region:string, NxDomainCount:long, FirewallBlocks:long, LongLabelQueries:long)[]),
    (AWS_Route53_5m_CL | where WindowStart between (Start .. End) | project WindowStart, AccountId, Region, NxDomainCount, FirewallBlocks, LongLabelQueries)
| where SummaryPref == "PreferSummary"
| where (AccountFilter == "*" or AccountId == AccountFilter) and (RegionFilter == "*" or Region == RegionFilter)
| summarize NxDomains=sum(NxDomainCount), FirewallBlocks=sum(FirewallBlocks), LongLabelQueries=sum(LongLabelQueries) by TimeBucket=bin(WindowStart, 15m);
let HasSummary = toscalar(SummaryDns | summarize count() > 0);
let RawDns = union isfuzzy=true
    (datatable(TimeGenerated:datetime, AccountId:string, Region:string, QueryName:string, Rcode:string, FirewallRuleAction:string)[]),
    (AWSRoute53Resolver | where TimeGenerated between (Start .. End) | project TimeGenerated, AccountId, Region, QueryName, Rcode, FirewallRuleAction)
| where SummaryPref == "RawOnly" or not(HasSummary)
| where (AccountFilter == "*" or AccountId == AccountFilter) and (RegionFilter == "*" or Region == RegionFilter)
| extend LeftLen = strlen(tostring(split(trim_end('.', QueryName), ".")[0]))
| summarize NxDomains=countif(Rcode =~ "NXDOMAIN"), FirewallBlocks=countif(FirewallRuleAction =~ "BLOCK"), LongLabelQueries=countif(LeftLen >= 32) by TimeBucket=bin(TimeGenerated, 15m);
union SummaryDns, RawDns
| order by TimeBucket asc
| take 5000

Explanation

This query is designed to analyze DNS activity within AWS environments, specifically looking for unusual patterns that might indicate security issues, such as NXDOMAIN bursts (which can be associated with Domain Generation Algorithms, or DGA) or spikes in DNS Firewall blocks. Here's a simplified breakdown of what the query does:

  1. Time Range and Filters: The query starts by setting a time range and various filters based on organization, account, region, environment, workload, severity, source, and selected principal or IP. These filters are decoded from base64 strings.

  2. Summary Data: It attempts to summarize DNS data using a union of a predefined empty table and actual data from AWS_Route53_5m_CL. It aggregates counts of NXDOMAIN responses, firewall blocks, and long label queries (queries with a label length of 32 or more characters) into 15-minute time buckets.

  3. Raw Data: If summary data is not preferred or unavailable, it falls back to raw data from AWSRoute53Resolver. This part of the query calculates similar metrics (NXDOMAINs, firewall blocks, and long label queries) directly from the raw logs, again aggregating them into 15-minute time buckets.

  4. Data Union and Output: The query combines the summarized and raw data, orders it by time, and limits the output to 5000 records.

  5. Purpose: The goal is to identify any spikes in NXDOMAIN responses or DNS Firewall blocks, which could indicate potential security threats or misconfigurations in any Virtual Private Cloud (VPC). If such spikes are detected, further investigation can be done using additional panels to pinpoint the source address and instance ID responsible.

  6. No Data Handling: If no relevant logs are found within the specified time window, it suggests verifying the AWSRoute53Resolver connector settings.

Overall, this query helps security teams monitor and respond to potential DNS-related security incidents in AWS environments.