分类 python 下的文章

zip_crack

#!/usr/bin/env python
# coding:utf-8
'''
zip文件暴力破解
'''
import zipfile
zippath = 'f:\\py_code\\test.zip'   # 待破解zip
pwdpath = 'f:\\py_code\\pwd.txt'    # 字典
def decompress(zippath, password):
    zf = zipfile.ZipFile(zippath, 'r', zipfile.zlib.DEFLATED)
    try:
        zf.extractall(path='f:\\py_code\\test2', members=zf.namelist(), pwd=password)
        print '---crack success! The password is %s ---' % password
        zf.close()
        return True
    except:
        pass

def getPass(pwdpath):
    pwdfile = open(pwdpath, 'r')
    for line in pwdfile.readlines():
        password = line.strip('\n')
        print 'Try the password: %s' % password
        if decompress(zippath, password):
            break
    pwdfile.close()
getPass(pwdpath)