05: Packet analysis with Wireshark & tshark
On this page
- 1. The capture engine (architecture)
- 2. Capture filters (BPF) vs display filters: a critical distinction
- 3. Core display filters (your daily toolkit)
- 4. Following & reassembling streams
- 5. Extracting cleartext credentials
- HTTP form POST (web-target, 10.77.0.10)
- FTP login (ftp-service, 10.77.0.20)
- Telnet (concept)
- Exporting captured objects (files transferred over HTTP)
- 6. Headless analysis with tshark
- Defensive counter-measures (blue-team lens)
- Common troubleshooting
Once you can capture traffic, the skill becomes reading it: reconstructing
what happened on the wire, extracting cleartextData sent without encryption, so anyone who can see the traffic can read it. HTTP, FTP, and Telnet send passwords in cleartext. secrets from insecure protocols,
and explaining how to fix it. This module covers the capture engine,
the two very different filter languages, the core display filters you'll reach
for daily, session reassembly, credential extraction, and headless analysis with
tshark. Practice against the bundled Docker lab.
Run the lab first: from the repo root,
./scripts/setup-lab-env.sh, then./scripts/setup-lab-env.sh shellto get a shell on the attacker box (10.77.0.5). Commands in this module assume that shell, where the lab interface iseth0. If you run Kali natively on a Linux host that runs Docker itself, capture onbr-pentestlabinstead (notdocker0; the lab uses its own bridge). Only ever sniff traffic you are authorized to see.Capture and generate traffic from the same place. Browsing
127.0.0.1:8080from your host goes through Docker's port proxy on the loopback interface, so a capture oneth0/br-pentestlabwould show the gateway10.77.0.1as the client, not you.
1. The capture engine (architecture)#
Wireshark itself doesn't touch the NIC, a packet-capture library does:
| Platform | Library | Notes |
|---|---|---|
| Linux/Kali | libpcap | Kernel hands frames up via AF_PACKET |
| Windows | Npcap (successor to WinPcap) | Installs a driver; supports loopback + monitor modeA Wi-Fi card mode that records every frame on a channel, including other people's, without joining a network. Needed to capture handshakes. |
Two capture modes to distinguish:
- Promiscuous mode: the NIC accepts all frames on the wire segment it can see, not just those addressed to it. On a switched network you mostly see your own traffic + broadcast/multicast unless the switch is mirroring a port. This is for wired/Ethernet sniffing.
- Monitor mode (RFMON): the wireless equivalent from module 04: capture raw 802.11 frames off the air. Different mechanism, different use case.
On Kali, Wireshark needs capture privileges. The clean way:
# [Level 1: Intermediate] Allow non-root capture (recommended)
sudo dpkg-reconfigure wireshark-common # answer "Yes" to non-superuser capture
sudo usermod -aG wireshark "$USER" # then log out / back in
groups | grep wireshark # confirm membership
2. Capture filters (BPF) vs display filters: a critical distinction#
Wireshark has two entirely different filter languages, and mixing them up is the #1 beginner confusion.
| Capture filterA filter applied while capturing, written in BPF. Anything it excludes is never saved. Compare display filter. (BPFThe capture filter language used by tcpdump, tshark -f, and Wireshark's capture dialog, for example host 10.77.0.20 and port 21. It decides which packets are recorded at all.) | Display filterA Wireshark or tshark -Y filter applied to packets already captured, for example ftp.request.command == "PASS". It hides packets from view but does not delete them. | |
|---|---|---|
| When applied | Before capture: decides what hits disk | After capture: decides what's shown |
| Language | Berkeley Packet Filter (tcpdump syntax) |
Wireshark's own expression language |
| Example | tcp port 80 |
http.request.method == "POST" |
| Can you recover filtered-out packets? | No: they were never recorded | Yes: clear the filter, they're still there |
| Memory/disk cost | Low: you only store what matches | High: everything is captured, then hidden |
Rule of thumb: use a capture filter to keep huge/high-rate captures manageable (you know in advance you only care about one host/port). Use a display filter for exploratory analysis, when you don't yet know what you're looking for and don't want to lose anything.
BPF capture filter examples (note the tcpdump-style syntax):
host 10.77.0.10
net 10.77.0.0/24
tcp port 80 or tcp port 21
src host 10.77.0.10 and not port 22
ether host aa:bb:cc:11:22:33
Display filter examples (note the protocol.field == value syntax):
ip.addr == 10.77.0.10
tcp.port == 80 && http
http.request.method == "POST"
ftp || ftp-data
They are not interchangeable, tcp port 80 is a syntax error in the
display bar; http.request.method == "POST" is illegal as a capture filter.
3. Core display filters (your daily toolkit)#
# --- Addressing & ports -----------------------------------------------------
ip.addr == 10.77.0.10 # traffic to OR from that host
ip.src == 10.77.0.10 # only sourced from it
ip.dst == 10.77.0.20 # only destined to it
tcp.port == 21 # either side is port 21
ip.addr == 10.77.0.10 && tcp.port == 80 # combine (X && Y)
# --- HTTP -------------------------------------------------------------------
http # all HTTP
http.request # requests only
http.request.method == "POST" # POSTs (where form creds live!)
http.request.method == "GET"
http.response.code == 200
http.host contains "acme"
# --- Credential hunting (cleartext protocols) -------------------------------
tcp contains "password" # any packet whose bytes contain the word
tcp contains "USER" || tcp contains "PASS" # FTP/POP/IMAP login verbs
ftp.request.command == "USER" # FTP username
ftp.request.command == "PASS" # FTP password (cleartext!)
http.authorization # HTTP Basic-Auth header (base64, trivially decoded)
# --- DNS --------------------------------------------------------------------
dns # all DNS
dns.flags.response == 0 # queries only (0 = request)
dns.flags.response == 1 # responses only
dns.qry.name contains "example"
# --- TCP mechanics / troubleshooting ----------------------------------------
tcp.flags.syn == 1 && tcp.flags.ack == 0 # connection attempts (SYN only)
tcp.flags.reset == 1 # RSTs (refused/closed)
tcp.analysis.retransmission # retransmits (loss/latency)
tcp.stream eq 3 # everything in TCP stream #3
# --- Booleans & negation ----------------------------------------------------
http && ip.addr == 10.77.0.10 # AND (&& or 'and')
ftp || http # OR (|| or 'or')
!(arp || dns) # NOT, hide noise
containsvsmatches:tcp contains "password"does a literal byte search;frame matches "pass.*word"applies a regex.containsis faster;matchessupports regular expressions.
4. Following & reassembling streams Level 2+: Advanced#
A single logical conversation (a login, a page load) is spread across many packets. Wireshark reassembles them:
- Right-click a packet → Follow → TCP Stream (or HTTP/UDP/TLS Stream). This stitches both directions of the conversation into one readable transcript, the fastest way to see a cleartext login or an HTTP request/response pair.
- The dialog shows client bytes and server bytes in different colors; you can switch the "Show as" view to ASCII, Hex Dump, or Raw.
- Filtering to one stream:
tcp.stream eq N(Wireshark fills in N when you follow a stream).
Statistics menu tools that pay off fast:
- Statistics → Conversations: every host/port pair, byte counts; find the loudest talkers.
- Statistics → Protocol Hierarchy: what protocols are present and in what proportion.
- Statistics → Endpoints: per-host totals, geolocation.
5. Extracting cleartext credentials Level 2+: Advanced#
These labs show why unencrypted protocols expose credentials to anyone who can see the traffic. Using the Docker lab:
HTTP form POST (web-target, 10.77.0.10)#
- Start capturing on the lab interface with display filter cleared, e.g. in
the attacker shell:
tshark -i eth0 -f "tcp port 80" -w web.pcapng &, thensleep 2. tsharkThe command-line version of Wireshark, for capturing and reading packets without a GUI. needs a moment to open the interface; traffic sent before that is lost. - Submit the login form from the same box:
curl -s -d 'username=admin&password=hunter2' http://10.77.0.10/login(With a GUI Kali on the lab network you can instead browsehttp://10.77.0.10/and click Sign in.) Thensleep 1so the last packets reach the file, and stop the capture withkill %1. - Open
web.pcapng(or usetshark -r web.pcapng -Y ...) and apply:http.request.method == "POST". - Select the POST and expand HTML Form URL Encoded in the detail pane, or
Follow → HTTP Stream. The
username=admin&password=hunter2body is right there in cleartext.
FTP login (ftp-service, 10.77.0.20)#
# Generate FTP auth traffic while capturing (cleartext USER/PASS on port 21)
tshark -i eth0 -f "tcp port 21" -w ftp.pcapng &
sleep 2 # let tshark open the interface first
curl -s ftp://labuser:labpass@10.77.0.20/ # or interactively: ftp 10.77.0.20
sleep 1 # let the last packets reach the file
kill %1
Apply ftp and read the command stream directly:
Request: USER labuser
Response: 331 Please specify the password.
Request: PASS labpass <- the password, in the clear
Response: 230 Login successful.
Telnet (concept)#
Telnet transmits every keystroke in cleartext, including the password one
character at a time. Follow → TCP Stream on a telnet session reconstructs the
entire interactive session, credentials included, the historical reason SSH
replaced it.
Exporting captured objects (files transferred over HTTP)#
File → Export Objects → HTTP lists every file that crossed the wire over HTTP (images, downloads, uploaded documents) and lets you save them to disk.
6. Headless analysis with tshark Level 2+: Advanced#
tshark is Wireshark's CLI. Essential for servers, scripting, and processing
capture files without a GUI, and the only realistic option under WSL2.
# List capture interfaces
tshark -D
# [Level 1: Intermediate] Live capture with a BPF capture filter, write to file
sudo tshark -i eth0 -f "tcp port 80 or tcp port 21" -w lab.pcapng
# Read a saved capture and apply a DISPLAY filter (-r read, -Y display filter)
tshark -r lab.pcapng -Y 'http.request.method == "POST"'
# Print only chosen fields (great for grep/CSV pipelines)
tshark -r lab.pcapng -Y ftp -T fields \
-e frame.number -e ip.src -e ftp.request.command -e ftp.request.arg
# Extract HTTP POST bodies / form fields
tshark -r lab.pcapng -Y 'http.request.method=="POST"' \
-T fields -e http.file_data
# One-liner credential sweep across a capture
tshark -r lab.pcapng -Y 'ftp.request.command=="USER" || ftp.request.command=="PASS"' \
-T fields -e ftp.request.command -e ftp.request.arg
# Protocol statistics without the GUI
tshark -r lab.pcapng -q -z io,phs # protocol hierarchy
tshark -r lab.pcapng -q -z conv,tcp # TCP conversations
tshark -r lab.pcapng -q -z endpoints,ip # per-IP endpoint totals
# Follow a specific TCP stream from the CLI
tshark -r lab.pcapng -q -z follow,tcp,ascii,3
Expected field-extraction output:
5 10.77.0.5 USER labuser
9 10.77.0.5 PASS labpass
dumpcap is the lightweight capture-only tool Wireshark/tshark use under the
hood; for long unattended captures with ring buffers use it directly:
sudo dumpcap -i eth0 -b filesize:100000 -b files:10 -w rolling.pcapng
Defensive counter-measures (blue-team lens)#
Every extraction above has a one-line fix:
- Encrypt everything in transit. HTTPS (TLS) instead of HTTP; FTPS/SFTP instead of FTP; SSH instead of Telnet. TLS turns the credential-in-the- clear labs into undecryptable ciphertext for a passive sniffer.
- HSTS to prevent HTTP downgrade; disable plaintext protocol fallbacks.
- Network segmentation + port security so an attacker can't easily get a mirror/tap position; 802.1X to authenticate devices onto the LAN.
- Detection: an IDS (Suricata/Zeek) watching for cleartext credentials,
unexpected plaintext protocols, or a NIC entering promiscuous mode
(
ip linkshowsPROMISC) is your sensor. - Remember: even with TLS, metadata (who talks to whom, when, how much) leaks, the Statistics tools above still reveal conversation patterns.
Common troubleshooting#
| Symptom | Cause | Fix |
|---|---|---|
| No interfaces listed / permission denied | Missing capture privileges | sudo dpkg-reconfigure wireshark-common; add self to wireshark group |
| Capture is empty | Wrong interface, or switched network isolates you | In the attacker container use eth0; on a Linux host running Docker natively use br-pentestlab (never docker0, which the lab does not use); confirm with tshark -D |
| See only your own traffic | Switched LAN (no port mirror) | Use the Docker lab, a hub/tap, or SPAN port |
| HTTPS payloads unreadable | TLS encryption (working as intended) | Need server key or SSLKEYLOGFILE; passive decrypt is otherwise impossible |
| "capture filter syntax error" | Used a display filter in the capture box | Capture box = BPF (tcp port 80); display bar = http.request |
| tshark: "couldn't run dumpcap" | Privilege/group issue | Run under sudo or fix the wireshark/setcap permissions |
| Huge file, Wireshark sluggish | Captured everything | Use a capture (BPF) filter next time; or slice with editcap |
Prove it on the lab with the self-grading Lab exercises: Packet analysis with Wireshark & tshark. The filter for each common task is in Wireshark and tshark filters.