-1

我正在尝试使用密码从 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

怎么了?我已经被我的问题困扰了一个小时,无法弄清楚问题出在哪里一旦它得到正确的密码,它就会崩溃并打印我上面输入的错误

4

1 回答 1

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
于 2013-11-04T20:18:34.473 回答