Skip to content

Instantly share code, notes, and snippets.

@jabofh
Created September 3, 2017 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jabofh/aa89801419ca98ddd3d3ad155447fe94 to your computer and use it in GitHub Desktop.
Save jabofh/aa89801419ca98ddd3d3ad155447fe94 to your computer and use it in GitHub Desktop.
Crack Zip File Passwords
#!/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)
@jabofh
Copy link
Author

jabofh commented Sep 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment