Python如何破解壓縮包密碼
更新時間:2022年05月21日 09:29:05 作者:平底鍋鍋鍋
破解rar和zip壓縮包。Windows下使用PyCharm軟件,本文給大家詳細(xì)介紹Python如何破解壓縮包密碼,感興趣的朋友一起看看吧
簡介:
破解rar和zip壓縮包。Windows下使用PyCharm軟件。
1.步驟
1.環(huán)境
- 指令pip install 安裝。
- 如果是rar文件需要把rar安裝包下的Rar.exe和UnRar.exe,放在對應(yīng)項目\venv\Scripts的路徑下。
- import失敗時,需要在File->Settings->Project Interpreter添加對應(yīng)的模塊。
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.密碼字典 自己寫或者下載相應(yīng)的軟件生成。
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.在線調(diào)試

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

到此這篇關(guān)于Python如何破解壓縮包密碼的文章就介紹到這了,更多相關(guān)Python破解壓縮包密碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于Python2、Python3中reload()的不同用法介紹
今天小編就為大家分享一篇基于Python2、Python3中reload()的不同用法介紹,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08
基于Python和openCV實現(xiàn)圖像的全景拼接詳細(xì)步驟
這篇文章主要介紹了基于Python和openCV實現(xiàn)圖像的全景拼接,本文分步驟通過實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2021-10-10
python3 實現(xiàn)除法結(jié)果為整數(shù)
這篇文章主要介紹了python3 實現(xiàn)除法結(jié)果為整數(shù),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03
Python中的?Numpy?數(shù)組形狀改變及索引切片
這篇文章主要介紹了Python中的?Numpy?數(shù)組形狀改變及索引切片,Numpy提供了一個reshape()方法,它可以改變數(shù)組的形狀,返回一個新的數(shù)組,更多相關(guān)內(nèi)容需要的小伙伴可以參考下面文章2022-05-05
python語言變量和數(shù)據(jù)類型基礎(chǔ)學(xué)習(xí)
這篇文章主要為大家介紹了python語言變量和數(shù)據(jù)類型基礎(chǔ)學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10

