30 Mins

4. Analyzing Protocol Streams & Conversations

Following TCP Streams

In packet analysis, individual segments often appear as isolated events. The 'Follow TCP Stream' feature in Wireshark reassembles the fragmented sequence of packets based on the TCP 3-way handshake and sequence numbers, presenting the session as a human-readable transcript.

To perform this, select a packet belonging to a TCP flow, right-click, and choose 'Follow -> TCP Stream'. This reveals the application-layer payload, stripping away Ethernet, IP, and TCP headers.

Alternatively, you can use TShark in the CLI to filter specific streams: tshark -r capture.pcap -q -z follow,tcp,ascii,0

Security Operator Note: If the TCP stream is garbled, check for missing packets in the Expert Information window; packet loss breaks reassembly.
Text
# Use TShark to extract stream zero content to a file
tshark -r traffic.pcap -z follow,tcp,ascii,0 > stream_output.txt

Reconstructing HTTP Objects

Wireshark allows for the extraction of files (HTTP Objects) transferred over cleartext HTTP. This is essential for malware analysis where a malicious payload is downloaded via a GET request.

Navigate to 'File -> Export Objects -> HTTP'. This opens a dialog listing every object captured in the session, such as images, scripts, or binaries. You can save these to your local disk for further forensic analysis.

The following Python script simulates how one might programmatically extract HTTP response headers from a captured payload.

Security Operator Note: Always verify file integrity using hash functions like SHA-256 after extraction to ensure no corruption occurred during the pcap capture.
Python 3
import re

def parse_http_header(raw_data):
    match = re.search(b'Content-Type: (.*?)(\\r\\n)', raw_data)
    if match:
        print(f'Detected File Type: {match.group(1).decode()}')

raw_payload = b'HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\n\r\n[BinaryData]'
parse_http_header(raw_payload)

Analyzing Conversation Statistics

Conversation Statistics provide a high-level view of network throughput. By navigating to 'Statistics -> Conversations', you can view total packets, bytes, and duration for every connection.

This is critical for identifying 'Top Talkers'—IP addresses consuming an abnormal amount of bandwidth—which often indicates exfiltration or a DoS attack.

The table below outlines common conversation metrics analyzed in the field.

Security Operator Note: Use the 'Limit to display filter' checkbox in the Conversations window to isolate talkers for a specific protocol, such as DNS or SMB.
Text
# Generate a summary of conversation statistics via CLI
tshark -r traffic.pcap -q -z conv,ip

Creating Custom Columns

Default Wireshark views prioritize generic headers. Custom columns allow you to pull specific fields—such as HTTP User-Agents, TLS SNI headers, or custom application flags—directly into the main packet list pane.

To create a column, right-click any field in the 'Packet Details' pane and select 'Apply as Column'. This creates a persistent view, allowing for rapid triage of millions of packets by scrolling through the specific data points of interest.

This saves massive amounts of time during deep investigations by removing the need to manually click into each packet.

Security Operator Note: Right-click the column header and select 'Column Preferences' to resize or hide columns to keep your workspace clean.
Python 3
import struct

# Simulated parsing of a custom protocol flag (offset 4)
def get_custom_flag(raw_packet):
    # Extract 1 byte at offset 4
    flag = struct.unpack('!B', raw_packet[4:5])[0]
    return f'Flag status: {hex(flag)}'

print(get_custom_flag(b'\x00\x00\x00\x00\xFF'))

Knowledge Check

Ready to test your understanding of 4. Analyzing Protocol Streams & Conversations?

Back