pentesting, updated
Extract embedded JavaScript, files and streams
Pull out everything a PDF carries beyond its visible pages: scripts, attachments and raw streams.
Goal
Recover any embedded object for separate analysis, since the PDF viewer never shows it.
How to test
pdf-parser.py -f -o 12 suspect.pdf # decompress/decode object 12's stream
pdf-parser.py --search JavaScript suspect.pdf # find objects containing JS
python3 -c "import peepdf" ; peepdf -i suspect.pdf # interactive: js_vars, js_beautify
binwalk -e suspect.pdf # carve any embedded file by signature
Decoded JavaScript should be beautified and read, not executed — run it only in an isolated JS sandbox (e.g. box-js) if dynamic behaviour is needed.
What to look for
Any /EmbeddedFile, an /JS object with obfuscated code (string concatenation, unescape, heavy hex escapes), or a file binwalk carves out that is not a font or image the document legitimately needs.
References
- YARA for matching known-malicious patterns across extracted content