Wireshark CTF pcap analysis: from filters to flags part 2

Depov

Moderator
Staff member
MODERATOR
ULTIMATE
SUPREME
PREMIUM
MEMBER
Joined
Feb 18, 2025
Messages
790
Reaction score
1,510
Extracting files from pcap using Export Objects

File → Export Objects → HTTPOpens a list of all files transferred via HTTP during the capture: images, scripts, documents, and binaries. Similar menus are available for SMB, TFTP, and email attachments (IMF). Essentially, this is automatic reconstruction of transferred files from network traffic ( File Carving, D3-FC according to the MITRE D3FEND classification ).
Analysis of extracted files and manual reconstruction

Save the files using Export Objects – then work in the terminal:

file имя_файлаDetermines the actual type based on magic bytes, even if the extension is incorrect or missing. At CTFs, authors often intentionally remove or replace extensions—a classic trick.
strings имя_файла | grep -i flagSearches for text strings in a binary file. The flag can be embedded in image metadata, in executable file strings, or in PDF comments.
md5sum имя_файлаcalculates the hash. In some CTF tasks, the malware's hash is the answer.

In the EscapeRoom analysis, three files were extracted via Export Objects: two ELF binaries and a Bash script (analysis on InfoSec Writeups). The type of each was determined via file, and the MD5 hash of the main malware became the answer to one of the questions in the task.

Export Objects only works for fully captured transmissions. If the pcap contains only part of a session (a truncated capture), the file will be corrupted. In this case— Follow TCP Stream → Save Aswith the Raw format. Manual reconstruction doesn't guarantee results, but CTF dumps usually contain complete sessions.

For SMB transfers, Wireshark automatically recognizes files - Export Objects → SMBTFTP is similar. If Wireshark doesn't recognize the protocol on a non-standard port, right-click the packet → Decode As→ manual protocol selection.
Credential Hunting: FTP, HTTP Basic, and Network Traffic Analysis

FTP transmits credentials without encryption—a perennial target for network forensics CTF exercises. In MITRE ATT&CK terms, these are Credentials in Files (T1552.001, Credential Access) and File Transfer Protocols (T1071.002, Command and Control).

Step-by-step algorithm for FTP analysis in pcap:

Filter ftpshows the control channel: commands USER, PASS, RETR(download), STOR (loading), LIST(catalog listing). Pair USER / PASS- a potential flag or part of it.
We mark the teams RETR And STOR- they indicate which files were transferred.
Filter ftp-datashows a separate channel with the contents of the files.
On any ftp-datapackage → Follow → TCP Stream→ we get the full contents of the file. For binary data - Save As → Raw.

FTP uses separate ports for data: port 20 in active mode, and a random port above 1024 in passive mode. Wireshark usually correctly associates the control and data channels, but with a non-standard configuration it may not recognize ftp-dataautomatically. Then Decode Ason the corresponding TCP stream.

HTTP Basic Authentication is also cleartext—Base64 is encoding, not encryption. Filter http.authbasicwill show all packets with Basic authentication. A line like admin:password123from the title Authorization: Basic YWRtaW46cGFzc3dvcmQxMjM=decode with one command:

echo "YWRtaW46cGFzc3dvcmQxMjM=" | base64 -d

SMTP authentication ( smtp.auth) works similarly. Commands AUTH LOGIN or AUTH PLAINcontain Base64-encoded login and password - are decoded in the same way.
DNS Exfiltration: Hidden Channels in Network Forensics CTF

DNS exfiltration is one of the most common techniques in intermediate and advanced CTFs. The idea is to encode data and transmit it as subdomains in DNS queries. Instead of legitimate www.example.coma request of the type flies away 666c61677b746573747d.evil.com, where the hex string in the subdomain is the encoded flag.

Signs of DNS exfiltration in a dump:

Unusually long domain names requested
Hex or Base64 strings instead of human-readable subdomains
Multiple requests to one base domain
TXT records with atypical content (TXT are used as a back channel)

Wireshark filters for detection:

dns.qry.name.len > 30— DNS queries with long names
dns.qry.type == 16— TXT record queries
dns.qry.name matches "^[a-f0-9]{8,}\\."— hex strings in subdomains
dns.qry.name contains "evil.com"— filter by a specific domain if the base domain is already defined through Conversations

Once suspicious DNS queries are detected, the next step is extracting and decoding. Manually using Wireshark is a pain: opening each packet, copying the subdomain, and concatenating. Here, tshark saves tens of minutes.
TLS in CTF: decrypting traffic with a pre-master secret

Most modern network traffic is encrypted with TLS. Without keys, the contents of these packets are a black box. But at CTFs, keys are sometimes provided intentionally—in the form of a pre-master secret log file or a server's private key.

How to use pre-master secret in Wireshark:

In the task files, look for a document with the extension .log, .pms, .keysor a text file with lines starting with CLIENT_RANDOM.
In Wireshark: Edit → Preferences → Protocols → TLS(in older versions - SSL).
In the field (Pre)-Master-Secret log filenameSpecify the path to the file with keys.
Wireshark automatically decrypts all TLS sessions that have matching records.

After decryption, encrypted traffic turns into regular HTTP/HTTP2—then the standard filters, Export Objects, and Follow Stream apply. Magic.

In a THM Wireshark CTF analysis on cyber-99.co.uk, the pre-master secret was found in an email message transmitted on port 25 (SMTP). The line CLIENT_RANDOMwas copied to a text file and loaded into the TLS settings. After this, HTTPS traffic on port 443 became accessible—it contained a file with another artifact. Without this step, the contents remained completely opaque. It's like a Russian doll: the TLS key was in SMTP, and SMTP itself was sent in cleartext.
Decode As: Non-Standard Ports and Protocols

Sometimes a protocol operates on a non-standard port—HTTP on 8080, FTP on 2121, RTP on 1313. Wireshark does not automatically recognize it and shows packets as "TCP" or "Data."

Solution: Right-click on the package → Decode As→ select the desired protocol from the list. In the same THM Wireshark CTF, the UDP stream on port 1313 after Decode As → RTPturned into an audio stream. It was played through Telephony → RTP → RTP Streams → Analyze → Playand received the answer to the task question. Without Decode AsThis traffic looked like a bunch of meaningless UDP packets - and then the voice dictated the flag.
tshark: Automate Wireshark Network Traffic Analysis

tshark is a console version of Wireshark from the same distribution. It has the same filters and protocol parsers, but without the GUI. It's indispensable for CTFs when you need to process a large dump, extract specific fields from thousands of packets, or work with multiple pcaps simultaneously.

Commands to keep handy:

All HTTP requests with host and URI: tshark -r dump.pcap -Y "http.request" -T fields -e http.host -e http.request.uri
Unique DNS queries: tshark -r dump.pcap -Y "dns.qry.name" -T fields -e dns.qry.name | sort -u
Search for a string in the entire dump with hex context: tshark -r dump.pcap -Y 'frame contains "flag"' -x
FTP credentials: tshark -r dump.pcap -Y "ftp.request.command == USER || ftp.request.command == PASS" -T fields -e ftp.request.arg
Protocol Hierarchy in CLI: tshark -r dump.pcap -z io,phs -q

DNS exfiltration decoding pipeline

When DNS queries contain hex-encoded data in subdomains (e.g. 48656c6c6f.evil.com), tshark allows you to assemble and decode them in one chain:

tshark -r dump.pcap -Y "dns.qry.name contains evil.com" \
-T fields -e dns.qry.name | \
sed 's/\.evil\.com//' | \
tr -d '\n' | \
xxd -r -p

The pipeline extracts the requested domain names, strips the base domain, concatenates the hex fragments and decodes via xxd -r -pIf the data is in Base64 instead of hex, replace the last command with base64 -d.
Working with multiple pcap files

For CTFs with multiple dumps (like the SHA2017 Abuse Mail challenge with three pcap files, described on Habr), tshark allows you to process everything at once:

for f in *.pcap; do
echo "=== $f ==="
tshark -r "$f" -Y 'frame contains "flag"' \
-T fields -e frame.number -e data.text
done

The script loops through all pcap files in the directory and searches for the "flag" string in each one. The output shows the file name, packet number, and text content. This is faster than opening each file in the GUI and manually running filters.
Checklist: Step-by-Step Pcap Analysis for CTF

To avoid wasting time during the competition, here's a route that works for most network forensics tasks:
Step Action Filter / menu
1 Protocol Hierarchy - evaluate protocols Statistics → Protocol Hierarchy
2 Conversations — find abnormal sessions Statistics → Conversations (TCP, по bytes)
3 Quick search for a flag in open view frame contains "flag" or frame matches "flag"
4 Extract all HTTP files File → Export Objects → HTTP
5 View TCP streams of unencrypted protocols Follow → TCP Stream(thread enumeration)
6 Check FTP credentials ftp — USER / PASS
7 DNS exfiltration — hex/Base64 in subdomains dns.qry.name.len > 30
8 TLS - Search for pre-master secret in task Edit → Preferences → Protocols → TLS
9 Non-standard ports Decode As
10 Automation for large dumps tshark with filters and pipelines

At each step, if you find a flag, stop. You don't need to go through all ten steps if you get the answer on the third.

80% of entry-level and intermediate network forensics CTF tasks are solved using three tools: frame contains, Follow TCP Stream, and Export Objects. The remaining 20% are DNS exfiltration, TLS decryption, and Decode As on non-standard ports. The problem isn't the complexity of the tools, but the lack of a systematic approach. Once Wireshark's pcap file parsing algorithm is automated, the solution time depends solely on the ingenuity of the task author, not on their interface skills.
 
Top Bottom