Network traffic analysis is essential for understanding protocols, capturing credentials in transit, and diagnosing network segmentation. Wireshark gives you a GUI; tcpdump gives you CLI speed and scripting.
tcpdump — Quick Reference Basic Capture tcpdump -D tcpdump -i eth0 tcpdump -i eth0 -w capture.pcap tcpdump -r capture.pcap tcpdump -i eth0 -v tcpdump -i eth0 -vv tcpdump -i eth0 -vvv tcpdump -i eth0 -X tcpdump -i eth0 -S tcpdump -i eth0 -n tcpdump -i eth0 -nn tcpdump -i eth0 -c 1000 tcpdump -i any
Capture Filters (BPF syntax) tcpdump -i eth0 host 192.168.1.100 tcpdump -i eth0 src host 192.168.1.100 tcpdump -i eth0 dst host 192.168.1.100 tcpdump -i eth0 net 192.168.1.0/24 tcpdump -i eth0 src net 10.0.0.0/8 tcpdump -i eth0 port 80 tcpdump -i eth0 port 80 or port 443 tcpdump -i eth0 portrange 8080-8090 tcpdump -i eth0 tcp tcpdump -i eth0 udp tcpdump -i eth0 icmp tcpdump -i eth0 arp tcpdump -i eth0 host 192.168.1.100 and port 443 tcpdump -i eth0 src 192.168.1.5 and dst port 80 tcpdump -i eth0 'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0' tcpdump -i eth0 port 53 -vvv tcpdump -i eth0 port 80 -A tcpdump -i eth0 not port 22 tcpdump -i eth0 not host 8.8.8.8 tcpdump -i eth0 'tcp[13] = 0x02' tcpdump -i eth0 'tcp[13] & 4 != 0' tcpdump -i eth0 'tcp[13] & 8 != 0'
Useful Capture Combinations tcpdump -i eth0 port 80 -A | grep -i "authorization\|password\|pass\|user\|login" tcpdump -i eth0 port 25 or port 587 or port 465 -A tcpdump -i eth0 'tcp[tcpflags] & tcp-syn != 0 and dst host TARGET_IP' tcpdump -i eth0 port 445 -w smb.pcap tcpdump -i eth0 port 21 -A tcpdump -i eth0 -w capture_%Y%m%d_%H%M%S.pcap -G 3600 -C 100
Wireshark Display Filters Protocol Filters # Basic protocols http https (use ssl or tls) dns tcp udp icmp arp smb smb2 ftp smtp pop imap ssh rdp kerberos ldap
IP / Network Filters # Source/destination IP ip.src == 192.168.1.100 ip.dst == 192.168.1.100 ip.addr == 192.168.1.100 # src OR dst # Subnet ip.src == 192.168.1.0/24 ip.addr == 10.0.0.0/8 # IPv6 ipv6.src == ::1 ipv6.addr == fe80::/10
TCP / UDP Filters # Port tcp.port == 80 tcp.dstport == 443 tcp.srcport == 1234 udp.port == 53 # TCP flags tcp.flags.syn == 1 # SYN packets tcp.flags.reset == 1 # RST packets tcp.flags.syn == 1 and tcp.flags.ack == 0 # SYN only (new connections) # TCP stream tcp.stream eq 5 # follow specific stream # Retransmissions / anomalies tcp.analysis.retransmission tcp.analysis.duplicate_ack tcp.analysis.zero_window
HTTP Filters # HTTP methods http.request.method == "POST" http.request.method == "GET" http.request.method == "PUT" # URI / paths http.request.uri contains "/admin" http.request.uri matches ".*\\.php" # Response codes http.response.code == 200 http.response.code == 302 http.response.code >= 400 # Headers http.host contains "target.com" http.cookie contains "session" http.authorization # show auth headers http.request.full_uri # show full URL # Body content http contains "password" http.request.line contains "login"
# HTTP Basic Auth http.authorization # Then decode: base64 decode the "Basic XXXX" part # FTP ftp.request.command == "PASS" ftp.request.command == "USER" # SMTP auth smtp.req.parameter contains "AUTH" # Telnet (cleartext) telnet # HTTP forms (POST data) urlencoded-form http.request.method == "POST" and urlencoded-form # Follow stream: right-click packet → Follow → TCP Stream
DNS Filters dns.qry.name contains "target.com" dns.resp.name contains "target.com" dns.flags.rcode != 0 # DNS errors dns.qry.type == 1 # A records dns.qry.type == 28 # AAAA records dns.qry.type == 16 # TXT records (DNS exfil)
TLS / SSL Filters tls.handshake.type == 1 # Client Hello tls.handshake.type == 2 # Server Hello tls.handshake.extensions_server_name # SNI (hostname in handshake) tls.record.content_type == 21 # Alert # Find handshakes (to see target domains even in encrypted traffic) tls.handshake.extensions.server_name contains "target.com"
Wireshark — Useful Features Statistics & Analysis Statistics → Protocol Hierarchy # see all protocols in captureStatistics → Conversations # list all TCP/UDP conversations Statistics → Endpoints # all IPs in captureStatistics → HTTP → Requests # all HTTP requestsStatistics → DNS # DNS query analysisAnalyze → Expert Information # errors, retransmissions, anomalies
File → Export Objects → HTTP File → Export Objects → SMB File → Export Objects → DICOMFile → Export Objects → IMF tshark -r capture.pcap --export -objects http,/tmp/extracted_http/
Decrypt TLS with Session Keys
tshark — Command Line Wireshark tshark -D tshark -i eth0 -f "port 80" -w output.pcap tshark -r capture.pcap -Y "http.request.method == POST" tshark -r capture.pcap -Y http.request -T fields -e http.host -e http.request.uri tshark -r capture.pcap -Y "dns" -T fields -e dns.qry.name | sort -u tshark -r capture.pcap -Y "http.authorization" -T fields -e http.authorization tshark -r capture.pcap -Y "http.request" -T fields \ -e frame.time -e ip.src -e ip.dst -e http.request.method -e http.request.full_uri tshark -r capture.pcap -q -z follow,tcp,ascii,0 tshark -r capture.pcap -q -z io,phs tshark -r capture.pcap --export-objects http,/tmp/http_objects/ tshark -i eth0 -Y "http.request.method == POST" -T fields \ -e ip.src -e http.host -e http.request.uri -e urlencoded-form.value
Common Analysis Scenarios tshark -r capture.pcap -Y arp -T fields -e arp.src.proto_ipv4 | sort -u tshark -r capture.pcap -Y "tcp.flags.syn==1 and tcp.flags.ack==0" \ -T fields -e ip.src -e ip.dst -e tcp.dstport | sort | uniq -c | sort -rn tshark -r capture.pcap -Y dns -T fields -e dns.qry.name | \ awk 'length($0) > 50' | sort -u tshark -r capture.pcap -Y http.request -T fields -e http.request.full_uri 2>/dev/null tshark -r capture.pcap -Y "tcp.len > 10000" \ -T fields -e ip.src -e ip.dst -e tcp.len tshark -r capture.pcap -Y "smb2.filename" -T fields -e smb2.filename | sort -u
No comments yet. Be the first.