Title: PDF Password Cracker - A Python GUI Application
Introduction:
In today's digital age, securing sensitive information is of utmost importance. However, situations may arise where you find yourself locked out of a password-protected PDF file. In such cases, having a reliable tool to crack the password can be invaluable. This article presents a Python GUI application that uses dictionary and brute force attacks to crack PDF passwords.
Here is a code snippet:
from tkinter import *
from tkinter import filedialog
from dictionary_attack import PDFcrack
import pyperclip
from brutforce import Brute
file_path = ""
passw_file_path = ""
passw = []
result = ""
def open_passlist():
global passw_file_path
passw_file_path = filedialog.askopenfilename()
with open(passw_file_path, 'r') as f:
global passw
passw = f.read().splitlines()
def open_file():
global file_path
file_path = filedialog.askopenfilename()
def dictionary():
global result
if file_path:
pdf_cracker = PDFcrack(file_path,passw)
result = pdf_cracker.crack()
result_label.config(text=f"Your PDF password is : {result}")
else:
result_label.config(text="Please select a PDF file first")
def copy():
if result:
pyperclip.copy(result)
# def brute_methode():
# global result
# if file_path:
# brute_force = Brute(pdf_path=file_path, length=len, num_symbols=sym, num_letters=lett, num_numbers=num)
# result = brute_force.brute_attack()
# result_label.config(text=f"Your PDF password is : {result}")
# else:
# result_label.config(text="Please select a PDF file first")
def brute_methode():
length = int(pass_length_entry.get())
sym = int(symbols_entry.get())
lett = int(letter_entry.get())
num = int(numbers_entry.get())
global result
if file_path:
brute_force = Brute(path=file_path, length=length, num_symbols=sym, num_letters=lett, num_numbers=num)
result = brute_force.brute_attack()
result_label.config(text=f"Your PDF password is : {result}")
else:
result_label.config(text="Please select a PDF file first")
root = Tk()
root.geometry("450x300")
open_pdf_btn = Button(text="Open pdf", command=open_file)
open_pdf_btn.place(x=20,y=0)
open_passw= Button(text="Open Password File", command=open_passlist)
open_passw.place(x=90,y=0)
dictionary_attack = Button(text="Dictionary Attack", command=dictionary)
dictionary_attack.place(x=220,y=0)
bruteforce_attack = Button(text="Bruteforce Attack",command=brute_methode)
bruteforce_attack.place(x=330,y=0)
result_label = Label(text=f"Your PDF password is : {result}")
result_label.place(x=20,y=50)
copy_btn = Button(text="Copy", command=copy)
copy_btn.place(x= 300,y=50)
pass_length_label = Label(text="Enter your password length")
pass_length_label.place(x=5,y=100)
pass_length_entry = Entry()
pass_length_entry.place(x=200,y=100)
symbols_label = Label(text="How many symbols are there")
symbols_label.place(x=5,y=150)
symbols_entry = Entry()
symbols_entry.place(x=200,y=150)
letter_label = Label(text="How many letters are there")
letter_label.place(x=5,y=200)
letter_entry = Entry()
letter_entry.place(x=200,y=200)
numbers_label = Label(text="How many numbers are there")
numbers_label.place(x=5,y=250)
numbers_entry = Entry()
numbers_entry.place(x=200,y=250)
root.mainloop()
Overview of the Code:
The provided code demonstrates a simple GUI application built with the Tkinter library. It allows users to open a PDF file, choose a password list, and initiate attacks to crack the password. The code utilizes two classes: `PDFcrack` and `Brute`. Let's explore how each class contributes to the functionality of the application.
The `PDFcrack` Class:
The `PDFcrack` class in the "dictionary_attack.py" file encapsulates the logic for the dictionary attack. When instantiated, it takes the path to the PDF file and a password list as parameters. The `crack()` method attempts to decrypt the PDF file using each password from the list. If a match is found, the password is returned. If no match is found, an appropriate message is returned.
The `Brute` Class:
The `Brute` class in the "brutforce.py" file implements the brute force attack. It accepts the PDF file path, desired password length, and the number of symbols, letters, and numbers as parameters. The `generate_password()` method generates a password by randomly selecting characters from the specified character sets. The `brute_attack()` method attempts to decrypt the PDF file using the generated password. If a match is found, the password is returned. Otherwise, a failure message is returned.
Using the GUI Application:
The GUI application allows users to perform dictionary and brute force attacks to crack PDF passwords. Here's a step-by-step guide on how to use the application:
1. Open the PDF File: Click the "Open PDF" button and select the desired PDF file using the file dialog.
2. Choose a Password List: Click the "Open Password File" button to select a text file containing a list of passwords.
3. Perform a Dictionary Attack: Click the "Dictionary Attack" button to initiate the dictionary attack. The application will iterate through the passwords in the list and display the result.
4. Perform a Brute Force Attack: Enter the desired password length, number of symbols, letters, and numbers in the respective fields. Click the "Brute Force Attack" button to start the attack. The application will generate passwords based on the provided parameters and attempt to crack the PDF password.
5. Copy the Result: If a password is successfully cracked, the result will be displayed in the application. Click the "Copy" button to copy the password to the clipboard for further use.
Conclusion:
In this article, we explored a Python GUI application that uses dictionary and brute force attacks to crack passwords of PDF files. The application leverages the `PDFcrack` and `Brute` classes to perform the attacks, providing users with a convenient way to unlock password-protected PDFs. By customizing the password length and character sets, users can increase their chances of success in cracking the password. Remember to use this tool responsibly and ensure that you have the necessary permissions to decrypt the PDF files you work with.
Download full code here
No comments:
Post a Comment