我尝试使用密码从zip文件中提取文件,这是我的代码
def extractFile(zfile,password):
"""
tries to open a file
prints SUCCESS if the file opend
prints FAILED if the file failed to open
"""
try:
z=zipfile.ZipFile(zfile)
t=z.namelist()
z.extractall("D://",t,password)
print ("Success the password is "+password)
return True
except RuntimeError:
print ("Fail! "+password+" is wrong!")
return False
def attack(zFile,dFile):
lines=dFile.readlines()
i=0
stop=len(lines)
while(1):
if i==stop:
print "end of passwords"
return False
pas=lines[i]
x=extractFile(zFile,pas.rstrip())
if x==True:
return True
else:
i=i+1
f=file("secret.zip")
f1=open("dict.txt","r")
total=attack(f,f1)
f.close()
f1.close()
每当我尝试提取文件时,我都会收到很多错误信息
Traceback (most recent call last):
File "D:\Test\crack.py", line 40, in <module>
total=attack(f,f1)
File "D:\Test\crack.py", line 33, in attack
x=extractFile(zFile,pas.rstrip())
File "D:\Test\crack.py", line 18, in extractFile
z.extractall("D://",t,password)
File "C:\Python27\lib\zipfile.py", line 1036, in extractall
self.extract(zipinfo, path, pwd)
File "C:\Python27\lib\zipfile.py", line 1024, in extract
return self._extract_member(member, path, pwd)
File "C:\Python27\lib\zipfile.py", line 1080, in _extract_member
shutil.copyfileobj(source, target)
File "C:\Python27\lib\shutil.py", line 49, in copyfileobj
buf = fsrc.read(length)
File "C:\Python27\lib\zipfile.py", line 628, in read
data = self.read1(n - len(buf))
File "C:\Python27\lib\zipfile.py", line 680, in read1
max(n - len_readbuffer, self.MIN_READ_SIZE)
error: Error -3 while decompressing: invalid distance too far back
有什么问题?我一直坚持我的问题一个小时,无法弄清问题在哪里 一旦它获得正确的密码,它就会崩溃并打印我在上面输入的错误
答案 0 :(得分:0)
假设您正试图从文件中包含的密码列表中破解zip:
import zipfile
def extractFile(zFile, password):
try:
zFile.extractall(pwd=password)
return password
except:
return
def attack():
zFile = zipfile.ZipFile('yourarchive.zip')
with open('dictionary.txt') as passFile:
for line in passFile:
password = line.strip('\n')
guess = extractFile(zFile, password)
if guess:
#do whatever u like here if the password is successful