Skip to content

VPC Flow Logs: how to use network logs for investigation and visibility

Without network logs, lateral movement and exfiltration go unseen. Learn how to capture and use VPC Flow Logs.

Reading time
8 min
Published

Identity logs answer who did what, but they do not show how traffic moved through the network. VPC Flow Logs fill that gap. They record connection metadata inside the VPC: source, destination, ports, protocol and whether the traffic was accepted or rejected. In an investigation, they are how you detect lateral movement, internal scanning and data exfiltration.

To capture and use VPC Flow Logs defensively, the challenge is gaining that visibility without drowning in volume. That means knowing exactly what they record (and what they leave out), choosing the capture format well before you need it and having the queries and the correlation with other sources ready in advance.

What Flow Logs record

Flow Logs capture flow metadata per network interface, per subnet or for the entire VPC. Each record includes the source and destination IPs, ports, protocol, bytes and the action (accepted or rejected). Rejected traffic deserves special attention, because a burst of rejected connections can indicate scanning. Accepted connections between workloads that should not talk to each other, on the other hand, suggest lateral movement.

Also know what is left out. Flow Logs record metadata, and packet contents are not part of the record. They tell you a connection happened, but not what went through it. To see the content, you need other approaches, such as application-layer inspection.

Custom format and the fields that matter

The default Flow Logs format covers the basics. The custom format adds fields that make a big difference in an investigation, such as those showing traffic direction, the real addresses behind network address translation and connection flags. Define the right format before the incident. Otherwise you risk finding out, in the middle of the analysis, that the data you needed was never captured.

Useful fields to include in the custom format
action           # ACCEPT or REJECTflow-direction   # ingress or egresspkt-srcaddr      # real source IP, before NATpkt-dstaddr      # real destination IP, before NATtcp-flags        # TCP connection flagstraffic-path     # path taken by egress traffic

The pkt-srcaddr and pkt-dstaddr fields matter because, when traffic passes through NAT or a load balancer, the traditional address fields show the intermediary. In this case, only the packet fields reveal who really originated or received the connection. The flow-direction field separates inbound from outbound, which helps when you suspect exfiltration. And tcp-flags lets you tell a scan apart from an established connection.

Investigating and correlating

Flow Logs are worth much more when cross-referenced with other sources. Combined with CloudTrail, they link network activity to the identity that provisioned the resource. With application logs, they gain business context. During an incident, they help map which hosts a compromised resource tried to reach and whether there was unusual outbound traffic, which is a sign of exfiltration.

Queries that keep coming up

Whether Flow Logs go to CloudWatch Logs or to S3 with Athena queries, some questions always come up: who generated the most outbound traffic, which connections were rejected (and on which ports) and which source and destination pairs exchanged the most bytes. Summing outbound bytes by destination helps catch exfiltration, and counting rejections by port makes scans stand out.

Logs Insights query: largest outbound volumes by destination
fields dstAddr, bytes| filter action = "ACCEPT"| stats sum(bytes) as total_out by dstAddr| sort total_out desc| limit 20
  • Review rejected connections for signs of scanning
  • Look for workloads talking when they should not (lateral movement)
  • Sum outbound bytes by destination to find exfiltration
  • Use pkt-srcaddr to see the real IP behind NAT and load balancers
  • Cross-reference with CloudTrail and application logs
  • Map everything a compromised host tried to reach

Storage, cost and focus

Flow Logs generate a lot of volume. Send them to cheap storage and use queries to analyze on demand, instead of trying to follow everything all the time. S3 is usually cheaper for long retention and analysis with Athena, while CloudWatch Logs makes quick queries and alerts easier. Many environments use both paths, each for a different need.

Choose the scope carefully. Capturing the whole VPC gives broad coverage, but enabling logs only on sensitive subnets and interfaces can balance visibility and cost. At a minimum, turn them on wherever there are critical workloads and exposure. Keep in mind that each record aggregates the flow over a time interval, so Flow Logs show connection patterns rather than individual packets. And there is traffic they do not capture, such as queries to the instance metadata server.

Practical checklist

  • Enable Flow Logs at least on critical VPCs and subnets
  • Capture both accepted and rejected traffic
  • Include pkt-srcaddr, flow-direction and tcp-flags in the custom format
  • Send logs to cheap storage, with S3 for long retention
  • Set a retention period that fits your investigation needs
  • Treat bursts of rejected connections as possible scanning
  • Investigate communication between workloads that should not talk to each other
  • Sum outbound bytes by destination to look for exfiltration
  • Correlate with CloudTrail and application logs
  • Have standard queries for network investigations
  • Fit the capture scope to a cost that makes sense

Best practices

  • Use Flow Logs for network visibility, which identity logs do not give you
  • Define a custom format with the fields that matter in an investigation
  • Pay attention to rejected traffic and unexpected communication
  • Use pkt-srcaddr to get to the real IP behind NAT
  • Correlate with other sources to get context
  • Send the volume to low-cost storage
  • Remember that records hold aggregated metadata, not packet contents

Common mistakes

Not enabling Flow Logs on any network
During the investigation, lateral movement and exfiltration do not show up.
Default format only, without the packet fields
You see the NAT or load balancer address instead of the real IP at the endpoint.
Capturing everything with no cost strategy
Volume and the bill grow much faster than visibility.
Expecting packet contents in Flow Logs
The expectation is wrong: records hold aggregated metadata and no content.
Ignoring rejected traffic
Scans and internal enumeration go unnoticed.
Flow Logs with no correlation to other sources
The network view stays isolated and does not link activity to an identity or a context.

Authorship and review

Cesar Gargiulo

CEO and founder of GUARDIASEC. Technical and editorial lead for the content published in this library.

Published on . Found a technical error? Write to [email protected] and we will correct it and keep a record of the change.

Frequently asked questions

Do VPC Flow Logs capture the content of connections?
No. They record flow metadata: source and destination IPs, ports, protocol, bytes and whether the traffic was accepted or rejected. They tell you that a connection happened and between whom, but not what traveled over it. To inspect the content, you need other approaches at other layers.
What is the difference between the default and the custom format?
The default format has the basic flow fields. The custom format lets you choose extra fields that change an investigation a great deal, such as flow-direction, tcp-flags and, above all, pkt-srcaddr and pkt-dstaddr. Since the format is set when the Flow Log is created, plan the fields ahead of time. That way you do not find out, in the middle of an incident, that the data you needed was never captured.
Why do the pkt-srcaddr and pkt-dstaddr fields matter?
Because when traffic passes through NAT or a load balancer, the traditional address fields show the intermediary. The pkt-srcaddr and pkt-dstaddr fields reveal the real source and destination IPs, before translation. Without them, the investigation may attribute the activity to the gateway rather than to the host that originated or received the connection.
Why is rejected traffic so useful?
Because rejected connections often give away suspicious behavior. A burst of rejected attempts can indicate port scanning, and rejection patterns between internal workloads help map attempts at lateral movement. Looking at what was blocked, as well as at what got through, makes the network investigation much more complete.
Should I send Flow Logs to S3 or to CloudWatch Logs?
It depends on the use. S3 is usually cheaper for long retention and for analysis with Athena over large volumes. CloudWatch Logs makes quick queries with Logs Insights and alert creation easier. Many environments use both: S3 keeps the history and handles the heavy analysis, and CloudWatch takes the quick investigation of the most critical networks.
Should I enable Flow Logs on the entire VPC?
Capturing the entire VPC gives broad coverage, but it generates high volume and cost. A middle ground is to enable them at least where there are critical workloads and exposure, and to expand as needed. What you cannot go without is visibility into the networks that matter most, with the logs going to cheap storage.
How do Flow Logs help during an incident?
With them you map which hosts a compromised resource tried to reach, identify anomalous outbound traffic that suggests exfiltration and detect unexpected communication between workloads. Cross-referenced with CloudTrail and application logs, they help rebuild the path the attack took through the network and also show who acted.

When to bring in specialist help

Deciding what to capture on the network and how to cross-reference that data with identity and application logs is part of GUARDIASEC's Monitoring and Response service, in which we set up visibility and investigation to fit your environment.