Query Details

21 Network Analyst Raw Vpc Drilldown

Query

// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: Network | Panel: analyst-raw-vpc-drilldown | Visualization: table | Mode: Analyst
// Security Question: What exact 5-tuple flow records, TCP flags, and byte counts involve SelectedIp?
// Drill-Through: Click any IP in Network, GuardDuty, DNS, or WAF tables (or type into SelectedIp above) to populate SelectedIp.
// Empty/No-Data Contract: Click an IP row in an upstream table (or enter an IPv4 in SelectedIp above) to inspect raw VPC flow records.
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}");
union isfuzzy=true
    (datatable(TimeGenerated:datetime, AccountId:string, Region:string, VpcId:string, SubnetId:string, InterfaceId:string, InstanceId:string, FlowDirection:string, Action:string, SrcAddr:string, SrcPort:int, DstAddr:string, DstPort:int, Protocol:int, Bytes:long, Packets:long, TcpFlags:int, PktSrcAddr:string, PktDstAddr:string, PktDstAwsService:string)[]),
    (AWSVPCFlow | where SelectedIpFilter != "*" and TimeGenerated between (Start .. End)
     | project TimeGenerated, AccountId, Region, VpcId, SubnetId, InterfaceId, InstanceId, FlowDirection, Action, SrcAddr, SrcPort=toint(SrcPort), DstAddr, DstPort=toint(DstPort), Protocol=toint(Protocol), Bytes=tolong(Bytes), Packets=tolong(Packets), TcpFlags=toint(TcpFlags), PktSrcAddr, PktDstAddr, PktDstAwsService)
| where SelectedIpFilter != "*" and (SrcAddr == SelectedIpFilter or DstAddr == SelectedIpFilter or PktSrcAddr == SelectedIpFilter or PktDstAddr == SelectedIpFilter)
| project TimeGenerated, AccountId, Region, VpcId, SubnetId, InterfaceId, InstanceId, FlowDirection, Action, SrcAddr, SrcPort, DstAddr, DstPort, Protocol, Bytes, Packets, TcpFlags, PktDstAwsService
| order by TimeGenerated desc
| take 5000

Explanation

This query is designed to analyze AWS VPC (Virtual Private Cloud) flow logs to identify specific network traffic patterns involving a selected IP address. Here's a simplified breakdown of what the query does:

  1. Time Range and Filters: It sets up a time range (Start and End) and various filters for organization, account, region, environment, workload, severity, source, summary mode, selected principal, and the selected IP address. These filters are decoded from base64 strings.

  2. Data Source: It pulls data from AWS VPC flow logs, focusing on network flow records. The query is interested in records where the selected IP address is involved, either as a source or destination.

  3. Data Selection: The query selects specific fields from the flow logs, including:

    • Time of the log entry (TimeGenerated)
    • AWS account and region details
    • Network identifiers like VPC ID, subnet ID, interface ID, and instance ID
    • Flow direction and action (e.g., accepted or rejected traffic)
    • Source and destination IP addresses and ports
    • Protocol used, byte and packet counts, and TCP flags
    • Destination AWS service if applicable
  4. Filtering: It filters the data to include only records where the selected IP address is involved, ensuring that the IP is either the source or destination in the flow.

  5. Sorting and Limiting: The results are sorted by the time the log was generated in descending order, and the query limits the output to the most recent 5000 records.

In summary, this query helps security analysts investigate network traffic involving a specific IP address by examining detailed flow records, including TCP flags and byte counts, within a specified time range and context.