Most times we find ourselves having zip files that are password protected. In this tutorial, I am going to show you how we can use python to crack the password.
Steps
- First we are going encrypt the sample file “test.txt” with the password – “pass” and save the zip file as “sample.zip”
- For cracking the password we going to use the password list from the text file (you can use the rockyou text file in the Kali Linux)
- Open the IDE and paste the below code
Program
import zipfile
a=input(“Enter the file name with the extension”)
obj=zipfile.ZipFile(a)
passfile=open(“pass.txt”,’r’)
for i in passfile:
i=i.strip(“\n”).strip(“\r”)
b = bytes(i, ‘utf-8’)
try:
obj.extractall(pwd=b)
print(i)
break
except:
print(“Currently in process”)
Explanation
- We are using the zipline library for handling the zip file
- We are using the variable a to read the file name.
- Using passfile variable we are going to open the file which contain the list of passwords.
- Using for loop we check for every possible combination of the password and the correct password will be displayed when found.
Sample output
