用python暴力破解压缩文件并不是万能,至少这个场景我告诉你密码你用代码也破解不了

看到论坛上各种贴子写用python进行暴力破解的文章,于是自己也想去尝试一下,不试不知道,一试吓一跳,真的就像那句有名的”python由入门到放弃“,把论坛上别人的脚本全部自己敲一遍,运行不报错,但也没有正常解压出来,然后就是全部拷下来运行,结果一样,不能正常解压。不知道在屏幕前的你看到我这篇文章有没有遇到同样问题,最后有没有解决掉。

下面我也把我所遇到的问题代码贴出来及解决的办法,相信会对你有所帮助:

1 # -*- coding:utf-8 -*- 2 \'\'\' 3 首先创建一个压缩包,压缩包密码是6位纯数字,该脚本的目的就是要正常解压出这个压缩包,我创建的压缩包解压密码为 000100,主要是能快速看到结果 4 \'\'\' 5 import zipfile 6 7 class ForceUnlock(): 8 9 # 先生成6位数字的密码表并存入文件中 10 def generate_password_table(self): 11 with open("pwd_table.txt", \'w\', encoding="utf-8") as f: 12 for i in range(1000000): 13 pwd = str(i).zfill(6) + "\n" 14 f.write(pwd) 15 16 def extract_file(self, zip_file, password): 17 try: 18 zip_file.extractall(pwd=bytes(password, "utf-8")) # 注意这个密码是要以字节方式传入 19 print("The extract password is:", password) 20 return True 21 except: 22 print(("current {} password is not correct").format(password)) 23 return False # 密码不对,继续破解 24 25 def main(self): 26 self.generate_password_table() 27 zip_file = zipfile.ZipFile("strict_test.zip") 28 with open("pwd_table.txt", \'r\', encoding="utf-8") as f: 29 pwd_list = f.readlines() 30 for line in pwd_list: 31 pwd = line.strip("\n") 32 if self.extract_file(zip_file, pwd): 33 break # 密码正确后退出循环 34 else: 35 continue 36 37 38 if __name__ == "__main__": 39 test = ForceUnlock() 40 test.main()

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzyyyw.html