• Stars
    star
    211
  • Rank 186,867 (Top 4 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Inject a JS file into a PDF file.

JS2PDFInjector

Use this tool to Inject a JavaScript file into a PDF file.

To do this you will need an existing PDF file, and a ".js" file which contains the commands you would like to run when the document is opened. I use this to create PDFs with some active code in there that I can email to customers, or download through their proxies, to check for the JavaScript being removed or blocked. When you open the produced PDF with the JavaScript injected in Adobe you should see your code execute. Mileage varys in other viewers and for certain Edge in Windows 10 does not execute.

JavaScript API available in PDF

The following URL contains the JavaScript API details:

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf

These are different from browser based JavaScript so reading that to achieve anything advanced is recommended.

Example JavaScript

Who doesn't love a simple alert message? I know I do. The following code is all you will need for your hello world alert message:

app.alert("Hello world!");

A little different from just "alert". Your alert method now lives attached to the "app" object. Nothing too crazy.

How to use

Follow the steps below to create your PDF:

  • Execute the jar file.
  • If no command line arguments are provided "usage" instructions will be provided
  • Then it will open a GUI prompt that asks you to point it at a PDF file.
  • Select the PDF file you would like to inject in to.
  • Another prompt will appear looking for the file containing your JavaScript.
  • Select that file.
  • This will create a new file in the same directory as the PDF with "js_injected_" prepended in the name.

To automate the process via the command line the following shows the new usage:

java -jar JS2PDFInjector.jar <PDF FILE> <JS FILE>

This does no checking that the files you provide exist so don't run with scissors.

If you need to inject one JS file into multiple PDF files then you can do so with a for loop. For bash that is shown below:

for pdf in /path/to/pdfs/*.pdf
do;
java -jar JS2PDFInjector.jar $pdf /path/to/javascript.js
done;

I have not spent time on crafting the interface. But this should work.

Common Error

When running in headless mode if you see a FileNotFoundException like this:

[*] Original PDF: dummy.pdf
[*] JavaScript Payload: test.js
[*] Output File Path: null/js_injected_dummy.pdf
java.io.FileNotFoundException: null/js_injected_dummy.pdf (No such file or directory)
	at java.base/java.io.FileOutputStream.open0(Native Method)
	at java.base/java.io.FileOutputStream.open(FileOutputStream.java:299)
	at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:238)
	at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:188)
	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1305)
	at com.cornerpirate.js2pdfinjector.JS2PDFInjector.main(JS2PDFInjector.java:107)

It means you used relative paths to the files. Please supply the absolute path as command line arguments. So instead of this command:

java -jar JS2PDFInjector.jar dummy.pdf test.js

You should use absolute paths like this:

java -jar JS2PDFInjector.jar /tmp/dummy.pdf /tmp/test.js

Full paths for the win.

How to use JS2PDFInjector to Test your Email or Internet filtering

For more information please see the blog post by the author:

https://cornerpirate.com/2017/02/10/js2pdfinjector-javascript-for-your-pdf/

The blog post is no outdated and shows only the GUI usage path.

Dislaimer

For research purposes only, do not use this on any target which you do not have permission to do so.

More Repositories

1

socat-shell

Socat can be used to establish a reverse shell with bash tab completion and full shell functionality
Shell
137
star
2

java-stager

A PoC Java Stager which can download, compile, and execute a Java file in memory.
Java
110
star
3

ReportCompiler

A tool for importing vulnerability scanner data and then allowing you to manipulate the risks, affected hosts, and create risk ordered output.
Batchfile
79
star
4

cve-offline

An easy to grep dump of the NVD database showing only; CVE-ID, CVSS Risk Score, and Summary.
Python
52
star
5

rdpupload

Python script which will type a file into an RDP session. For when drag and drop and disk mounting is not possible
Python
31
star
6

nmap-summariser

another nmap summarising script
Python
26
star
7

gitshell

A PoC .net shell which uses a GitHub.com repository for the communication channel.
C#
13
star
8

iRecon

Of the thousands of lazy reconnaissance scripts, this one is by far the one in this repository.
Python
11
star
9

ReportCompilerSource

Source Code for ReportCompiler
Java
8
star
10

git-fingerprint

Enumerate information from a target using git
Python
7
star
11

teachingMoments

A collection of cyber security teaching materials.
PHP
7
star
12

git-version

Find out what version of a file you have access to
Python
5
star
13

BurpExtenderForge

An Extender for Burp Suite allowing you to quickly craft Extenders in Burp.
Java
3
star
14

metasploit-modules

A repo where I lob metasploit modules
Ruby
3
star
15

find-encoder

Scripts that help me find encoding mechanisms.
Python
3
star
16

DemoExtender

Code used for a tutorial to get Netbeans GUI editor to work with a Burp Suite Extender
Java
3
star
17

http-options

A dirty script to run HTTP OPTIONS against a list of directories
Python
2
star
18

rdp-enum

PowerShell script that enumerates RDP security settings
PowerShell
2
star
19

ReportCompilerWordMacroDemo

A demo showing a Macro enabled Word Template which can import XML file from ReportCompiler
1
star