PyZipper使用正确的密码返回“文件密码错误”

2024-06-01 10:23:32 发布

您现在位置:Python中文网/ 问答频道 /正文

嗯,我正在编写一个软件,它将使用"Passwords.txt"文件中给定的密码(逐行读取[每行都有其密码])强制执行一个名为"Blockers password.zip"的文件

问题是,我在ZipFile模块中得到了错误"Bad password for file",然后我进行了一些搜索,发现ZipFile模块不支持AES加密(PyZipper支持),所以我无法用它解密文件,现在,使用PyZipper,我得到了相同的错误,我不知道为什么

"Passwords.txt“文件的内容: https://prnt.sc/rueuf1

这是代码

import pyzipper

name_file = 'Passwords.txt'

# This file contains all the generated passwords
# for bruteforcing the file which has
# my blockers password
passwords_for_bruteforce = open(name_file, 'r')

# My goal here is use every password in the 'Passwords.txt' file
# to do a bruteforce on the 'Blockers password.zip'
# but it can't be bruteforced because of the "RuntimeError: Bad password for file"
# and the correct password is in the last line of the 'Passwords.txt'
for line in passwords_for_bruteforce:
    password = line.rstrip('\n')
    with pyzipper.AESZipFile('Blockers password.zip', 'r') as zip_file:
        zip_file.pwd = password
        zip_file.extractall()
passwords_for_bruteforce.close()

Tags: 文件theintxt密码forlinepassword
1条回答
网友
1楼 · 发布于 2024-06-01 10:23:32

你想用暴力来对付它。这意味着您需要处理错误的密码,否则第一个密码必须是正确的,否则它将抛出您的错误。 正如@Todd所说,try/except块应该可以解决问题:

for line in passwords_for_bruteforce:       
    password = line.rstrip('\n')
    with pyzipper.AESZipFile('Blockers password.zip', 'r') as zip_file:
        try:
            zip_file.pwd = password 
            zip_file.extractall()
         except RuntimeError:
            continue

依我看,你也可以打开文件一次,然后尝试多次解压缩。这将为您节省一些IO操作

with pyzipper.AESZipFile('Blockers password.zip', 'r') as zip_file:
    for line in passwords_for_bruteforce:       
        zip_file.pwd = line.rstrip('\n')
        try:
            zip_file.extractall()
        except RuntimeError:
            continue

相关问题 更多 >