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:
- Inside the file: EXIF, XMP, document properties.
- In the filesystem: timestamps, owner, permissions, path.
- In transit: email headers, HTTP headers.
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:
- Forensics: build a timeline, link a file to a device or a person, spot tampering.
- Recon: read what a target published by accident.
- Hygiene: remove it from your own files before sharing.
Core workflow
- Hash the original.
- Work on a copy.
- Identify the true file type.
- Extract embedded metadata.
- Extract filesystem metadata.
- Correlate and check for inconsistencies.
- 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
- Never edit the original.
- Log how each file reached you. Copying and moving change timestamps.
- Metadata is trivial to edit. Treat it as a lead. Corroborate it.
- Report observations first. Label inferences as inferences.
2. Types of Metadata
Embedded metadata
Stored inside the file. Travels with it.
- EXIF: camera or phone make and model, serial number, capture time, GPS, lens, editing software.
- XMP: XML packet. Edit history, tool names, document IDs. Found in images, PDFs and Office files.
- IPTC: captions, credits, keywords. Common in press photos.
- ICC profile: colour profile. Can name the device or software.
- PDF info dictionary: title, author, creator, producer, creation and modification dates.
- Office core and app properties: author, last modified by, revision count, template, company, application version.
- Embedded thumbnails: may show the original frame before cropping.
Filesystem metadata
Stored by the OS, outside the file. Lost or rewritten on copy, upload or download.
- Modify (mtime): content last written.
- Access (atime): last read. Often unreliable.
- Change (ctime): inode last changed. Permissions, rename, move.
- Birth (btime): creation time, where the filesystem records it.
- Owner, permissions, path.
Transport metadata
- Email headers:
Received,Message-ID,X-Mailer,X-Originating-IP. ReadReceivedlines bottom to top. - HTTP headers:
Server,Last-Modified,ETag.
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
-ashows duplicate tags. The same tag can hold different values in different groups.-G1shows which group each value came from (EXIF, XMP, IPTC, File).- Conflicting values for one tag across groups are worth noting.
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
- Compare against filesystem times from
stat. - Check timezone tags:
OffsetTimeOriginal,TimeZone.
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
- PDF writes are incremental. Rewrite with
qpdf --linearizeafterwards. - Always verify with a second read:
exiftool -a -G1 -s cleaned.jpg.
4. Other Kali Tools
Built-in and packaged tools worth knowing.
| Tool | Use | Command |
|---|---|---|
file | True file type from magic bytes | file * |
xxd | Hex view, check headers and trailers | xxd file | head |
strings | Readable text. Paths, usernames, URLs | strings -a file and strings -el file for UTF-16 |
stat | Filesystem timestamps and inode | stat file |
find | Timestamps across a tree | find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort |
sha256sum | Integrity | sha256sum -b file |
exiv2 | Second opinion on EXIF, IPTC, XMP | exiv2 -pa photo.jpg |
identify (ImageMagick) | Image properties and profiles | identify -verbose photo.jpg |
mat2 | List and strip metadata | mat2 --show file then mat2 file |
pdfinfo | PDF info and XMP | pdfinfo -meta file.pdf |
pdfdetach | List embedded PDF attachments | pdfdetach -list file.pdf |
pdfimages | List images inside a PDF | pdfimages -list file.pdf |
pdfid, pdf-parser | PDF structure, JavaScript, embedded files, objects | pdfid file.pdf |
unzip, xmllint | Open Office packages and read the XML | unzip -p f.docx docProps/core.xml | xmllint --format - |
oleid, olemeta, olevba | Legacy Office (.doc, .xls): OLE properties and macros | olemeta file.doc |
ffprobe, mediainfo | Audio and video container metadata | ffprobe -show_format -show_streams file.mp4 |
binwalk | Embedded files and appended data | binwalk file |
foremost, scalpel | Carve files out of images and unallocated space | foremost -i disk.dd -o out/ |
fls, istat, mactime (Sleuth Kit) | Filesystem timestamps from disk images | fls -r -m / disk.dd > body.txt then mactime -b body.txt -d |
grep | Email headers | grep -i '^received:' mail.eml |
metagoofil | Search and download public documents from a domain | metagoofil -d target.example -t pdf,docx -o loot |
- Cross-check with two tools. If they disagree, trust neither until you know why.
- Check
--helpon your install. Options differ between versions.
5. Common Metadata Leaks
| Leak | Where | What it gives |
|---|---|---|
| GPS coordinates | Photo EXIF | Exact location. Home, office, site. |
| Device serial number | Photo EXIF | Links photos to one device. |
| Author, last modified by | Office, PDF | Real names. Username format. |
| Creator, producer, application version | PDF, Office | Software and version. Patch level hints. |
| Internal paths and machine names | Office, PDF, XMP | Drive letters, share names, user profile folders. |
| Printer name | Office, PDF | Internal print infrastructure. |
| Tracked changes, comments, hidden text | Office | Deleted content and reviewer remarks. |
| Old content after edits | Earlier revisions kept by incremental updates. | |
| Original thumbnail | Photo EXIF | Uncropped or unredacted frame. |
| Mail server hops and IPs | Email headers | Internal 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
- Authors give a username convention to test.
- Software and versions give a target list for further checks.
- Paths give internal naming and structure.
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
- Embedded capture time later than the file modify time: possible clock or timezone issue, or tampering.
- Editing software named in a "straight from camera" photo.
- Producer string does not match the claimed origin of a document.
- Identical metadata across files that claim different authors.
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
- Use Inspect Document in the application. Remove comments, revisions, hidden text and personal information.
- Check the package after saving.
unzip -l cleaned.docx
unzip -p cleaned.docx docProps/core.xml
unzip -p cleaned.docx word/comments.xml
- Safer option for sharing: export to PDF, then clean the PDF as above.
General-purpose tools
mat2 --show file.docx # list what mat2 sees
mat2 file.docx # writes file.cleaned.docx
Habits
- Turn off geotagging in the camera app.
- Screenshot instead of sharing the original image when only the picture matters. Check that the screenshot tool adds nothing.
- Do not rely on a platform to strip metadata for you.
- A cleaned copy gets new filesystem timestamps. The original times do not carry over. Account for this before sharing.
- Strip, then inspect with a different tool from the one that stripped.
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
inspect PATH:--shallowskips subfolders.--format text|json|csv.--outputsaves a report. CSV requires--output.clean PATH:-o/--outputis required. File in, file out. Folder in, folder out with the same layout.--shallowskips subfolders.--overwritereplaces existing outputs.
Supported files
- Images: JPG, JPEG, PNG, WebP, TIF, TIFF, BMP, GIF.
- PDF.
Exit codes
0: success.1: at least one file failed, was skipped, or no supported files were found.2: path does not exist, or invalid options such as CSV without--output.
Scripts can branch on these.
How inspect works
find_filescollects supported files by extension, recursively by default.inspect_filepicks the reader from the extension.- Images use Pillow. Output: format, dimensions, mode, frame count, EXIF tags, container fields, ICC profile presence.
- PDFs use pypdf. Output: page count, encryption status, document information fields.
- Binary values are reported as
<binary data: N bytes>. - 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.
- Images: apply EXIF orientation to the pixels, then copy only the pixel data into a new image and save it. EXIF, ICC profiles, comments and container fields are not carried over. Animated images are rejected.
- PDFs: copy pages into a new PDF. The document information dictionary is not copied. Encrypted PDFs are rejected. Decrypt first.
Code layout
core.py:inspect_image,inspect_pdf,inspect_file,find_files,clean_image,clean_pdf,clean_file,write_report.cli.py: argparse parser, text summary, exit codes.- Inspection and cleaning are separate functions. A new format needs a reader and a cleaner, not changes to the CLI.
Limits
- No redaction of text or images on PDF pages.
- No guarantee that every metadata structure is removed.
- Re-encoding can change file size and colour slightly.
- Office documents are not supported.
- Output files get new filesystem timestamps. Source timestamps are not copied.
Inspect the cleaned copy with ExifTool before sharing. MetaClean is not a forensic sanitisation guarantee.
Python techniques
- argparse: subcommands, options, help text.
- pathlib: path handling, extension checks, recursive search, output paths.
- Type hints:
Path,dict[str, Any],-> int. - Context managers:
withcloses images and output streams on error. - Defensive handling: one bad file does not stop a batch. Exit codes report the outcome.
- Structured output: dictionaries serialised with
jsonandcsv. - Packaging:
pyproject.tomldeclares dependencies and installs themetacleancommand.