From fbc8195cadb4c7fd3f6742ccb7411fae46459973 Mon Sep 17 00:00:00 2001 From: Kalpak Take Date: Mon, 3 Jul 2017 19:55:23 +0530 Subject: [PATCH 01/13] Add support for python 2.x, 3.x/ more user friendly --- crack_pw.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/crack_pw.py b/crack_pw.py index b6fdcf7..a3d4bce 100644 --- a/crack_pw.py +++ b/crack_pw.py @@ -1,27 +1,29 @@ import sys import zipfile import itertools +import string filename = "" try: filename = sys.argv[1]; except: - print "The filename was not a valid string" + print("The filename was not a valid string") exit(1) - -#characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" -characters = "abcdefghijklmnopqrstuvwxyz" + +#characters = string.ascii_letters +characters = string.ascii_lowercase zipFile = zipfile.ZipFile(filename, "r") #iterate all possible lengths of the password for leng in range(1, len(characters)+1): - print "lenght of password: ", leng + print("Length of password: ", leng) #create an iterator over the cartesian product of all possible permuations - it = itertools.product(characters, repeat=leng) + opts = itertools.product(characters, repeat=leng) #iterate all created permutations - for passw in it: + for passw in opts: + print("Trying with password {} ...".format(passw)) try: #join the tupel to a string and set the password passwd = ''.join(passw) @@ -35,13 +37,14 @@ zipFile.extractall() #if there was no error the password will be shown and the programm exits - print "The password is: ", passwd + print("The password for file is: " + str(passwd)) exit() except RuntimeError: - pass + print("\nFailed For {}".format(passw)) except zipfile.BadZipfile: - pass - except Exception as e: + print("Error opening/operating zipfile") + exit(1) + except: pass -print "no pw found..." +print("No passwords were found...\n") From 254e48fe23c388ac36589e2dc2b9bc4a56ce4daf Mon Sep 17 00:00:00 2001 From: Kalpak Take Date: Mon, 3 Jul 2017 20:07:08 +0530 Subject: [PATCH 02/13] Update bit ui --- crack_pw.py | 59 ++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/crack_pw.py b/crack_pw.py index a3d4bce..36b0dd9 100644 --- a/crack_pw.py +++ b/crack_pw.py @@ -5,46 +5,45 @@ filename = "" try: - filename = sys.argv[1]; + filename = sys.argv[1]; except: - print("The filename was not a valid string") - exit(1) - + print("The filename was not a valid string") + exit(1) + #characters = string.ascii_letters characters = string.ascii_lowercase zipFile = zipfile.ZipFile(filename, "r") #iterate all possible lengths of the password for leng in range(1, len(characters)+1): - print("Length of password: ", leng) + print("Length of password: ", leng) - #create an iterator over the cartesian product of all possible permuations - opts = itertools.product(characters, repeat=leng) + #create an iterator over the cartesian product of all possible permuations + opts = itertools.product(characters, repeat=leng) - #iterate all created permutations - for passw in opts: - print("Trying with password {} ...".format(passw)) - try: - #join the tupel to a string and set the password - passwd = ''.join(passw) - zipFile.setpassword(passwd) + #iterate all created permutations + for passw in opts: + print("Trying with password {} ...".format(passw)) + 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() + """ + 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 for file is: " + str(passwd)) - exit() - except RuntimeError: - print("\nFailed For {}".format(passw)) - except zipfile.BadZipfile: - print("Error opening/operating zipfile") - exit(1) - except: - pass + #if there was no error the password will be shown and the programm exits + print("The password for file is: " + str(passwd)) + exit() + except RuntimeError: + print("Failed For {}\n".format(passw)) + except zipfile.BadZipfile: + print("Error opening/operating zipfile\n") + except: + pass print("No passwords were found...\n") From c1aa5ab107ce37f41e36e6e002e6b7f624f5f51e Mon Sep 17 00:00:00 2001 From: Kalpak Take Date: Mon, 3 Jul 2017 20:13:16 +0530 Subject: [PATCH 03/13] Fix passwd to passw --- crack_pw.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crack_pw.py b/crack_pw.py index 36b0dd9..e54668f 100644 --- a/crack_pw.py +++ b/crack_pw.py @@ -15,7 +15,7 @@ zipFile = zipfile.ZipFile(filename, "r") #iterate all possible lengths of the password -for leng in range(1, len(characters)+1): +for leng in range(1, 5): print("Length of password: ", leng) #create an iterator over the cartesian product of all possible permuations @@ -23,11 +23,12 @@ #iterate all created permutations for passw in opts: - print("Trying with password {} ...".format(passw)) + tmp = ''.join(passw) + print("Trying with password {} :".format(tmp)) try: - #join the tupel to a string and set the password + #join the tuple to a string and set the password passwd = ''.join(passw) - zipFile.setpassword(passwd) + zipFile.setpassword(passw) """ try to extract the files from the file @@ -37,7 +38,7 @@ zipFile.extractall() #if there was no error the password will be shown and the programm exits - print("The password for file is: " + str(passwd)) + print("The password for file is: " + str(passw)) exit() except RuntimeError: print("Failed For {}\n".format(passw)) From bb4020bb3475ad75a88077205ef6b97cef492b74 Mon Sep 17 00:00:00 2001 From: Kalpak Take Date: Mon, 3 Jul 2017 20:34:30 +0530 Subject: [PATCH 04/13] Update case for file IOError and Fix bit ui --- crack_pw.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/crack_pw.py b/crack_pw.py index e54668f..72a70df 100644 --- a/crack_pw.py +++ b/crack_pw.py @@ -7,15 +7,21 @@ try: filename = sys.argv[1]; except: - print("The filename was not a valid string") - exit(1) + print("The filename is not a valid string!") + sys.exit(1) -#characters = string.ascii_letters +#characters = string.ascii_letters characters = string.ascii_lowercase -zipFile = zipfile.ZipFile(filename, "r") +try: + zipFile = zipfile.ZipFile(filename, "r") +except IOError: + # rather than raise() we'll simple print it to screen because we dont't want to scare the user + print("IOError: \nFile you entered was not found!\nTry again!") + sys.exit(1) +found = False #iterate all possible lengths of the password -for leng in range(1, 5): +for leng in range(1, len(characters)+1): print("Length of password: ", leng) #create an iterator over the cartesian product of all possible permuations @@ -23,28 +29,28 @@ #iterate all created permutations for passw in opts: + if found: + sys.exit(0) + else: tmp = ''.join(passw) print("Trying with password {} :".format(tmp)) try: #join the tuple to a string and set the password passwd = ''.join(passw) - zipFile.setpassword(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 + 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 for file is: " + str(passw)) - exit() + print("Password Found\n Password is ->" + str(passwd)) + found = True except RuntimeError: - print("Failed For {}\n".format(passw)) - except zipfile.BadZipfile: - print("Error opening/operating zipfile\n") + print("Failed for test{}\n".format(tmp)) except: - pass + print("Error opening/operating zipfile\n") print("No passwords were found...\n") From 60436be83e0ba2a5c1eb945ef4a53d844afd2443 Mon Sep 17 00:00:00 2001 From: Kalpak Take Date: Mon, 3 Jul 2017 21:13:58 +0530 Subject: [PATCH 05/13] Update crack_pw.py --- crack_pw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crack_pw.py b/crack_pw.py index 72a70df..f03b5d8 100644 --- a/crack_pw.py +++ b/crack_pw.py @@ -49,7 +49,7 @@ print("Password Found\n Password is ->" + str(passwd)) found = True except RuntimeError: - print("Failed for test{}\n".format(tmp)) + print("Failed for test {}\n".format(tmp)) except: print("Error opening/operating zipfile\n") From 7d737ac381e00d1a596c6146fd3106b037b69aa2 Mon Sep 17 00:00:00 2001 From: Kalpak Take Date: Tue, 4 Jul 2017 11:09:56 +0530 Subject: [PATCH 06/13] Made more precise exception on line 53 --- crack_pw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crack_pw.py b/crack_pw.py index f03b5d8..a663d45 100644 --- a/crack_pw.py +++ b/crack_pw.py @@ -50,7 +50,7 @@ found = True except RuntimeError: print("Failed for test {}\n".format(tmp)) - except: + except Exception as e: print("Error opening/operating zipfile\n") print("No passwords were found...\n") From a0191b396efc7cecaa6bf259eb33f95459f53e51 Mon Sep 17 00:00:00 2001 From: Kalpak Take Date: Sat, 15 Jul 2017 17:40:36 +0530 Subject: [PATCH 07/13] Update README.md --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f7fd3ac..4c62f5c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ -python_zip_cracker -================== +# Python Zipfiles 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. From 436b70c11dd81cba96d678ec78b29834e99fb306 Mon Sep 17 00:00:00 2001 From: Kalpak Take Date: Mon, 24 Jul 2017 23:59:41 +0530 Subject: [PATCH 08/13] Update crack_pw.py --- crack_pw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crack_pw.py b/crack_pw.py index a663d45..9231eae 100644 --- a/crack_pw.py +++ b/crack_pw.py @@ -53,4 +53,4 @@ except Exception as e: print("Error opening/operating zipfile\n") -print("No passwords were found...\n") +print("The password was not found...\n") From 038b62555f940fbc82471c62b1776501e9184a67 Mon Sep 17 00:00:00 2001 From: Kalpak Take Date: Tue, 25 Jul 2017 00:11:52 +0530 Subject: [PATCH 09/13] Update crack_pw.py --- crack_pw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crack_pw.py b/crack_pw.py index 9231eae..f9c8a53 100644 --- a/crack_pw.py +++ b/crack_pw.py @@ -10,7 +10,7 @@ print("The filename is not a valid string!") sys.exit(1) -#characters = string.ascii_letters +#characters = string.ascii_letters + string.digits characters = string.ascii_lowercase try: zipFile = zipfile.ZipFile(filename, "r") From 5c28c11edfabfe050891e6670a00cb4f9e7a45b7 Mon Sep 17 00:00:00 2001 From: Kalpak Take Date: Wed, 7 Mar 2018 19:31:31 +0530 Subject: [PATCH 10/13] Update crack_pw.py --- crack_pw.py | 93 +++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 50 deletions(-) diff --git a/crack_pw.py b/crack_pw.py index f9c8a53..29f444c 100644 --- a/crack_pw.py +++ b/crack_pw.py @@ -3,54 +3,47 @@ import itertools import string -filename = "" -try: - filename = sys.argv[1]; -except: - print("The filename is not a valid string!") - sys.exit(1) - -#characters = string.ascii_letters + string.digits -characters = string.ascii_lowercase + +# 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): + + # passwords generated using cartesians product, to given length + pools = itertools.product(chars, repeat = length) + + # Try each generated password + for pool in pools: + passwd = bytes("".join(pool)) + + # If contents are successfully extracted, password is valid + # If Runtime Error is caught then password in Invalid, thus try next + try: + zipfn.extractall(pwd=passwd) + return passwd + except RuntimeError: + continue + + # Flag for password not found + return False + + +# UI +file_name = "" try: - zipFile = zipfile.ZipFile(filename, "r") -except IOError: - # rather than raise() we'll simple print it to screen because we dont't want to scare the user - print("IOError: \nFile you entered was not found!\nTry again!") - sys.exit(1) - -found = False -#iterate all possible lengths of the password -for leng in range(1, len(characters)+1): - print("Length of password: ", leng) - - #create an iterator over the cartesian product of all possible permuations - opts = itertools.product(characters, repeat=leng) - - #iterate all created permutations - for passw in opts: - if found: - sys.exit(0) - else: - tmp = ''.join(passw) - print("Trying with password {} :".format(tmp)) - try: - #join the tuple 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() - - print("Password Found\n Password is ->" + str(passwd)) - found = True - except RuntimeError: - print("Failed for test {}\n".format(tmp)) - except Exception as e: - print("Error opening/operating zipfile\n") - -print("The password was not found...\n") + 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) From 26c779991d3ce7a930ca637c8b48b62a97aa9ef9 Mon Sep 17 00:00:00 2001 From: "Do (A)I Matter?" <20800689+zeta-punk-x1@users.noreply.github.com> Date: Fri, 2 Aug 2024 20:06:08 +0000 Subject: [PATCH 11/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c62f5c..fcc7938 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Python Zipfiles cracker +# Python Zip files cracker 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 From 07665a8ffa7484cde05c0bae3f1587bd0067dee3 Mon Sep 17 00:00:00 2001 From: "Do (A)I Matter?" <20800689+zeta-punk-x1@users.noreply.github.com> Date: Fri, 2 Aug 2024 20:06:50 +0000 Subject: [PATCH 12/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fcc7938..9b0f379 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Python Zip files cracker +# Python Zip files Cracker 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 From d83c0d746669b164d6863774b9a3d4cf5d1dbd33 Mon Sep 17 00:00:00 2001 From: "Do (A)I Matter?" <20800689+zeta-punk-x1@users.noreply.github.com> Date: Fri, 2 Aug 2024 20:09:57 +0000 Subject: [PATCH 13/13] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9b0f379..402b3e7 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,4 @@ 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