#!/usr/bin/python from time import time from itertools import chain, product import zipfile import os import sys import tempfile import shutil import sys charset = "abcdefghijklmnopqrstuvwxyz" charset = charset + charset.upper() charset = charset + "0123456789- ." # def bruteforce(maxlength): return (''.join(candidate) for candidate in chain.from_iterable(product(charset, repeat=i) for i in range(1, maxlength + 1))) def main(): while True: try: myZip = zipfile.ZipFile("z.zip") except zipfile.BadZipfile: print("[!] There was an error opening your zip file.") return passwordFound = False for password in bruteforce(1): try: myZip.extract("z.zip", "tmp/", password.encode("utf-8")) shutil.move("tmp/z.zip", "z.zip") sys.stdout.write(password) sys.stdout.flush() passwordFound = True break except Exception as e: if 'Bad password for file' in str(e) or "Bad CRC-32 for file" in str(e): pass else: print(e) if not passwordFound: print("Sorry, password not found.") return if __name__ == '__main__': main()