Header Ads

ZIP Cracker tool using Pyhton || Ethical Hacking || Python Project

ZIP cracker tool is the cracking tool to unlock zip or rar files passwords using brute force. We will use the file which contains different password and try to extract the zip file with password in the list. If the zip file is unzipped then congratulation, we found the password. We will use zipfile library to perform this task.





Code :

import zipfile

def crack_password(password_list, obj):
idx = 0
with open(password_list, 'rb') as file:
for line in file:
for word in line.split():
try:
idx += 1
obj.extractall(pwd=word)
print("Password found at line",idx)
print("Password is",word.decode())
return True
except:
continue
return False

if __name__ == '__main__':
zip_file = input("Enter zip file to extract: ")
password_list = input("Provide list of passwords to use: ")

obj = zipfile.ZipFile(zip_file)
cnt = len(list(open(password_list,'rb')))
print("There are total",cnt,"number of password to test.")

if crack_password(password_list, obj) == False:
print("Password not found in the list provided")


Password Cracked :

Enter zip file to extract: test.zip
Provide list of passwords to use: passlist.txt
There are total 23 number of password to test.
Password found at line 4
Password is test123


Explanation :

import zipfile is a statement that imports the zipfile module in Python, which provides tools for creating, reading, and extracting ZIP archives.

In the given code, obj = zipfile.ZipFile(zip_file) creates an instance of the ZipFile class by passing the name of the ZIP file to open as an argument. This instance can then be used to perform operations on the ZIP file, such as extracting its contents.

The crack_password function takes two arguments: password_list and obj. password_list is the name of a file containing a list of possible passwords to try, and obj is the ZipFile instance representing the ZIP file to crack.

The function reads the contents of password_list line by line and tries to extract the contents of the ZIP file using each password in turn until it finds the correct one. If it finds the correct password, it prints a message indicating where the password was found and returns True. If it reaches the end of the password list without finding the correct password, it returns False.

Finally, the code prompts the user to enter the name of a ZIP file to extract and a file containing a list of possible passwords to try. It then creates an instance of ZipFile representing the specified ZIP file and prints the number of passwords in the password list. It then calls the crack_password function to try to extract the contents of the ZIP file using the passwords in the list. If the function returns False, it prints a message indicating that the password was not found in the list.




Related Links :


Post a Comment

0 Comments