backalyzer now works with PDDB in hosted mode.

Specify file as `-f pddb-images/hosted.bin` and use `--hosted`
This commit is contained in:
bunnie 2022-07-26 03:42:11 +08:00
parent e943b35512
commit 6266101727

View file

@ -50,22 +50,32 @@ def main():
parser = argparse.ArgumentParser(description="Debug Backup Images") parser = argparse.ArgumentParser(description="Debug Backup Images")
parser.add_argument( parser.add_argument(
"-p", "--pin", required=True, help="unlock PIN", type=str, "-p", "--pin", help="Unlock PIN", type=str,
) )
parser.add_argument( parser.add_argument(
"--backup-key", required=False, help="Backup key as BIP-39 words", type=str, default="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art" "--backup-key", help="Backup key as BIP-39 words", type=str, default="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art"
) )
parser.add_argument( parser.add_argument(
"--basis", required=False, type=str, help="Extra Bases to unlock, as `name:pass`. Each additional basis requires another --basis separator. Note that : is not legal to use in a Basis name.", action="append", nargs="+" "--basis", type=str, help="Extra Bases to unlock, as `name:pass`. Each additional basis requires another --basis separator. Note that : is not legal to use in a Basis name.", action="append", nargs="+"
) )
parser.add_argument( parser.add_argument(
"--loglevel", required=False, help="set logging level (INFO/DEBUG/WARNING/ERROR)", type=str, default="INFO", "--loglevel", help="set logging level (INFO/DEBUG/WARNING/ERROR)", type=str, default="INFO",
) )
parser.add_argument( parser.add_argument(
"-d", "--dump", help="Print data records in detail", action="store_true" "-d", "--dump", help="Print data records in detail", action="store_true"
) )
parser.add_argument(
"--hosted", help="Analyze a hosted mode PDDB image.", action="store_true"
)
parser.add_argument(
"-f", "--file", help="Input file (defaults to backup.pddb).", type=str, default="backup.pddb"
)
args = parser.parse_args() args = parser.parse_args()
if args.hosted == False and args.pin == None:
print("Unlock PIN argument is required, please specified with `-p [pin]`")
exit(0)
numeric_level = getattr(logging, args.loglevel.upper(), None) numeric_level = getattr(logging, args.loglevel.upper(), None)
if not isinstance(numeric_level, int): if not isinstance(numeric_level, int):
raise ValueError('Invalid log level: %s' % args.loglevel) raise ValueError('Invalid log level: %s' % args.loglevel)
@ -89,12 +99,13 @@ def main():
key = Bip39MnemonicDecoder().Decode(mnemonic) key = Bip39MnemonicDecoder().Decode(mnemonic)
logging.debug("Using backup key: 0x{}".format(key.hex())) logging.debug("Using backup key: 0x{}".format(key.hex()))
with open("backup.pddb", "rb") as backup_file: with open(args.file, "rb") as backup_file:
global VERSION global VERSION
SYSTEM_BASIS = ".System" SYSTEM_BASIS = ".System"
VERSION = 0x201.to_bytes(4, 'little') # update this manually here if the PDDB version gets bumped :P VERSION = 0x201.to_bytes(4, 'little') # update this manually here if the PDDB version gets bumped :P
AAD = b"PDDB backup v0.1.0" AAD = b"PDDB backup v0.1.0"
backup = backup_file.read() backup = backup_file.read()
if args.hosted == False:
PT_HEADER_LEN = 4 + 16 * 4 + 4 + 8 + 64 + 4 + 4 # ignore the pt header PT_HEADER_LEN = 4 + 16 * 4 + 4 + 8 + 64 + 4 + 4 # ignore the pt header
NONCE_LEN = 12 NONCE_LEN = 12
CT_LEN = PT_HEADER_LEN + 1024 + 64 CT_LEN = PT_HEADER_LEN + 1024 + 64
@ -203,8 +214,16 @@ def main():
logging.debug("hashed_key: {}".format(list(user_key))) logging.debug("hashed_key: {}".format(list(user_key)))
pddb = backup[4096:] pddb = backup[4096:]
PDDB_A_LEN = 0x620_0000 else:
pt_len = (PDDB_A_LEN // 0x1000) * 16 dna_int = 0
user_key = bytes([0] * 32)
pddb = backup
pddb_len = len(pddb)
pddb_size_pages = pddb_len // PAGE_SIZE
logging.info("Database size: 0x{:x}".format(pddb_len))
pt_len = pddb_size_pages * 16
static_crypto_data = pddb[pt_len:pt_len + 0x1000] static_crypto_data = pddb[pt_len:pt_len + 0x1000]
scd_ver = int.from_bytes(static_crypto_data[:4], 'little') scd_ver = int.from_bytes(static_crypto_data[:4], 'little')
if scd_ver != 2: if scd_ver != 2:
@ -224,7 +243,6 @@ def main():
keys = {} keys = {}
keys[SYSTEM_BASIS] = [key_pt, key_data] keys[SYSTEM_BASIS] = [key_pt, key_data]
for name, pw in basis_credentials.items(): for name, pw in basis_credentials.items():
bname_copy = [0]*64 bname_copy = [0]*64
plaintext_pw = [0]*73 plaintext_pw = [0]*73
@ -256,9 +274,6 @@ def main():
# data_aad = SYSTEM_BASIS + PDDB_VERSION + dna # data_aad = SYSTEM_BASIS + PDDB_VERSION + dna
# now that we have the credentials, extract the baseline image # now that we have the credentials, extract the baseline image
pddb_len = len(pddb)
pddb_size_pages = pddb_len // PAGE_SIZE
logging.info("Database size: 0x{:x}".format(pddb_len))
mbbb_offset = pddb_size_pages * Pte.PTE_LEN + PAGE_SIZE * KEY_PAGES mbbb_offset = pddb_size_pages * Pte.PTE_LEN + PAGE_SIZE * KEY_PAGES
if mbbb_offset & (PAGE_SIZE - 1) != 0: if mbbb_offset & (PAGE_SIZE - 1) != 0: