How to Crack PDF Files in Python?
Last Updated :
26 Dec, 2020
Prerequisite: tqdm
In this article, we will learn How to Crack a Protected PDF File Using Python. Here we will use the Brute force Method, to Crack a PDF File using pikepdf module in Python.
Required Modules :
- pikepdf is a Python module, which is used to create, manipulate, and repair PDF Files.
pip install pikepdf
- tqdm is one of the more comprehensive packages for progress bars with python and is handy for those instances you want to build scripts that keep the users informed on the status of your application.
pip install tqdm
We won’t be using pikepdf for that though, we just gonna need to open the password-protected PDF file, if it succeeds, that means it’s a correct password, and it’ll raise a PasswordError exception otherwise.
Understand step by step Implementation:
- Here we will use a text file that contains a password list, get it here.
- We will iterate through all password lists and try to open the file with each password, bypassing the password argument to open() method, if the password will not match it will raise PasswordError.
- The last step is progress, like how many words are remaining, for showing the progress we will use tqdm module.
Below is the full implementation:
Python3
import pikepdf
from tqdm import tqdm
passwords = []
password_text_file = "Password Text File"
for line in open (password_text_file):
passwords.append(line.strip())
for password in tqdm(passwords, "Cracking PDF File" ):
try :
with pikepdf. open ( "Protected PDF File" ,
password = password) as p:
print ( "[+] Password found:" , password)
break
except pikepdf._qpdf.PasswordError as e:
continue
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...