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

July 28, 2016 | Views: 20712

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 zipcracker.py

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

– 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 zipcracker.py 

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

import optparse

import zipfile

from threading import Thread

def extract_zip(zFile, password):

try:

zFile.extractall(pwd=password)

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

except:

pass

/* 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

exit(0)

else:

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))

t.start()

if __name__ == ‘__main__’:

Main()

:wq

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

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

/* Make sure that, all three files zipcracker.py, dictionary.txt and secured.zip 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 : twitter.com/acharya_bijay

Website : bijayacharya.com

Share with Friends
FacebookTwitterLinkedInEmail
Use Cybytes and
Tip the Author!
Join
Share with Friends
FacebookTwitterLinkedInEmail
Ready to share your knowledge and expertise?
19 Comments
  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:- http://stelladatarecovery.com/zip-password-recovery.html

  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 “zipcracker.py”, line 11
    try:
    ^
    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.

Support Cybrary

Donate Here to Get This Month's Donor Badge

 

We recommend always using caution when following any link

Are you sure you want to continue?

Continue
Cancel