24 DNS Dns Threat Intel Matches
Query
// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: DNS | Panel: dns-threat-intel-matches | Visualization: table | Mode: All
// Security Question: Did any AWS VPC resolve a domain matching active ThreatIntelIndicators, and did DNS Firewall block it?
// Drill-Through: Escalate unblocked TI domain resolutions (`FirewallRuleAction != BLOCK`) immediately.
// Empty/No-Data Contract: Zero Route 53 queries matched active domain indicators in ThreatIntelIndicators.
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 ActiveDomainTi = union isfuzzy=true
(datatable(TimeGenerated:datetime, Id:string, IsActive:bool, IsDeleted:bool, Revoked:bool, ValidUntil:datetime, ObservableKey:string, ObservableValue:string, Confidence:int, Tags:string)[]),
(ThreatIntelIndicators | where TimeGenerated > ago(14d)
| project TimeGenerated, Id, IsActive, IsDeleted, Revoked, ValidUntil, ObservableKey, ObservableValue, Confidence=toint(Confidence), Tags=tostring(Tags))
| summarize arg_max(TimeGenerated, *) by Id
| where IsActive == true and IsDeleted != true and Revoked != true and ValidUntil > now()
| where ObservableKey has "domain" and isnotempty(ObservableValue)
| project TiDomain=tolower(trim_end('.', ObservableValue)), TiConfidence=Confidence, TiTags=Tags;
union isfuzzy=true
(datatable(TimeGenerated:datetime, AccountId:string, Region:string, VpcId:string, SrcAddr:string, SrcIds:dynamic, QueryName:string, FirewallRuleAction:string, Answers:string)[]),
(AWSRoute53Resolver | where TimeGenerated between (Start .. End)
| project TimeGenerated, AccountId, Region, VpcId, SrcAddr, SrcIds=todynamic(SrcIds), QueryName, FirewallRuleAction, Answers=tostring(Answers))
| where (AccountFilter == "*" or AccountId == AccountFilter) and (RegionFilter == "*" or Region == RegionFilter)
| 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)
| join kind=inner ActiveDomainTi on $left.ParentDomain == $right.TiDomain
| summarize FirstSeen=min(TimeGenerated), LastSeen=max(TimeGenerated), Queries=count(),
FirewallActions=make_set(FirewallRuleAction, 5), SampleAnswers=make_set(Answers, 5)
by AccountId, Region, VpcId, SrcAddr, InstanceId, ParentDomain, TiConfidence, TiTags
| order by TiConfidence desc, Queries desc
| take 5000Explanation
This query is designed to analyze DNS activity within AWS Virtual Private Clouds (VPCs) to identify any domain resolutions that match active threat intelligence indicators. Here's a simple breakdown of what the query does:
-
Time and Filters Setup: It sets up a time range and various filters (like organization, account, region, environment, workload, severity, source, principal, and IP) to narrow down the data being analyzed.
-
Threat Intelligence Data: It retrieves active threat intelligence indicators related to domains. These indicators are filtered to ensure they are currently active, not deleted, not revoked, and still valid.
-
DNS Query Data: It gathers DNS query data from AWS Route 53 Resolver logs within the specified time range and applies the filters set up earlier.
-
Domain Matching: The query looks for matches between the parent domains of DNS queries and the threat intelligence indicators. It checks if any DNS queries resolved domains that are flagged as threats.
-
Firewall Action Check: It checks the actions taken by the DNS Firewall on these queries, specifically looking for any that were not blocked.
-
Summarization: The results are summarized to show the first and last time the domain was seen, the number of queries, the actions taken by the firewall, and sample answers returned by the DNS queries. The results are ordered by the confidence level of the threat intelligence and the number of queries.
-
Output: The query outputs up to 5000 records, showing details like account ID, region, VPC ID, source address, instance ID, parent domain, threat intelligence confidence, and tags.
In essence, this query helps security teams identify potential security threats by detecting DNS queries to domains flagged by threat intelligence and checking if the DNS Firewall appropriately blocked them. If any threats were not blocked, they are highlighted for immediate escalation.