Web Security - Gathering the Magic Number for an Unknown Content Type
Overview
Every file format starts with a short, fixed sequence of bytes that identifies it, known as its magic number or file signature. A PDF always starts with %PDF-, a Windows program with MZ, a ZIP archive with PK. Unlike the file extension or the Content-Type header a website sends, the magic number comes from the file itself, so it can't be changed by renaming the file.
Web Security identifies files by their contents when applying MIME Type matches on Filter Rules. If a file type isn't recognised, it can't be matched by a MIME Type rule, and may be reported as an unknown content type. To add detection for it, TrustLayer Support need the file's magic number and a few supporting details. This guide shows how to collect them on Windows, macOS and Linux.
[Screenshot: Activity Report entry showing an unknown content type]
What to Collect
Please gather the following before raising a ticket:
- File name and extension exactly as downloaded (do not rename the file).
- Full URL the file was downloaded from.
- Date, time and user of the download, and the rule that matched, from the Web Security Activity Report.
- The application that creates or opens this type of file (for example, "CAD drawing from Autodesk Vault").
- The header dump (
magic-number.txt) produced by the steps below. - The SHA-256 hash of the file, so Support can confirm any sample matches.
- Optionally, a sample file, if it contains no confidential data (see Sending it to Support).
If you can, also note the Content-Type the website sent: in Chrome or Edge, press F12, open the Network tab, download the file again and select the request; the value is under Response Headers.
Getting a Copy of the File Safely
If Web Security is blocking the download, you'll need a copy of the file from somewhere else. In order of preference:
- Ask the supplier or sender for a copy by another route (for example, a shared folder they control).
- Use a copy that already exists on a file server or user's device.
- Download it on a test device with a test user that isn't in scope of the blocking rule.
Whichever route you use:
- Do not open or run the file. The steps in this guide only read its first bytes.
- Scan it with your antivirus before collecting anything.
- Keep the original file name and extension.
The examples below assume the file is saved as example.bin in your Downloads folder. Replace this with the real file name.
Windows (PowerShell)
Open PowerShell from the Start menu (no admin rights needed). These commands work in both Windows PowerShell 5.1 and PowerShell 7.
Step 1: Set the file path
$f = "$env:USERPROFILE\Downloads\example.bin"
Step 2: Copy the first 512 bytes and create the header dump
This reads only the start of the file, saves it as header.bin, then writes a readable hex dump to magic-number.txt on your Desktop.
$s = [System.IO.File]::OpenRead($f); $buf = New-Object byte[] 512; $n = $s.Read($buf, 0, 512); $s.Close()
[System.IO.File]::WriteAllBytes("$env:USERPROFILE\Desktop\header.bin", $buf[0..($n - 1)])
Format-Hex -Path "$env:USERPROFILE\Desktop\header.bin" | Out-File "$env:USERPROFILE\Desktop\magic-number.txt"
Step 3: Add the file hash and size
Get-FileHash -Algorithm SHA256 -Path $f | Format-List | Out-File "$env:USERPROFILE\Desktop\magic-number.txt" -Append
(Get-Item $f).Length | Out-File "$env:USERPROFILE\Desktop\magic-number.txt" -Append
Step 4: Check the output
notepad "$env:USERPROFILE\Desktop\magic-number.txt"
The first line of the dump shows the first 16 bytes in hex, with their text equivalent on the right. Those bytes are the magic number.
[Screenshot: Format-Hex output in Notepad]
macOS and Linux (Terminal)
Open Terminal (on macOS: Applications → Utilities → Terminal). No admin rights needed.
Step 1: Create the header dump
This writes the first 512 bytes as hex to magic-number.txt on your Desktop.
xxd -l 512 ~/Downloads/example.bin > ~/Desktop/magic-number.txt
Step 2: Add the detected type, hash and size
file gives the operating system's own view of the file type, which is useful for Support to compare against.
file ~/Downloads/example.bin >> ~/Desktop/magic-number.txt
file -b --mime-type ~/Downloads/example.bin >> ~/Desktop/magic-number.txt
shasum -a 256 ~/Downloads/example.bin >> ~/Desktop/magic-number.txt
wc -c < ~/Downloads/example.bin >> ~/Desktop/magic-number.txt
On Linux, if shasum isn't installed, use sha256sum ~/Downloads/example.bin instead.
Step 3: Check the output
cat ~/Desktop/magic-number.txt
[Screenshot: xxd output in Terminal]
Alternative: Using a Browser-Based Tool
If you can't run PowerShell or Terminal, you can view the magic number in CyberChef, a free tool from GCHQ. CyberChef runs entirely in your browser, so the file is not uploaded anywhere.
- Open CyberChef and drag the file into the Input pane (top right).
- From the Operations list, drag Detect File Type into the Recipe. The Output pane shows the detected type, or nothing if the type isn't recognised.
- Replace it with To Hex to see the bytes. The first values in the output are the magic number.
- Copy the first few lines of the To Hex output into your ticket.
Do not use sites that upload the file to a server to identify it. In particular, files submitted to VirusTotal are shared with its security community, so never submit customer or confidential files there.
[Screenshot: CyberChef with Detect File Type and To Hex]
Checking the Result
Compare the first bytes of your dump with the common signatures below. If it matches one of these, the file may be a known type with an unusual extension (for example, a .pkg that is really a ZIP), which is still worth reporting.
Hex (start of file) | Text | File type |
|
| |
|
| ZIP, and ZIP-based formats (DOCX, XLSX, PPTX, JAR, APK) |
|
| Windows executable or library (EXE, DLL) |
| Legacy Office and installers (DOC, XLS, PPT, MSI) | |
|
| Linux executable |
| macOS executable (Mach-O 64-bit) | |
| GZIP (GZ, TGZ) | |
|
| 7-Zip |
|
| RAR |
|
| PNG image |
| JPEG image |
Signatures that aren't at the start
Some formats put their signature further into the file, which is why this guide captures 512 bytes rather than just the first few:
- MP4, MOV, HEIC:
66 74 79 70(ftyp) at offset 4. - TAR:
75 73 74 61 72(ustar) at offset 257 (0x101). - ISO disk images:
43 44 30 30 31(CD001) at offset 32769 (0x8001). If you suspect a disk image, capture 36 KB instead by changing512to36864in the commands above.
If the file starts with 50 4B 03 04, it's a ZIP container. Support will use the rest of the 512 bytes (which usually include the name of the first file inside the archive) to tell the specific format apart.
Sending it to Support
Raise a ticket with TrustLayer Support and attach magic-number.txt along with the details from What to Collect. The header dump alone is usually enough.
If Support ask for a sample file, put it in a password-protected ZIP so that email and web security filters don't strip or block it, and include the password in the ticket.
Windows (with 7-Zip installed):
& "C:\Program Files\7-Zip\7z.exe" a -tzip -pinfected "$env:USERPROFILE\Desktop\sample.zip" $f
macOS and Linux (you'll be asked to enter a password):
zip -e ~/Desktop/sample.zip ~/Downloads/example.bin
Once you've finished, delete header.bin, sample.zip and any test copies of the file from your Desktop and Downloads folders.