Skip to content
Tutorials Center
My learning

Topics

Lesson 56 of 80 ยท Security Operations and Incident Response

Network Traffic Analysis and Packet Capture

Learn how defenders capture and read network traffic: Wireshark and tcpdump basics, capture versus display filters, flow records, and spotting scans and exfiltration.

When something looks wrong on a network, logs tell you what applications said happened, but the network shows what actually crossed the wire. Network traffic analysis (NTA) is the practice of capturing and examining that traffic to find attacks, diagnose problems and gather evidence. It answers questions like: Which host is talking to that strange address? Is that connection encrypted? Did the file leave the network? Is a device scanning its neighbours?

There are two levels of detail. Packet capture records individual packets, sometimes with their full contents, and is read with tools such as Wireshark and tcpdump. Flow analysis keeps only a summary of each conversation (who, to whom, how much, when), which is far smaller and can run all the time. This lesson shows how both work, how to read captures defensively, and how to simulate both ideas in Python. Only capture traffic on networks you own or are authorized to monitor, because captures can contain passwords, personal data and private messages (Privacy and Data Protection). The lesson assumes the basics in Networking Essentials for Defenders.

Where traffic is captured

To see traffic you need a vantage point:

  • On the host: a capture running on the machine itself sees its own traffic, including decrypted data inside the application when a tool supports it.
  • SPAN or mirror port: the switch copies traffic from selected ports to a monitoring port.
  • Network TAP: a passive device inserted into a link that copies everything without loading the switch.
  • Cloud mirroring: virtual-network features copy traffic from instances or load balancers.
  • Gateways and proxies: perimeter devices see traffic crossing the boundary (Firewalls, Segmentation and Zero Trust).

On switched networks, a laptop in promiscuous mode sees only its own traffic and broadcasts, which is why mirroring or a TAP is needed. Remember encryption: with TLS you still see who talked to whom, when, and how much, but not the content, which is one reason metadata analysis matters (TLS, Certificates and PKI).

Wireshark and tcpdump

Wireshark is a graphical analyzer that decodes hundreds of protocols; tcpdump is its command-line cousin for servers; tshark is Wireshark's terminal version, and both read and write the pcap/pcapng file format. A typical Wireshark window has three panes: the packet list (one row per packet with time, source, destination, protocol, length and an info summary), the packet details (a tree showing each protocol layer, from Ethernet up to the application), and the packet bytes (the raw hex and ASCII). Useful features include:

  • Follow TCP stream: reassembles the conversation so you can read an entire request and response.
  • Statistics menu: protocol hierarchy, conversations and endpoints (who talks most), I/O graphs over time.
  • Expert information: flags retransmissions, resets and malformed packets.
  • Colouring rules and name resolution: easier reading, but name resolution can generate extra DNS traffic, so turn it off when investigating.
  • Export objects: extract files transferred over unencrypted HTTP, which is useful for malware analysis in a lab (Reverse Engineering Basics).

Capture filters vs display filters

Two kinds of filters are easy to mix up:

Capture filter Display filter
When it applies While recording After recording, on what you see
Syntax BPF (Berkeley Packet Filter), used by tcpdump Wireshark's own, with protocol fields
Effect Packets that do not match are never saved Packets are hidden but remain in the file
Example host 10.0.0.5 and port 443 ip.addr == 10.0.0.5 && tcp.port == 443

Use a capture filter to limit volume and privacy exposure on busy links, but be careful: data you filter out at capture time is gone. Use display filters to explore.

Common display filters:

TEXT
ip.addr == 192.0.2.10                 traffic to or from one host
tcp.port == 22                        SSH traffic
dns                                   DNS only
dns.qry.name contains "example"       DNS queries for matching names
http.request.method == "POST"         HTTP uploads
tcp.flags.syn == 1 && tcp.flags.ack == 0   connection attempts (SYN, no ACK)
tcp.analysis.retransmission           retransmitted packets
tls.handshake.type == 1               TLS client hello (shows server name)
frame.time_delta > 1                  gaps of more than one second

Reading a capture is mostly pattern recognition: a normal TCP connection begins with the three-way handshake (SYN, SYN-ACK, ACK), ends with FIN or RST, and has a steady flow of ACKs. Many SYNs to different ports with RSTs back suggest a scan; a series of DNS queries for long random-looking names suggests tunnelling or generated domains (Botnets and Command-and-Control); cleartext credentials in HTTP, FTP or Telnet mean those protocols must be replaced.

Filtering a capture in code

Below is a small, synthetic "capture" as a list of records, plus a mini display-filter function. It lets you practise the thinking without any real network data.

Python Query a synthetic packet capture

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 filters recover three findings: DNS activity (one query with a long random-looking name worth investigating), a burst of SYNs to different ports (a scan, answered with RST), and cleartext credentials in an HTTP POST. A real capture has millions of packets, which is why analysts rely on filters and statistics rather than reading rows.

Flow analysis and NetFlow

Full capture is expensive: a busy link produces gigabytes per minute and raises privacy concerns. Flow records (NetFlow, IPFIX, sFlow, cloud VPC flow logs) summarize each conversation with a handful of fields: source and destination address and port, protocol, packet and byte counts, start and end time, and TCP flags. They hold no payload, so they are small, cheap to keep for months, and very good for answering "who talked to whom, and how much".

Full packet capture Flow records
Detail Everything on the wire, including payloads Metadata summaries only
Storage Very large Small
Privacy High risk Lower
Best for Deep investigation, protocol bugs, evidence Baselines, scan and exfiltration detection, long retention

Flow data supports several detections, which SOC analysts build into their SIEM rules (Logging, Log Analysis and SIEM): a host contacting many internal addresses or ports (scan or lateral movement), an unusually large amount of outbound data to one external address (exfiltration), connections at odd hours, regular small connections (beaconing), and traffic to destinations never seen before.

Python Detect scans and exfiltration from flow records

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 no payload was needed: counts and addresses alone expose a scanning host (10.0.0.9, 60 targets on port 445) and one machine uploading 450 MB to a single external address. Flag these as leads, then confirm with packet capture, endpoint data and context (a backup job, a software update) before acting (The Incident Response Process).

Reading a capture defensively: a checklist

  1. Define the question first (which host, which time window), then capture or filter narrowly.
  2. Get the big picture: protocol hierarchy, top talkers and conversations, and a timeline.
  3. Look for what should not exist: cleartext protocols (Telnet, FTP, HTTP logins), outdated TLS versions, direct connections to IP addresses, DNS to unusual servers, and internal hosts talking to each other when they should not.
  4. Check the rhythm: regular intervals, constant packet sizes and traffic at unusual hours.
  5. Follow the stream for anything suspicious, then extract indicators (IP addresses, domains, hashes of transferred files).
  6. Preserve evidence: save the original capture file read-only, record its hash, and note times and sensor locations (Digital Forensics Basics).
  7. Correlate: match what you saw on the wire to host logs and alerts (Spotting Attacks in Logs).

Tools beyond Wireshark

Purpose Examples
Command-line capture tcpdump, tshark, dumpcap
Network security monitoring Zeek (rich connection and protocol logs), Suricata (IDS with traffic logging)
Flow collection and analysis NetFlow/IPFIX collectors, nfdump, SiLK, cloud flow logs
Full-packet recorders Arkime (formerly Moloch), commercial packet brokers
Detection platforms NDR (network detection and response) products, SIEM correlation (Intrusion Detection and Network Monitoring)

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

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

    Packets excluded by a capture filter are never stored, while display filters can be changed freely during analysis.
  2. 2. What kind of data do flow records contain?

    Flows summarize conversations without payload, which makes them small, long-lived and less privacy-intrusive.
  3. 3. A host sends SYN packets to dozens of ports on another host and receives RSTs. What does this most likely indicate?

    Many connection attempts to different ports, mostly refused, is the classic scan pattern. Confirm it against known scanners such as authorized vulnerability tools.
  4. 4. Why might you need a SPAN port or network TAP to capture traffic?

    Switches forward unicast traffic only to its destination port, so you need mirroring or a TAP to see other hosts' conversations.

Summary

  • Network traffic analysis shows what really crossed the wire; capture only on networks you are authorized to monitor, because captures hold sensitive data.
  • Traffic is collected through host captures, SPAN ports, TAPs, cloud mirroring and gateways; Wireshark, tshark and tcpdump read pcap files.
  • Capture filters (BPF) limit what is recorded; display filters explore what is saved. Learn the TCP handshake and common filters.
  • Flow records (NetFlow, IPFIX, VPC flow logs) are small summaries, ideal for baselines, scan and exfiltration detection and long retention.
  • Follow a checklist: define the question, get the big picture, look for cleartext and rare destinations, check rhythm, follow streams, preserve evidence and correlate with logs.

Next: Network and Mobile Forensics.