hexdump in CTF: How to Inspect Binary Files and Extract Hidden Data


✅ What is hexdump?

hexdump is a command-line utility that displays the binary contents of a file in hexadecimal format, often alongside ASCII representations.

In CTF challenges, hexdump is commonly used to:

  • Inspect unknown binaries
  • Examine file headers and magic numbers
  • Detect hidden flags or embedded data
  • Analyze memory or disk dumps

It’s a fast and lightweight tool for low-level forensic analysis.


🛠️ Basic hexdump Commands

1. Display a file in hex

hexdump file.bin
  • Outputs the file content in hexadecimal format.

2. Canonical format (hex + ASCII)

hexdump -C file.bin
  • Shows both hexadecimal bytes and their ASCII characters, making it easier to spot text and flags.

3. Specify bytes per line

hexdump -v -e '16/1 "%02X " "\n"' file.bin
  • Customizes the output format (16 bytes per line in hex).

4. Inspect specific offsets

hexdump -s 1024 -C file.bin
  • Starts reading from offset 1024 bytes into the file. Useful for skipping headers or irrelevant sections.

5. Output to a file

hexdump -C file.bin > output.txt
  • Saves the hex view for later inspection or searching.

🎯 How hexdump is Used in CTF Challenges

1. Analyze file headers

  • Identify file types via magic numbers (e.g., 89 50 4E 47 for PNG, 50 4B 03 04 for ZIP).
  • Useful for corrupted or disguised files.

2. Extract hidden flags

  • Flags may be embedded in non-printable bytes or appended to a file.
  • hexdump allows you to view and extract such data manually.

3. Examine binaries

  • Inspect compiled programs to find strings, offsets, or instruction sequences.
  • Helps in reverse-engineering challenges.

4. Analyze memory or disk dumps

  • hexdump is excellent for scanning RAM or disk images for hidden data fragments or ASCII sequences.

5. Detect steganography or padding

  • Patterns like repeated bytes, unusual null padding, or LSB encoding can be detected visually in hex.

🔍 Common CTF Patterns with Hexdump

PatternDescriptionHow Hexdump Helps
Hidden flagsAppended or embedded text in binaryDisplays ASCII for quick spotting
Corrupted filesPNG, ZIP, or ELF with altered headersIdentify and fix magic numbers manually
Custom binariesReverse-engineering tasksExamine offsets and instructions
Memory fragmentsASCII or hex data in RAM dumpsLocate secret data quickly
SteganographySubtle LSB or null byte patternsVisual inspection reveals anomalies
Encoded dataBase64 or XORed contentSpot hints in ASCII regions for decoding

📌 Tips for Using hexdump in CTFs

  • Combine hexdump -C with grep to search for flag patterns.
  • Start by inspecting magic numbers to identify file types.
  • Use offset options (-s) for large files to skip irrelevant sections.
  • Save output to a file for offline analysis or to try decoding later.
  • hexdump is complementary to tools like strings, binwalk, and hexedit.

🧩 Recommended Workflow in CTF

  1. Run hexdump -C file.bin to visualize the file content.
  2. Inspect the header for magic numbers or anomalies.
  3. Scan through ASCII portions for potential flags.
  4. Examine specific offsets if the flag is appended or embedded.
  5. Combine with other tools (strings, binwalk, zsteg) for multi-layer challenges.

Leave a Reply

Your email address will not be published. Required fields are marked *