用python写了一个zip文件暴力破解的程序
这里查阅许多资料,学习用python写了一个zip文件暴力破解的程序。若有不足之处请大家多多指教!
本随笔仅供学习交流,切勿拿去做违法之事!
import itertools as its
import threading
import zipfile
import sys
import time
from tqdm import tqdm
class product_doct(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.pd1=False
self.pd2 = False
if len(sys.argv) >1:
self.words = sys.argv[1].strip()
# self.word1 = input("请输入前面的固定字符,若没有直接enter:").strip()
# self.word2 = input("请输入后面的固定字符,若没有直接enter:").strip()
self.len = int(sys.argv[2].strip())
self.filename= sys.argv[3].strip()
else:
self.words = input('请输入要密码包含的字符:').strip()
# self.word1 = input("请输入前面的固定字符,若没有直接enter:").strip()
# self.word2 = input("请输入后面的固定字符,若没有直接enter:").strip()
self.len = int(input('请输入要密码长度:').strip())
self.filename = input('请输入要破解的zip文件目录:').strip()
self.zfile =zipfile.ZipFile(self.filename)#zipfile.ZipFile(input('请输入文件路径:').strip())
self.s = False
self.i = 0
self.threading_list = []
def run(self):
print("开始")
self.produ_miam()
while True:
if self.pd1 and self.pd2:
if self.s:
break
else:
print('结束')
with open('passwoed.txt', 'w', encoding='utf-8') as fp:
fp.write(f'在【{self.words}】字符中按1到{self.len}位排列未找到密码!')
fp.close()
break
def produ_miam(self):
words = set(self.words) # 去重
words = ''.join(words) # 拼接
for lon in range(1,self.len+1):
if not self.s:
l=threading.Thread(target=self.start_pj, args=(words, lon))
l.start()
#print('线程数量:' + str(len(threading.enumerate())))
while True:
if (len(threading.enumerate()) < 600):
break
else:
break
self.pd1=True
def start_pj(self,words,lon):
r = its.product(words, repeat=lon)
for i in r:
password = "".join(i)
# password = self.word1 + password + self.word2
#print(password)
if not self.s:
t = threading.Thread(target=self.Crack_zip, args=(self.zfile, password))
t.start()
while True:
if (len(threading.enumerate()) < 600):
break
else:
break
if lon == self.len : self.pd2 = True
def Crack_zip(self,zfile,password):
try:
if not self.s:
zfile.extractall(pwd=bytes(password, "utf8"))
print("文件解压密码为: ", password)
self.s = True
with open('passwoed.txt','w',encoding='utf-8') as fp:
fp.write(password)
fp.close()
return password
else:
pass
except:
pass
if __name__ == '__main__':
p=product_doct()
p.run()