python 暴力破解加密过的zip文件

分了两种情况,一种是单线程另一种是多线程,zipfile=压缩文件库,time=时间库,sys=提供了常用的变量和函数,threading=线程库

一、单线程:
import zipfile,time,sys,threading
# 获取时间节点
time1 = time.time()
# 获取zip文件
def extarct_zip():
   zfile = zipfile.ZipFile('vba.zip')
   # 动态生成密码库
   for num in range(1,9999):
#         捕获异常
       try:
           # 数字转换成字符串类型
           pwd = str(num)
           # 破解到当前路径,传入密码
           zfile.extractall(path='./',pwd=pwd.encode('utf-8'))
           print('当前压缩文件密码为%s'%pwd)
           time2=time.time()
           print('单线程本次破解压缩文件密码所花费的时间%s'%str(time2-time1))
           sys.exit(0)
       except Exception as e:
           pass

if __name__=='__main__':
   extarct_zip()

二、多线程
import zipfile,time,sys,threading
# 获取时间节点
time1 = time.time()
flag=True
def do_word(num,zfile):
   try:
       pwd = str(num)
       zfile.extractall(path='./',pwd=pwd.encode('uft-8'))
       print('当前压缩文件密码为:%s' % pwd)
       time2 = time.time()
       print('多线程本次破解压缩文件密码所花费的时间%s' % str(time2 - time1))
       global flag
       flag = False
   except Exception as e:
       print(e)
# 获取zip文件
def extarct_zip():
   zfile = zipfile.ZipFile('vba.zip')
   # 动态生成密码库
   for num in range(1,9999):
       if flag:
           thr = threading.Thread(target=do_word,args=(num,zfile))
           thr.start()
           thr.join()

if __name__=='__main__':
   extarct_zip()
    原文作者:顾四秋
    原文地址: https://www.jianshu.com/p/d24d22291680
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞