diff --git a/README.md b/README.md index f7fd3ac..402b3e7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -python_zip_cracker -================== +# Python Zip files Cracker -with this script you are able to brute force a password protected -zip file. it may take some while, but if you are patient, you will be able to recover -the password for the file. +Using this script you are able to bruteforce a password protected +zip file. It may take some while, but if you are patient, you will +be able to recover the password for the file. +Note: Repo will be available as archive only diff --git a/crack_pw.py b/crack_pw.py index b6fdcf7..29f444c 100644 --- a/crack_pw.py +++ b/crack_pw.py @@ -1,47 +1,49 @@ import sys import zipfile import itertools +import string -filename = "" -try: - filename = sys.argv[1]; -except: - print "The filename was not a valid string" - exit(1) -#characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" -characters = "abcdefghijklmnopqrstuvwxyz" -zipFile = zipfile.ZipFile(filename, "r") +# zipfn : zip-file-name, +# chars : are list of chars that can be used in generation of password +# max_len : maximum length of password to try +def crack_pw(zipfn, max_len, chars = string.ascii_lowercase): + for length in range(max_len+1): -#iterate all possible lengths of the password -for leng in range(1, len(characters)+1): - print "lenght of password: ", leng + # passwords generated using cartesians product, to given length + pools = itertools.product(chars, repeat = length) - #create an iterator over the cartesian product of all possible permuations - it = itertools.product(characters, repeat=leng) + # Try each generated password + for pool in pools: + passwd = bytes("".join(pool)) - #iterate all created permutations - for passw in it: + # If contents are successfully extracted, password is valid + # If Runtime Error is caught then password in Invalid, thus try next try: - #join the tupel to a string and set the password - passwd = ''.join(passw) - zipFile.setpassword(passwd) - - """ - try to extract the files from the file - if the password is wrong, an exception is thrown, - (RuntimeError), which is caught in the except part - """ - zipFile.extractall() - - #if there was no error the password will be shown and the programm exits - print "The password is: ", passwd - exit() + zipfn.extractall(pwd=passwd) + return passwd except RuntimeError: - pass - except zipfile.BadZipfile: - pass - except Exception as e: - pass + continue + + # Flag for password not found + return False -print "no pw found..." + +# UI +file_name = "" +try: + file_name = sys.argv[1] + zip_file = zipfile.ZipFile(file_name, "r") +except (IOError, Exception): + print("File not found! Try another valid string!") + sys.exit(1) + +print("..Try all possible password combinations!\n Keep Patience!") +recovered_passwd = crack_pw(zip_file, 16) +zip_file.close() + +if not recovered_passwd: + print("\n > No password found! Try expanding character set!") +else: + print("\n > Password for %s: %s" %(file_name, recovered_passwd)) +sys.exit(0)