Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 31 ยท Scanning and Enumeration Concepts

Packet Capture and Analysis

Learn how Wireshark and tcpdump capture traffic, how capture and display filters differ, how to read a TCP handshake and how to spot cleartext protocols in a capture.

When a tool says "connection refused" or a user says "the site is slow", the network itself knows exactly what happened. A packet capture records the traffic so you can read it afterwards. It is the ground truth for troubleshooting and for security work: you can see which hosts talk, which protocols they use, whether a handshake completes, and whether passwords cross the wire in plain text. Kali includes both Wireshark (a graphical analyzer) and tcpdump (a command-line capture tool). This lesson explains how they work and how to read what they show.

Capture only networks you own or are authorized to monitor. Packets contain other people's data, and recording them can be illegal without permission (Law, Ethics and Authorization). The commands here are read-only on this site; the runnable examples decode invented bytes.

How capture works

A network card normally hands the operating system only frames addressed to it. A capture tool asks the OS to deliver a copy of the frames it sees on an interface. On a switched network you only see your own traffic plus broadcasts, unless you capture on the device itself (a server, a router) or a switch port is configured to mirror traffic to you (a SPAN port). Captures are saved as .pcap or .pcapng files that any analyzer can open.

Two tools, one idea

tcpdump Fast, scriptable, works over SSH.
Wireshark Rich GUI with protocol decoders.
pcap file Capture on one, analyze in the other.

Capture on a server with tcpdump, then study the file in Wireshark.

1 / 2

tcpdump essentials

Terminal
sudo tcpdump -i eth0 -nn -c 5 'tcp port 80'
sudo tcpdump -i eth0 -w capture.pcap 'host 192.0.2.10 and port 443'
tcpdump -nn -r capture.pcap
  • -i eth0 selects the interface; -nn disables name and service lookups so you see raw addresses and port numbers (and so tcpdump does not generate DNS traffic itself).
  • -c 5 stops after five packets; -w writes a file; -r reads one.
  • The quoted expression is a capture filter.

A typical line of output, with invented addresses, looks like this:

TEXT
10:02:11.482 IP 192.0.2.50.51432 > 192.0.2.10.80: Flags [S], seq 3120, win 64240, length 0
10:02:11.482 IP 192.0.2.10.80 > 192.0.2.50.51432: Flags [S.], seq 7788, ack 3121, win 65160, length 0
10:02:11.483 IP 192.0.2.50.51432 > 192.0.2.10.80: Flags [.], ack 7789, win 502, length 0

Read it as "time, protocol, source.port > destination.port, flags". In tcpdump, [S] is SYN, [S.] is SYN+ACK (the dot means ACK), [.] is a plain ACK, [P.] is push+ack with data, [F.] is FIN, [R] is reset. Those three lines are the complete three-way handshake from TCP/IP Essentials for Security.

Capture filters vs display filters

These are two different languages, and mixing them up is the most common beginner mistake.

Capture filter Display filter
Used by tcpdump, Wireshark capture Wireshark view
Applied While recording; unmatched packets are never stored After recording; hides packets from view
Syntax BPF: host 192.0.2.10 and tcp port 80 ip.addr == 192.0.2.10 && tcp.port == 80

Use capture filters to keep files small on busy links, but remember that you cannot recover what you did not capture. Display filters can be changed freely. Handy Wireshark display filters:

TEXT
tcp.flags.syn == 1 && tcp.flags.ack == 0     # connection attempts
http.request.method == "POST"                # form submissions
dns                                          # name lookups
tcp.analysis.retransmission                  # signs of packet loss

Wireshark can also reassemble a whole conversation ("Follow TCP Stream") so you can read a request and its answer as text.

Spotting cleartext protocols

Protocols designed before encryption was common still run on many networks: HTTP (80), FTP (21), Telnet (23), SMTP without TLS (25), POP3 (110), IMAP (143) and SNMP v1/v2c (161). Anyone who can capture the traffic can read credentials and content. A defensive review of a capture asks:

  • Do any logins or tokens appear in readable text?
  • Which hosts still use these protocols, and can they move to the encrypted versions (HTTPS, SFTP/SSH, IMAPS)?
  • Is anything unexpected talking to the internet, such as a device with a chatty protocol?

Encrypted traffic (TLS) still leaks metadata: addresses, ports, timing, sizes and often the server name. You can see who talks to whom, but not what is said.

Stand-in: decode sample packets

The first TryIt decodes a few invented frames from a "capture": it unpacks the TCP flags and prints lines in a tcpdump-like style. The bytes are made up; the field layout is the real TCP header format.

Python Decode a handshake from raw bytes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The second TryIt scans decoded payloads for cleartext credentials, the check a defender would do on a capture of their own lab. The payloads are invented.

Python Find cleartext credentials in sample payloads

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the stand-in prints only the user name, not the password. In a real review, treat captured secrets as sensitive data: store pcaps securely, redact them in reports and rotate any credential that was exposed.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main difference between a capture filter and a display filter?

    Capture filters use BPF syntax and discard unmatched packets at record time. Display filters are Wireshark's own language applied afterwards.
  2. 2. In tcpdump output, what does Flags [S.] mean?

    S is SYN and the dot stands for ACK. Together they are the server's reply to a connection attempt.
  3. 3. Why does tcpdump use -nn in many examples?

    -nn turns off name and port-name resolution, which keeps output exact and stops lookups from adding traffic.
  4. 4. What can an observer still learn from a fully TLS-encrypted capture?

    Encryption hides content, not the fact of communication. Who talked to whom and how much remains visible.

Summary

  • Capture tools record copies of frames; tcpdump suits servers and scripts, Wireshark suits deep analysis.
  • Capture filters (BPF) limit what is stored; display filters change the view of a stored capture.
  • A handshake in tcpdump reads [S], [S.], [.].
  • Cleartext protocols (HTTP, FTP, Telnet, POP3, IMAP, SNMPv1/v2c) expose credentials to anyone who can capture.
  • TLS hides content but not metadata. Handle pcaps like sensitive data.
  • The Python examples decode invented bytes as stand-ins for an analyzer.

Next: Vulnerability Assessment Workflow