Friday, November 27, 2026

malicious-pdf for testing document-borne SSRF, XSS and callback detection

malicious-pdf for testing document-borne SSRF, XSS and callback detection

jonaslejon/malicious-pdf is a Python utility that generates deliberately malicious PDF test documents so authorized testers can validate detection of phone-home callbacks, SSRF, XSS and NTLM credential leaks in document-handling pipelines.

Tooljonaslejon/malicious-pdf — generates malicious PDF test files for evaluating SSRF, XSS, NTLM-hash-leak and callback detection
CategoryAdversarial document generation / detection testing utility
Primary UseProducing synthetic malicious PDFs to test how mail gateways, sandbox systems, and PDF parsers in bugbounty and authorized pentest scopes handle embedded JavaScript, external resources, and redirect tricks
Safe UseUse only within authorized engagements, lab environments, and defensive tool validation — the generated files are test artifacts for gauging detection coverage, not weapons for targeting third parties
Telemetry NoteGenerated PDFs trigger outbound connection attempts and parser warnings observable in proxy logs, sandbox detonation reports, and mail-gateway alerts — defenders should treat unexpected embedded URI actions and JavaScript as signals

jonaslejon/malicious-pdf occupies a specific niche in the testing toolbox: it fabricates PDF files that are deliberately hostile in structure, so that blue and red teams alike can measure whether their controls actually react. The repository's own description lists its core test scenarios — phone-home callbacks, SSRF, XSS, and NTLM credential disclosure — which map directly to the most common ways real malicious documents abuse the PDF format's richer features. With roughly 4,500 stars and a BSD-2-Clause license, it has clearly resonated with the pentesting and bugbounty communities that dominate its topic tags. This writeup treats it purely as an educational and documentary analysis for authorized professionals.

The underlying premise is simple but operationally important. PDF is not a flat document format; it is a container that can embed JavaScript, launch actions, external URI references, and embedded files. When a viewer, an automated preview service, or a sandboxed document parser processes such a file, those features can be coerced into making outbound connections. malicious-pdf generates files exercising those behaviors against hosts you control, letting you watch whether your monitoring stack sees the callback. It is essentially a detection-evaluation payload factory, not an exploitation framework.

The SSRF angle deserves emphasis because it is where this class of test artifact pays off most in modern cloud environments. Many SaaS platforms render user-uploaded PDFs server-side — invoicing systems, preview thumbnails, e-signature flows. A PDF that references external resources can, if the renderer follows those references, become an SSRF probe against internal endpoints. In an authorized engagement against your own upload-and-render pipeline, malicious-pdf files give you concrete evidence of whether the renderer resolves external references, and defenders can use the same artifacts to verify that their egress controls block such resolution.

The NTLM credential-leak scenario reflects a Windows-specific weakness that remains stubbornly relevant in enterprise testing. Documents that trigger outbound SMB or HTTP authentication from a Windows host can cause automatic NTLM handshake attempts, exposing challenge-response material to a capture point. On authorized internal networks with explicit permission, testing whether document-handling workflows leak NTLM traffic is a standard hygiene check; the generated PDFs function as the trigger, and the assessment is judged by what the monitoring side captures. The tool does the document side of that equation, not the capture side.

XSS via PDF is the third pillar. Embedded JavaScript in a PDF, when executed by a vulnerable viewer or by an HTML-based in-browser renderer, can become a script-execution vector inside an origin the attacker does not control. Testing this against your own document-preview feature in a bugbounty program scope is a legitimate and frequently rewarded class of finding. The repository's bugbounty and bugbounty-tool topic tags suggest this is a primary intended audience — researchers who need a quick way to probe how a target's viewer handles document-embedded script, without hand-crafting raw PDF object streams each time.

From an architecture standpoint, the tool is a straightforward Python generator: you point it at an operator-controlled host, and it writes PDFs containing the relevant embedded actions and references aimed at that host. The design philosophy — generate against your own listener rather than embedding any attacker infrastructure — is what keeps it a testing utility rather than a delivery weapon. There is no command-and-control component, no payload delivery automation, and no targeting logic in the tool itself; the observable behavior comes entirely from how the target application chooses to process the document.

For defenders, the telemetry value is the real story. Every file this tool produces is, by construction, a tripwire. If your mail security gateway lets one through to a user's inbox, that is a filtering gap. If your sandbox detonates the PDF and the embedded callback never appears in your proxy or DNS logs, that is a visibility gap. If your server-side renderer resolves an external resource reference, that is an SSRF exposure. Running the full generated set through your pipeline periodically — in a lab, with the callback pointed at a host you own — gives you a cheap, repeatable regression test for document-borne threat handling, which is exactly how mature programs treat it.

The 4,500-star traction is itself a useful signal for threat-intel and detection-engineering teams: malicious PDF generation is common enough in testing that detections tuned only to real campaign infrastructure will misfire or miss entirely. Detections should key on structural properties — embedded JavaScript objects, /URI actions, external resource resolution, Launch actions — rather than on specific hashes or domains, precisely because tools like this make trivially regenerable variants. Treating malicious-pdf's output as a canonical corpus for tuning those structural detections is one of the more practical defensive applications of the repo.

Usage-wise, the entry point is the standard pattern for a small Python CLI from GitHub: clone jonaslejon/malicious-pdf, install any declared dependencies into your environment, and run the generator pointed at a listener host you control. The exact flag set lives in the repository, and the README is the authoritative reference; consult it on the repo page rather than relying on third-party summaries, since the interface can evolve with the main branch. What matters operationally is that every generated file is aimed at infrastructure you own, keeping the whole exercise inside authorized bounds.

Caveats worth stating plainly: these files will trip endpoint protections, and mishandling them — emailing them to real users, uploading them to third-party services, or detonating them outside a controlled lab — is both counterproductive and outside any legitimate scope. The tool's value collapses the moment it is aimed at systems you do not own or are not contracted to test. Used correctly, though, malicious-pdf is a compact, well-scoped instrument for a genuinely hard problem: proving, not assuming, that your document-handling stack behaves safely when handed a hostile file.

Official project repository for jonaslejon/malicious-pdf.
Download Tool

Educational analysis for authorized security professionals. Use only in controlled, authorized environments.

Sponsored
Share articleFacebookXLinkedIn

Continue exploring

Browse all articles →

0 comentários:

Post a Comment

Note: Only a member of this blog may post a comment.