193k views
1 vote
Write a Python script to save the dictionary words in the 'wordlist.txt' file, and then compress it to a zip file with a protected password. Then, write a Python script to perform brute force to extract the password protected zip file. The password is believed to be associated with one of the dictionary words in the 'wordlist.txt file. (hint import zipfile) wordlist.txt is just a list of dictionary word.

User Kevinpo
by
8.6k points

1 Answer

6 votes

import zipfile

# Create a list of dictionary words

dictionary_words = ['apple', 'banana', 'cherry', 'dog', 'elephant']

# Save the words to a file

with open('wordlist.txt', 'w') as f:

for word in dictionary_words:

f.write(word + '\\')

# Compress the file into a password-protected zip file

zip_file = zipfile.ZipFile('wordlist.zip', mode='w', compression=zipfile.ZIP_DEFLATED)

zip_file.setpassword(b'mypassword')

zip_file.write('wordlist.txt')

zip_file.close()

# Perform a brute force attack to extract the password

with open('wordlist.txt', 'r') as f:

words = f.readlines()

for word in words:

word = word.strip()

try:

with zipfile.ZipFile('wordlist.zip') as zip_file:

zip_file.extractall(pwd=bytes(word, 'utf-8'))

print(f'Password found: {word}')

break

except:

pass

User Brendan Vogt
by
7.5k points