#Why this matters
When recovering files from disk images or triage captures, filenames cannot be trusted. An insider or challenge author can rename a ZIP archive to avatar.jpg, leave sensitive coordinates inside EXIF metadata, or append a secret file past a PNG's end marker. Triage from the outer container inward saves hours by checking signatures, metadata, and appended archives before touching pixel-level steganography.
#Magic bytes and file signatures
Extensions such as .png, .docx, or .txt are only OS naming hints. Parsers inspect magic bytes at fixed offsets (usually byte 0) and footer markers at the end.
| Format | Header magic bytes (hex) | ASCII / pattern | Footer / end marker |
|---|---|---|---|
| PNG | 89 50 4E 47 0D 0A 1A 0A |
.PNG.... |
IEND (49 45 4E 44 AE 42 60 82) |
| JPEG | FF D8 FF |
SOI + marker (E0/E1) |
FF D9 (EOI) |
| ZIP / DOCX | 50 4B 03 04 |
PK.. |
End of central directory (50 4B 05 06) |
25 50 44 46 2D |
%PDF- |
%%EOF |
|
| ELF binary | 7F 45 4C 46 |
.ELF |
Section headers |
Run file to match magic bytes against a signature database, and xxd to view raw hex and ASCII side by side.
#Reading EXIF and embedded metadata
Cameras, phones, and editors embed EXIF, IPTC, and XMP tags inside media files. ExifTool reads these tags safely without executing scripts:
- Timeline:
DateTimeOriginal,CreateDate,ModifyDate. - Origin:
Make,Model,Software(such asGIMP),Artist. - Location:
GPSLatitude,GPSLongitude,GPSAltitude. - Custom notes:
Comment,UserComment,ImageDescription.
$ file photo.jpg
photo.jpg: PNG image data, 800 x 600, 8-bit/color RGBA, non-interlaced
$ xxd -l 16 photo.jpg
00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
$ exiftool photo.jpg | grep -E "File Type|Software|Comment"
File Type : PNG
Software : LabExporter 2.1
Comment : case=lab-04; pass=northgate
$ binwalk photo.jpg
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 PNG image, 800 x 600, 8-bit/color RGBA, non-interlaced
41 0x29 Zlib compressed data, default compression
18422 0x47F6 Zip archive data, at least v2.0 to extract, name: notes.txtHere photo.jpg actually uses PNG magic bytes (89 50 4E 47), stores a clue in Comment, and hides a ZIP archive at offset 18422 past IEND.
#Carving appended data with binwalk
Viewers stop parsing at the end-of-file marker (FF D9 for JPEG, IEND for PNG) and ignore trailing bytes. Running binwalk -e suspect.png extracts recognized streams into _suspect.png.extracted. Check exiftool and strings first in case an extracted archive requires a passphrase.
#Steganography triage: LSB and DCT
Check pixel or frequency steganography only after inspecting magic bytes, metadata, and appended archives:
- file & xxdConfirm true format vs extension
- exiftool & stringsExtract metadata and readable hints
- binwalkDetect and carve appended archives
- zsteg (PNG/BMP)Probe LSB pixel bit-planes
- steghide (JPEG/WAV)Check DCT / passphrase embedding
Match the tool to the container format:
- Lossless (PNG, BMP): Exact pixel bits allow Least Significant Bit (LSB) embedding across RGB/Alpha channels.
zsteg -a image.pngtests common channel orders and bit depths automatically. - Lossy (JPEG): Quantized Discrete Cosine Transform (DCT) compression destroys spatial LSB bits, so tools such as
steghidemodify DCT coefficients instead. Runsteghide info image.jpgto check for embedded data andsteghide extract -sf image.jpgwith a passphrase.
#Defending and common mistakes
- Strip metadata on public uploads: Remove EXIF GPS and device tags from user uploads before publishing.
- Validate magic bytes: Inspect file signatures server-side (and re-encode untrusted images in a sandbox) instead of trusting filenames.
- Wrong tool for the format: Running
steghideon a PNG fails becausesteghidesupports JPEG, BMP, WAV, and AU, not PNG. - Misreading Zlib streams: A Zlib stream inside PNG
IDATchunks is normal image compression, not an appended archive; look for distinct headers pastIEND.
#Summary
- Verify real file types with magic bytes (
file,xxd) rather than trusting extensions. - Run
exiftoolearly for timestamps, GPS, software tags, and comment clues. - Carve appended archives past EOF markers (
IEND,FF D9) withbinwalk -e. - Match steganography tools to format:
zstegfor PNG/BMP LSBs, andsteghidefor JPEG DCT payloads.