网络编程
位置:首页>> 网络编程>> Python编程>> Python如何破解压缩包密码

Python如何破解压缩包密码

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

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

简介:

破解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

0
投稿

猜你喜欢

  • 区块链概念狭义:区块链是一种按照时间顺序将数据区块以顺序相连的方式组合成的一种链式数据结构,并以密码方式保证的不可篡改和不可伪造的分布式账本
  • 发现报错对于Navicat连接数据库mysql 出现报错2003(10060),如下所示报错经过查询总结以上出现问题的主要解决方法三种:1、
  • 本文实例讲述了PHP检查端口是否可以被绑定的方法。分享给大家供大家参考,具体如下:<?php/** * 检查端口是否可以被绑定 * @
  • 第一种:利用functools 工具处理import functoolsresult = (lambda k: functools.redu
  • Python写一些简单的GUI界面也是非常简单的,并且Python有着丰富的库,这些库可以很方便我们去操作Windows系统,搭配界面,可以
  • 事件是javascript中的核心内容之一,在对事件的应用中不可避免的要涉及到一个重要的概念,那就是事件冒泡,在介绍事件冒泡之前,先介绍一下
  • numpy中轴参数的意义指定的轴是被压缩的轴沿轴的时候可以指定两个轴,即面被压缩,以面作为输入numpy中轴转动numpy中添加新轴np.n
  • 最近一直在研究 Javascript 相关的技术。在《Javascript 高级程序设计》有篇章节着重阐述了优化 Javascri
  • 写项目时,发现 element 里的图标没有我需要的图标,两种情况:① 简单的替换小图标,没有选中变色等要求② 有选中变色等要求,稍微复杂的
  • kelon 问:格式如下:s="地,在要,大,奇功,不知,但是,不示"我想把它split分出來,变成数组來循环,但是不知
  • 1.Vue父子组件通信方式父子组件通信方式一般为props和emit组合使用,那么在不同的文件中应该如何使用呢?|.vue文件和.jsx文件
  • 平常我都是直接执行 pip install 安装的第三方库,很多教程也是这么介绍的,一直以来我都认为这是标准的、正确的安装 Python 第
  •    从网上找了很多django单元测试的案例,感觉不是很好用,于是自己写了一套测试方法,在测试环境我们只需要传uri 、请求方式、参数即可
  • 通配符:通配符描述示例%包含零个或更多字符的任意字符串。WHERE title LIKE '%computer%' 将查找处
  • 下面我挑选出的这几个技巧常常会被人们忽略,但它们在日常编程中能真正的给我们带来不少帮助。1. 字典推导(Dictionary compreh
  • Bootstrap,来自 Twitter,是目前最受欢迎的前端框架。Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的,
  • 本文实例讲述了es6函数之严格模式用法。分享给大家供大家参考,具体如下:从es5开始,函数内部可以设定为严格模式。function doSo
  • 设置自动生成作者信息1、file->settings->Editor->file and code templates-&
  • 计算交并比:交的面积除以并的面积。要求矩形框的长和宽应该平行于图片框。不然不能用这样的公式计算。原理,从一维上来理解:两条红线的距离之和减去
  • 一、MYSQL的索引索引(Index):帮助Mysql高效获取数据的一种数据结构。用于提高查找效率,可以比作字典。可以简单理解为排好序的快速
手机版 网络编程 asp之家 www.aspxhome.com