-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

なにが問題ですか?私は自分の問題に1時間ほど立ち往生しており、どこに問題があるのか​​ わかりませんでした。正しいパスワードに到達すると、クラッシュして上記で入力したエラーが出力されます

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 に答える