背景:1.自己壓縮的一個文件(很重要),忘了密碼(不知道當時手抖,還是怎么了,明明記得是自己常用的密碼,卻提示錯誤)
2.自己知道位數,可能是哪個字母或者數字敲錯了,所以自己根據有可能輸入的字母和數字,生成密碼字典,然后暴力破解
下面是代碼:
"""
@author :Eric-chen
@contact :sygcrjgx@163.com
@time :2019/7/5 9:28
@desc :
"""
import zipfile
from threading import Thread
import itertools
def extractFile(zipFile, password): ###提取文件的方法
try:
zipFile.extractall(pwd=bytes(password, "utf8")) ##打開壓縮文件,提供密碼
print("This file\'s password is " + password) ###破解到的密碼
except:
# print(password)
pass ###假如失敗,就跳過繼續
def mainStep():
zipFile = zipfile.ZipFile('C:\\Users\\chen\\Desktop\\test\\out.zip','r') #讀取zip文件
pwds = open('C:\\Users\\chen\\Desktop\\test\\password.txt','r') # 讀入所有密碼
for line in pwds.readlines(): # 挨個挨個的入讀密碼
pwd = line.strip('\n')
t = Thread(target=extractFile, args=(zipFile, pwd))
t.start()
# 生成密碼字典
def dict():
list=[]
fp = open('C:\\Users\\chen\\Desktop\\test\\password.txt', 'w+')
for i in itertools.permutations('qwe123.QWE', 7):
str=''.join(i)+"\n"
# list.append(str)
fp.write(str)
fp.close();
# print(list)
if __name__ == '__main__':
dict()
mainStep()
