【发布时间】:2022-05-03 02:32:37
【问题描述】:
我有一个问题。我制作了一个简单的 zip 文件,密码为 12345。 现在,当我尝试使用蛮力提取密码时,zipfile 选择了错误的密码。它说它找到了密码 aaln0,但提取的文件完全是空的。有没有办法“修复”图书馆?或者有替代品吗?谢谢
程序代码:
#!/usr/bin/env python
import itertools
import threading
import argparse
import time
import zipfile
import string
global found
found = False
def extract_zip(zFile, password):
"""
Extract archive with password
"""
try:
zFile.extractall(pwd=password)
write("[+] Password found:", password, "\n")
global found
found = True
except Exception, e:
pass
def write(*args):
print "[%s] %s" % (time.ctime(), " ".join(args))
def main_loop(zFile, length):
"""
Main loop
"""
write("[*] Python Brute-Force zip cracker")
write("[*] Zipfile: %s; password length: %s" % (zFile, length))
try:
zfile = zipfile.ZipFile(zFile)
except:
write("Cannot open zip file")
exit(1)
for combo in itertools.imap(''.join, itertools.product(string.letters + string.digits,
repeat=length)):
if found:
break
thread = threading.Thread(target=extract_zip, args=(zfile, combo))
thread.start()
if not found:
write("[-] Password not found")
def main():
"""
Main function
"""
parser = argparse.ArgumentParser(usage="brute-force-zipcracker.py -f <zipfile> -l <password length>")
parser.add_argument("-f", "--zipfile", help="specify zip file", type=str)
parser.add_argument("-l", "--length", type=int, help="password length", default=5)
args = parser.parse_args()
if (args.zipfile == None):
print parser.usage
exit(0)
main_loop(args.zipfile, args.length)
if __name__ == '__main__':
main()
【问题讨论】:
-
在这个问题中没有任何信息可以使用。
zipfile你需要什么“修复”?你的代码是什么样的,aaln0来自哪里? -
@Torxed,正如我所说,我正在使用蛮力。我正在生成长度为 5 的所有可用组合,然后尝试使用这些密码打开 zip。 zip 文件的密码是
12345,但程序说密码是aaln0。我添加了代码 -
没有得到异常意味着解压器在处理解密数据时没有问题。它仍然可能是错误的数据。
-
@JanneKarila,我知道。但我想问:有没有办法防止
zipfile选择错误的密码? -
您可以做的一件事是对照 zip 目录检查解压缩文件的大小。
标签: python passwords python-zipfile