Wireshark is the world's most popular network protocol analyzer. It captures network traffic in real-time and breaks it down layer by layer (OSI model). In cybersecurity, it is critical for Network Forensics (DFIR), malware analysis, and detecting data leaks.
To capture traffic, your network card enters Promiscuous Mode. Captures are saved as .pcap or .pcapng files.
# Capture from CLI using tshark:
tshark -i eth0 -w incident_capture.pcapng
# Read an existing .pcapng:
tshark -r incident_capture.pcapng
Applied BEFORE capturing to drop unwanted traffic and save disk space.
# Only capture web server traffic:
tshark -i eth0 -f "host 192.168.1.50"
# Ignore SSH to avoid infinite noise loops:
tshark -i eth0 -f "not port 22"
Applied AFTER capturing. These are the analyst's scalpel. They don't delete packets, just hide the noise.
# By IP Address:
ip.addr == 192.168.1.100 # Source or Destination
ip.src == 10.0.0.5 # Source only
ip.dst == 8.8.8.8 # Destination only
# By Protocol & Port:
tcp.port == 443 # HTTPS
udp.dstport == 53 # DNS Queries
# Payload Content (String search):
frame contains "password"
tcp.payload contains "MZ" # Detect Windows executable signatures
You have a 2GB PCAP file from an incident. You know the infected IP 192.168.1.100 established a secure connection and exfiltrated data to port 443. Write the exact Display Filter to isolate ONLY the packet that initiated this connection (the TCP SYN packet).
To view encrypted traffic in clear text, you need the client's symmetric keys.
# 1. Set environment variable before the victim opens the browser:
export SSLKEYLOGFILE=/tmp/sslkeylog.log
# 2. In Wireshark: Edit -> Preferences -> Protocols -> TLS
# 3. Load sslkeylog.log into "(Pre)-Master-Secret log filename".
# Encrypted traffic is now readable!
If malware was downloaded via cleartext HTTP, Wireshark can rebuild the executable.
Understand TCP Flags to detect DoS or port scans.
# Detect Nmap Stealth SYN Scan:
tcp.flags.syn == 1 and tcp.flags.ack == 0
# Detect Connection Drops (RST):
tcp.flags.reset == 1
For massive PCAPs, use tshark to extract specific fields without crashing your GUI.
# Extract all Source IPs and HTTP Hosts visited:
tshark -r capture.pcap -Y "http.request" -T fields -e ip.src -e http.host
# Top Talkers (Which IP generated the most traffic?):
tshark -r capture.pcap -q -z endpoints,ip