banner
andrewji8

Being towards death

Heed not to the tree-rustling and leaf-lashing rain, Why not stroll along, whistle and sing under its rein. Lighter and better suited than horses are straw sandals and a bamboo staff, Who's afraid? A palm-leaf plaited cape provides enough to misty weather in life sustain. A thorny spring breeze sobers up the spirit, I feel a slight chill, The setting sun over the mountain offers greetings still. Looking back over the bleak passage survived, The return in time Shall not be affected by windswept rain or shine.
telegram
twitter
github

Python暴力破解加密的壓縮包附帶源碼

image

命令行版:#

import argparse
import zipfile
import rarfile

def extract_zip(zip_file_path, password_dict_path):
    zip_file = zipfile.ZipFile(zip_file_path)
    with open(password_dict_path, 'r') as f:
        passwords = f.readlines()
    for password in passwords:
        password = password.strip()
        try:
            zip_file.extractall(pwd=bytes(password, 'utf-8'))
            print(f'破解成功,密碼為:{password}')
            with open('密碼.txt', 'w') as f:
                f.write(f'檔案名稱:{zip_file_path}\n密碼:{password}')
            input("破解成功,按回車鍵繼續...")
            break
        except zipfile.BadZipFile:
            print(f'檔案格式錯誤,無法解壓縮:{zip_file_path}')
            break
        except RuntimeError:
            print(f'破解失敗,嘗試密碼:{password}')
    zip_file.close()

def extract_rar(rar_file_path, password_dict_path):
    rar_file = rarfile.RarFile(rar_file_path)
    with open(password_dict_path, 'r') as f:
        passwords = f.readlines()
    for password in passwords:
        password = password.strip()
        try:
            rar_file.extractall(pwd=bytes(password, 'utf-8'))
            print(f'破解成功,密碼為:{password}')
            with open('密碼.txt', 'w') as f:
                f.write(f'檔案名稱:{rar_file_path}\n密碼:{password}')
            input("破解成功,按回車鍵繼續...")
            break
        except rarfile.BadRarFile:
            print(f'檔案格式錯誤,無法解壓縮:{rar_file_path}')
            break
        except RuntimeError:
            print(f'破解失敗,嘗試密碼:{password}')
    rar_file.close()

if __name__ == '__main__':
    zip_file_path = input("請輸入要破解的壓縮檔案路徑(本目錄下輸入名字即可):")
    password_dict_path = input("請輸入密碼字典檔案路徑(本目錄下輸入名字即可):")

    if zip_file_path.endswith('.zip'):
        extract_zip(zip_file_path, password_dict_path)
    elif zip_file_path.endswith('.rar'):
        extract_rar(zip_file_path, password_dict_path)
    else:
        print('不支援的檔案格式')

界面 GUI 版:#

import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
import zipfile
import rarfile

def extract_zip(zip_file_path, password_dict_path):
    zip_file = zipfile.ZipFile(zip_file_path)
    with open(password_dict_path, 'r') as f:
        passwords = f.readlines()
    for password in passwords:
        password = password.strip()
        try:
            zip_file.extractall(pwd=bytes(password, 'utf-8'))
            messagebox.showinfo('破解成功', f'破解成功,密碼為:{password}')
            with open('密碼.txt', 'w') as f:
                f.write(f'檔案名稱:{zip_file_path}\n密碼:{password}')
            break
        except zipfile.BadZipFile:
            lbl_result.config(text=f'檔案格式錯誤,無法解壓縮:{zip_file_path}')
            break
        except RuntimeError:
            lbl_result.config(text=f'破解失敗,嘗試密碼:{password}')
    else:
        lbl_result.config(text='破解失敗,未找到正確的密碼')
    zip_file.close()

def extract_rar(rar_file_path, password_dict_path):
    rar_file = rarfile.RarFile(rar_file_path)
    with open(password_dict_path, 'r') as f:
        passwords = f.readlines()
    for password in passwords:
        password = password.strip()
        try:
            rar_file.extractall(pwd=bytes(password, 'utf-8'))
            messagebox.showinfo('破解成功', f'破解成功,密碼為:{password}')
            with open('密碼.txt', 'w') as f:
                f.write(f'檔案名稱:{rar_file_path}\n密碼:{password}')
            break
        except rarfile.BadRarFile:
            lbl_result.config(text=f'檔案格式錯誤,無法解壓縮:{rar_file_path}')
            break
        except RuntimeError:
            lbl_result.config(text=f'破解失敗,嘗試密碼:{password}')
    else:
        lbl_result.config(text='破解失敗,未找到正確的密碼')
    rar_file.close()

def browse_zip_file():
    zip_file_path = filedialog.askopenfilename(filetypes=[('Zip 檔案', '.zip')])
    entry_zip_file.delete(0, tk.END)
    entry_zip_file.insert(tk.END, zip_file_path)

def browse_password_dict():
    password_dict_path = filedialog.askopenfilename(filetypes=[('文字檔案', '.txt')])
    entry_password_dict.delete(0, tk.END)
    entry_password_dict.insert(tk.END, password_dict_path)
    
def crack_zip():
    zip_file_path = entry_zip_file.get()
    password_dict_path = entry_password_dict.get()
    if zip_file_path.endswith('.zip'):
        extract_zip(zip_file_path, password_dict_path)
    else:
        lbl_result.config(text='不支援的檔案格式')

def crack_rar():
    rar_file_path = entry_zip_file.get()
    password_dict_path = entry_password_dict.get()
    if rar_file_path.endswith('.rar'):
        extract_rar(rar_file_path, password_dict_path)
    else:
        lbl_result.config(text='不支援的檔案格式')

root = tk.Tk()
root.title("壓縮檔案密碼破解-微信公眾號:藍胖子之家")
root.geometry("400x200")

lbl_zip_file = tk.Label(root, text="壓縮檔案路徑:")
lbl_zip_file.pack()
entry_zip_file = tk.Entry(root)
entry_zip_file.pack()
btn_browse_zip_file= tk.Button(root, text="瀏覽", command=browse_zip_file)
btn_browse_zip_file.pack()

lbl_password_dict = tk.Label(root, text="密碼字典路徑:")
lbl_password_dict.pack()
entry_password_dict = tk.Entry(root)
entry_password_dict.pack()
btn_browse_password_dict = tk.Button(root, text="瀏覽", command=browse_password_dict)
btn_browse_password_dict.pack()

btn_crack_zip = tk.Button(root, text="破解Zip檔案", command=crack_zip)
btn_crack_zip.pack()
btn_crack_rar = tk.Button(root, text="破解Rar檔案", command=crack_rar)
btn_crack_rar.pack()

lbl_result = tk.Label(root, text="")
lbl_result.pack()

root.mainloop()

Screenshot_1

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。