Python破解pdf打开密码

2021/5/23 14:26:59

本文主要是介绍Python破解pdf打开密码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Python破解pdf打开密码

环境版本
系统uos
Python版本Python3
模块PyPDF2、pikepdf、tqdm

安装相应的模块

sudo pip3 install PyPDF2
sudo pip3 install pikepdf
sudo pip3 install tqdm

运行破解代码

import pikepdf
import os
from PyPDF2 import PdfFileReader
from tqdm import tqdm
filename = "/home/uos/Desktop/PyQt5入门.pdf" #pdf文件路径
wordlist = "/home/uos/Desktop/wordlists/rockyou.txt" #密码字典路径
n_words = len(list(open(wordlist, 'rb')))
fp = open(filename, "rb+")
pdfFile = PdfFileReader(fp)
filepath, tempfilename = os.path.split(filename)
with open(wordlist, "rb") as wordlist:
    if pdfFile.isEncrypted:
        for word in tqdm(wordlist, total=n_words, unit="word"):
            try:
                pdf = pikepdf.open(filename, password=word.strip())
            except:
                continue
            else:
                print("[+] Password found:", word.decode().strip())
                exit(0)
        print("[!] Password not found, try other wordlist!")

运行结果
密码为:bengie04

/home/uos/PycharmProjects/pythonProject1/venv/bin/python /home/uos/PycharmProjects/pythonProject1/main.py
  7%|▋         | 1011828/14344392 [22:20<4:54:19, 754.96word/s]
[+] Password found: bengie04

Process finished with exit code 0
  1. 密码字典获取
    可以在kali系统的/usr/share/wordlists目录下拷贝一份到uos系统中或者百度rockyou.txt文件
  2. 是否可以100%破解
    破解速度与成功率和压缩密码的长度和复杂度有关,简单密码比较容易破解,复杂密码破解时间比较长甚至会破解失败
  3. 做实验时尽量选取密码字典中开头的密码以节约时间


这篇关于Python破解pdf打开密码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程