Created
April 26, 2022 18:00
-
-
Save mrts/43653efcbba440f93b8cab1ec57f56a7 to your computer and use it in GitHub Desktop.
Recover KeePass password that was entered with a typo with John the Ripper.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Generate wordlist for recovering a password that was entered with a typo. | |
Assume the password consists of three elements of random words generated by gpw, | |
separated by punctuation marks and numbers. | |
python password-permutations.py > passwords.txt | |
sudo snap install john-the-ripper | |
john-the-ripper.keepass2john Database.kdbx > passwordhash.txt | |
john-the-ripper --wordlist=passwords.txt passwordhash.txt | |
""" | |
import itertools | |
def flatten(list_of_lists): | |
return itertools.chain.from_iterable(list_of_lists) | |
def uppercase_either_first_or_second_letter(word): | |
return [word, | |
word.title(), | |
word[0] + word[1].swapcase() + word[2:]] | |
def word_permutations(word, min_len, max_len=None): | |
if not max_len: | |
max_len = len(word) | |
lengths = range(min_len, max_len + 1) | |
result = [] | |
for length in lengths: | |
words = flatten(uppercase_either_first_or_second_letter(''.join(p)) | |
for p in itertools.permutations(word, length)) | |
result.extend(words) | |
return result | |
def all_annas(): | |
return [c for c in word_permutations('anna', 3) | |
if c[0].lower() == 'a' | |
or c[0].lower() == 'n'] | |
def all_bertas(): | |
return [c for c in word_permutations('berta', 4) | |
if c[0].lower() == 'b' | |
or c[0].lower() == 'e' | |
or c[0].lower() == 'r'] | |
def all_cecils(): | |
return [c for c in word_permutations('cecil', 4) | |
if c[0].lower() == 'c' | |
or c[0].lower() == 'e'] | |
if __name__ == '__main__': | |
for anna in all_annas(): | |
for comma in [',', '.', ';', ':']: | |
for berta in all_bertas(): | |
for num in [2, 3, 4, 5]: | |
for cecil in all_cecils(): | |
word = f"{anna}{comma}{berta}{num}{cecil}" | |
print(word) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment