AWS SecOps P1-01b - Route 53 Queries Matching Threat Intel and Correlated VPC Egress
P1 01b Route53 Dns Ti Vpc Guardduty Correlated
Query
// REVIEW ONLY. Validate AWSRoute53Resolver, ThreatIntelIndicators, and AWSVPCFlow schemas first.
let ActiveDomainTi = ThreatIntelIndicators
| where TimeGenerated > ago(14d)
| summarize arg_max(TimeGenerated, *) by Id
| where IsActive == true and IsDeleted != true and Revoked != true
| where ValidUntil > now() and Confidence >= 60
| where ObservableKey has "domain" and isnotempty(ObservableValue)
| project TiDomain=tolower(trim_end(@"\.", ObservableValue)), TiId=Id, TiConfidence=Confidence, TiTags=Tags;
let DnsHits = AWSRoute53Resolver
| where TimeGenerated > ago(2h) and ingestion_time() > ago(1h)
| extend CleanQname = trim_end(@"\.", tolower(QueryName))
| extend Labels = split(CleanQname, ".")
| extend LabelCount = array_length(Labels)
| where LabelCount >= 2
| extend ParentDomain = strcat(tostring(Labels[LabelCount - 2]), ".", tostring(Labels[LabelCount - 1])),
InstanceId = tostring(SrcIds.instance),
FirstAnswerIp = tostring(Answers[0].Rdata)
| join kind=inner ActiveDomainTi on $left.ParentDomain == $right.TiDomain
| summarize FirstQueryUtc=min(TimeGenerated), QueryCount=count(), SampleQueries=make_set(CleanQname, 10),
ResolvedIp=take_any(FirstAnswerIp)
by AccountId, Region, VpcId, SrcAddr, InstanceId, ParentDomain, TiId, TiConfidence, FirewallRuleAction;
let VpcConnections = AWSVPCFlow
| where TimeGenerated > ago(1h) and Action == "ACCEPT"
| summarize ConnectedBytes=sum(Bytes), ConnectedPackets=sum(Packets), DstPorts=make_set(DstPort, 10)
by AccountId, SrcAddr, ResolvedIp=DstAddr;
DnsHits
| join kind=leftouter VpcConnections on AccountId, SrcAddr, ResolvedIp
| extend PostResolutionState = case(
FirewallRuleAction =~ "BLOCK", "BlockedByRoute53DnsFirewall",
coalesce(ConnectedBytes, 0) > 0, "ResolvedAndConnectedInVpcFlow",
"DnsLookupObservedNoMatchedIpFlow"),
ConnectedBytesStr = tostring(coalesce(ConnectedBytes, 0)),
TiConfidenceStr = tostring(TiConfidence)
| project TimeGenerated=FirstQueryUtc, AWSAccountId=AccountId, AWSRegion=Region, VpcId,
SourceIpAddress=SrcAddr, InstanceId, ParentDomain, ResolvedIp, PostResolutionState,
ConnectedBytesStr, TiId, TiConfidenceStrExplanation
This query is designed to enhance security monitoring by analyzing DNS queries and network traffic in AWS environments. Here's a simplified breakdown:
-
Purpose: The query aims to identify potential security threats by correlating DNS queries made through AWS Route 53 with known malicious domains and checking if these queries result in actual network connections.
-
Data Sources:
- AWS Route 53 Resolver: Monitors DNS queries.
- AWS VPC Flow Logs: Tracks network traffic within AWS Virtual Private Clouds (VPCs).
- Threat Intelligence Indicators: Provides a list of known malicious domains.
-
Process:
- Threat Intelligence Filtering: It filters active and high-confidence threat intelligence indicators related to domains.
- DNS Query Analysis: It examines recent DNS queries to see if they match any of the malicious domains.
- Network Traffic Correlation: It checks if the DNS queries that resolved to IP addresses also resulted in outbound network connections from the same source IP within the VPC.
-
Outcome:
- The query identifies whether a DNS query led to a blocked connection, an active connection, or just a DNS lookup without a corresponding network flow.
- It generates alerts for potential command-and-control (C2) activities, which are tactics used by attackers to control compromised systems.
-
Alert Configuration:
- Alerts are generated if any suspicious activity is detected.
- Incidents are created and grouped based on IP addresses and AWS account details to facilitate investigation.
-
Frequency and Scope:
- The query runs every hour and looks back over the past 14 days to ensure comprehensive monitoring.
Overall, this query helps security teams identify and respond to potential threats by correlating DNS activity with network traffic and threat intelligence data.