Posted in Python onJanuary 13, 2020
1、单线程破解纯数字密码
注意: 不包括数字0开头的密码
import zipfile,time,sys start_time = time.time() def extract(): zfile = zipfile.ZipFile('IdonKnow.zip')#读取压缩包,如果用必要可以加上'r' for num in range(1,99999,1): try: pwd = str(num) zfile.extractall(path='.',pwd=pwd.encode('utf-8')) print ("当前压缩密码为:",pwd) end_time = time.time() print ('单线程破解压缩包花了%s秒'%(end_time-start_time)) sys.exit(0) except Exception as e: pass if __name__=="__main__": extract()
破解结果:
2、多线程破解纯数字密码
注意: 不包括数字0开头的密码
import zipfile,time,threading start_time = time.time() flag = True # 用于判断线程是否需要终止,为True时程序执行 def extract(password, file): try: password = str(password) file.extractall(path='.', pwd=password.encode('utf-8')) print ("当前压缩密码为:",password) end_time = time.time() print ('多线程破解压缩包花了%s秒'%(end_time-start_time)) global flag flag = False#成功解压其余线程终止 except Exception as e: pass def main(): zfile = zipfile.ZipFile("test.zip", 'r') for number in range(1, 99999,1): if flag: thr1 = threading.Thread(target=extract, args=(number, zfile)) thr2 = threading.Thread(target=extract, args=(number, zfile)) thr1.start() thr2.start() thr1.join() thr2.join() if __name__ == '__main__': main()
破解结果:
提示: 多线程对数字型的运算没有多大帮助
3、破解英文+数字型的密码
import random,zipfile,time,sys class MyIter(): cset = 'abcdefghijklmnopqrstuvwxyz0123456789' def __init__(self,min,max):#迭代器实现初始方法,传入参数 if min < max: self.minlen = min self.maxlen = max else: self.ninlen = max self.maxlen = min def __iter__(self):#直接返回slef实列对象 return self def __next__(self):#通过不断地轮循,生成密码 rec = '' for i in range(0,random.randrange(self.minlen,self.maxlen+1)): rec += random.choice(MyIter.cset) return rec def extract(): start_time = time.time() zfile = zipfile.ZipFile('test1.zip','r') for password in MyIter(1,4):#随机迭代出1~4位数的密码,在不明确位数的时候做相应的调整 if zfile: try: zfile.extractall(path='.',pwd=str(password).encode('utf-8')) print ("当前压缩密码为:",password) end_time = time.time() print ('当前破解压缩包花了%s秒'%(end_time-start_time)) sys.exit(0) except Exception as e: print ('pass密码:',password) pass if __name__=="__main__": extract()
破解结果:
总结
以上所述是小编给大家介绍的python破解zip文件密码的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
详解python破解zip文件密码的方法
- Author -
阿优乐扬声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@