Python如何破解压缩包密码

作者:平底锅锅锅 时间:2023-09-01 19:15:41 

简介:

破解rar和zip压缩包。Windows下使用PyCharm软件。

1.步骤

1.环境

  • 指令pip install 安装。

  • 如果是rar文件需要把rar安装包下的Rar.exe和UnRar.exe,放在对应项目\venv\Scripts的路径下。

  • import失败时,需要在File->Settings->Project Interpreter添加对应的模块。

2.判断文件格式

type = os.path.splitext(path)[-1][1:]
if type == "zip":
elif type == "rar":

3.判断是否有密码

type = os.path.splitext(path)[-1][1:]
       if type == "zip":
               fileGet = zipfile.ZipFile(path)
               with fileGet as z:
                   for l in z.infolist():
                       is_encrypted = l.flag_bits & 0x1
                       if is_encrypted:
                           print("have password ")
                           break
                       else:
                           pass

elif type == "rar":
           fileGet = rarfile.RarFile(path)
           with fileGet as z:
               if z.needs_password():
                   print("have password ")
               else:
                   print("no password")
                   return

4.密码字典 自己写或者下载相应的软件生成。

5.解压文件

1.zip和rar

fileGet = zipfile.ZipFile(path)
fileGet = rarfile.RarFile(path)

2.解压

fileExtr.extractall(pwd=password)

2.代码

import sys
import zipfile
import rarfile
import threading
import datetime
import os
import subprocess
import  getopt
i = 0
fileGet = ""
class MyThread(threading.Thread):
   def __init__(self, func, args, name=''):
       threading.Thread.__init__(self)
       self.name = name
       self.func = func
       self.args = args
       self.result = self.func(*self.args)
   def get_result(self):
       try:
           return self.result
       except Exception:
           return None
def extractFile(fileExtr, password, fileType):
   try:
       encodestr = str.encode(password)
       if (fileType == "zip"):
          fileExtr.extractall(pwd=str.encode(password))
       else:
           fileExtr.extractall(pwd=password)
       global i
       i = i + 1
       print("search count : %d,real password is : %s" % (i, password))
       return password
   except:
       i = i + 1
       print("search count : %d,test password : %s, err:%s" % (i, password, sys.exc_info()[0]))
       pass
def mainStep():
   path = input("please input path:")
   try:
       if os.path.exists(path) == False:
           print("%s : path error!"%(path))
           return
       type = os.path.splitext(path)[-1][1:]
       if type == "zip":
               fileGet = zipfile.ZipFile(path)
               with fileGet as z:
                   for l in z.infolist():
                       is_encrypted = l.flag_bits & 0x1
                       if is_encrypted:
                           print("have password ")
                           break
                       else:
                           pass
               fileGet = zipfile.ZipFile(path)
       elif type == "rar":
           fileGet = rarfile.RarFile(path)
           with fileGet as z:
               if z.needs_password():
                   print("have password ")
               else:
                   print("no password")
                   return
       else:
           print("file not right")
           return
       pwdLists = open("D:\Python工程\mutou.txt")
       startTime = datetime.datetime.now()
       for line in pwdLists.readlines():
           Pwd = line.strip('\n')
           t = MyThread(extractFile, (fileGet, Pwd, type))
           t.start()
           if (t.get_result() is Pwd):
               break
       endTime = datetime.datetime.now()
       timeSpan = endTime - startTime
       print("search time:%ss" % (timeSpan.total_seconds()))
   except:
      print("err:%s" % sys.exc_info()[0])
if __name__ == '__main__':
   mainStep()

1.在线调试

Python如何破解压缩包密码

2.脚本运行

  • cmd 窗口打开方式:右键开始菜单,选择‘命令提示符(管理员)’即可。或者从开始菜单->运行->输入cmd,回车。

  • 关于 cd 命令:用于改变当前目录路径。使用方式:cd[空格][路径]。例如 cd d:/Python27/Mytest 转到该路径下。

  • 注意:如果当前盘符不是 D 盘,需要先转到 D 盘,输入 d: 回车即可。然后才可以使用 cd d:/Python27/Mytest 。

  • 输入python test.py。test.py是对应的文件名。

Python如何破解压缩包密码

来源:https://blog.csdn.net/C_gyl/article/details/89407824

标签:Python,破解,压缩包,密码
0
投稿

猜你喜欢

  • Python实现简单的可逆加密程序实例

    2022-12-18 10:39:56
  • Python分析彩票记录并预测中奖号码过程详解

    2023-07-20 04:49:18
  • 使用SQL Server 2000索引视图提高性能

    2009-01-13 13:47:00
  • SQL Server TEXT、NTEXT字段拆分的问题

    2008-10-26 12:28:00
  • Python中的pygal安装和绘制直方图代码分享

    2021-11-18 15:09:50
  • Python自动化实战之接口请求的实现

    2021-01-15 15:44:58
  • python ftp 按目录结构上传下载的实现代码

    2021-01-28 00:38:33
  • Pyqt5 实现跳转界面并关闭当前界面的方法

    2023-02-02 13:59:19
  • SQL Server误区30日谈 第20天 破坏日志备份链之后,需要一个完整备份来重新开始日志链

    2024-01-22 15:39:53
  • python dict remove数组删除(del,pop)

    2022-11-17 05:24:03
  • Python基于smtplib协议实现发送邮件

    2021-03-02 07:26:36
  • 带你深入了解Access数据库的4种安全方式

    2008-11-28 14:34:00
  • Eclipse + Python 的安装与配置流程

    2021-07-25 06:34:18
  • 利用Javascript实现一套自定义事件机制

    2024-05-03 15:59:07
  • 有关perl的内置特殊变量介绍

    2023-08-02 23:29:29
  • python跨文件使用全局变量的实现

    2023-11-27 00:16:40
  • SQL Server获取磁盘空间使用情况

    2024-01-21 17:30:43
  • 使用 Django Highcharts 实现数据可视化过程解析

    2022-12-27 19:18:51
  • python利用蒙版抠图(使用PIL.Image和cv2)输出透明背景图

    2023-09-06 10:45:28
  • python元类编程的基本使用

    2023-07-25 06:51:48
  • asp之家 网络编程 m.aspxhome.com