Cyber Services / All lessons / CEH — Ethical Hacking / Network Traffic Monitoring & Analysis

Network Traffic Monitoring & Analysis

Module 60 of 130 · 9 min read · Free to read

MODULES ↓ Command blocks have a COPY button
The Role of Network Monitoring in Ethical Hacking

For a Certified Ethical Hacker (CEH), understanding and analyzing network traffic is critical across multiple phases of an engagement:

  • Reconnaissance: Passively discovering hosts, services, and network topology by observing broadcast traffic (ARP, DHCP, NetBIOS) or baseline communications.
  • Scanning Analysis: Observing network responses during active scans (e.g., Nmap) to understand firewall rules, IDS/IPS behavior, and target system responses.
  • Exploitation Analysis: Monitoring traffic during exploit attempts to troubleshoot failures or confirm success (e.g., reverse shell callbacks).
  • Post-Exploitation: Identifying Command & Control (C2) channels, detecting data exfiltration attempts, monitoring lateral movement.
  • Security Auditing & Defense: Establishing baselines, detecting anomalies, identifying misconfigurations, verifying security control effectiveness (firewall rules, IDS signatures).

Kali Linux provides a rich arsenal of tools for these tasks, ranging from high-level dashboards to deep packet inspection.

Legality and Ethics: Network traffic can contain sensitive information. Always ensure you have explicit, written authorization before monitoring any network or capturing packets. Unauthorized monitoring is illegal and unethical. Use these techniques responsibly in controlled lab environments or during authorized penetration tests.

I. Real-time Interface Statistics & High-Level Usage

These tools provide immediate visibility into traffic rates, top connections, and overall interface health, crucial for quick assessments and anomaly detection.

iftop

Displays bandwidth usage sorted by connection pairs (source/destination). Excellent for identifying "top talkers" and visualizing active flows.

sudo iftop -i eth0 -n -N -P -B

-i eth0: Specify interface.
-n: Don't resolve hostnames (essential for speed and seeing raw IPs).
-N: Show port numbers instead of service names.
-P: Show ports in the host display.
-B: Display bandwidth rates in Bytes per second (useful for comparison).
Press 'h' inside for help (e.g., 's'/'d' to hide source/destination).

CEH Use Case: Quickly spot potential C2 server connections (unexpected external IPs), identify hosts involved in large data transfers (exfiltration?), detect sources of DoS traffic, see active scanning activity by connection counts.
iptraf-ng

A versatile ncurses-based monitor providing multiple views: general/detailed interface stats, TCP/UDP traffic by port, packet size distribution, and LAN station monitor (detects active hosts via broadcasts).

sudo iptraf-ng

Navigate the menus. 'Detailed interface statistics' and 'TCP/UDP traffic monitor' are very useful. The LAN station monitor helps in passive reconnaissance.

CEH Use Case: Visualize traffic distribution by protocol/port (spotting unusual services), detect ARP spoofing attempts (via LAN monitor warnings), identify broadcast storms, monitor for specific flags (e.g., high SYN rate in TCP monitor).
nload / bmon / speedometer

Simple console tools for visualizing real-time network traffic throughput as graphs. Good for understanding overall load.

# nload (Human-readable units)
nload -u H devices eth0

# bmon (Detailed stats for interface)
bmon -p eth0

# speedometer (Separate Rx/Tx graphs)
speedometer -r eth0 -t eth0
CEH Use Case: Visually confirm the impact of a DoS attack (sustained high traffic), identify bandwidth saturation points, monitor egress traffic during simulated exfiltration tests.
ip -s link (with watch)

Provides detailed packet/byte counters and crucially, error/drop counters for an interface. The modern `ifconfig` replacement for stats.

watch -n 1 -d 'ip -s link show eth0'

watch -n 1 -d: Refresh every second, highlight changes.
ip -s link show eth0: Show detailed stats for `eth0`. Look at RX/TX packets, bytes, errors, dropped.

CEH Use Case: Detect network interface issues, spot potential signs of overwhelming traffic (rapidly increasing dropped packets during a DoS), track total data transfer over time.

II. Packet Capturing & Deep Dive Analysis

Capturing raw packets is essential for understanding exactly what's happening on the wire. These tools allow filtering, saving, and dissecting network traffic.

tcpdump

The fundamental command-line packet sniffer. Powerful filtering (BPF syntax) allows capturing precisely the traffic of interest.

# Capture first 100 packets, show link-layer headers, no name resolution
sudo tcpdump -i eth0 -c 100 -e -n

# Capture all TCP SYN packets (potential scan detection)
sudo tcpdump -i eth0 'tcp[tcpflags] & tcp-syn != 0 and tcp[tcpflags] & tcp-ack == 0' -n

# Capture traffic to/from a specific host and port, show ASCII payload
sudo tcpdump -i eth0 host 192.168.1.10 and port 80 -A -n

# Capture traffic, excluding SSH, and write to file
sudo tcpdump -i eth0 not port 22 -w capture_`date +%Y%m%d_%H%M%S`.pcap -n

# Read file and display packets matching a filter
tcpdump -r capture.pcap 'host 10.0.0.5' -n

BPF (Berkeley Packet Filter) syntax is used directly on the command line for *capture* filtering. -w saves to file, -r reads from file. -A shows printable payload.

CEH Use Case: Essential for evidence gathering, analyzing specific protocol interactions (ARP, DHCP, DNS, HTTP), capturing credentials sent in clear text (HTTP POST, FTP, Telnet), identifying scan types (SYN, FIN, XMAS scans), troubleshooting exploit failures by examining traffic flow.
tshark

The command-line engine for Wireshark. Can capture like `tcpdump` but excels at reading capture files and applying Wireshark's powerful *display filters* and dissectors for detailed analysis in the terminal.

# Capture on eth0, resolve network/transport names
sudo tshark -i eth0 -n N nt

# Read capture file, apply Wireshark display filter for HTTP GET requests
tshark -r capture.pcap -Y "http.request.method == GET"

# Extract specific fields (IP source/dest, TCP stream index, HTTP Host header) for HTTP traffic
tshark -r capture.pcap -Y http -T fields -e ip.src -e ip.dst -e tcp.stream -e http.host

# Count DNS queries per source IP
tshark -r capture.pcap -Y "dns.flags.response == 0" -T fields -e ip.src | sort | uniq -c | sort -nr

Uses Wireshark display filters (-Y or -R), which are different and often more intuitive than BPF capture filters. -T fields combined with -e is extremely powerful for extracting specific data.

CEH Use Case: Automating analysis of large capture files, extracting Indicators of Compromise (IoCs), identifying specific malware communication patterns (e.g., JA3 hashes with ssl.handshake.ja3), analyzing protocol fields not easily accessible with `tcpdump`, filtering based on expert knowledge dissectors.
Wireshark (GUI)

The graphical standard for network protocol analysis. Provides intuitive visualization, powerful filtering, protocol dissection, session reconstruction, graphing, VoIP analysis, and much more.

# Launch Wireshark (may require sudo or specific group membership for live capture)
wireshark

Select an interface to start live capture, or open a capture file (`.pcap`, `.pcapng`). Use the filter bar for display filters (e.g., ip.addr == 192.168.1.10, tcp.port == 80, http.request). Right-click packets -> Follow -> TCP Stream (or UDP/HTTP) to reconstruct sessions.

CEH Use Case: The primary tool for deep manual analysis. Following streams to see full conversations (HTTP, SMB, FTP including credentials/data), visualizing protocol handshakes, identifying malformed packets, analyzing encrypted traffic metadata (TLS handshakes), exploring unfamiliar protocols, generating network statistics and graphs.

III. Correlating Network Activity with Local Processes

Identifying which process on your *own* Kali system (or a compromised host) is responsible for specific network traffic is crucial.

ss (Socket Statistics)

The modern replacement for `netstat`. Efficiently displays socket information, including listening ports and established connections, and can show the associated process.

# Show listening TCP and UDP sockets with process information, no name resolution
sudo ss -tulpn

# Show established TCP connections with process information
sudo ss -tpn state established

# Filter for connections involving a specific port (e.g., 4444 for a reverse shell)
sudo ss -tpn 'dport = :4444 or sport = :4444'

-t: TCP, -u: UDP, -l: Listening, -p: Show Process, -n: Numeric IPs/Ports.

CEH Use Case: Identify unexpected listening services (backdoors, unauthorized services), find the process ID of a reverse shell or C2 connection, verify if a specific service is bound correctly, check for connections initiated by malware running locally.
htop / glances

Advanced interactive process viewers that can display network I/O rates per process, helping link high bandwidth usage seen in `iftop` back to a specific application.

htop
# Press F2 (Setup) -> Columns -> Add IO_READ_RATE / IO_WRITE_RATE

glances
# Network I/O often shown by default
CEH Use Case: Pinpoint the specific local process consuming excessive bandwidth (malware, P2P software, misbehaving tool) after identifying the activity with other network tools.

IV. Specialized Monitoring Scenarios

Sometimes specific network types require specialized tools.

airodump-ng

Part of the aircrack-ng suite, essential for capturing 802.11 (Wi-Fi) management and data frames. Used for discovering wireless networks, connected clients, and capturing handshakes.

# Put interface in monitor mode first (e.g., sudo airmon-ng start wlan0)
sudo airodump-ng wlan0mon

# Target a specific network and capture to file
sudo airodump-ng --bssid AA:BB:CC:DD:EE:FF --channel 6 -w wifi_capture wlan0mon
CEH Use Case: Wireless reconnaissance (finding hidden SSIDs, identifying client MACs), capturing WPA/WPA2 handshakes for offline cracking, detecting rogue access points, analyzing wireless probe requests.

V. CEH Focus: Identifying Suspicious Traffic Patterns

Key Indicators for Ethical Hackers:
  • Scanning Activity:
    • tcpdump/tshark/Wireshark: Look for bursts of TCP SYN packets to many ports/hosts from a single source (SYN Scan), packets with unusual flag combinations (FIN, URG, PSH - FIN/XMAS Scans), large numbers of ICMP Echo Requests (Ping Sweep).
    • iftop/iptraf-ng: High connection rates from a single source to multiple destinations/ports.
  • Command & Control (C2) Traffic:
    • iftop: Persistent connections to unusual external IPs/ports.
    • tcpdump/tshark/Wireshark: Periodic, small "beacon" connections; traffic using non-standard protocols over common ports (e.g., DNS tunneling - excessive TXT queries, ICMP tunneling); analysis of TLS handshake metadata (JA3/JA3S) for known malware signatures; cleartext protocols like HTTP used for C2.
    • ss: Identify the local process making the C2 connection.
  • Data Exfiltration:
    • iftop/nload: Sustained high outbound bandwidth usage, especially to unexpected destinations.
    • tcpdump/tshark/Wireshark: Large file transfers over protocols like FTP, HTTP, SMB; data hidden within other protocols (ICMP, DNS); large volumes of encrypted traffic to unusual destinations.
  • Lateral Movement:
    • tcpdump/tshark/Wireshark: Attempts to connect to SMB/RPC ports (445, 135, 139), WinRM (5985, 5986), RDP (3389), SSH (22) between internal hosts; PsExec indicators; Kerberos ticket requests.
    • iptraf-ng LAN Monitor: New or unexpected hosts appearing.
  • Cleartext Credentials/Sensitive Data:
    • Wireshark/tcpdump -A: Filter for protocols like HTTP (POST requests), FTP, Telnet, POP3, IMAP, SNMP (v1/v2c community strings) and look for keywords like 'user', 'pass', 'login', 'password', 'community'.
  • ARP Spoofing (MitM):
    • Wireshark/tcpdump: Look for frequent, unsolicited ARP replies, or ARP replies mapping a gateway/host IP to a different MAC address.
    • iptraf-ng: Warnings about MAC address changes for a given IP.

Conclusion

Effective network traffic monitoring and analysis are indispensable skills for a Certified Ethical Hacker. Kali Linux offers a comprehensive suite of tools, from real-time dashboards like `iftop` and `iptraf-ng` for quick situational awareness, to powerful command-line sniffers like `tcpdump` and `tshark`, and the unparalleled graphical analysis capabilities of `Wireshark`. By mastering these tools and understanding how to apply them to detect scanning, C2 communication, exfiltration, and other malicious activities, ethical hackers can significantly enhance their ability to assess security posture, identify vulnerabilities, and simulate real-world attacks within authorized engagements.

Modules (130) ← CEH — Ethical Hacking