Use python to crack zip file | LSABLOG

首页 » NetworkSec » AWD » 正文

Use python to crack zip file

Environment:win7+python2.7

I use zipfile’s method—extractall(),and multithreading .

#coding:utf-8
#Author:LSA
#Description:Use zipfile's extractall to crack zip password.
#Date:2010219

import zipfile
import optparse
from threading import Thread


def extractFile(zFile,password):
    try:
        zFile.extractall(pwd=password)
        print 'Found password '+password+'\n'
    except:
        pass


def main():
    parser = optparse.OptionParser("usage %prog "+\
      "-f <zipfile> -d <dictionary>")
    parser.add_option('-f',dest='zname',type='string',\
      help='specify zip file')
    parser.add_option('-d',dest='dname',type='string',\
      help='specify dictionary file')
    (options, args) = parser.parse_args()
    if (options.zname==None) | (options.dname==None):
        print parser.usage
        exit(0)
    else:
        zname = options.zname
        dname = options.dname

    zFile = zipfile.ZipFile(zname)
    pFile = open(dname)

    for line in pFile:
        password = line.strip('\n')
        t = Thread(target=extractFile,args=(zFile,password))
        t.start()

if __name__ == '__main__':
    main()

Comment