Just last saturday Icarus Perseus He asked me to program a script or 'something' that would allow him to find out the password of a .PDF file, I started to do it now looking for applications in the repository that would allow me this and ... I found pdfcrack
pdfcrack It is testing passwords in a PDF file until it finds the correct one and indicates it to us, you can test passwords by brute force or by using a dictionary that we indicate (as we will do below).
Suppose we have a file called pdf-protected.pdf As its name indicates, a password is required to open it. The password will be: bmxrider
Let's install first pdfcrack, in distros like Debian, Ubuntu or based on these:
sudo apt-get install pdfcrack
On other distros, just look for that package in their official repositories.
Once we have the package installed, using it is really simple, but first let's download the dictionary that I have prepared for you. A dictionary is a lot of possible passwords, usually there are millions and the applications (in this case pdfcrack) will search those millions of passwords, testing each one of them and trying to 'discover' the correct password for what you want to violate. The password dictionary that I have prepared for you has almost 6 million passwords, it weighs approximately 60MBs:
Once downloaded, unzip it and voila, we are ready to use pdfcrack + Dictionary
Open a terminal where we are located in the same folder as dictionary.lst (file that appeared when unzipping dictionary-of-passwords.7z) and also pdf-protected.pdf and put the following:
pdfcrack pdf-protegido.pdf --wordlist=diccionario.lst
This will suffice for pdfcrack try using the database dictionary.lst know the password of the file pdf-protectedHere is a screenshot of the process and the result:
As you can see, the password of the protected PDF file is: bmxrider , just the one I told you above. That password is obviously in dictionary.lst. In the screenshot you can see that almost 25.000 passwords are tested per second, in the example almost 2 million passwords (until I find bmxrider, the one) in only 2 and a half minutes 😀
This is using a dictionary, in case you don't want to use a dictionary (and try to get the password brute force) just do not put the end of the instruction, that is, they would have:
This will test hundreds of thousands, millions of combinations yes ... but it will be a long process, very long depending on the complexity of the password, it could take hours or days 😉
To crack the password of a PDF file need to install pdfcrack, they need a password dictionary (download and unzip it) and then execute the instruction mentioning the file you want to crack and the location of the password dictionary, for example:
pdfcrack /home/usuario/Documentos/pdf-protegido.pdf --wordlist=/home/usuario/Descargas/diccionario.lst
What is simple? 🙂
Anyway, it is not very common to find password protected pdf files nowadays (at least I rarely find one) but you know, here is the solution in case you forget or do not know the password.