HARDCORE BLUE ← Home
Articles

Metadata: Extract and Strip

1. Orientation

Metadata is structured information that describes a file: what it is, who created or changed it, when, where, and with which tool.

It lives in three places:

Software writes most of it automatically. Users rarely see it. Anyone with the right tool can edit it.

Example: the photo is the content. The phone model, capture time and GPS position stored in it are the metadata.

Forensic value comes from four properties: provenance, attribution, timeline and integrity.

The same data serves three jobs:

Core workflow

  1. Hash the original.
  2. Work on a copy.
  3. Identify the true file type.
  4. Extract embedded metadata.
  5. Extract filesystem metadata.
  6. Correlate and check for inconsistencies.
  7. Record tool, version, command and output.

Setup

sha256sum evidence.jpg | tee evidence.jpg.sha256
mkdir work && cp -p evidence.jpg work/
file work/evidence.jpg
xxd work/evidence.jpg | head

Compare the magic bytes to the extension. A mismatch is a finding.

Rules

2. Types of Metadata

Embedded metadata

Stored inside the file. Travels with it.

Filesystem metadata

Stored by the OS, outside the file. Lost or rewritten on copy, upload or download.

Transport metadata

Extraction commands

# everything, grouped by source
exiftool -a -u -G1 -s file

# images: location and device
exiftool -n -GPSLatitude -GPSLongitude -Make -Model -SerialNumber photo.jpg

# embedded thumbnail
exiftool -b -ThumbnailImage photo.jpg > thumb.jpg

# Office: raw XML properties
unzip -l report.docx
unzip -p report.docx docProps/core.xml | xmllint --format -
unzip -p report.docx docProps/app.xml  | xmllint --format -
unzip -p report.docx docProps/custom.xml | xmllint --format -

# PDF
pdfinfo -meta report.pdf
exiftool -a -G1 -s report.pdf

# filesystem
stat file
stat -c '%n | birth=%w | modify=%y | change=%z | access=%x' file

3. ExifTool Workflow

ExifTool is the main tool. It reads and writes EXIF, XMP, IPTC, PDF, Office, audio and video metadata. Kali package: libimage-exiftool-perl.

exiftool -ver

Read

exiftool file                      # default view
exiftool -a -u -G1 -s file         # all tags, duplicates, unknown tags, group names, tag names
exiftool -n file                   # raw numeric values (GPS, orientation)
exiftool -ee file                  # also extract embedded data (video tracks, documents)
exiftool -b -ThumbnailImage file > thumb.jpg
exiftool -b -PreviewImage file   > preview.jpg

Select tags and fields

exiftool -Make -Model -SerialNumber -Software photo.jpg
exiftool -time:all -a -G1 -s file          # every timestamp in the file
exiftool -gps:all -a -G1 -s photo.jpg
exiftool -Author -Creator -Producer -Company -LastModifiedBy doc.docx

Bulk and recursive

exiftool -r -csv ./case > case-meta.csv
exiftool -r -json ./case > case-meta.json
exiftool -r -ext jpg -ext jpeg ./case          # restrict by extension
exiftool -r -ext pdf -p '$FileName | $Author | $Producer | $CreateDate' ./case

Filter

# files that contain GPS
exiftool -r -if '$GPSLatitude' -p '$FileName $GPSPosition' ./case

# files from one device
exiftool -r -if '$Model eq "iPhone 13"' -p '$FileName' ./case

# files edited in software
exiftool -r -if '$Software' -p '$FileName | $Software' ./case

Build a timeline

exiftool -r -d '%Y-%m-%d %H:%M:%S' \
  -p '$DateTimeOriginal | $Make $Model | $FileName' \
  -ext jpg ./case | sort

Write and strip

Work on copies. ExifTool modifies files in place by default and leaves a _original backup.

exiftool -all= -o cleaned.jpg original.jpg           # strip all, new file
exiftool -gps:all= -o nogps.jpg original.jpg          # strip GPS only
exiftool -xmp:all= -o noxmp.jpg original.jpg          # strip XMP only
exiftool -all= -tagsfromfile @ -Orientation -o out.jpg in.jpg   # strip all, keep orientation
exiftool -P -overwrite_original -all= file.jpg        # in place, keep file modify time, no backup

4. Other Kali Tools

Built-in and packaged tools worth knowing.

ToolUseCommand
fileTrue file type from magic bytesfile *
xxdHex view, check headers and trailersxxd file | head
stringsReadable text. Paths, usernames, URLsstrings -a file and strings -el file for UTF-16
statFilesystem timestamps and inodestat file
findTimestamps across a treefind . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
sha256sumIntegritysha256sum -b file
exiv2Second opinion on EXIF, IPTC, XMPexiv2 -pa photo.jpg
identify (ImageMagick)Image properties and profilesidentify -verbose photo.jpg
mat2List and strip metadatamat2 --show file then mat2 file
pdfinfoPDF info and XMPpdfinfo -meta file.pdf
pdfdetachList embedded PDF attachmentspdfdetach -list file.pdf
pdfimagesList images inside a PDFpdfimages -list file.pdf
pdfid, pdf-parserPDF structure, JavaScript, embedded files, objectspdfid file.pdf
unzip, xmllintOpen Office packages and read the XMLunzip -p f.docx docProps/core.xml | xmllint --format -
oleid, olemeta, olevbaLegacy Office (.doc, .xls): OLE properties and macrosolemeta file.doc
ffprobe, mediainfoAudio and video container metadataffprobe -show_format -show_streams file.mp4
binwalkEmbedded files and appended databinwalk file
foremost, scalpelCarve files out of images and unallocated spaceforemost -i disk.dd -o out/
fls, istat, mactime (Sleuth Kit)Filesystem timestamps from disk imagesfls -r -m / disk.dd > body.txt then mactime -b body.txt -d
grepEmail headersgrep -i '^received:' mail.eml
metagoofilSearch and download public documents from a domainmetagoofil -d target.example -t pdf,docx -o loot

5. Common Metadata Leaks

LeakWhereWhat it gives
GPS coordinatesPhoto EXIFExact location. Home, office, site.
Device serial numberPhoto EXIFLinks photos to one device.
Author, last modified byOffice, PDFReal names. Username format.
Creator, producer, application versionPDF, OfficeSoftware and version. Patch level hints.
Internal paths and machine namesOffice, PDF, XMPDrive letters, share names, user profile folders.
Printer nameOffice, PDFInternal print infrastructure.
Tracked changes, comments, hidden textOfficeDeleted content and reviewer remarks.
Old content after editsPDFEarlier revisions kept by incremental updates.
Original thumbnailPhoto EXIFUncropped or unredacted frame.
Mail server hops and IPsEmail headersInternal hostnames and addresses.

Recon workflow

Authorised scope only.

# collect public documents
wget -r -l2 -np -A pdf,docx,xlsx,pptx,jpg https://target.example/

# extract the useful fields in bulk
exiftool -r -csv -ext pdf -ext docx -ext xlsx -ext pptx \
  -Author -Creator -Producer -LastModifiedBy -Software -Company . > meta.csv

# unique author names and software
cut -d, -f2- meta.csv | sort | uniq -c | sort -rn | head -30

Checking a PDF for hidden revisions

grep -a -c '%%EOF' report.pdf

More than one match means the file was updated incrementally. Earlier versions of objects may still be in the file.

Forensic checks

6. Getting Rid of Your Own Metadata

Strip, then verify. Never assume it worked.

Images

# write a stripped copy, keep the original untouched
exiftool -all= -o cleaned.jpg original.jpg

# verify
exiftool -a -G1 -s cleaned.jpg

# diff before and after
exiftool -a -G1 -s original.jpg > before.txt
exiftool -a -G1 -s cleaned.jpg  > after.txt
diff before.txt after.txt

PDFs

ExifTool writes PDF changes as an incremental update. The old values stay in the file and can be recovered. Rewrite the file after stripping.

exiftool -all= -o stripped.pdf original.pdf
qpdf --linearize stripped.pdf cleaned.pdf
grep -a -c '%%EOF' cleaned.pdf

Check the result with pdfinfo -meta cleaned.pdf.

Office documents

unzip -l cleaned.docx
unzip -p cleaned.docx docProps/core.xml
unzip -p cleaned.docx word/comments.xml

General-purpose tools

mat2 --show file.docx      # list what mat2 sees
mat2 file.docx             # writes file.cleaned.docx

Habits

7. MetaClean

MetaClean is a Python command-line tool. It inspects metadata in common images and PDFs and writes cleaned copies. Source: github.com/Hardcore-Blue/metaclean

Usage

metaclean inspect photo.jpg
metaclean inspect ./documents --shallow
metaclean inspect ./documents --format json --output report.json
metaclean inspect ./documents --format csv  --output report.csv
metaclean clean photo.jpg -o cleaned/photo.jpg
metaclean clean ./documents -o ./cleaned --overwrite

Options

Supported files

Exit codes

Scripts can branch on these.

How inspect works

  1. find_files collects supported files by extension, recursively by default.
  2. inspect_file picks the reader from the extension.
  3. Images use Pillow. Output: format, dimensions, mode, frame count, EXIF tags, container fields, ICC profile presence.
  4. PDFs use pypdf. Output: page count, encryption status, document information fields.
  5. Binary values are reported as <binary data: N bytes>.
  6. One failing file is recorded as an error record. The batch continues.

How clean works

The source is never modified. Output goes to a new path. Identical input and output paths are rejected.

Code layout

Limits

Inspect the cleaned copy with ExifTool before sharing. MetaClean is not a forensic sanitisation guarantee.

Python techniques