Skip to content

Instantly share code, notes, and snippets.

@vaelen
Last active July 29, 2020 14:27
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 vaelen/9bf6356c2952e41518645f24c6db8625 to your computer and use it in GitHub Desktop.
Save vaelen/9bf6356c2952e41518645f24c6db8625 to your computer and use it in GitHub Desktop.
A python script for guessing zip file passwords.
#!/usr/bin/env python3
# Guess a zip file password using a word list.
#
# Copyright 2020, Andrew C. Young <andrew@vaelen.org>
# License: MIT
#
# Usage: guess.py <zip_file> <words_file>
# NOTE: The words file should be a gzip file that contains a list of words separated by spaces or newlines
import subprocess
import sys
import gzip
import zipfile
if len(sys.argv) < 3:
print("Zip file password guesser")
print()
print("Copyright 2020, Andrew C. Young <andrew@vaelen.org>")
print("License: MIT")
print()
print("Usage: guess.py <zip_file> <words_file>")
print()
print("NOTE: The words file should be a gzip file that contains a list of words separated by spaces or newlines")
print()
exit(1)
filename = sys.argv[1]
words_filename = sys.argv[2]
def try_password(password):
with zipfile.ZipFile(filename) as zip_file:
try:
zip_file.extractall(pwd=password)
except:
return False
return True
words = []
with gzip.open(words_filename, "r") as f:
for line in f:
for word in line.split():
words.append(word)
print(f'Using {len(words)} words')
for word in words:
print("#", end='', flush=True)
word_list = [word.title(), word.lower(), word.upper()]
for pw in word_list:
if try_password(pw):
print()
print(f'Success! Password: {pw.decode("utf-8")}')
exit(0)
print()
print("Password Not Found")
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment