| name | tcpdump |
| description | Auth/lab ref: CLI packet capture and BPF filter tool. |
| license | BSD-3-Clause |
| compatibility | Linux/macOS/*BSD/Windows (Npcap); tcpdump.org. |
| metadata | {"author":"AeonDave","version":"2.0"} |
tcpdump
CLI packet capture + BPF filter. Capture traffic, filter PCAPs, extract payloads, triage network activity.
Installation
sudo apt install tcpdump
brew install tcpdump
Core Flags Reference
| Flag | Purpose |
|---|
-i <iface> | Interface to capture on |
-r <file> | Read from PCAP file (instead of live capture) |
-w <file> | Write captured packets to PCAP file |
-n | No DNS resolution (IP addresses only) |
-nn | No DNS + no port name resolution (shows port numbers) |
-v | Verbose output |
-vv | More verbose (full TCP flags, options) |
-vvv | Maximum verbosity |
-s <n> | Snap length (0 = unlimited, capture full packets) |
-c <n> | Capture exactly n packets then stop |
-A | Print packet payload as ASCII |
-X | Print packet payload as hex + ASCII |
-XX | Print packet header + payload as hex + ASCII |
-q | Quiet — minimal output |
-e | Print link-layer header (MAC addresses) |
-tttt | Human-readable timestamps |
-D | List available interfaces |
-G <n> | Rotate capture file every n seconds |
-C <n> | Rotate capture file every n MB |
-Z <user> | Drop privileges after capture starts |
host | BPF primitive — filter by IP |
port | BPF primitive — filter by port |
net | BPF primitive — filter by network |
Capture Patterns
Basic capture to file
tcpdump -D
sudo tcpdump -i eth0 -nn -s 0 -w capture.pcap
sudo tcpdump -i eth0 -nn -s 0 -c 1000 -w capture.pcap
sudo tcpdump -i eth0 -nn -s 0 -tttt -w capture.pcap
Targeted captures
sudo tcpdump -i eth0 -nn -s 0 -w host.pcap 'host 10.10.10.5'
sudo tcpdump -i eth0 -nn -s 0 -w http.pcap 'port 80'
sudo tcpdump -i eth0 -nn -s 0 'portrange 8000-9000'
sudo tcpdump -i eth0 -nn -s 0 -w dns.pcap 'udp port 53'
sudo tcpdump -i eth0 -nn -s 0 -w icmp.pcap 'icmp'
sudo tcpdump -i eth0 -nn -s 0 -w web.pcap 'port 80 or port 443'
sudo tcpdump -i eth0 -nn -s 0 -w external.pcap 'not net 192.168.0.0/16 and not net 10.0.0.0/8'
sudo tcpdump -i eth0 -nn 'tcp[tcpflags] & tcp-syn != 0 and tcp[tcpflags] & tcp-ack == 0'
sudo tcpdump -i eth0 -nn 'tcp[tcpflags] & tcp-rst != 0'
Reading and Filtering Existing PCAPs
tcpdump -nn -r capture.pcap
tcpdump -nn -vv -r capture.pcap
tcpdump -nn -r capture.pcap 'port 80'
tcpdump -nn -r capture.pcap 'host 10.10.10.5'
tcpdump -nn -r capture.pcap 'src host 10.10.10.5 and dst port 443'
tcpdump -nn -r capture.pcap -w filtered.pcap 'port 80'
tcpdump -nn -r capture.pcap 'tcp[tcpflags] == tcp-syn'
tcpdump -nn -r capture.pcap -w window.pcap 'greater 14:30:00 and less 15:00:00'
Payload Extraction
tcpdump -nn -A -r capture.pcap 'port 80'
tcpdump -nn -X -r capture.pcap 'port 21'
tcpdump -nn -A -r capture.pcap 'port 80' | grep -v "^[0-9a-f][0-9a-f]:[0-9a-f]" | grep -v "^$"
tcpdump -nn -A -r capture.pcap 2>/dev/null | grep -i "password\|passwd\|pass=\|login\|credential"
tcpdump -nn -A -r capture.pcap 'tcp port 80 and (tcp[tcpflags] & tcp-push != 0)' | grep -A 20 "POST"
tcpdump -nn -A -r capture.pcap 2>/dev/null | grep -iE "flag\{|HTB\{|picoCTF"
BPF Filter Syntax Reference
Primitives
host 192.168.1.1
src host 192.168.1.1
dst host 192.168.1.1
net 192.168.1.0/24
src net 10.0.0.0/8
port 80
src port 1234
dst port 443
portrange 1024-65535
tcp
udp
icmp
arp
Operators
and / &&
or / ||
not / !
Complex filters
'host 192.168.1.1 and host 192.168.1.2'
'src host 10.10.10.5 and dst port 4444'
'port 80 or port 8080 or port 8443'
'not host 10.0.0.1'
'tcp[tcpflags] & (tcp-syn|tcp-ack) == (tcp-syn|tcp-ack)'
'greater 1400'
'vlan'
'ip6'
'tcp port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'
Investigation Workflows
Workflow 1: Quick PCAP triage
tcpdump -nn -q -r capture.pcap | awk '{print $3, $5}' | sort | uniq -c | sort -rn | head 30
tcpdump -nn -r capture.pcap | awk '{print $3}' | cut -d. -f1-4 | sort | uniq -c | sort -rn
tcpdump -nn -r capture.pcap | grep -oP 'dst \d+\.\d+\.\d+\.\d+\.\K\d+' | sort | uniq -c | sort -rn
Workflow 2: Extract cleartext credentials
tcpdump -nn -A -r capture.pcap 'port 21' | grep -iE "USER|PASS"
tcpdump -nn -A -r capture.pcap 'port 80' | grep -i "Authorization: Basic"
tcpdump -nn -A -r capture.pcap 'port 23'
tcpdump -nn -A -r capture.pcap 'port 25' | grep -iE "auth|user|pass"
Workflow 3: Detect port scanning
tcpdump -nn -r capture.pcap 'tcp[tcpflags] == tcp-syn' | awk '{print $3}' | \
cut -d. -f1-4 | sort | uniq -c | sort -rn | head
tcpdump -nn -r capture.pcap 'tcp[tcpflags] & tcp-rst != 0' | wc -l
tcpdump -nn -r capture.pcap 'udp' | awk '{print $5}' | sort | uniq -c | sort -rn
Workflow 4: Find C2 beaconing
tcpdump -nn -r capture.pcap 'host SUSPECT_IP' | awk '{print $1}' | \
awk 'NR>1{printf "%.1f\n", $1-prev} {prev=$1}' | sort | uniq -c | sort -rn | head
Workflow 5: Extract files from PCAP
sudo apt install tcpflow
tcpflow -r capture.pcap -o output_dir/
tshark -r capture.pcap -z follow,tcp,raw,0 2>/dev/null | xxd -r -p > stream0.bin
Useful Combinations
sudo tcpdump -i eth0 -nn -A 2>/dev/null | grep -i "password\|flag\|secret"
sudo tcpdump -i eth0 -nn -s 0 -w capture.pcap | tcpdump -nn -r -
sudo tcpdump -i eth0 -nn -s 0 -G 300 -w "capture_%Y%m%d_%H%M%S.pcap"
tcpdump -nn -r huge.pcap -w small.pcap -C 100
tcpdump -nn -q -r capture.pcap | awk '{print $2}' | sort | uniq -c | sort -rn
tcpdump -nn -tttt -r capture.pcap > capture.txt
grep -i "interesting_string" capture.txt
Integration
| Tool | Use case |
|---|
wireshark / tshark | Deep protocol dissection, file extraction, stream following |
zeek | Convert PCAP to structured logs (dns.log, http.log, etc.) |
strings | Quick string extraction from raw PCAP |
scapy (Python) | Scripted PCAP parsing and packet manipulation |
tcpflow | TCP stream reassembly and file extraction from PCAP |
binwalk | Carve embedded files from reassembled streams |
yara | Scan packet payloads for patterns |
Resources
| File | When to load |
|---|
references/ | BPF filter recipes, tshark equivalents, complex protocol analysis patterns |