diff --git a/CHANGELOG.md b/CHANGELOG.md index a1b5fd6b6..800061191 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... +## [unreleased][unreleased] +- Fixed `hf mfu restore` to support Ultralight AES (@iceman1001) +- Fixed `hf mfu info` to print UL-AES config pages again (@iceman1001) + ## [Frosty Lemon.4.23346][2026-09-18] - Fixed `hf mfdes sim` - the ATS now advertises 106 kbit/s only, PPS to a higher rate is refused, a selected card ignores REQA/WUPA, and ISO-DEP block recovery now follows the card sequence (@mistial-dev) - Added `hf mfdes sim` - answers ISO 7816 SELECT by DF name or file id with real status words, so a reader that opens with a SELECT reaches the card (@mistial-dev) diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 96531ce6b..58d3d8764 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -65,6 +65,14 @@ #define MAX_ST25TN512 0x3F #define MAX_ST25TN01K 0x3F +// UL-AES fixed memory map, MF0AES(H)20 +#define MFU_AES_USER_FIRST 0x04 +#define MFU_AES_USER_LAST 0x27 +#define MFU_AES_LOCK_PAGE 0x28 +#define MFU_AES_CFG0_PAGE 0x29 +#define MFU_AES_CFG1_PAGE 0x2A +#define MFU_AES_KEY0_PAGE 0x30 + #define MIFAREU3P_KEY_SIZE 16 #define MIFAREULC_KEY_INDEX 3 #define MFU_DEFAULT_KEY_DIC "mfulc_default_keys.dic" @@ -4043,6 +4051,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { "hf mfu restore -f myfile -s -> special write\n" "hf mfu restore -f myfile -k AABBCCDD -s -> special write, use key\n" "hf mfu restore -f myfile -k AABBCCDD -ser -> special write, use key, write dump pwd, ...\n" + "hf mfu restore -f myfile -k 00112233445566778899AABBCCDDEEFF -> UL-C / UL-AES, use key\n" "\n" "Note: Restoring a NTAG/UL dump to a UMC will likely result in incorrect PWD and PACK\n" ); @@ -4050,7 +4059,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { void *argtable[] = { arg_param_begin, arg_str1("f", "file", "", "Specify a filename for dump file"), - arg_str0("k", "key", "", "key for authentication (UL-C 16 bytes, EV1/NTAG 4 bytes)"), + arg_str0("k", "key", "", "key for authentication (UL-C/UL-AES 16 bytes, EV1/NTAG 4 bytes)"), arg_lit0("l", NULL, "swap entered key's endianness"), arg_lit0("s", NULL, "enable special write UID -MAGIC TAG ONLY-"), arg_lit0("e", NULL, "enable special write version/signature -MAGIC NTAG 21* ONLY-"), @@ -4142,6 +4151,8 @@ static int CmdHF14AMfURestore(const char *Cmd) { return PM3_ESOFT; } + bool is_ulaes = ((tagtype & MFU_TT_UL_AES) == MFU_TT_UL_AES); + if ((tagtype & MFU_TT_UL_C) == MFU_TT_UL_C) { if ((has_key == true) && (ak_len != 16)) { PrintAndLogEx(ERR, "UL-C key must be 16 bytes"); @@ -4172,12 +4183,6 @@ static int CmdHF14AMfURestore(const char *Cmd) { } } - if ((tagtype & MFU_TT_UL_AES) == MFU_TT_UL_AES) { - PrintAndLogEx(ERR, "Sorry, UL-AES not yet supported. Feel free to implement!"); - free(dump); - return PM3_ENOTIMPL; - } - PrintAndLogEx(INFO, "Restoring " _YELLOW_("%s")" to card", filename); mfu_print_dump(mem, pages, 0, dense_output); @@ -4279,7 +4284,19 @@ static int CmdHF14AMfURestore(const char *Cmd) { // write all other data // Skip block 0,1,2,3 (only magic tags can write to them) // Skip last 5 blocks usually is configuration - for (uint8_t b = 4; b < pages - 5; b++) { + uint8_t first_page = 4; + uint8_t last_page = pages - 5; + + if (is_ulaes) { + // UL-AES user memory stops before the lock, config and key pages + first_page = MFU_AES_USER_FIRST; + last_page = MFU_AES_USER_LAST + 1; + if (pages < last_page) { + last_page = pages; + } + } + + for (uint8_t b = first_page; b < last_page; b++) { //Send write Block memcpy(packetw.data, mem->data + (b * 4), 4); @@ -4306,8 +4323,19 @@ static int CmdHF14AMfURestore(const char *Cmd) { // otp, uid, lock, dynlockbits, cfg0, cfg1 uint8_t blocks[] = {3, 0, 1, 2, pages - 5, pages - 4, pages - 3}; #endif - for (uint8_t i = 0; i < ARRAYLEN(blocks); i++) { - uint8_t b = blocks[i]; + // otp, uid, lock, cfg0, cfg1. + // RFU pages (0x2B, 0x2C) and the key lock bits (0x2D) are left alone, they are one way + uint8_t ulaes_blocks[] = {3, 0, 1, 2, MFU_AES_LOCK_PAGE, MFU_AES_CFG0_PAGE, MFU_AES_CFG1_PAGE}; + + uint8_t *pblocks = blocks; + uint8_t blockcnt = ARRAYLEN(blocks); + if (is_ulaes) { + pblocks = ulaes_blocks; + blockcnt = ARRAYLEN(ulaes_blocks); + } + + for (uint8_t i = 0; i < blockcnt; i++) { + uint8_t b = pblocks[i]; memcpy(packetw.data, mem->data + (b * 4), 4); packetw.block_no = b; clearCommandBuffer(); @@ -4319,6 +4347,12 @@ static int CmdHF14AMfURestore(const char *Cmd) { DropField(); free(dump); + + if (is_ulaes) { + PrintAndLogEx(INFO, "Key pages 0x%02X..0x%02X not restored", MFU_AES_KEY0_PAGE, MAX_UL_AES); + PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf mfu setkey -k <16 hex bytes>") "` to restore the AES keys"); + } + PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf mfu dump --ns") "` to verify"); PrintAndLogEx(INFO, "Done!"); return PM3_SUCCESS; diff --git a/doc/commands.json b/doc/commands.json index 7e9fdb119..364afb575 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -9636,6 +9636,7 @@ "hf mfu restore -f myfile -s -> special write", "hf mfu restore -f myfile -k AABBCCDD -s -> special write, use key", "hf mfu restore -f myfile -k AABBCCDD -ser -> special write, use key, write dump pwd, ...", + "hf mfu restore -f myfile -k 00112233445566778899AABBCCDDEEFF -> UL-C / UL-AES, use key", "", "Note: Restoring a NTAG/UL dump to a UMC will likely result in incorrect PWD and PACK" ], @@ -9643,7 +9644,7 @@ "options": [ "-h, --help This help", "-f, --file Specify a filename for dump file", - "-k, --key key for authentication (UL-C 16 bytes, EV1/NTAG 4 bytes)", + "-k, --key key for authentication (UL-C/UL-AES 16 bytes, EV1/NTAG 4 bytes)", "-l swap entered key's endianness", "-s enable special write UID -MAGIC TAG ONLY-", "-e enable special write version/signature -MAGIC NTAG 21* ONLY-",