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 Files', '.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=[('Text Files', '.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

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.