Network Traffic Analysis with Wireshark (Debian/Ubuntu)

🧭 Two filter languages, and they are not the same

Wireshark has two kinds of filters, and most of the confusion comes from mixing them:

Capture filterDisplay filter
Decideswhat gets recordedwhat you see of what was recorded
LanguageBPF, the one of tcpdumpWireshark’s own
Exampletcp port 80tcp.port == 80
Wheretshark -f, the field on the welcome screentshark -Y, the bar above the packet list
A mistake costspackets lost forevernothing: change the filter

Hence the rule of thumb: capture wide, look narrow. When you are not sure what you are looking for, record more and filter the view.

The two look alike, so they get swapped. A capture filter typed into the display bar turns red and the status bar explains why:

A capture filter in the display filter bar: red, with an error in the status bar

The same intent as a display filter: green

πŸ“¦ Install, and the permission trap

sudo apt update
sudo apt install wireshark tshark
sudo usermod -aG wireshark $USER

Answer Yes when the installer asks whether non-superusers should be able to capture: capturing is then done by dumpcap, and only for members of the wireshark group.

The trap is that the group only counts from the next login. In the same session nothing changes:

tshark: Couldn't run dumpcap in child process: Permission denied
0 packets captured

And the graphical Wireshark, started from a desktop session that predates the group, is even more misleading: no error at all, simply no network interfaces in the list, only the “remote capture” entries:

Wireshark start screen with no network interfaces, only extcap entries

Log out and back in (or reboot), then check:

id -nG | grep -w wireshark || echo "not yet: log out and back in"
tshark -D

If you answered No during the installation:

sudo dpkg-reconfigure wireshark-common

🎯 Capture

# Interface names are enp2s0, ens3, wlp3s0... on current systems, rarely eth0
ip -br link

# Capture filter (BPF): decides what gets recorded
tshark -i enp2s0 -f "tcp port 80" -w http.pcapng

# In another terminal, generate some traffic
curl -s -o /dev/null http://example.com/

Ctrl+C stops tshark. In the GUI, the same capture filter goes in the field of the start screen, before double-clicking the interface. Save the file (-w, or File β†’ Save As): a capture you can reopen is worth more than one you watched scroll by.

πŸ”Ž What does the program actually send?

Reopen the capture with a display filter:

tshark -r http.pcapng -Y http.request
    4 0.014939878 192.168.122.18 β†’ 104.20.23.154 HTTP 140 GET / HTTP/1.1

In the GUI, select that packet and use Analyze β†’ Follow β†’ TCP Stream (Ctrl+Alt+Shift+T): Wireshark puts the whole conversation back together, request in red and answer in blue.

Follow TCP Stream: the HTTP request and the server’s answer

🚫 A refused connection looks like this

# Capture on loopback, then try a port where nothing listens
tshark -i lo -f "tcp port 81" -w rst.pcapng
curl http://localhost:81/        # curl: (7) Failed to connect

tshark -r rst.pcapng
    3 0.000085535    127.0.0.1 β†’ 127.0.0.1    TCP 74 35950 β†’ 81 [SYN] Seq=0 Win=65495 Len=0 ...
    4 0.000098947    127.0.0.1 β†’ 127.0.0.1    TCP 54 81 β†’ 35950 [RST, ACK] Seq=1 Ack=1 Win=0 Len=0

[SYN] and then [RST, ACK] from the target: the host is reachable and nothing is listening on that port. Filter for it with tcp.flags.reset == 1:

Packets with the RST flag in a refused connection

When instead only [SYN] packets appear, repeated with growing intervals and never answered, something is dropping them on the way (a firewall, a wrong route): a different problem, and a different place to look.

πŸ” HTTPS: decrypting your own traffic

TLS hides the content, but a client can be told to write down its session keys: with them Wireshark decrypts what that client sent and received. Nothing else.

# 1. Capture, and make the client write its session keys
tshark -i enp2s0 -f "tcp port 443" -w tls.pcapng
SSLKEYLOGFILE=$HOME/tls-keys.log curl -s -o /dev/null https://example.com/

# 2. Without the keys: only "Application Data"
tshark -r tls.pcapng -Y tls.app_data

# 3. With the keys: the HTTP inside
tshark -r tls.pcapng -o tls.keylog_file:$HOME/tls-keys.log -Y http

# The same in the GUI
wireshark -o tls.keylog_file:$HOME/tls-keys.log -r tls.pcapng
   11 0.041216857 192.168.122.18 β†’ 172.66.147.243 HTTP 162 GET / HTTP/1.1
   14 0.064270505 172.66.147.243 β†’ 192.168.122.18 HTTP 93 HTTP/1.1 200 OK  (text/html)

TLS traffic without the keys: Client Hello, then only Application Data

The same capture with the key log: GET and 200 OK in clear

curl honours SSLKEYLOGFILE (tested above); Firefox and Chromium-based browsers read the same variable when started from a terminal that sets it. In the GUI the setting lives in Edit β†’ Preferences β†’ Protocols β†’ TLS β†’ (Pre)-Master-Secret log filename.

πŸ“Š Who talks to whom

tshark -r http.pcapng -q -z conv,ip
================================================================================
IPv4 Conversations
Filter:<No Filter>
                                   |       <-      | |       ->      | |     Total     |
                                   | Frames  Bytes | | Frames  Bytes | | Frames  Bytes |
192.168.122.18 <-> 104.20.23.154        5 1271 bytes       7 544 bytes      12 1815 bytes
================================================================================

(Columns trimmed.) The -q matters: without it tshark first prints every packet and only then the statistics. In the GUI: Statistics β†’ Conversations and Statistics β†’ Protocol Hierarchy.

πŸ›°οΈ Capturing on a remote machine

# On the remote host your user must be in the wireshark group:
# ssh has no terminal to type a sudo password into
ssh user@remote-host "tshark -i enp2s0 -f 'not port 22' -w -" > remote.pcapng
wireshark remote.pcapng

The not port 22 is not optional. The capture travels back inside the SSH session it is capturing: every packet sent creates more packets to capture. In the test, 6 seconds on an almost idle link gave 42 packets, 40 of which were the SSH session itself; with the filter, 2.

πŸͺ€ Traps, in one table

SymptomCause
No interfaces in the GUI, no errorNot yet in the wireshark group in this session: log out and back in
Couldn't run dumpcap in child process: Permission deniedSame cause, from tshark
Red filter bar, "80" was unexpected in this contextA capture filter (BPF) typed as a display filter
A remote capture that is mostly SSHThe capture’s own transport: add not port 22
-z conv,ip floods the terminalMissing -q
HTTPS shows only “Application Data”No key log: SSLKEYLOGFILE on the client, then tls.keylog_file
eth0 does not existPredictable interface names: ip -br link

πŸ“š Resources