Ready to Start Your Career?

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

bjacharya 's profile image

By: bjacharya

July 28, 2016

brown-carpet-python-cybraryWelcome 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 optparseimport zipfilefrom threading import Threaddef 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_bijayWebsite : bijayacharya.com
Schedule Demo