In: Computer Science
•Write a Write a Python script that performs brute force to extract a password protected zip file named sec3.zip. The password is believed to be associated with one of the dictionary words in the 'wordlist.txt file. The password policy enforces that all employees MUST use passwords that include at least one capital and one digit. The files are attached (hint must import zipfile)
Code test with Python 3.6.9 in Linux operating system.
Code
import zipfile
zip_file = zipfile.ZipFile('./sec3.zip')
found = False
with open('./wordlist.txt', "rb") as wordlist:
words_count = len(list(wordlist))
print("Total no. of passwords to try:", words_count)
wordlist.seek(0)
for current_word in wordlist:
# Check if the word does not contain a digit
if not any([str(x) in current_word for x in range(10)]):
# If yes, ignore this word
continue
# Check if the word does not contain an uppercase letter
if not any([x.isupper() for x in a]):
# If yes, ignore this word
continue
try:
# Try to extract file
zip_file.extractall(pwd=current_word.strip())
except:
# If error is throw, try next password
continue
else:
# No error occured -> password found
found = True
print("Password found:", current_word.decode().strip())
if not found:
print('Password not found in the given wordlist.')