Created
September 3, 2017 17:17
-
-
Save jabofh/aa89801419ca98ddd3d3ad155447fe94 to your computer and use it in GitHub Desktop.
Crack Zip File Passwords
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#import the required modules | |
import optparse | |
import zipfile | |
from time import time | |
#parse arguments | |
parser = optparse.OptionParser() | |
parser.add_option('-f', '--file', action="store", dest="file_path", help="Zip File Path", default=None) | |
parser.add_option('-w', '--word_list', action="store", dest="word_list", help="Word List Path", default=None) | |
options, args = parser.parse_args() | |
def main(file_path, word_list): | |
#check if the Zip file exists | |
try: | |
zip_ = zipfile.ZipFile(file_path) | |
except zipfile.BadZipfile: | |
print "Please check the file's path. It doesn't seem to be a zip file." | |
quit() | |
password = None #just in case if the word list is empty | |
i = 0 #password count | |
c_t = time() #start time | |
with open(word_list, "r") as f: #open the word list | |
passes = f.readlines() #read the text file line by line | |
for x in passes: | |
i += 1 #increment the password try count | |
password = x.split("\n")[0] #splitting the newline character | |
try: | |
zip_.extractall(pwd=password) #try the password | |
t_t = time() - c_t #total time | |
print "\nPassword cracked: %s\n" % password #print the password | |
print "Took %f seconds to crack the password. That is, %i attempts per second." % (t_t,i/t_t) #stats | |
quit() #stop the script | |
except Exception: | |
pass | |
print "Sorry, password not found." | |
if __name__ == '__main__': | |
main(options.file_path, options.word_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://codingsec.net/2016/11/crack-password-zip-files-using-python/