Make the brute-force more sensitive and bug fix

This commit is contained in:
KnugiHK
2022-02-22 21:19:19 +08:00
parent 08c5979eed
commit 3e71817778
2 changed files with 5 additions and 4 deletions

View File

@@ -121,7 +121,7 @@ def main():
" are not present. For details, see README.md.") " are not present. For details, see README.md.")
exit(3) exit(3)
elif error == 2: elif error == 2:
print("Failed when decompressing the decrypted backup." print("Failed when decompressing the decrypted backup. "
"Possibly incorrect offsets used in decryption.") "Possibly incorrect offsets used in decryption.")
exit(4) exit(4)
else: else:

View File

@@ -57,8 +57,8 @@ class Crypt(Enum):
def brute_force_offset(): def brute_force_offset():
for iv in range(60, 80): for iv in range(0, 200):
for db in range(80, 130): for db in range(0, 200):
yield iv, iv + 16, db yield iv, iv + 16, db
@@ -136,11 +136,12 @@ def decrypt_backup(database, key, output, crypt=Crypt.CRYPT14):
current_try += 1 current_try += 1
if current_try < len(CRYPT14_OFFSETS): if current_try < len(CRYPT14_OFFSETS):
offsets = CRYPT14_OFFSETS[current_try] offsets = CRYPT14_OFFSETS[current_try]
t2 = database[offsets["t2"]:offsets["t2"] + 32]
iv = database[offsets["iv"]:offsets["iv"] + 16] iv = database[offsets["iv"]:offsets["iv"] + 16]
db_ciphertext = database[offsets["db"]:] db_ciphertext = database[offsets["db"]:]
continue continue
else: else:
print("Common offsets are not applicable to "
"your backup. Trying to brute force it...")
for start_iv, end_iv, start_db in brute_force_offset(): for start_iv, end_iv, start_db in brute_force_offset():
iv = database[start_iv:end_iv] iv = database[start_iv:end_iv]
db_ciphertext = database[start_db:] db_ciphertext = database[start_db:]