Python Programming For Hackers (Part 5) – Cracking Zipped Passwords

July 28, 2016 | Views: 18227

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

Welcome to next part, Python Programming For Hackers (Part 5) – Cracking Zipped Passwords


> Before starting, you must be familiar with .RAR and .ZIP

> This process quickly tries for different passwords. If it misses, then it moves to the next one. If the password matches, then the zip file is easily extracted.


# Creating a Program

– We create python file called

– Lock your zip file with common password like abcdef or 123456 (whatever). Rename file to as your wish. Here, I’ll use the name ““.

– Next, we need a dictionary file that contains our list of passwords. Create a dictionary file in .txt format. Place that common password in .txt file. Like abcdef or 123456 or whatever. Read my previous article on Dictionaries. Or optionally, you can search for dictionary files in google too.

– In this python program,we’ll need the main and extract_zip functions.


# OS used for writing python script is ‘Ubuntu‘.

# let’s begin writing our .py file in terminal of ubuntu. 

python@ubuntu:-/bj/pytut5$   vim 

/* vim opens vim editor box, so now write below commands */

import optparse

import zipfile

from threading import Thread

def extract_zip(zFile, password):



print “[+] Pass Found: ” + password + ‘n’



/* The above line of code from DEF to PASS works if password is found. If it’s not found, then it just passes. And, this will help program not to crash */

def Main():

parser = optparse.OptionParser(“usage %prog “+

“-f <zipfile> -d <dictionary>”)

        parser.add_option(‘-f’, dest=’zname’, type=’string’,

help=’specify zip file’)

parser.add_option(‘-d’, dest=dname’, type=’string’,

help=’specify dictionary file’) 

(options, arg) = parser.parse_args()

if (options.zname == None) | (options.dname == None):

print parser.usage



zname = options.zname

dname = options.dname


zFile = zipfile.ZipFile(zname)

passFile = open(dname)


for line in passFile.readlines():

password = line.strip(‘n’)

t = Thread(target=extract_zip, args=(zFile, password))


if __name__ == ‘__main__’:



/* The program is finished. Now, lets run our in terminal. Note: I’ve assigned -d and -f for file and dictionary */

python@ubuntu:-/bj/pytut5$   python -f -d dictionary.txt   /*press Enter. You’ll get the password in a picture format */

/* Make sure that, all three files, dictionary.txt and are in same folder. This is for beginners. But once you knew about it, you can place them anywhere and can start cracking */

By : Bijay Acharya (CEHv9. Trained Personnel)

Follow :

Website :

Share with Friends
Use Cybytes and
Tip the Author!
Share with Friends
Ready to share your knowledge and expertise?
  1. Now it too easy and simple to unlock zip archive file password with the help of Stella zip password recovery software using by three method like brute force attack/dictionary attack and mask attack.

    Read more information from here:-

  2. builtins.UnboundLocalError: local variable ‘zname’ referenced before assignment

    I got this error, how can I fix it?

  3. Bro this error shows up : File “”, line 11
    IndentationError: expected an indented block

  4. Where is part 1 please provide links for that

Page 3 of 3«123
Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Cybrary On The Go

Get the Cybrary app for Android for online and offline viewing of our lessons.

Get it on Google Play

Support Cybrary

Donate Here to Get This Month's Donor Badge

Skip to toolbar

We recommend always using caution when following any link

Are you sure you want to continue?