The training method behind a top Chinese CTF team: Part 5 forensics and misc

CTF · Part 5

A CTF finals competition hall

This is Part 5 of my walk through "Handbook for CTFers", the training book from Nu1L, one of China's strongest CTF teams. Part 1 was the overview, and the three parts since covered web, reverse engineering and PWN, and cryptography. This part covers the misc category: steganography, encrypted archives, and forensics. It is the broadest category in any CTF, the home for everything that does not fit elsewhere, and the one where a methodical first pass beats cleverness almost every time.

Summary

Misc is a catch-all, but most of it is three things. Steganography hides data inside a file, so you look for the data the file viewer does not show you. Archive challenges wrap the flag in a zip you cannot open, so you attack the container rather than guess the password. Forensics hands you a recording (network traffic, a memory image, a disk image) and asks you to reconstruct what happened.

The thread through all of it is the same. You are not breaking maths or memory, you are being thorough. The flag is already in front of you, appended to a PNG, sitting in an EXIF tag, or spread across a capture of USB frames. The skill is a disciplined first pass with the right tool, before you start staring at pixels. Below is the map.

The territory

The book groups misc into stego, archives, and forensics. Here is the whole map before the detail.

#TechniqueWhat it doesTools
1File carvingFinds data appended or embedded after a file endsbinwalk, foremost
2EXIF metadataReads data hidden in image tagsexiftool
3LSB stegoExtracts bits hidden in pixel low bitsStegsolve, zsteg
4Audio stegoReads data in a spectrogram or waveformSonic Visualiser, Audacity
5Archive brute forceCracks a weak zip or rar passwordfcrackzip, John
6ZIP pseudo-encryptionFlips a fake encryption flag in the headerbinwalk, hex editor
7ZIP known-plaintextRecovers keys from one known file, no passwordbkcrack
8Traffic analysisReconstructs files and sessions from a pcapWireshark, tshark
9USB keystroke recoveryRebuilds typing from captured HID framestshark
10Memory forensicsPulls processes, files and secrets from a RAM imageVolatility
11Disk forensicsMounts and carves a disk image for deleted datamount, testdisk

Steganography: hiding in a file

File carving

The first move on any file is to check whether something is hidden after its real end. A PNG starts with a fixed magic number and ends at its IEND marker; anything appended after that is invisible to an image viewer but still sits in the bytes. binwalk scans for the signatures of embedded files and extracts them.

binwalk suspicious.png           # lists embedded file signatures it finds
binwalk -e suspicious.png        # extracts every embedded file it detects
strings -n 8 suspicious.png      # cheap first look for an appended flag

This catches a surprising share of stego challenges outright: a zip, a second image, or the flag as plain text glued onto the end of a real file. Run it before anything cleverer.

EXIF metadata

Images carry metadata in EXIF tags: author, date, GPS, a comment field, even a thumbnail that can differ from the main image. Challenge authors hide text in those tags because the picture looks ordinary. exiftool reads and writes all of them.

exiftool photo.jpg               # dumps every tag, the flag is often in Comment
exiftool -thumbnailimage -b photo.jpg > thumb.jpg   # the thumbnail may differ

LSB stego

The classic image technique hides data in the least significant bit of each colour channel. Changing the lowest bit of a byte shifts a colour value by one, which the eye cannot see, so a few bits per pixel carry a hidden message. You pull it back out by reading those low bits in order. Stegsolve views each bit plane by hand; zsteg automates the common layouts for PNG and BMP.

zsteg -a cover.png               # tries every LSB order and channel, prints hits
# Stegsolve: step through bit planes and channel XORs by eye when zsteg misses

The detail that trips people is bit order. The hidden data can be read red-green-blue or in a different channel order, row-first or column-first, most significant bit first or least. zsteg sweeps those combinations; when it misses, Stegsolve lets you try them by hand.

Audio stego

Sound files hide data two ways. In the time domain it is LSB again, on the raw samples. In the frequency domain the message is drawn into the spectrogram, so the waveform sounds like noise but a picture appears when you plot frequency against time. This survives resizing and compression, which is why it is common.

audio stego, the first pass:
1. open in Audacity or Sonic Visualiser
2. switch from waveform to spectrogram view
3. a hidden image or text often appears as shapes in the frequency band
4. for time-domain LSB, extract the low bit of each sample instead

The book's own forensics examples lean on this, and so does CyberLearner's Intercept lab, where an SSTV image is hidden in audio noise and recovered from the spectrogram.

Archives: cracking the container

Archive brute force

A password-protected zip or rar with a weak password falls to a wordlist or a short brute force. The move is to extract the password hash and run a real cracker rather than trying passwords through the zip tool one at a time.

zip2john secret.zip > hash.txt   # extract the crackable hash
john --wordlist=rockyou.txt hash.txt
fcrackzip -u -D -p rockyou.txt secret.zip   # alternative, straight at the zip

ZIP pseudo-encryption

Often the zip is not really encrypted at all. The format stores an encryption flag in its headers, and flipping that one bit makes an unencrypted archive refuse to open as if it had a password. You detect it because the archive claims encryption but holds no real encrypted data, and you fix it by clearing the bit.

ZIP pseudo-encryption:
- central directory header starts 50 4B 01 02, the flag bit is +8 bytes in
- local file header starts 50 4B 03 04, same bit is +6 bytes in
- set the lowest bit back to 0 in a hex editor, or just run binwalk -e

ZIP known-plaintext

When the password is strong, there is still a way in if you know any one file the archive contains. The classic ZipCrypto scheme is weak, so one file's plaintext plus its encrypted copy recovers the internal keys and decrypts the whole archive without ever finding the password. bkcrack is the modern tool for it.

# you have (or can guess) one file's plaintext, e.g. a known README
bkcrack -C secret.zip -c readme.txt -p known_readme.txt   # recover the keys
bkcrack -C secret.zip -k KEY0 KEY1 KEY2 -D out.zip        # decrypt everything

Forensics: reading the evidence

Traffic analysis

A packet capture is a recording of a conversation, and the flag is somewhere in it. Wireshark is the GUI: filter to the protocol you care about, follow a TCP stream to read a session end to end, and use Export Objects to pull whole files straight out of HTTP traffic. tshark is the command-line version, faster on large captures.

tshark -r capture.pcap -Y "http.request" -T fields -e http.host -e http.request.uri
tshark -r capture.pcap -Y "ftp"          # read an FTP session's commands
# Wireshark GUI: File > Export Objects > HTTP pulls transferred files out whole

Watch for data hidden in protocols that should not carry it, such as payload stuffed into ICMP packets. If the traffic is TLS and you are given a key log file, Wireshark decrypts it from the session keys.

USB keystroke recovery

A capture of USB traffic can contain everything someone typed. A USB keyboard sends an eight-byte frame per event: one byte of modifiers (shift, control) and one byte that is a key code from a standard table. You extract those frames and map the codes back to characters to replay the typing.

tshark -r usb.pcap -T fields -e usb.capdata > frames.txt
# each frame's third byte is the keycode; byte 0 bit for shift.
# map keycodes (0x04='a', 0x05='b', ...) back to text to recover what was typed

A mouse capture works the same way with three-byte frames of button and movement, which you can plot to recover something drawn on screen.

Memory forensics

A memory image is a snapshot of running RAM, and Volatility reads it. You find the profile first, then list processes, scan for open files, and pull secrets straight out. The flag is often in a running process's memory, a file that was open, or a password hash.

vol.py -f mem.raw windows.pslist          # running processes
vol.py -f mem.raw windows.filescan        # files open at capture time
vol.py -f mem.raw windows.dumpfiles --virtaddr 0xADDR   # extract one
vol.py -f mem.raw windows.hashdump        # account password hashes

The usual chain is to list processes, spot the suspicious one, dump what it had open, and then run stego or archive analysis on whatever you recovered. CyberLearner's VolShadow lab is exactly this, unmasking a disguised process in a real Linux memory dump and recovering a key from its heap.

Disk forensics

A disk image is a filesystem you reconstruct. You identify the partitions, mount them read-only, and look in the places a user leaves traces: shell history, recent files, the recycle bin. The sharper challenges delete the target file first, so you carve it back from the raw bytes because deleting only unlinks the metadata, not the data blocks.

fdisk -l disk.img                         # find partitions and their offsets
mount -o loop,ro,offset=1048576 disk.img /mnt   # mount one partition read-only
# deleted file still in the raw bytes: carve by its known header
testdisk disk.img                         # recover a corrupted table or deleted file

CyberLearner's DiskShadow lab runs this end to end: the primary partition table is wiped, you rebuild it from the backup copy a disk keeps at its end, then carve a deleted classified note out of the raw partition.

Practice beats theory

1. Carve before you stare. Most stego is not subtle. Run binwalk, strings, and exiftool before you open a bit-plane viewer, because the flag is usually an appended file or a metadata tag, not a clever pixel trick. The methodical first pass solves more than the clever second one.

2. The container is not the cipher. A locked zip is rarely a real cryptographic problem. Check for pseudo-encryption, try a known-plaintext attack, or crack a weak password with a wordlist, before you assume you need to break anything. Attack the archive format, not the password.

3. Forensics is reconstruction. A pcap or a memory image is a recording of something that already happened. You do not guess, you replay it: rebuild the keystrokes from USB frames, pull the files out of the HTTP stream, list the processes from the RAM image. The evidence is complete; your job is to read it properly.

Prepare for CTF with CyberLearner

The forensics techniques here all have hands-on labs on CyberLearner for free.

  • Intercept. An image hidden in audio noise, recovered from the spectrogram, the exact frequency-domain stego above.
  • WireTap. A VoIP packet capture where a password is hidden in the low bits of the audio payload, combining traffic analysis and stego.
  • VolShadow. Linux memory forensics with Volatility: unmask a process disguised by a fake name, then recover an encryption key from its heap.
  • DiskShadow. Disk forensics: rebuild a wiped partition table from the backup copy, then carve a deleted file out of the raw filesystem.

Browse the full set on the challenges page.

Next

Part 6 moves to the finals: attack-and-defence and full network penetration testing: Part 6: the finals.

Sources


TopicsCTFForensicsSteganographyMemory forensicsVolatility
Share this article LinkedIn X Facebook Email
← Back to all posts