S04 Vpcflow 5m Summary
Query
// REVIEW ONLY - Summary Rule KQL Spec: S04 -> Target Table: AWS_VPCFlow_5m_CL
// Schedule: Every 5m over AWSVPCFlow. Compresses high-volume flow logs into 5-minute aggregates
// while preserving AccountId, Region, VpcId, SubnetId, InterfaceId, InstanceId, ports, protocol, action, and bytes.
AWSVPCFlow
| where TimeGenerated > ago(15m)
| where LogStatus != "NODATA" and LogStatus != "SKIPDATA"
| extend EffectiveDstAddr = iff(isnotempty(PktDstAddr), PktDstAddr, DstAddr),
EffectiveSrcAddr = iff(isnotempty(PktSrcAddr), PktSrcAddr, SrcAddr)
| summarize
FlowRecords = count(),
TotalBytes = sum(Bytes),
TotalPackets = sum(Packets),
DistinctDstIps = dcount(EffectiveDstAddr),
DistinctDstPorts = dcount(DstPort),
SynOnlyFlows = countif(TcpFlags == 2)
by WindowStart=bin(TimeGenerated, 5m), AccountId, Region, VpcId, SubnetId, InterfaceId,
InstanceId, FlowDirection, Action, EffectiveSrcAddr, EffectiveDstAddr, DstPort, Protocol,
PktDstAwsService, SublocationType
| take 10000Explanation
This query is designed to process AWS VPC flow logs and generate summarized data every 5 minutes. Here's a simple breakdown of what it does:
-
Data Source: It uses the
AWSVPCFlowtable, which contains flow logs from AWS VPC. -
Time Filter: It only considers logs generated in the last 15 minutes.
-
Log Status Filter: It excludes logs with a status of "NODATA" or "SKIPDATA".
-
Address Handling: It determines effective destination and source addresses by checking if packet-specific addresses are available; if not, it uses the default destination and source addresses.
-
Data Aggregation: It aggregates the data into 5-minute windows and calculates several metrics:
FlowRecords: The total number of flow records.TotalBytes: The sum of bytes transferred.TotalPackets: The sum of packets transferred.DistinctDstIps: The count of distinct destination IP addresses.DistinctDstPorts: The count of distinct destination ports.SynOnlyFlows: The count of flows with only SYN flags set (indicating connection attempts).
-
Grouping: The data is grouped by various attributes such as account ID, region, VPC ID, subnet ID, interface ID, instance ID, flow direction, action, effective source and destination addresses, destination port, protocol, AWS service, and sublocation type.
-
Result Limitation: It limits the output to a maximum of 10,000 records.
In summary, this query compresses high-volume AWS VPC flow logs into manageable 5-minute summaries, providing insights into network traffic patterns while maintaining key attributes for analysis.