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)文章
簡單掌握Python的Collections模塊中counter結(jié)構(gòu)的用法
counter數(shù)據(jù)結(jié)構(gòu)被用來提供技術(shù)功能,形式類似于Python中內(nèi)置的字典結(jié)構(gòu),這里通過幾個小例子來簡單掌握Python的Collections模塊中counter結(jié)構(gòu)的用法:2016-07-07
Python 保持登錄狀態(tài)進(jìn)行接口測試的方法示例
這篇文章主要介紹了Python 保持登錄狀態(tài)進(jìn)行接口測試的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-08-08
Python如何利用Har文件進(jìn)行遍歷指定字典替換提交的數(shù)據(jù)詳解
這篇文章主要給大家介紹了關(guān)于Python如何利用Har文件進(jìn)行遍歷指定字典替換提交的數(shù)據(jù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
Jupyter Notebook折疊輸出的內(nèi)容實例
這篇文章主要介紹了Jupyter Notebook折疊輸出的內(nèi)容實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04
python神經(jīng)網(wǎng)絡(luò)MobileNetV3?large模型的復(fù)現(xiàn)詳解
這篇文章主要為大家介紹了python神經(jīng)網(wǎng)絡(luò)MobileNetV3?large模型的復(fù)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05
python實現(xiàn)比對美團(tuán)接口返回數(shù)據(jù)和本地mongo數(shù)據(jù)是否一致示例
這篇文章主要介紹了python實現(xiàn)比對美團(tuán)接口返回數(shù)據(jù)和本地mongo數(shù)據(jù)是否一致,涉及Python基于requests模塊的數(shù)據(jù)請求與比較運算相關(guān)操作技巧,需要的朋友可以參考下2019-08-08

