我有麻烦了。我用密码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()发布于 2014-02-25 12:40:43
首先,你要做的是:
for combo in itertools.imap(...):
if found:
break
thread = ...
thread.start()
if not found:
...看一下就好。
found是在线程中定义的,但是您正在启动多个线程,并且全局希望在其中一个线程中设置它。如何确保正确的线程完成了正确的工作?如果其中一个线程中存在假阳性,并且您不需要从每个单独的线程中检索值,那该怎么办?小心你的线!
其次,如果线程没有及时完成您的combo循环,您将进入if not found,因为线程尚未完成运行以找到您要查找的内容,特别是如果您有一个更大的压缩文件,需要几秒钟才能完成(成功的密码将开始解压缩文件,可能需要几分钟,并且在完成该过程之前不会设置found )。
最后,获得用于保护这个zip文件的参数是很好的。
编辑:
您还可以以以下格式向我们提供更多信息:
zFile.debug(3)
zFile.testzip()
zFile.extractall(pwd=password)以及来自zipfile.ZipInfo(filename)的其他有用的东西
到那个解决方案
#!/usr/bin/env python
import itertools
import argparse
import zipfile
import string
def extract_zip(filename, password):
try:
zFile = zipefile.ZipFile(filename)
zFile.extractall(pwd=password)
return True
except zipfile.BadZipFile:
return False
def main_loop(filename, length):
print("[*] Python Brute-Force zip cracker")
print("[*] Zipfile: %s; password length: %s" % (zFile, length))
cracked = False
for combo in itertools.imap(''.join, itertools.product(string.letters + string.digits, repeat=length)):
cracked = extract_zip(filename, combo)
if cracked:
print('Yaay your password is:',combo)
break
if not cracked:
print('Sorry, no luck..')
def main():
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()https://stackoverflow.com/questions/22014220
复制相似问题