From 7346db71ffcb457822e00c79850f969e32108f69 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 22 Sep 2026 15:05:38 +0200 Subject: [PATCH] hf mfu view: print the stored UL-C / UL-AES key `hf mfu dump -k` appends the authentication key to the dump file, but `view` never showed it. The key was there in the hex listing all along, split across four pages and byte-swapped, which is not something you read off the screen. With `-v`, view now prints it. UL-C takes pages 0x2C..0x2F, UL-AES pages 0x30..0x33, and both are unswapped back into the form `-k` expects, so the printed line can be pasted straight into the next command. The existing ulc_print_3deskey() does the UL-C side; ulaes_print_key() is its UL-AES sibling. Tag type comes from the dump header rather than a card: the three UL-AES version signatures that ul_select_card() matches on a live tag, and for UL-C, which answers no GET_VERSION, all-zero version bytes plus a page count of 0x2F. Key pages that are all zero say so and point at `dump -k`, since a dump taken without a key legitimately has none. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 1 + client/src/cmdhfmfu.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e3b1a777..1475aaa1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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] +- Added `hf mfu view -v` - prints the UL-C 3DES key or UL-AES key stored in the dump file (@iceman1001) - Added `hf mf sen --ns` - skip writing the key and dump files (@iceman1001) - Fixed `hf mf autopwn --ns` on FM11RF08S - the flag is now honoured by the static encrypted nonce recovery instead of being dropped (@iceman1001) - Added `hf mf sen --suffix` - generated files can be named `hf-mf---` (@iceman1001) diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 58d3d8764..0b0a667f7 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -65,6 +65,9 @@ #define MAX_ST25TN512 0x3F #define MAX_ST25TN01K 0x3F +// UL-C key pages +#define MFU_ULC_KEY0_PAGE 0x2C + // UL-AES fixed memory map, MF0AES(H)20 #define MFU_AES_USER_FIRST 0x04 #define MFU_AES_USER_LAST 0x27 @@ -1188,6 +1191,15 @@ static int ulc_print_3deskey(uint8_t *data) { return PM3_SUCCESS; } +static int ulaes_print_key(uint8_t *data) { + PrintAndLogEx(INFO, " aeskey [48/0x30]: %s [%s]", sprint_hex(data, 4), sprint_ascii(data, 4)); + PrintAndLogEx(INFO, " aeskey [49/0x31]: %s [%s]", sprint_hex(data + 4, 4), sprint_ascii(data + 4, 4)); + PrintAndLogEx(INFO, " aeskey [50/0x32]: %s [%s]", sprint_hex(data + 8, 4), sprint_ascii(data + 8, 4)); + PrintAndLogEx(INFO, " aeskey [51/0x33]: %s [%s]", sprint_hex(data + 12, 4), sprint_ascii(data + 12, 4)); + PrintAndLogEx(INFO, "aes key: " _GREEN_("%s"), sprint_hex_inrow(SwapEndian64(data, 16, 16), 16)); + return PM3_SUCCESS; +} + // Only takes 16 bytes of data. Now key data available here static int ulc_print_configuration(uint8_t *data) { @@ -8322,6 +8334,71 @@ static int CmdHF14AMfuESave(const char *Cmd) { return res; } +// Derive the tag type from the dump header, version bytes and page count. +// Uses the same version byte signatures as ul_select_card() does on a live tag. +static uint64_t mfu_dump_get_tagtype(const mfu_dump_t *card) { + + if (memcmp(card->version, "\x00\x04\x03\x01\x04\x00\x0F\x03", 8) == 0 || + memcmp(card->version, "\x00\x04\x03\x02\x04\x00\x0F\x03", 8) == 0 || + memcmp(card->version, "\x00\x04\x03\x03\x04\x00\x0F\x03", 8) == 0) { + return MFU_TT_UL_AES; + } + + // UL-C has no GET_VERSION, the dump holds zeroes there + bool version_zero = true; + for (uint8_t i = 0; i < ARRAYLEN(card->version); i++) { + if (card->version[i] != 0x00) { + version_zero = false; + break; + } + } + + if (version_zero && card->pages == MAX_ULC_BLOCKS) { + return MFU_TT_UL_C; + } + + return MFU_TT_UNKNOWN; +} + +// `hf mfu dump` appends the authentication key to the dump when one was given. +// UL-C: pages 0x2C..0x2F, stored as SwapEndian64(key, 16, 8) +// UL-AES: pages 0x30..0x33, stored as SwapEndian64(key, 16, 16) +static void mfu_print_dump_keys(mfu_dump_t *card, uint16_t block_cnt) { + + uint64_t tagtype = mfu_dump_get_tagtype(card); + + uint8_t page; + if ((tagtype == MFU_TT_UL_C) && (block_cnt > (MFU_ULC_KEY0_PAGE + 3))) { + page = MFU_ULC_KEY0_PAGE; + } else if ((tagtype == MFU_TT_UL_AES) && (block_cnt > (MFU_AES_KEY0_PAGE + 3))) { + page = MFU_AES_KEY0_PAGE; + } else { + return; + } + + uint8_t *key = card->data + (page * MFU_BLOCK_SIZE); + + PrintAndLogEx(NORMAL, ""); + if (tagtype == MFU_TT_UL_C) { + PrintAndLogEx(INFO, "--- " _CYAN_("UL-C 3DES key") " -------------------------"); + } else { + PrintAndLogEx(INFO, "--- " _CYAN_("UL-AES key") " ----------------------------"); + } + + uint8_t zeros[MIFAREU3P_KEY_SIZE] = {0x00}; + if (memcmp(key, zeros, sizeof(zeros)) == 0) { + PrintAndLogEx(INFO, " " _RED_("n/a") " - page %u..%u is all zero", page, page + 3); + PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf mfu dump -k ") "` to store the key in the dump"); + return; + } + + if (tagtype == MFU_TT_UL_C) { + ulc_print_3deskey(key); + } else { + ulaes_print_key(key); + } +} + static int CmdHF14AMfuView(const char *Cmd) { CLIParserContext *ctx; @@ -8375,6 +8452,10 @@ static int CmdHF14AMfuView(const char *Cmd) { mfu_dump_t *p = (mfu_dump_t *)dump; mfu_print_dump(p, block_cnt, 0, dense_output); + if (verbose) { + mfu_print_dump_keys(p, block_cnt); + } + // we need to skip prefix if (ndef_detect_message(p->data, block_cnt * MFU_BLOCK_SIZE)) { PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf mfu ndefread")"`");