UPDATE 21 Dec 2017
The script pdf2john.py doesn't exist anymore. It has been substituted by a perl version, pdf2john.pl.
Extracted from HashCat Forums, this method works for me (requires Perl):
--Download pdf2john.pl from the suite John the Ripper (OCLHashCat works with the same hash format as John the Ripper):
wget https://github.com/magnumripper/JohnTheRipper/archive/bleeding-jumbo.zip
unzip bleeding-jumbo.zip
--Use it to extract the hash from your .pdf file:
perl JohnTheRipper-bleeding-jumbo/run/pdf2john.pl MyPDF.pdf > MyPDF-Hash.txt
--Output file MyPDF-Hash.txt
must be edited. Original would be something like:
MyPDF.pdf:$pdf$4*4*128*1028*1*16*652fc762fdb12c47a5f90ddd2b99b809*32*dd86d858f914809078a4a47348d32c0fc4e9c08042a10e6434b48b698de7731f*32*3c1e693526d5bc8da15b99eea6cbc6ed2c2397e23e2c39d1974fdc004c588cff:::::MyPDF.pdf
so use your preferred editor:
nano MyPDF-Hash.txt
notepad MyPDF-Hash.txt
and leave only the part inside double colons :
:
$pdf$4*4*128*1028*1*16*652fc762fdb12c47a5f90ddd2b99b809*32*dd86d858f914809078a4a47348d32c0fc4e9c08042a10e6434b48b698de7731f*32*3c1e693526d5bc8da15b99eea6cbc6ed2c2397e23e2c39d1974fdc004c588cff
--Hint: you can do the extraction and the edition in one step by using sed
(UnxUtils version too, if you are doing it from Windows):
perl JohnTheRipper-bleeding-jumbo/run/pdf2john.pl MyPDF.pdf | sed "s/::.*$//" | sed "s/^.*://" > MyPDF-Hash.txt
--Your MyPDF-Hash.txt
file is now ready to use with OCLHashCat (or John the Ripper).
NOTES:
- Tested working on CygWin (Windows).
- Tested working on Kali and Ubuntu Linux.