Malware Exploitation in PDFs: A Red Team Perspective

Filipi Pires (Head of Identity Threat Labs and Global Product Advocate · Scythe)

RTV Overflow 2026 (Red Team Village) · Day 1 · Main Stream

Overview

In his RTV Overflow talk, "Malware Exploitation in PDFs: A Red Team Perspective," Filipi Pires, Head of Identity Threat Labs and Global Product Advocate at Scythe, delved into the enduring threat of malicious PDF documents as an initial access vector. Pires meticulously unpacked the internal structure of PDFs, demonstrated how attackers embed and obfuscate malicious code, and guided the audience through a practical analysis workflow. The session provided invaluable insights for both offensive security practitioners seeking to craft effective PDF-based exploits and blue team defenders striving to fortify their defenses against such pervasive threats.

Watch on YouTube

Visual summary for Malware Exploitation in PDFs: A Red Team Perspective by Filipi Pires
Visual summary for Malware Exploitation in PDFs: A Red Team Perspective by Filipi Pires

Key moments

  1. 0:00 Introduction and talk overview
  2. 6:30 PDF physical and logical structure explained
  3. 9:40 Misleading file type identification with magic numbers
  4. 25:30 Key indicators of malicious PDFs (Object Stream, JS, OpenAction)
  5. 34:50 Extracting malicious URIs from PDF objects
  6. 43:50 Deobfuscating embedded JavaScript exploit code
  7. 51:00 Q&A: The biggest challenge in PDF exploitation

Malware Exploitation in PDFs: A Red Team Perspective

Speakers: Filipi Pires, Head of Identity Threat Labs and Global Product Advocate, Scythe

Conference: RTV Overflow

YouTube: https://www.youtube.com/watch?v=4_5lk2Mh4D8

Overview

In his RTV Overflow talk, "Malware Exploitation in PDFs: A Red Team Perspective," Filipi Pires, Head of Identity Threat Labs and Global Product Advocate at Scythe, delved into the enduring threat of malicious PDF documents as an initial access vector. Pires meticulously unpacked the internal structure of PDFs, demonstrated how attackers embed and obfuscate malicious code, and guided the audience through a practical analysis workflow. The session provided invaluable insights for both offensive security practitioners seeking to craft effective PDF-based exploits and blue team defenders striving to fortify their defenses against such pervasive threats.

Pires emphasized that despite the evolution of cybersecurity defenses, PDFs remain a highly reliable method for delivering malware due primarily to their ubiquitous use in everyday business and personal communications. Users routinely open PDF attachments, such as resumes, invoices, or instructional documents, often without a second thought, making them a prime target for social engineering campaigns. The talk highlighted the critical need for a deep understanding of PDF internals, not just relying on surface-level indicators, to effectively detect and neutralize these sophisticated attacks.

The presentation underscored that effective defense against malicious PDFs requires more than just basic antivirus solutions; it demands a comprehensive approach that includes user education, advanced static and dynamic analysis techniques, and a thorough understanding of common exploitation methods. By dissecting real-world examples and walking through the deobfuscation process of embedded JavaScript, Pires equipped attendees with the knowledge to approach PDF analysis with a red team mindset, ultimately bolstering their ability to build more resilient defensive strategies.

Background

▶ Watch: Introduction and talk overview (0:00)

The landscape of malware analysis is broadly categorized into two primary approaches: statistical analysis (also known as static analysis) and dynamic analysis. Statistical analysis involves examining the program's code, structure, and imported functions without executing it. This method, while generally safer, requires a deep understanding of file formats, assembly language, and programming constructs. Conversely, dynamic analysis observes the malware's behavior during execution, typically within a controlled environment like a sandbox. A sandbox is a virtual machine or isolated environment equipped with engines designed to monitor and report on the malware's interactions with the system, such as file modifications, network connections, and process injections. Pires highlighted that while dynamic analysis can quickly reveal malicious behavior, a thorough understanding of static analysis is crucial for deeper insights and for bypassing sophisticated evasive techniques.

PDFs, or Portable Document Format files, are intrinsically complex, structured documents designed for reliable presentation across different platforms. Their internal architecture is typically divided into four main sections: the header, body, cross-reference table, and trailer. The header specifies the PDF version. The body contains the actual content, including pages, images, text, and other objects. The cross-reference table is vital for efficient random access to objects within the file, listing the byte offset of each object. Finally, the trailer links together all the objects and points to the cross-reference table, marking the end of the file. Pires explained that this intricate, tree-like object structure, where objects reference each other, forms the backbone of how PDF content is organized and rendered. He referenced Dean Stevens' work on PDF structure for this concept.

The pervasive nature of PDFs in daily workflows—from sharing resumes and invoices to distributing official documents—makes them an ideal vector for initial access. Users are conditioned to trust and open PDF attachments, often without scrutinizing their origin or content. This inherent trust, combined with the format's complexity and support for embedded scripts (like JavaScript) and interactive elements (AcroForms), creates fertile ground for attackers. Malicious actors leverage these features to embed sophisticated payloads, often obfuscated and triggered by seemingly innocuous actions such as simply opening the document. Pires also acknowledged the foundational work of Fernando Mercês in explaining concepts like magic numbers, which are crucial for file type identification and often manipulated by attackers to mislead analysis tools. The challenge for defenders lies in unmasking these hidden threats within a file format designed for versatility and rich interactivity.

Key Findings

▶ Watch: Misleading file type identification with magic numbers (9:40)

Pires's presentation illuminated several critical findings regarding malware exploitation in PDFs, particularly from a red team perspective:

  1. PDFs Remain a Reliable Initial Access Vector: Despite advancements in security, the ubiquitous nature of PDFs in business and personal communication ensures their continued efficacy as a primary method for delivering malware. Users' habitual trust in PDF documents makes them susceptible to social engineering attacks.
  2. Sophisticated Obfuscation and Encoding are Standard: Attackers routinely employ advanced techniques to hide malicious payloads. This includes embedding heavily obfuscated JavaScript, concatenating strings, and utilizing various encoding schemes such as Unicode (specifically UCS-2) which is then converted to hexadecimal and ultimately to binary for execution. This multi-layered approach significantly complicates static analysis.
  3. JavaScript and OpenAction are Key Triggers: The combination of embedded JavaScript and the OpenAction directive is a prevalent exploitation technique. OpenAction ensures that the embedded script executes automatically as soon as the user opens or views the PDF, bypassing the need for further user interaction.
  4. Object Streams Complicate Analysis: PDFs can use object streams to compress multiple objects together, effectively hiding the true number and complexity of objects within the document. This technique can mislead analysts who might assume a PDF with few visible objects is less complex or malicious, only to find hundreds of hidden objects upon decompression.
  5. Understanding Tool Behavior is Paramount: Pires demonstrated how common tools like the file command can be misled. The file command primarily relies on magic numbers (specific byte sequences at the beginning of a file) and, to a lesser extent, file extensions for identification. Attackers can manipulate these to trick tools into misidentifying a file, diverting analysts down the wrong path. Similarly, understanding how strings behaves with packed executables (e.g., not showing the "MZ" header immediately) is crucial.
  6. Deobfuscation Requires Multi-Step Process: Unpacking a malicious PDF payload is rarely straightforward. It involves identifying encoded sections, often requiring custom Python scripts to reverse the obfuscation, piece together fragmented code, and finally extract the underlying exploit or command-and-control (C2) information. Pires illustrated this with an example of an Apache vulnerability exploit and C2 server details.

Technical Deep Dive

▶ Watch: Key indicators of malicious PDFs (Object Stream, JS, OpenAction) (25:30)

Pires initiated the technical deep dive by reiterating the fundamental approaches to malware analysis: statistical (static) analysis and dynamic analysis. Statistical analysis involves scrutinizing the code, imported DLLs, and libraries without execution, offering a safer but often more time-consuming investigative path. Dynamic analysis, conversely, focuses on observing the malware's runtime behavior within a controlled sandbox environment, which typically includes an analysis engine to report on malicious activities. Pires stressed that while sandboxes provide quick insights, a foundational understanding of static analysis is indispensable for uncovering sophisticated evasion tactics.

The core of PDF exploitation lies in understanding its intricate structure. A PDF document is logically divided into a header, body, cross-reference table, and trailer. The header specifies the PDF version (e.g., %PDF-1.4). The body contains the document's content, organized as a collection of various objects—such as pages, images, fonts, and annotations. The cross-reference table acts as an index, mapping each object's ID to its byte offset within the file, enabling efficient random access. The trailer, located at the end of the file, points to the cross-reference table and other essential document properties. Pires illustrated that PDFs form a tree-like object structure, where objects can reference other objects, creating a complex dependency graph that attackers often exploit to hide malicious components.

Pires then demonstrated the practical application of analysis tools, starting with the ubiquitous file command. He highlighted its reliance on magic numbers—specific byte sequences at the beginning of a file that indicate its type—and, secondarily, its extension. Through a clever manipulation of a .js file by adding Python triple quotes, he showed how file could be tricked into identifying a JavaScript file as a Python script, underscoring that attackers can manipulate file headers or content to mislead analysis. He emphasized the importance of consulting tool manuals (like man file) to understand their underlying logic. Similarly, he used the strings command to show how packed executables might not immediately display the "MZ" magic number at their start, as the initial bytes could be part of a compressed section, requiring deeper inspection or specific strings parameters (e.g., -a for all sections).

For PDF-specific analysis, Pires introduced PDFID.py and PDF-parser.py.

PDFID.py is crucial for initial triage, providing a summary of a PDF's characteristics, such as the number of objects, streams, pages, and the presence of suspicious elements like /JavaScript, /OpenAction, /AcroForm, or /EmbeddedFile. A high count of objects, especially with few pages, or the presence of /JavaScript and /OpenAction, are strong indicators of potential malicious activity.

PDF-parser.py allows for deeper inspection, enabling analysts to parse specific objects, extract raw data, and trace object references. Pires showed how PDF-parser.py -a can list all objects and their relationships, which is vital for understanding the PDF's internal flow.

Key indicators of malicious PDFs discussed included:

  • /JavaScript and /OpenAction: This combination is a classic technique. /JavaScript indicates embedded JavaScript, and /OpenAction ensures that this script executes automatically when the PDF is opened, often without user interaction.
  • /AcroForm: While legitimate for interactive forms, it can also be abused to trigger actions.
  • /ObjectStream: This compresses multiple objects, making manual analysis harder as the true object count is hidden until decompressed. Pires demonstrated how a PDF identified by PDFID.py as having 18 objects could, in reality, contain many more when object streams were present.
  • Large Streams: Streams often contain compressed data. Unusually large streams, especially those not associated with images, can hide exploits or payloads.
  • /URI: These can be used to embed external links, some of which might point to malicious downloads.

The deobfuscation process for embedded JavaScript was detailed through a resume.pdf example. Pires identified the malicious JavaScript within object 19 using PDF-parser.py. The script was heavily obfuscated, using techniques like string concatenation and encoding. He explained that such obfuscation often requires custom Python scripts to reverse. In his example, the JavaScript used a unique key (gkph) and was encoded in Unicode (specifically UCS-2). The deobfuscation involved converting the Unicode-encoded hexadecimal strings into binary, which then revealed the final payload. This payload was identified as an exploit targeting an Apache vulnerability and included details of a Command and Control (C2) server located in the Netherlands. This multi-stage deobfuscation process highlights the complexity attackers introduce to evade detection and the analytical rigor required to uncover their intentions.

Demo / Proof of Concept

▶ Watch: Deobfuscating embedded JavaScript exploit code (43:50)

Filipi Pires's presentation was rich with live demonstrations, showcasing the practical aspects of PDF analysis and exploitation. He walked through several scenarios, starting with basic file identification and progressing to complex deobfuscation.

1. Misleading File Identification with file command:

Pires began by demonstrating how the file command, a common tool for identifying file types, can be misled. He showed an RTV.js file, which file correctly identified as "ASCII text." However, by prepending three double-quotes (Python's multiline string delimiter) to the file, file then identified it as a "Python script." This simple trick highlighted that file relies on magic numbers and initial file content, not just extensions, and that attackers can manipulate these to misdirect analysts. He then changed the extension to .Corey and .pdf, showing how the icon changed but file still identified it as "ASCII text" or "Python script," while PDFID.py correctly stated "Not a PDF document." This emphasized that relying solely on extensions or basic tools can be dangerous.

2. Analyzing a Malicious PDF (Thor.pdf) with PDFID.py and PDF-parser.py:

Pires then moved to a genuinely malicious PDF, Thor.pdf. Using PDFID.py, he quickly identified key indicators: 18 objects, 6 streams, and the presence of /JavaScript and /OpenAction. This immediately signaled potential malicious activity. He then used PDF-parser.py -a Thor.pdf to list all objects. Crucially, he pointed out that while PDFID.py reported 18 objects, PDF-parser.py revealed references to objects beyond this count (e.g., 35, 36, 34). This discrepancy was explained by the presence of /ObjectStream, indicating that multiple objects were compressed together, effectively hiding their true number and complexity from initial scans. This demonstrated how attackers use compression to obscure the full scope of a PDF's malicious content.

3. Identifying Malicious URIs in partner.pdf:

Next, Pires analyzed partner.pdf, a PDF seemingly related to a YouTube partnership for "The Wolf Among Us" game. PDFID.py initially showed no JavaScript. However, PDF-parser.py -a partner.pdf revealed several /URI objects (specifically objects 39, 40, 41, 42). Pires extracted these URIs using PDF-parser.py -o [object_number]. He showed that while some URIs led to legitimate sites like Twitter or Telltale Games, one specific URI (from object 39) pointed to a Dropbox link: https://www.dropbox.com/.../doc.har. This .har file, described in the PDF as a "zip file" requiring a password (war codes) for an "agreement," was the malicious payload. Pires used this example to illustrate the social engineering aspect, where legitimate-looking content (game partnership) is combined with a malicious download link, leveraging user trust and curiosity.

4. Deobfuscating JavaScript in resume.pdf:

The most detailed demo involved resume.pdf, a common lure for job seekers. PDFID.py confirmed the presence of /JavaScript and /OpenAction, indicating automatic execution. Using PDF-parser.py -a resume.pdf, Pires identified the specific objects containing JavaScript (7, 9, 8, 18, 19) and confirmed that the OpenAction was linked to this JavaScript. He then zeroed in on object 19, which contained the heavily obfuscated malicious JavaScript.

Pires explained the multi-stage deobfuscation process:

  • Identification of Obfuscation: The JavaScript was a long, concatenated string with a specific key (gkph) and showed characteristics of Unicode encoding.
  • Python Script for Decoding: He used a custom Python script (available on the Segura blog) to automate the deobfuscation.
  • Unicode to Hexadecimal Conversion: The script converted the Unicode-encoded characters (UCS-2) into hexadecimal.
  • Hexadecimal to Binary: This hexadecimal representation was then converted into a binary executable.
  • Payload Identification: The final payload was identified as an exploit for an Apache vulnerability, and the script revealed the Command and Control (C2) server IP address located in the Netherlands.

This comprehensive demonstration underscored the complexity of analyzing and deobfuscating malicious PDFs, requiring a combination of specialized tools, an understanding of PDF internals, and custom scripting for deeper analysis.

Defensive Implications

▶ Watch: Q&A: The biggest challenge in PDF exploitation (51:00)

The detailed analysis of malicious PDFs by Filipi Pires provides critical insights for strengthening defensive postures against these persistent threats. The following implications and recommendations are crucial for defenders:

  1. Enhance User Education and Awareness: Given that PDFs are a primary initial access vector through social engineering, continuous and targeted user training is paramount. Users must be educated on the risks associated with opening unexpected or suspicious PDF attachments, especially those disguised as resumes, invoices, or urgent documents. They should be taught to verify senders and exercise caution before opening any attachment.
  1. Implement Multi-Layered Email and Endpoint Security: Relying on a single security layer is insufficient. Organizations need robust email gateway security that performs deep content inspection of PDFs, looking for embedded scripts, unusual object structures, and suspicious keywords. Endpoint Detection and Response (EDR) solutions should be configured to monitor for process execution originating from PDF readers, unusual file writes, and network connections initiated by PDF processes.
  1. Leverage Advanced PDF Analysis Tools: Blue teams should integrate specialized tools like PDFID.py and PDF-parser.py into their incident response and threat hunting workflows. Training analysts to use these tools to identify indicators such as /JavaScript, /OpenAction, /AcroForm, /EmbeddedFile, and object streams is essential for proactive threat detection and post-incident analysis.
  1. Employ Dynamic Analysis (Sandboxing): All suspicious or untrusted PDFs should be subjected to dynamic analysis in a sandbox environment. This allows for the safe execution of the document, observing its behavior, identifying any attempts to exploit vulnerabilities, drop payloads, or establish C2 communications without risking the production environment. Automated sandboxing solutions can significantly reduce manual analysis burden.
  1. Monitor for Obfuscated and Encoded Content: Defenders should be aware that attackers frequently obfuscate and encode malicious JavaScript and payloads. Security solutions must be capable of detecting and, ideally, deobfuscating such content. Network Intrusion Detection/Prevention Systems (NIDS/NIPS) should be configured to flag unusual outbound connections, especially to geographies associated with known C2 infrastructure (e.g., the Netherlands IP identified in the demo).
  1. Maintain Patch Management Discipline: Exploits targeting PDF readers (e.g., Adobe Acrobat Reader, Foxit Reader) and underlying browser components (if PDFs are viewed in-browser) are common. A rigorous patch management program for all end-user software, particularly PDF viewing applications and operating systems, is critical to mitigate known vulnerabilities like the Apache exploit discussed.
  1. Develop Threat Intelligence and Sharing: Understanding current attack trends and specific TTPs (Tactics, Techniques, and Procedures) used in PDF-based attacks is vital. Sharing indicators of compromise (IOCs) within the security community and subscribing to relevant threat intelligence feeds can provide early warnings and enhance detection capabilities.
  1. Implement Application Whitelisting/Control: In highly sensitive environments, consider implementing application whitelisting to restrict which applications can execute on endpoints. This can prevent unknown or malicious executables dropped by PDF exploits from running.

By adopting these defensive implications, organizations can significantly reduce their attack surface and improve their resilience against the persistent and evolving threat of malicious PDF exploitation.

Key Takeaways

  • PDFs remain a critical initial access vector: Their widespread use and the inherent trust users place in them make them a prime target for malware delivery, particularly through social engineering.
  • Deep understanding of PDF structure is crucial: Effective analysis and defense require knowledge of PDF internals, including headers, objects, cross-reference tables, and the tree-like object structure, to identify hidden malicious components.
  • Tools like file, PDFID.py, and PDF-parser.py are indispensable but require nuanced understanding: Basic tools can be misled by attackers manipulating magic numbers or file extensions, necessitating a deeper grasp of how these tools function and what their output truly signifies.
  • Attackers heavily rely on obfuscation and specific PDF features: Malicious JavaScript, often heavily obfuscated, combined with OpenAction directives and object streams, are common techniques used to hide payloads and ensure automatic execution upon document opening.
  • Deobfuscation is a multi-stage process: Unpacking complex PDF malware often involves identifying various encoding schemes (e.g., Unicode, hexadecimal), breaking down concatenated strings, and employing custom Python scripts to reveal the final exploit code and Command and Control (C2) infrastructure.
  • Layered defense and user education are paramount: A combination of robust email and endpoint security, dynamic analysis (sandboxing), continuous patch management, and comprehensive user awareness training is essential to defend against sophisticated PDF-based attacks.

About the Speaker(s)

Filipi Pires is a prominent figure in the cybersecurity community, currently serving as the Head of Identity Threat Labs and Global Product Advocate at Scythe. His expertise spans various facets of cybersecurity, focusing on red team activities, purple teaming, and threat intelligence. Beyond his corporate role, Pires is deeply involved in community initiatives. Pires directs sponsorships for the Red Team Village, demonstrating his commitment to fostering community growth and knowledge exchange. He is also the organizer of BSides Porto in Portugal, his current base, and founded a red team-focused community for Latin America to support events like Hacker to Hackers. He also supports a community initiative that helps people enter the cybersecurity field. Originally from Brazil, he frequently travels between the US, Portugal, and Brazil, bringing a global perspective to his work and community engagements.

Reviews

Dr. Zero (Offensive Security Researcher) — WEAK

This is a 2010 malware analysis 101 class dressed up as a modern red team talk. Running Didier Stevens' pdfid.py and explaining what a magic number is does not constitute novel research. If you're a SOC analyst on your first day, take notes; otherwise, you've seen this exact presentation a dozen times.

Heather Calloway (CISO) — SOLID

This is a tactical walkthrough for SOC analysts on how attackers obfuscate malware inside PDFs to bypass static analysis. It isn't a talk for your leadership team, but it validates why we need layered endpoint controls rather than relying entirely on our email gateways to catch initial access payloads.

→ Top-rated talks at RTV Overflow 2026 (Red Team Village)

All talks from RTV Overflow 2026 (Red Team Village)