Python 3 - How do I brute force a password for a PDF file using all possible 6-digit employee ID's?

我与影子孤独终老i 提交于 2020-12-13 03:30:04

问题


I am practicing generating all possible 6-digit employee ID's (all having 900 at the beginning followed by all possible 6-digit numbers) to brute force a password for a PDF file named PS7_encrypted.pdf. So far, I have successfully generated all 6-digit pins (with 900 at the front) and stored them into a dictionary.txt file. I am working on a program that would read the file and brute force the PDF using that text file that has all the possible numbers. When I run the program however, I got no results, no password printed. What did I do wrong? Code for generating the ID's:

#!/bin/python3
def genEmployeeID():
        with open('dictionary.txt', 'w') as wfile:
                for i in range(1000000):
                        wfile.write(f'900{i:06}' + "\n")
genEmployeeID()

Code for brute-forcing the PDF file:

#!/bin/python3
import PyPDF2
import sys
filename = 'PS7_encrypted.pdf' 
dictionary = 'dictionary.txt' 

password = None 
file_to_open = PyPDF2.PdfFileReader(filename) 
with open(dictionary, 'r') as f: 
   for line in f.readlines(): 
         password = line.strip('\n') 
         try: 
               pss = bytes(password, 'utf-8')
               file_to_open.extractText(pwd = pss) 
               password = 'Password found: %s' % pss 
               print(password) 
         except: 
               pass

回答1:


Is extractText a function of this object? I can't find it in the documentation. Since you don't specify a specific exception to catch, I assume it passes right into the except block when it doesn't find that function. What you are looking for seems to be decrypt(password).



来源:https://stackoverflow.com/questions/60997193/python-3-how-do-i-brute-force-a-password-for-a-pdf-file-using-all-possible-6-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!