diff --git a/CHANGELOG.md b/CHANGELOG.md index 4781df148..6f1511adf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac ## [unreleased][unreleased] - Fixed `lf em 4x50 rdbl/info/dump`, `lf search` - RM was sent into the tag data instead of the second listen window on strong, AC-coupled signals, so every command failed; reads now retry within 1 s (@abou28) - Added `lf em 4x50 config` - runtime EM4x50 reader timings, and `lf_em4x50_tune.lua` to sweep them; extended debug level captures the raw exchange for `data samples` (@abou28) +- Fixed `hf thinfilm sim` - a second simulation in the same client no longer ends at once with `Done!` (@matrix) - Added `hf mf supercard -u` - UID change on super card generation 2 (@mishamyte) - Changed `hf mf supercard` - a refused `-r`/`-u` now exits non-zero instead of reporting success (@mishamyte) - Fixed `wiegand` formats - HPP32, H10320 and S12906b encode as laid out, HGen37 decode checks the right parity bit, the limits of nine formats match their fields, `wiegand list -h` shows its own usage (@matrix) @@ -18,6 +19,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Fixed `mfulc_des_brute` build on macOS without `openssl@3.6` - OpenSSL is found with `brew --prefix openssl` as in `mfd_aes_brute` (@matrix) - Fixed CI - ProxSpace installs its packages again, WSL builds in its own file system, Ubuntu and CodeQL skip the slow Azure apt mirror (@matrix) - Fixed `recovery.bin` on the AT91 platforms - the bootrom is padded to 0x102000 again, so the OS image is at its load address (@matrix) +- Added `hf mfu info` weak-PRNG backstop - detects counterfeit ULC via RndB collision (@Ryan4n6) - Updated `/Getting_Started_With_PM5.md` (@innocentbystanderproxmark) - Fixed `hf seos pacs`/`write` - 2K3DES GET/UPDATE DATA no longer fails silently with exit 236; print APDU exchange errors, check DES-CMAC, decode SELECT `85` at its real length, and use short-form `85` when the cryptogram is under 128 bytes - Fixed client build with `-march=x86-64-v3` (CentOS/RHEL 10 default) - false `-Wstringop-overflow` in the EMV AID list table (@r3wretrhy) diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 9255a3a21..35c885384 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -2028,6 +2028,69 @@ int mfu_get_version_uid(uint8_t *version, uint8_t *uid) { return PM3_SUCCESS; } +// Weak-PRNG backstop: RndB collision => counterfeit LFSR +#define MFULC_PRNG_SAMPLES 40 +#define MFULC_PRNG_CLEAR 39 + +static int mfulc_prng_test(uint32_t samples) { + if (samples < 2) { + samples = 2; + } + if (samples > 64) { + samples = 64; + } + + uint8_t rndb[64][8]; + uint32_t got = 0; + + for (uint32_t i = 0; i < samples; i++) { + iso14a_card_select_t card; + if (ul_select(&card) == false) { + continue; + } + uint8_t nonce[11] = {0x00}; + int rl = ulc_requestAuthentication(nonce, sizeof(nonce)); + DropField(); + // response is AF || ek(RndB)[8] || CRC[2]; compare the 8-byte ek(RndB) + if (rl < 9 || nonce[0] != 0xAF) { + continue; + } + memcpy(rndb[got], &nonce[1], 8); + got++; + } + + if (got < 2) { + PrintAndLogEx(INFO, "PRNG......... could not collect nonces (got %u)", got); + return PM3_ESOFT; + } + + uint32_t first_dup = 0; + uint32_t dups = 0; + for (uint32_t i = 0; i < got; i++) { + for (uint32_t j = 0; j < i; j++) { + if (memcmp(rndb[i], rndb[j], 8) == 0) { + if (first_dup == 0) { + first_dup = i + 1; // 1-based draw index + } + dups++; + break; + } + } + } + + if (dups > 0) { + PrintAndLogEx(SUCCESS, "PRNG......... " _RED_("Weak") " (RndB collision at %u)", first_dup); + return PM3_SUCCESS; + } + + if (got >= MFULC_PRNG_CLEAR) { + PrintAndLogEx(SUCCESS, "PRNG......... " _GREEN_("Genuine")); + } else { + PrintAndLogEx(INFO, "PRNG......... inconclusive (%u/%u nonces)", got, (uint32_t)MFULC_PRNG_CLEAR); + } + return PM3_SUCCESS; +} + static int mfulc_fingerprint(void) { iso14a_card_select_t card; PacketResponseNG resp; @@ -2139,6 +2202,8 @@ static int mfulc_fingerprint(void) { } } } + // weak-PRNG backstop + mfulc_prng_test(MFULC_PRNG_SAMPLES); PrintAndLogEx(INFO, "likely MF0ICU2"); DropField(); return PM3_SUCCESS; diff --git a/client/src/cmdhfthinfilm.c b/client/src/cmdhfthinfilm.c index 54e4699a2..141b1d67e 100644 --- a/client/src/cmdhfthinfilm.c +++ b/client/src/cmdhfthinfilm.c @@ -179,9 +179,17 @@ int CmdHfThinFilmSim(const char *Cmd) { data[data_len++] = b1; } + // end a simulation still running from an earlier call and drop its reply + PacketResponseNG resp; + clearCommandBuffer(); + SendCommandNG(CMD_PING, NULL, 0); + if (WaitForResponseTimeout(CMD_PING, &resp, 3000) == false) { + PrintAndLogEx(WARNING, "command execution time out"); + return PM3_ETIMEOUT; + } + clearCommandBuffer(); SendCommandNG(CMD_HF_THINFILM_SIMULATE, (uint8_t *)&data, data_len); - PacketResponseNG resp; PrintAndLogEx(SUCCESS, "press " _GREEN_("pm3 button") " to abort simulation"); int ret;