Answer the question
In order to leave comments, you need to log in
7z archive password guessing script in python?
Task: to find the forgotten password to the archive.
Conditions: the length of the password is no more than 4 words without spaces. There is a list of 5 words that can be in the password in an unknown order.
Done:
With the help of itertools.product, I generated all possible variants of word order in the password and wrote it to a file.
for word in itertools.product(['first','second','third','fourth','fiftht'], repeat=4):
print(''.join(word))
with py7zr.SevenZipFile('encrypted.7z', mode='r', password='secret') as Archive:
Archive.extractall()
. passfile = open('\pass.txt', 'r') # открываю файл с паролями для чтения
Lines = passfile.readlines() # в файле каждый вариант пароля на новой строке. Читаем файл построчно.
for word in Lines:
arch = py7zr.SevenZipFile('\Archive.7z', mode='r', password=word)
arch.extractall(path="\")
Answer the question
In order to leave comments, you need to log in
You need to add a kind of "crash" check:
passfile = open('\pass.txt', 'r') # открываю файл с паролями для чтения
Lines = passfile.readlines() # в файле каждый вариант пароля на новой строке. Читаем файл построчно.
for word in Lines:
try:
arch = py7zr.SevenZipFile('\Archive.7z', mode='r', password=word)
arch.extractall(path="\\")
print('Пароль "' + word + '" подошёл!')
except Exception:
print('Пароль "' + word + '" не подошёл')
The speed is approximately 1 password per second. I'm not a programmer myself, I didn't teach PEP 8. I apologize to those who will get unpleasant reflexes from this code.
PossiblePassList = ['first','second','third']
for word in PossiblePassList:
try:
arch = py7zr.SevenZipFile('\arch.7z', mode='r', password=word)
arch.extractall(path="\")
arch.reset() #из документации Once extract() called, the SevenZipFIle object become exhausted and EOF state. If you want to call extractall() again, you should call reset() before it.
print('Password detected - ' + word)
break
except py7zr.Bad7zFile:
print('Wrong password! ' + word)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question