利用python暴力破解压缩文件密码

2019-02-20 00:45:51来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折



import random
import sys
import zipfile
import time
from threading import Thread
from multiprocessing import Process

class MyIterator:
# letters = '0123456789abcdefghijklmnopqrstuvwxyz'
letters = '1234zjcv'
min_dig = 0
max_dig = 0

def __init__(self, min_dig, max_dig):

if min_dig < max_dig:
self.min_dig = min_dig
self.max_dig = max_dig

else:
self.min_dig = max_dig
self.max_dig = min_dig

def __iter__(self):
return self

def __next__(self):
rst = str()
for item in range(0,random.randrange(self.min_dig,self.max_dig+1)):
rst += random.choice(MyIterator.letters)
return rst

def extract():
start_time = time.time()
zfile = zipfile.ZipFile('123.zip')

for p in MyIterator(4, 6):
print(p)
try:
zfile.extractall(path='.', pwd=str(p).encode('utf-8'))
print('文件密码为:{}'.format(p))

now_time = time.time()
print('破解用时:{}'.format(now_time - start_time))
sys.exit()

except Exception as e:
pass

if __name__ == '__main__':
tl = Thread(target=extract)
tl.start()
tl.join()

 


原文链接:https://www.cnblogs.com/zjcsn/p/10393531.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:python闭包和装饰器

下一篇:python3 用户登录验证的小功能