用Python怎样破解zip加密文件,操作是什么
Admin 2022-08-26 群英技术资讯 739 次浏览
解压时可以提供密码zfile.extractall("./", pwd=password.encode("utf8"))
通过函数itertools.permutations("abc", 3)实现全字符的全排列:abc/acb/bca/bac/cab/cba
本文介绍的zip文件知道密码一共是4位的,密码字符的范围是a-z1-0。并且不存在重复字符的,不会有“aabb”的密码。zip压缩时是选择了zip传统加密!
导入zipfile模块,使用其中的extractall()函数。
import itertools filename = "readme.zip" # 创建一个解压的函数,入参为文件名和密码 # 并使用try-except,避免报错中断程序。 def uncompress(file_name, pass_word): try: with zipfile.ZipFile(file_name) as z_file: z_file.extractall("./", pwd=pass_word.encode("utf-8")) return True except: return False
import zipfile import itertools filename = "readme.zip" # 创建一个解压的函数,入参为文件名和密码 # 并使用try-except,避免报错中断程序。 def uncompress(file_name, pass_word): try: with zipfile.ZipFile(file_name) as z_file: z_file.extractall("./", pwd=pass_word.encode("utf-8")) return True except: return False # chars是密码可能的字符集 chars = "abcdefghijklmnopqrstuvwxyz0123456789" for c in itertools.permutations(chars, 4): password = ''.join(c) print(password) result = uncompress(filename, password) if not result: print('解压失败。', password) else: print('解压成功。', password) break
文件压缩时,一些注意的事项:
查过一些资料,zip压缩文件密码最长为12位,在原来的程序上增加上一个for循环就可以实现破解密码了。
import zipfile import itertools filename = "readme.zip" def uncompress(file_name, pass_word): try: with zipfile.ZipFile(file_name) as z_file: z_file.extractall("./", pwd=pass_word.encode("utf-8")) return True except: return False chars = "abcdefghijklmnopqrstuvwxyz0123456789" for i in range(12): for c in itertools.permutations(chars, i): password = ''.join(c) print(password) result = uncompress(filename, password) if not result: print('解压失败。', password) else: print('解压成功。', password) break
此方法可以是实现破解zip文件的密码,python可以完成一些好玩的事情。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要介绍了一文了解Python 流程控制,Python 中有while和for两种循环机制,其中while循环是条件循环,文章通过展开循环内容展开控制流程详情,需要的小伙伴可以参考一下
这篇文章介绍了Python中的collections集合与typing数据类型模块,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
这篇文章给大家分享的是如何解决python中文乱码的问题,下文有多种python中文乱码的情况以及解决办法的介绍,小编觉得挺实用的,因此分享给大家做个参考,接下来一起跟随小编看看吧。
这篇文章主要介绍了python使用matplotlib显示图像失真的解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
newLine()方法可用于输出一个换行字符"/n",下面这篇文章主要给大家介绍了关于python open函数中newline参数的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008