Created
March 30, 2020 15:54
-
-
Save imvasen/3d50797bb8ce4e4f7b776e583752a904 to your computer and use it in GitHub Desktop.
Uses brute force to get a numerical password from a PDF.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Requirements: | |
| * pdftops installed on your system. | |
| * Usage: | |
| * $ node pdf.js filename.pdf | |
| */ | |
| const { exec } = require('child_process'); | |
| async function fn(file) { | |
| return new Promise((resolve, reject) => { | |
| // Search for password in the range [0000-9999] | |
| for (let i = 0; i < 1e4; i++) { | |
| const password = `${i}`.padStart(4, '0'); | |
| exec( | |
| `pdftops -upw ${password} ${file}`, | |
| (error, stdout, stderr) => { | |
| if (error) { | |
| return; | |
| } | |
| resolve(password); | |
| }); | |
| } | |
| }); | |
| } | |
| // Throws error if no name is provided | |
| const filename = process.argv[2]; | |
| fn().then(password => console.log(`Password: ${password}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment