手機如何解壓忘記密碼的壓縮包 手機壓縮包忘了密碼怎么打開



文章插圖
手機如何解壓忘記密碼的壓縮包 手機壓縮包忘了密碼怎么打開

文章插圖
一、破解原理
其實原理很簡單,一句話概括就是「大力出奇跡」,Python 有兩個壓縮文件庫:zipfile 和 rarfile,這兩個庫提供的解壓縮方法 extractall()可以指定密碼,這樣的話首先生成一個密碼字典(手動或用程序),然后依次嘗試其中的密碼,如果能夠正常解壓縮表示密碼正確 。
二、實驗環境
本文采取的虛擬環境為 Pipenv.

zipfile:Python 標準庫,使用時直接導入即可rarfile:Python 第三方庫
利用 Pipenv 安裝 rarfile
pipenv install rarfile最后,再將一個帶有密碼的壓縮包放入實驗環境中即可 。
三、編碼
知道原理后,編碼就會非常簡單了
準備密碼本
「密碼本」其實就是一個包含了所有可能密碼的文件,用戶可以手動錄入,也可以用程序錄入 。文末還會有一個介紹 。
讀取壓縮文件
# 根據文件擴展名,使用不同的庫if filename.endswith('.zip'):fp = zipfile.ZipFile(filename)elif filename.endswith('.rar'):fp = rarfile.RarFile(filename)嘗試解壓
先嘗試不用密碼解壓縮,如果成功則表示壓縮文件沒有密碼
fp.extractall(desPath)fp.close()print('No password')return暴力破解
try:# 讀取密碼本文件fpPwd = open('pwd.txt')except:print('No dict file pwd.txt in current directory.')returnfor pwd in fpPwd:pwd = pwd.rstrip()try:fp.extractall(path=desPath, pwd=pwd.encode())print('Success! ====>'+pwd)fp.close()breakexcept:passfpPwd.close()程序入口
if __name__ == '__main__':filename = sys.argv[1]if os.path.isfile(filename) and filename.endswith(('.zip', '.rar')):decryptRarZipFile(filename)else:print('Must be Rar or Zip file')四、使用
如果想要使用上述代碼,我們只需在命令行執行python main.py <filename>即可 。例如python main.py test.zip
運行結果:
$ python main.py test.zipSuccess! ====>323126
五、擴展
【手機如何解壓忘記密碼的壓縮包 手機壓縮包忘了密碼怎么打開】密碼本如何獲取?
https://github.com/YueYongDev/Blasting_dictionary