import zipfile import random import itertools import time """ Solves a challenge on pentester academy's Labs. Inefficiently writes passwords to the screen, only be cause it was used as a debugging method to figure out how python3 was jacking up the string encoding. Might clean up into a usable program someday, so that's why I am saving it here... """ secrets_file = '/root/Downloads/secret.zip' pw_file = 'dict.txt' new_line = '\n'.encode('utf-8') # Read zipped file contents zipped = zipfile.ZipFile(secrets_file, mode="r") zip_contens = zipped.printdir() # generate wordlist print('Generating wordlist... ') wordlen = 6 chars = "abcde12345" f = open(pw_file, "wb") for password in itertools.product(chars, repeat=wordlen): f.write(''.join(password).encode('ascii') + '\n'.encode('ascii')) f.close time.sleep(2) cracked = False with open(pw_file) as f: lines = f.readlines() for password in lines: password = password.replace('\n','') print("Trying this password - " + password) try: zipped.extractall(pwd=password.encode('ascii')) correct_password = 'Correct password: %s' % password cracked = True break except: pass if cracked: print(correct_password) else: print("Password not found")