Author: Valli-Nayagam Chokkalingam

A PDF+ZIP polyglot can smuggle an EXE, DLL, or other blocked file type past Gmail’s attachment scanner by appearing as a PDF to Gmail while remaining a fully extractable ZIP to 7-Zip, WinRAR, or any standard archive tool.

Contents

Introduction

Have you ever tried to email a simple script or a password-protected ZIP, only to have Gmail slam the door in your face? It’s frustrating. But Gmail’s attachment security is a prime example of how consumer email services try to keep you safe from malware.

When Gmail blocks a message, you typically see: “This message was blocked because its content presents a potential security issue.”

Here’s exactly how Gmail decides what gets through—and how a clever file format trick let me slip an EXE past its defenses.

Figure 1. Gmail blocking an EXE attachment with a security error message.

The Strict Extension Blocklist

To protect users, Gmail simply refuses to attach certain file types. This ban extends to compressed versions of those files (like .gz or .bz2) and files hidden inside archives (like .zip or .tgz).

The blocked list is long and updated often. If your file ends in any of these, Gmail will reject it:

  • Executables & Scripts: .exe, .bat, .cmd, .com, .lnk, .pif, .ps1, .scr, .shb, .vb, .vbe, .vbs, .wsf, .wsh
  • System & Library Files: .cab, .cpl, .dll, .drv, .img, .iso, .lib, .msc, .msi, .msp, .mst, .sys, .vhd, .vxd
  • Application & Developer Packages: .apk, .appx, .appxbundle, .msix, .msixbundle, .jar, .jnlp, .js, .jse, .mjs, .xll
  • Microsoft Office & System Macros: .ade, .adp, .chm, .hta, .ins, .isp, .mde, .sct
  • Diagnostic Logs: .diagcab, .diagcfg, .diagpkg

And remember: Gmail’s filtering goes beyond extensions. Even messages without attachments can be blocked if the body text, images, or links look malicious.

Figure 2. Google Help page listing all file types blocked in Gmail.

How Gmail Scans Your Email (Layer by Layer)

Gmail doesn’t just look at the file name. Its filtering works in multiple layers.

1. Content Compliance Rules
This layer scans messages and attachments for specific text or patterns set by administrators.

  • Content filters scan up to 1 MB.
  • For extracted text (like from a PDF), only the first 1 MB is scanned.
  • Gmail does not convert or scan files larger than 10 MB under this layer.

2. The Security Sandbox
For Google Workspace, the Security Sandbox runs attachments in a virtual environment to catch zero-day malware.

Scanning can delay delivery by up to 3 minutes.

Supported files include Windows executables (.exe), Microsoft Office files, and PDFs.

Why Password-Protected Archives Can Trigger Gmail Blocking

Gmail automatically scans email attachments for malicious content. However, Google’s documentation acknowledges an important limitation: Gmail cannot open or inspect the contents of password-protected files or archives, and it cannot scan the inner contents of an encrypted archive.

This creates an important security limitation. A password-protected ZIP containing a PDF may be delivered because Gmail cannot inspect the protected PDF. However, if the archive contains a file type that Gmail blocks—such as an executable or another prohibited attachment type—the message may be blocked even when that file is hidden inside the password-protected archive.

In other words, password protection does not necessarily make a blocked file extension acceptable to Gmail. Gmail’s attachment-security rules can still prevent messages containing prohibited file types from being delivered.

The key distinction is that Gmail may be unable to scan the protected contents, while its attachment policies can still block certain prohibited file types contained within an archive.

Figure 3. Gmail warning that a password-protected ZIP cannot be scanned.

The Polyglot Bypass: When a PDF Is Also a ZIP

A polyglot file is a single file that is valid in two formats at once. The one I used is a PDF+ZIP polyglot: it starts with a PDF header (%PDF-) and ends with a valid ZIP end-of-central-directory record (PK\x05\x06).

To Gmail, it looks like a PDF. Gmail applies its PDF scanning logic and never treats the file as a ZIP. The ZIP portion lives after the PDF structure ends and is simply not inspected.

To 7-Zip, WinRAR, or any standard archive tool, however, the same file is a ZIP archive. These tools ignore the PDF header and read the archive, revealing the files inside.

The trick is to adjust the ZIP’s internal offsets so they account for the PDF prefix. Without that fix, the ZIP wouldn’t extract correctly in any archive tool. With it, the file is genuinely dual-natured—a valid PDF to a document viewer, and a valid ZIP to 7-Zip, WinRAR, or Windows Explorer’s built-in archive handler.

Figure 4. Hex view of the polyglot file’s first bytes showing the ASCII %PDF- header (hex: 25 50 44 46 2D) that Gmail reads to classify the file as a PDF document.

Figure 5. Hex view of the polyglot file’s final bytes showing the ZIP end-of-central-directory signature PK\x05\x06 (hex: 50 4B 05 06) that 7-Zip and WinRAR read to treat the same file as a ZIP archive.

Testing with Gmail

I built a PDF+ZIP polyglot that looks like a bank statement. The outer PDF shows a balance and a note: “To access the full transaction details, open this file with 7-Zip and run Statement_Launcher.bat.”

The ZIP contains Statement_Launcher.bat, payload.exe, and a README.txt. The detailed transaction PDF is not stored as a separate file. Instead, it’s base64-encoded and embedded inside the launcher. When run, the launcher decodes the PDF to %TEMP%, opens it, and then silently runs payload.exe.

I sent this file through Gmail. It was not blocked. It arrived in the inbox like any normal PDF.

Figure 6. Screenshot of the sent email’s attachment section showing the polyglot bank statement PDF attached with no security warning or block.

Flow of Events

  1. Generate the outer PDF – A bank statement summary with account details and a 7-Zip instruction note.
  2. Generate the detailed PDF – The full transaction history.
  3. Embed the detailed PDF in the launcher – Base64-encoded inside Statement_Launcher.bat.
  4. Build the ZIP – Contains the launcher, payload, and README. The detailed PDF is not a separate file.
  5. Adjust ZIP offsets – Increment every offset by the PDF’s length so the ZIP extracts cleanly.
  6. Assemble the polyglot – Concatenate PDF + adjusted ZIP into statement.pdf.
  7. Send through Gmail – Gmail sees a PDF and applies PDF scanning. It never looks inside the ZIP.
  8. Recipient opens the PDF – Sees the summary and the 7-Zip note.
  9. Recipient opens with 7-Zip – Sees the launcher, payload, and README.
  10. Runs the launcher – Detailed PDF is dropped to %TEMP% and opened; payload runs silently.
  11. User sees the detailed statement – The scanner never saw the archive.

Figure 7. Screenshot of the outer PDF bank statement showing the instruction note directing the user to open the file with 7-Zip, extract the archive, and run Statement_Launcher.bat to view the detailed statement.

Figure 8. Opening the polyglot PDF in 7-Zip to reveal and extract its hidden archive contents.

Figure 9. File Explorer view showing the extracted contents: payload.exe, Statement_Launcher.bat, and README.txt.

Figure 10. The detailed statement opens in the PDF viewer, showing the full transaction history from the file silently dropped to the temp folder. This happens once Statement_Launcher.bat is launched.

Figure 11. While the detailed decoy PDF is displayed to the victim, payload.exe executes silently in the background.

A Practical Note on Ethics and Scope

This research is for authorized security testing only. Always work on systems you own or have explicit permission to test, use benign payloads, and share findings responsibly.

Companion Repository

The full PoC is on GitHub: github.com/adversarycraft/janus-file

It contains the polyglot generator script and a short README explaining how to use it. Clone it, install ReportLab, and run the command from the usage section above.

Feedback and pull requests welcome.

Closing Thoughts

Polyglot files aren’t vulnerabilities—they’re just a quirk of file formats. But they expose the assumption many scanners make: that a file has only one type. When a file is two things at once, the scanner must choose which interpretation to apply. That choice is what lets a PDF+ZIP polyglot slip past Gmail’s defenses.

If you’re evaluating email security, add a few polyglot test cases to your suite. You might learn something the documentation doesn’t tell you.

References

  1. Google Support – File types blocked in Gmail: https://support.google.com/mail/answer/6590
  2. Google Workspace Admin Help – Gmail attachment compliance: https://support.google.com/a/answer/2364580
  3. Google Workspace Admin Help – Gmail Security Sandbox: https://support.google.com/a/answer/7676854
  4. PKWARE – ZIP File Format Specification (APPNOTE): https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
Posted in

Leave a Reply