How to crack zip file password using python

How to crack zip file password using python

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

  1. We are using the zipline library for handling the zip file
  2. We are using the variable a to read the file name.
  3. Using passfile variable we are going to open the file which contain the list of passwords.
  4. Using for loop we check for every possible combination of the password and the correct password will be displayed when found.

Sample output

Leave a Reply

Your email address will not be published. Required fields are marked *