Python如何破解壓縮包密碼
更新時間:2022年05月21日 09:29:05 作者:平底鍋鍋鍋
破解rar和zip壓縮包。Windows下使用PyCharm軟件,本文給大家詳細介紹Python如何破解壓縮包密碼,感興趣的朋友一起看看吧
簡介:
破解rar和zip壓縮包。Windows下使用PyCharm軟件。
1.步驟
1.環(huán)境
- 指令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")
return4.密碼字典 自己寫或者下載相應的軟件生成。
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.在線調試

2.腳本運行
- cmd 窗口打開方式:右鍵開始菜單,選擇‘命令提示符(管理員)’即可?;蛘邚拈_始菜單->運行->輸入cmd,回車。
- 關于 cd 命令:用于改變當前目錄路徑。使用方式:cd[空格][路徑]。例如 cd d:/Python27/Mytest 轉到該路徑下。
- 注意:如果當前盤符不是 D 盤,需要先轉到 D 盤,輸入 d: 回車即可。然后才可以使用 cd d:/Python27/Mytest 。
- 輸入python test.py。test.py是對應的文件名。

到此這篇關于Python如何破解壓縮包密碼的文章就介紹到這了,更多相關Python破解壓縮包密碼內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
簡單掌握Python的Collections模塊中counter結構的用法
counter數據結構被用來提供技術功能,形式類似于Python中內置的字典結構,這里通過幾個小例子來簡單掌握Python的Collections模塊中counter結構的用法:2016-07-07
Python如何利用Har文件進行遍歷指定字典替換提交的數據詳解
這篇文章主要給大家介紹了關于Python如何利用Har文件進行遍歷指定字典替換提交的數據的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-11-11
python神經網絡MobileNetV3?large模型的復現詳解
這篇文章主要為大家介紹了python神經網絡MobileNetV3?large模型的復現詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05
python實現比對美團接口返回數據和本地mongo數據是否一致示例
這篇文章主要介紹了python實現比對美團接口返回數據和本地mongo數據是否一致,涉及Python基于requests模塊的數據請求與比較運算相關操作技巧,需要的朋友可以參考下2019-08-08

