August 17th, 2024

Hacking with PDF (2022)

The article outlines how PDF files can be exploited through techniques like injection and XSS, emphasizing the need for understanding PDF structure to prevent attacks and analyze malicious content.

Read original articleLink Icon
Hacking with PDF (2022)

The article discusses the use of PDF files as an attack vector, detailing various techniques for exploiting vulnerabilities within PDFs. It emphasizes the importance of understanding the PDF structure to effectively execute attacks such as PDF injection, cross-site scripting (XSS), credential theft, and remote code execution (RCE). The author explains how to create malicious PDFs that can execute JavaScript to display alerts, steal user credentials, or redirect users to harmful websites. Specific examples include using the app.alert() function for XSS and the submitForm() method to send stolen credentials to an attacker's server. The article also highlights the risks associated with outdated PDF readers and provides a demonstration of exploiting a vulnerability in Foxit Reader to achieve RCE. Additionally, it covers methods for analyzing malicious PDFs using tools like peepdf and pdf-parser, which can help identify and extract harmful JavaScript code embedded within PDF files. The author concludes by stressing the importance of both offensive and defensive skills in cybersecurity.

- PDF files can be exploited through various techniques, including injection and XSS.

- Attackers can steal credentials by embedding JavaScript in PDFs that prompts users for sensitive information.

- Remote code execution can be achieved by exploiting vulnerabilities in outdated PDF readers.

- Tools like peepdf and pdf-parser are useful for analyzing and extracting malicious content from PDFs.

- Understanding PDF structure is crucial for both launching attacks and developing defenses against them.

Link Icon 4 comments
By @JKCalhoun - 5 months
FWIW, ages ago I wrote the PDFKit framework for the Mac (used by Preview and the built-in PDF viewer in Safari).

The only exploit listed here that has a chance of working with Preview/Safari (PDFKit) is the URI one — none of the Javascript exploits will work.

Why? I never implemented Javascript support [1].

Security was extremely important at Apple (there's a whole security team that frequently interact with the various project owners around the company, write and deploy file fuzzers, create must-fix Radars around exploits found in the wild, etc.).

In fact though I had no idea how I would hoist a Javascript runtime and I didn't really have the cycles to implement it if I had known how to. Anyways we were content to support the 99% of PDFs out there.

[1] In fact there were a few US tax documents that used very simple Javascript snippets to take the values from two fields, add them, and put the result in a third. Some code in PDFKit I added would identify these few very simple patterns and implement them sans JS runtime.

By @jjbinx007 - 5 months
I've always held the opinion that viewing PDFs in something other than Adobe Acrobat gives the user more of a chance of avoiding such attacks... is there any credence to this or is it just wishful thinking?
By @banku_brougham - 5 months
This is a great demo, ive been concerned about all these pdfs i like to read, this gives me a little more confidence about tools to scan odfs for attacks.
By @nicolodev - 5 months
I’m writing a little tool for analysing a pdf and its internals, if author is interested or anyone else, just let me know :)