Skip to content

Instantly share code, notes, and snippets.

@joenorton8014
Created October 21, 2018 00:52
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 joenorton8014/72ef863c67263225d96f9f540407a43c to your computer and use it in GitHub Desktop.
Save joenorton8014/72ef863c67263225d96f9f540407a43c to your computer and use it in GitHub Desktop.
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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment