网络编程
位置:首页>> 网络编程>> Python编程>> Python脚本破解压缩文件口令实例教程(zipfile)

Python脚本破解压缩文件口令实例教程(zipfile)

作者:谢公子  发布时间:2023-03-14 08:31:08 

标签:python,破解,压缩

zipfile模块是python中一个处理压缩文件的模块,解决了不少我们平常需要处理压缩文件的需求 ,本文主要谈谈zipfile几个常用的用法。

环境:Windows python版本2.7.15

Python中操作zip压缩文件的模块是 zipfile 。

相关文章:Python中zipfile压缩文件模块的使用

我们破解压缩文件的口令也是用的暴力破解方法。我们提前准备好密码字典用来爆破,如果密码字典中存在密码,则会打印出该密码,否则提示密码字典中无密码。

main()函数用来打开密码字典 key.txt ,然后读取其中每一行的内容,调用Test()函数去一个个的试密码,如果密码错误,Test函数就会抛出异常,如果密码正确,则不会抛出异常。所以我们在main()函数中以是否接收到异常判断密码是否正确。如果没有接收到异常,说明密码正确!

以下代码是python2.7环境!


# -*- coding: utf-8 -*-
"""
Created on Thu Nov 1 09:00:26 2018
@author: 小谢
"""

import zipfile
import os
def Test(line):
try:
 with zipfile.ZipFile("c://users//17250//desktop//test.zip","r") as f:
  f.extractall("c://users//17250//desktop//",pwd=line) #利用密码字典中的密码解压缩
except Exception as e:
 return e
finally:
 f.close()
def main():
try:
 with open("c://users//17250//desktop//key.txt") as file:
  lines=file.readlines()
  for line in lines:
   line=line.strip("\n")
   e=Test(line)
   if e:
    pass
   else:
    print("************压缩文件的密码是:%s"%line)
    return line
except Exception as e:
 print("异常对象的类型是:%s"%type(e))
 print("异常对象的内容是:%s"%e)
finally:
 file.close()
if __name__=='__main__':
re=main()
if re:
 pass
else:
 print("对不起,密码字典中未匹配到密码!")

来源:https://blog.csdn.net/qq_36119192/article/details/83615327

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com