Query Details

AWS SecOps P1-03b - VPC Flow Threat-Intel IP Egress and Low-Jitter Beaconing

P1 03b Vpcflow Ti And Beacon Correlated

Query

// REVIEW ONLY. Validate AWSVPCFlow and ThreatIntelIndicators schemas first.
let InfraAllowlist = _GetWatchlist('AWS_NetworkInfraAllowlist')
| where tolower(tostring(column_ifexists("Verified", ""))) == "true" and isnotempty(tostring(column_ifexists("InterfaceId", "")))
| project tostring(column_ifexists("InterfaceId", ""));
let ActiveIpTi = 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 >= 65
| where ObservableKey has "ipv4" and isnotempty(ObservableValue)
| project TiIp=ObservableValue, TiId=Id, TiConfidence=Confidence;
let RecentEgress = materialize(
    AWSVPCFlow
    | where TimeGenerated > ago(2h) and LogStatus == "OK" and Action == "ACCEPT"
    | where InterfaceId !in (InfraAllowlist)
    | extend OrigSrc = iff(isnotempty(PktSrcAddr), PktSrcAddr, SrcAddr),
        OrigDst = iff(isnotempty(PktDstAddr), PktDstAddr, DstAddr)
    | where ipv4_is_private(OrigSrc) and isnotnull(parse_ipv4(OrigDst)) and ipv4_is_private(OrigDst) == false
    | where isempty(PktDstAwsService) and DstPort != 123
);
let TiMatches = RecentEgress
| where ingestion_time() > ago(30m)
| join kind=inner ActiveIpTi on $left.OrigDst == $right.TiIp
| summarize TimeGenerated=min(TimeGenerated), TotalBytes=sum(Bytes), TotalPackets=sum(Packets),
    ActiveBins=dcount(bin(TimeGenerated, 5m))
    by AccountId, Region, VpcId, SubnetId, InterfaceId, InstanceId, OrigSrc, OrigDst, DstPort, Protocol, TiId, TiConfidence
| project TimeGenerated, AWSAccountId=AccountId, AWSRegion=Region, VpcId, SubnetId, InterfaceId,
    InstanceId, SourceIpAddress=OrigSrc, DestinationIpAddress=OrigDst, DstPortStr=tostring(DstPort),
    ProtocolStr=tostring(Protocol), TotalBytesStr=tostring(TotalBytes),
    SignalType=strcat("ThreatIntelIpMatch(Confidence=", TiConfidence, ",Id=", TiId, ")");
let BeaconCandidates = RecentEgress
| summarize BinBytes=sum(Bytes), BinFlows=count()
    by Window5m=bin(TimeGenerated, 5m), AccountId, Region, VpcId, SubnetId, InterfaceId, InstanceId, OrigSrc, OrigDst, DstPort, Protocol
| summarize TimeGenerated=max(Window5m), ActiveBins=count(), AvgBinBytes=avg(todouble(BinBytes)),
    StdevBinBytes=stdev(todouble(BinBytes)), TotalBytes=sum(BinBytes)
    by AccountId, Region, VpcId, SubnetId, InterfaceId, InstanceId, OrigSrc, OrigDst, DstPort, Protocol
| extend CoeffVariation = StdevBinBytes / max_of(AvgBinBytes, 1.0)
| where ActiveBins >= 16 and AvgBinBytes between (64.0 .. 65536.0) and CoeffVariation <= 0.20
| project TimeGenerated, AWSAccountId=AccountId, AWSRegion=Region, VpcId, SubnetId, InterfaceId,
    InstanceId, SourceIpAddress=OrigSrc, DestinationIpAddress=OrigDst, DstPortStr=tostring(DstPort),
    ProtocolStr=tostring(Protocol), TotalBytesStr=tostring(TotalBytes),
    SignalType=strcat("LowJitterPeriodicBeacon(Bins=", ActiveBins, ",CV=", round(CoeffVariation, 3), ")");
union TiMatches, BeaconCandidates

Explanation

This query is designed to monitor and detect suspicious network activity within an AWS environment, specifically focusing on outbound internet traffic from AWS VPCs (Virtual Private Clouds). Here's a simplified breakdown of what the query does:

  1. Purpose: The query aims to identify potential security threats by analyzing outbound network traffic from AWS VPCs. It looks for two main types of suspicious activities:

    • Traffic to IP addresses that are flagged as threats by threat intelligence sources.
    • Low-jitter periodic egress beaconing, which is a pattern of regular, consistent data transmissions that could indicate malicious activity such as data exfiltration.
  2. Data Sources: The query uses data from AWS VPC Flow logs and threat intelligence indicators. It requires connectors to AWS S3 for VPC Flow logs and a Threat Intelligence source.

  3. Process:

    • Allowlist Filtering: It first filters out traffic from known and verified network interfaces to focus on potentially suspicious traffic.
    • Threat Intelligence Matching: It checks if any outbound traffic is going to IP addresses that are currently flagged as threats by threat intelligence sources.
    • Beaconing Detection: It analyzes traffic patterns to detect low-jitter periodic beaconing, characterized by consistent data sizes sent at regular intervals to external, non-AWS destinations.
  4. Detection Criteria:

    • For threat intelligence matches, it looks for traffic to IPs with a confidence level of 65 or higher.
    • For beaconing, it identifies patterns with at least 16 active 5-minute intervals, consistent byte sizes, and low variability in data size.
  5. Output: The query generates alerts for any detected suspicious activities, including details such as AWS account ID, region, VPC ID, source and destination IP addresses, and the type of signal detected (either a threat intelligence match or beaconing).

  6. Incident Management: If suspicious activity is detected, the query is configured to create an incident and group related alerts to help with investigation and response.

Overall, this query is a scheduled security monitoring tool that helps identify and alert on potential command-and-control activities within an AWS environment.