This is how a PDF document looks — with a JavaScript execution. Note that with OpenAction 6 (object block 6) this block is executed when the document is opened.
%PDF-1.6
1 0 obj
<< /Type /Catalog
/Pages 2 0 R
/OpenAction 6 0 R
>>
endobj
2 0 obj
<< /Type /Pages
/Kids [3 0 R]
/Count 1
>>
endobj
3 0 obj
<< /Type /Page
/Parent 2 0 R
/MediaBox [0 0 595 842]
/Contents 4 0 R
/Resources << /Font << /F1 5 0 R >> >>
>>
endobj
4 0 obj
<< /Length 44 >>
stream
BT
/F1 20 Tf
100 700 Td
(Hello World) Tj
ET
endstream
endobj
5 0 obj
<< /Type /Font
/Subtype /Type1
/BaseFont /Helvetica
>>
endobj
6 0 obj
<< /S /JavaScript
/JS (app.alert("Hello");)
>>
endobj
7 0 obj
<< /Type /Action
/S /JavaScript
/JS 6 0 R
>>
endobj
xref
0 8
0000000000 65535 f
0000000010 00000 n
0000000060 00000 n
0000000110 00000 n
0000000210 00000 n
0000000266 00000 n
0000000322 00000 n
0000000381 00000 n
trailer
<< /Size 8
/Root 1 0 R
>>
startxref
450
%%EOF
Other way to create a malicious PDF:
- Prepare / download a trustworthy looking PDF.
- Use exploit/windows/fileformat/adobe_utilprintf to create a PDF with a shell listener.
- Open a listener
- Bring the victim to open the file.
Analyse a PDF file
If a PDF file is compressed, decompress it first.
pdftk input.pdf output output.pdf uncompress
Get details with Pdfinfo
pdfinfo file.pdf
Get infos with Pdf-parser.py
- Get general infos
pdf-parser.py file.pdfpdf-parser 2020-12-15-upload.pdf | grep /Creator - At a object (obj 10 0) there could be binary files attached, which are not in the output. If you see something like a checksum or an indication that a file could be included at this object, try the following:
pdf-parser.py -o 10 -d out file.pdf
Check for integrated streams, variant with pdfdetach. (If the file is compressed, try it with both ones!)
- Use
pdfdetach -list $fileto get the included streams. - Extract a stream with
pdfdetach -save $streamId $file
Check for integrated streams, variant with base64dump.: (If the file is compressed, try it with both ones!)
- Check streams:
base64dump.py -e bc file.pdf - Extract stream 1 in a file:
base64dump.py -e bx -s 1 -d file.pdf > stream1.exe_
Check for integrated… files with binwalk; it could be, that files are integrated which are not stored as a stream: (If the file is compressed, try it with both ones!)
- Check for integrated files:
binwalk file.pdf - Extract files:
binwalk --dd '.*' file.pdf
Now, the current directory has subdirectories with the extracted files.
Get the pdf source
pdftosrc file.pdf
Injection in PDF files
Include other files via annotation: See https://github.com/mpdf/mpdf/issues/356
Leave a Reply
You must be logged in to post a comment.