Chapter 9: Packet Analysis and Protocol Investigation
Learning Objectives
Extract files and artifacts from TCP streams using PCAP captures and Wireshark
Identify intrusion key elements from PCAP data: source/destination addresses, ports, protocols, and payloads
Interpret protocol headers for intrusion analysis across Ethernet, IPv4/IPv6, TCP, UDP, ICMP, DNS, HTTP, SMTP, and ARP
Apply basic regular expressions to filter and identify security artifacts in Wireshark and SIEM platforms
Section 1: PCAP Analysis and File Extraction
A PCAP (Packet CAPture) file is a binary file containing timestamped network frames. Two formats are common: the original libpcap format and PCAPNG (Wireshark's default), which supports multiple interfaces and extended metadata.
Capture Tools
Tool
Role
Primary Use Case
tcpdump
CLI capture and filter
Headless servers, scripted capture, IR triage
Wireshark
GUI capture and analysis
Deep inspection, stream reassembly, file extraction
tshark
CLI version of Wireshark
Scripted analysis, automation, SIEM integration
NetworkMiner
Passive analysis
Artifact extraction, host profiling
Common tcpdump Capture Commands
# Capture all traffic on eth0, rotate every 100MB
tcpdump -i eth0 -w /evidence/capture-%Y%m%d-%H%M%S.pcap -C 100 -Z analyst
# Capture only traffic to/from a suspected C2 server
tcpdump -i eth0 host 203.0.113.55 -w /evidence/c2-traffic.pcap
# Capture DNS and HTTP for exfiltration analysis
tcpdump -i eth0 'port 53 or port 80' -w /evidence/dns-http.pcap
TCP Stream Reassembly in Wireshark
TCP is stream-oriented — application data is segmented across multiple packets. Wireshark's reassembly engine merges segments in sequence number order.
Following a TCP Stream: Right-click any packet → Follow > TCP Stream. Switch to Raw or Hex mode for binary data. A binary starting with MZ bytes is a Windows PE executable.
Exporting HTTP Objects
For HTTP traffic: File > Export Objects > HTTP lists every reassembled HTTP object — HTML pages, images, executables, ZIP archives. This is far more efficient than manual stream following.
Encrypted Traffic Limitations
Approach
Requirement
Notes
Pre-master secret log
Browser key logging pre-configured
Set SSLKEYLOGFILE env variable
Server private key
Access to TLS private key
Only works for non-PFS cipher suites
Endpoint inspection
EDR/agent on the host
Captures data before encryption
JA3/JA3S fingerprinting
Metadata only
Identifies TLS client/server fingerprints
PCAP Incident Response Triage Workflow
Key Points — Section 1
PCAP vs PCAPNG: PCAPNG is Wireshark's extended format supporting multi-interface captures and metadata comments.
TCP Reassembly: Wireshark automatically merges segments; right-click any packet and select Follow > TCP Stream to see the full conversation.
MZ magic bytes (4D 5A) at the start of a TCP stream payload identify a Windows PE executable being transferred.
File > Export Objects > HTTP recovers all reassembled HTTP objects (files, scripts, archives) from a PCAP in one step.
Encrypted traffic requires key material (SSLKEYLOGFILE, server private key, or endpoint EDR) for plaintext recovery; without it, use JA3 fingerprinting.
Pre-Check — Section 1
1. What are the magic bytes (hex) that identify a Windows PE executable at the start of a TCP stream payload?
2. Which Wireshark menu path lets you extract all HTTP objects (files, images, scripts) from a PCAP in one step?
Section 2: Intrusion Key Elements in Packet Data
The 5-Tuple
Every network session is uniquely identified by its 5-tuple:
Element
Description
Example
Source IP
Originating host address
192.168.1.105
Destination IP
Target host address
203.0.113.55
Source Port
Originating application port
54231 (ephemeral)
Destination Port
Target service port
443 (HTTPS)
Protocol
Layer 4 protocol
TCP (6)
Port/Service Anomalies
Scenario
What to Look For
Non-standard port for common service
HTTP on port 8888, SSH on port 2222
Legitimate port, wrong protocol
IRC traffic on port 443, DNS tunneling on port 53
High ephemeral-range destination port
Possible reverse shell or C2 callback
Sequential port scanning pattern
SYN packets to consecutive destination ports
Payload Inspection — File Magic Bytes
Magic Bytes (Hex)
File Type
4D 5A
Windows PE executable (EXE/DLL)
50 4B 03 04
ZIP archive
25 50 44 46
PDF document
FF D8 FF
JPEG image
89 50 4E 47
PNG image
Protocol Anomalies
ICMP packet with 1,400-byte payload (normal ping is 32–56 bytes) → data exfiltration
DNS response > 512 bytes without EDNS0 → malformed / amplification attempt
HTTP GET with no Host: header → scanner or RFC violation
TVqQ in an HTTP response body → Base64-encoded MZ header (PE executable delivery)
Key Points — Section 2
The 5-tuple (src IP, dst IP, src port, dst port, protocol) is the universal session anchor across Wireshark, firewall logs, IDS alerts, and SIEM events.
Combining IP reputation, port anomaly detection, and payload magic-byte inspection gives a complete attacker intent picture without decryption.
Base64 string TVqQ in an HTTP body signals a PE executable is being delivered encoded.
Wireshark filter to correlate a 5-tuple: ip.addr == 203.0.113.55 && tcp.port == 443
Multiple internal hosts connecting to the same external IP can indicate centralized C2 or lateral movement infrastructure.
Pre-Check — Section 2
3. An analyst sees an ICMP Echo Request with a 1,400-byte payload. What does this most likely indicate?
4. The five elements of a network session 5-tuple are: src IP, dst IP, src port, dst port, and ___?
Section 3: Protocol Header Analysis
Ethernet and ARP
Field
Size
Intrusion Relevance
Destination MAC
6 bytes
Broadcast (FF:FF:FF:FF:FF:FF) used in ARP scans
Source MAC
6 bytes
Spoofed MACs indicate MAC flooding or evasion
EtherType
2 bytes
0x0800=IPv4; 0x86DD=IPv6; 0x0806=ARP
VLAN Tag (802.1Q)
4 bytes (optional)
Double-tagging (0x8100) = VLAN hopping attack
ARP Spoofing: An attacker broadcasts gratuitous ARP replies claiming a victim IP maps to the attacker's MAC. Detection: multiple ARP replies for the same IP from different MACs in rapid succession.
IPv4 TTL Baseline
OS
Default TTL
Linux/Unix
64
Windows
128
Cisco IOS
255
Solaris
255
A packet arriving with TTL=64 claiming to be from a Windows machine is suspicious — it may be spoofed or the OS fingerprint is masked.
SYN+FIN, NULL, and Xmas flag combinations are never valid in legitimate TCP — their presence in a PCAP is an immediate alert.
TTL baseline analysis: Linux defaults to TTL=64, Windows to TTL=128. A mismatch between claimed OS and observed TTL suggests spoofing.
ARP spoofing detection: Multiple ARP replies for the same IP from different MACs in rapid succession — use filter arp.duplicate-address-detected.
ICMP tunneling is detected by payload size anomalies: icmp.type == 8 && data.len > 100.
VLAN double-tagging (0x8100 0x8100 EtherType) is the hallmark of a VLAN hopping attack.
Pre-Check — Section 3
5. A packet arrives claiming to originate from a Windows system, but its IP TTL is 64. What does this indicate?
6. Which TCP flag combination is used by Nmap's Xmas scan?
Section 4: Application Protocol Analysis
DNS Tunneling Detection
DNS (UDP/TCP port 53) is almost universally allowed through firewalls, making it a favored channel for data exfiltration and C2. Data is encoded into DNS query subdomain labels:
Wireshark uses PCRE (Perl-Compatible Regular Expressions) via the matches operator (also ~); the filter bar turns green for valid syntax.
The (?i) flag enables case-insensitive matching — critical since attackers vary casing to evade string-based signatures.
Named capture groups(?P<name>...) in Splunk rex extract fields for correlation and statistical analysis.
Regex finds patterns; combining with statistical thresholds (count, rate, frequency) converts patterns into actionable alerts.
Patterns developed in Wireshark translate directly to SIEM platforms with minor syntax adjustments — build once, deploy everywhere.
Post-Check — Sections 1–5
9. What Wireshark filter detects suspicious file downloads by matching executable extensions in HTTP request URIs?
10. In Splunk's rex command, what is the purpose of named capture groups like (?P<src_ip>...)?
11. Which of the following is the correct Wireshark filter to detect SQL injection attempts in HTTP URIs?
12. An analyst wants to extract all IP addresses from Splunk firewall logs. Which Splunk command should they use?
13. What does the Wireshark filter tcp.flags == 0x000 detect?
14. A host at 10.1.2.50 is generating 847 DNS queries in 30 minutes, all to subdomains of c2.evildomain.xyz, with subdomain labels 40–60 characters long. What attack is most likely occurring?
15. To decrypt HTTPS traffic in Wireshark when using a browser, which approach should an analyst set up before capturing?