tcpdump: Packet Capture Tool

The essential command-line packet analyzer for network forensics

Interactive tcpdump Examples

analyst@soc:~
$ sudo tcpdump -i eth0 -c 5
14:23:45.123456 IP 192.168.1.100.49152 > 10.0.0.50.443: Flags [S], seq 1234567890 14:23:45.123567 IP 10.0.0.50.443 > 192.168.1.100.49152: Flags [S.], seq 987654321, ack 1234567891 14:23:45.123678 IP 192.168.1.100.49152 > 10.0.0.50.443: Flags [.], ack 987654322 14:23:45.234567 IP 192.168.1.100.49152 > 10.0.0.50.443: Flags [P.], seq 1:50, ack 1 14:23:45.345678 IP 10.0.0.50.443 > 192.168.1.100.49152: Flags [.], ack 50 5 packets captured

Essential tcpdump Commands

tcpdump -i any

Capture on all interfaces

tcpdump -nn port 443

Capture HTTPS traffic, no DNS resolution

tcpdump host 192.168.1.100

Filter by specific IP address

tcpdump -w capture.pcap

Write packets to file for later analysis

tcpdump -r capture.pcap

Read packets from saved file

tcpdump -X

Show packet contents in hex and ASCII

BPF Filter Syntax — The Language of Packet Capture

Berkeley Packet Filter (BPF) syntax is used by tcpdump, Wireshark capture filters, and most network tools. Master these building blocks:

FilterMeaningSOC Use Case
host 10.0.0.50Traffic to OR from this IPIsolate a suspected compromised host
src host 10.0.0.50Traffic FROM this IP onlySee what a host is sending (exfil detection)
dst port 443Traffic going TO port 443Monitor HTTPS connections
port 53DNS traffic (both directions)DNS tunneling detection
net 192.168.1.0/24Entire subnetMonitor a specific network segment
not port 22Exclude SSH trafficFilter out your own management traffic
tcp[tcpflags] & tcp-syn != 0SYN flag setDetect port scanning (SYN scan)
icmpICMP traffic onlyDetect ICMP tunneling or ping sweeps

Combine with and, or, not:

$ tcpdump -i eth0 'src net 10.0.0.0/8 and dst port 443 and not host 10.0.0.1'
# Internal hosts going to HTTPS, excluding the proxy

IR Capture Recipes

Copy-paste these during incident response:

tcpdump -i any -w /tmp/evidence.pcap -G 3600 -W 24

Rotate capture files every hour, keep 24 hours

tcpdump -i eth0 'tcp[tcpflags] == tcp-rst' -nn

Catch connection resets (firewall blocks, IPS drops)

tcpdump -i eth0 'port 53 and udp[10] & 0x80 = 0' -nn

DNS queries only (not responses) — C2 hunting

tcpdump -i eth0 'greater 1400 and dst not net 10.0.0.0/8'

Large outbound packets — exfiltration indicator

NetFlow: Flow-Based Visibility

Network traffic metadata for large-scale monitoring

What is NetFlow?

NetFlow (and its variants: IPFIX, sFlow) provides summarized flow records rather than full packet captures. A "flow" is defined by:

  • 5-Tuple: Source IP, Dest IP, Source Port, Dest Port, Protocol
  • Timing: Start time, duration, last seen
  • Metrics: Bytes transferred, packet count
  • Interfaces: Ingress/egress interface IDs

Sample NetFlow Record

NetFlow v9 Record
Start Time: 2024-01-15 14:23:45 Duration: 5.23 seconds Source: 192.168.1.100:49152 Destination: 10.0.0.50:443 Protocol: TCP (6) Bytes: 15,360 Packets: 24 TCP Flags: S,A,P,F Input IF: GigabitEthernet0/1 Output IF: GigabitEthernet0/0

SOC Use Cases for NetFlow

Use CaseHow NetFlow Helps
C2 DetectionIdentify periodic beaconing patterns to suspicious IPs
Data ExfiltrationSpot unusual outbound data volumes
Lateral MovementTrack internal connection patterns
DDoS AnalysisVisualize attack traffic sources and volumes
Baseline DeviationAlert on anomalous traffic patterns

tcpdump vs. NetFlow

Choosing the right tool for the job

Feature Comparison

Aspecttcpdump/PCAPNetFlow
Data CapturedFull packet (headers + payload)Flow metadata only
Storage RequiredVery High (~100GB+/day)Low (~1GB/day)
RetentionHours to daysWeeks to months
VisibilityComplete - see everythingSummary - who talked to whom
Performance ImpactHigh CPU on capture deviceLow - done by routers/switches
Best ForDeep forensics, malware analysisTrending, baseline, detection

When to Use Each

Use tcpdump/PCAP when:

  • Analyzing malware payload
  • Extracting files from traffic
  • Debugging protocol issues
  • Deep forensic investigation

Use NetFlow when:

  • Identifying top talkers
  • Detecting C2 beaconing
  • Capacity planning
  • Long-term trend analysis

Knowledge Assessment

Test your understanding of tcpdump and NetFlow

Assessment Complete!

0%