Capturing network traffic in pcap/pcapng¶
The following are some common methods for capturing network traffic in PCAP or PCAPNG format.
Wireshark: Capture network traffic in pcap format¶
Wireshark provides a convenient way to capture network traffic and export it in PCAP format for further analysis.
To capture network traffic in PCAP using Wireshark:
Identify the network interface card (NIC) on which network traffic will be captured. Select it and click the fin icon on the top left to start packet capture.
Wait until a sufficient number of packets has been captured. Click the red square icon on the top left to stop packet capture.
Click
File > Save As. InSave as, selectWireshark/tcpdump/... - pcap, enter a file name, and clickSave.
Wireshark: Capture network traffic in pcapng format¶
Wireshark provides a convenient way to capture network traffic and export it in PCAPNG format for further analysis.
To capture network traffic in PCAPNG using Wireshark:
Identify the network interface card (NIC) on which network traffic will be captured. Select it and click the fin icon on the top left to start packet capture.
Wait until a sufficient number of packets has been captured. Click the red square icon on the top left to stop packet capture.
Click
File > Save As. InSave as, selectWireshark/... - pcapng, enter a file name, and clickSave.
tcpdump: Capture network traffic in pcap format¶
tcpdump is a CLI tool useful for capturing network traffic on headless Linux devices, such as Ubuntu Server environments, and can also be used in shell scripts for automated packet capture workflows.
To capture network traffic in PCAP using tcpdump:
Run the following command to identify the network interface card (NIC) on which network traffic will be captured.
ip addrRun the following command to begin a basic packet capture. Replace
your_nicwith the NIC from which traffic is captured. For additional packet capture configuration options, refer to the official tcpdump manual.sudo tcpdump -i your_nic -s 0 -w packets.pcapWait until a sufficient number of packets has been captured. Press
Ctrl + Cto end network traffic capture.
Fig. 31 Finding your NIC¶
tshark: Capture network traffic in pcapng format¶
TShark is a terminal-oriented version of Wireshark useful for capturing network traffic on headless Linux devices, such as Ubuntu Server environments, and can also be used in shell scripts for automated packet capture workflows.
To capture network traffic in PCAPNG using TShark:
Run the following command to identify the network interface card (NIC) on which network traffic will be captured.
ip addrRun the following command to begin a basic packet capture. Replace
your_nicwith the NIC from which traffic is captured. For additional packet capture configuration options, refer to the official tshark manual.sudo tshark -i your_nic -w /tmp/packets.pcapngWait until a sufficient number of packets has been captured. Press
Ctrl + Cto end network traffic capture.
Fig. 32 Finding your NIC¶
Filtering for TLS, SSH and IPsec¶
Filtering a capture to TLS, SSH and IPsec keeps the file small and focused on the handshakes PacketQC analyses.
Capture filters are set before capturing. Only matching packets are recorded.
Display filters only hide packets from view. They do not remove them from the file.
Protocol |
Default ports |
Capture filter |
Display filter |
|---|---|---|---|
TLS (for example, HTTPS) |
TCP 443 |
|
|
TLS 1.3 over QUIC |
UDP 443 |
|
|
SSH |
TCP 22 |
|
|
IPsec (IKEv1 and IKEv2) |
UDP 500 and UDP 4500 |
|
|
IKEv1 only |
UDP 500 and UDP 4500 |
|
|
IKEv2 only |
UDP 500 and UDP 4500 |
|
|
To capture all of them in one file:
tcp port 443 or udp port 443 or tcp port 22 or udp port 500 or udp port 4500
If your services use other ports, add them to the filter, for example or tcp port 8443.
Note
Start capturing before connections open. PacketQC needs each connection’s handshake, so a connection that is already open, such as an existing SSH session, will not appear until it reconnects.
Wireshark: Capture with a capture filter
On the Wireshark start screen, select the network interface card (NIC) on which network traffic will be captured.
In the capture filter field (
Enter a capture filter), enter a capture filter from the table above. The field turns green when the filter is valid.Click the fin icon on the top left to start packet capture.
Wait until a sufficient number of packets has been captured. Click the red square icon on the top left to stop packet capture.
Save the capture as described in Wireshark: Capture network traffic in pcap format or Wireshark: Capture network traffic in pcapng format.
Wireshark: Check that the capture contains handshakes
In the display filter bar (
Apply a display filter), enter a display filter from the table above, such astls.handshake, and pressEnter.If no packets are shown, there are no handshakes for that protocol. Capture again, starting before the connections open.
SSH on a non-standard port
PacketQC detects SSH on any port. By default, Wireshark only labels traffic as SSH on port 22, so SSH on other ports needs extra steps:
To find SSH on any port, use the display filter
tcp contains "SSH-".To view the traffic as SSH, click
Analyze > Decode As..., add an entry for the TCP port, and selectSSH. Thesshdisplay filter then shows the traffic on that port.When capturing, add the port to the capture filter, for example
tcp port 22 or tcp port 2222.
Wireshark: Save a smaller file from an existing capture
Enter this display filter to show the TLS, SSH and IPsec traffic on the default ports:
tcp.port == 443 or udp.port == 443 or tcp.port == 22 or udp.port == 500 or udp.port == 4500Click
File > Export Specified Packets....Under
Packet Range, make sureAll packetsandDisplayedare selected.Select the pcap or pcapng format, enter a file name, and click
Save.
Warning
Export by port, not with the handshake filters (tls.handshake, ssh or isakmp). Post-quantum handshakes are often split across several packets, and a handshake-only export drops parts of them, so PacketQC cannot read those connections.
Tip
PacketQC also accepts gzip-compressed captures (.gz). In the Wireshark save dialog, select Compress with gzip to reduce the file size.
tcpdump and TShark: Capture with a capture filter
Add the capture filter to the end of the tcpdump command, or after the -f option for TShark:
sudo tcpdump -i your_nic -s 0 -w packets.pcap 'tcp port 443 or udp port 443 or tcp port 22 or udp port 500 or udp port 4500'
sudo tshark -i your_nic -f "tcp port 443 or udp port 443 or tcp port 22 or udp port 500 or udp port 4500" -w /tmp/packets.pcapng