Query Details

P1 01b Route53 Dns Ti Vpc Guardduty Correlated

Query

// Standalone KQL for Analytic Rule: AWS SecOps P1-01b - Route 53 Queries Matching Threat Intel and Correlated VPC Egress
// Rule File: analytics/P1-01b-route53-dns-ti-vpc-guardduty-correlated.yaml | Rule ID: REPLACE_WITH_RULE_GUID | Severity: High
// Schedule: 1h / Lookback: 14d | REVIEW ONLY - Do not deploy/schedule without approval.
// 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, TiConfidenceStr

Explanation

This KQL query is designed to identify and analyze suspicious DNS queries in AWS environments by correlating them with threat intelligence data and VPC flow logs. Here's a simplified explanation of what the query does:

  1. Threat Intelligence Data Preparation:

    • It retrieves active threat intelligence indicators related to domains from the ThreatIntelIndicators table.
    • It filters these indicators to ensure they are active, not deleted or revoked, valid, and have a confidence level of at least 60. - The relevant domain information is extracted and formatted for further analysis.
  2. DNS Query Analysis:

    • It examines DNS queries from the AWSRoute53Resolver table within the last 2 hours.
    • It processes the queried domain names to extract the parent domain and other relevant details.
    • It joins this data with the threat intelligence data to find DNS queries that match known suspicious domains.
  3. VPC Flow Correlation:

    • It looks at VPC flow logs from the AWSVPCFlow table for the last hour, focusing on accepted connections.
    • It summarizes the data to get the total bytes and packets transferred and the destination ports used.
  4. Combining DNS and VPC Data:

    • It combines the DNS query data with the VPC flow data to determine if there was any network activity following the DNS resolution.
    • It categorizes the post-resolution state of each DNS query, indicating whether it was blocked, connected, or had no matching IP flow.
  5. Output:

    • The final output includes details such as the time of the first query, AWS account and region, VPC ID, source IP, instance ID, parent domain, resolved IP, post-resolution state, and threat intelligence confidence.

This query is part of an analytic rule designed to detect potential security threats by monitoring DNS queries and their subsequent network activities in AWS environments. It is set to run every hour and looks back over the past 14 days for threat intelligence data.