From 72057f9b81796f35574f8080235f9c3fb77a4cd8 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 24 Jul 2023 13:34:24 +0200 Subject: [PATCH] text --- client/src/cmdhfmf.c | 21 ++++++++++++++++----- client/src/mifare/mifare4.c | 14 +++++++++++--- client/src/mifare/mifare4.h | 1 + 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index 8c03888f0..6f28d7d7c 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -153,26 +153,37 @@ static int initSectorTable(sector_t **src, size_t items) { static void decode_print_st(uint16_t blockno, uint8_t *data) { if (mfIsSectorTrailer(blockno)) { PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "----------------------- " _CYAN_("Sector trailer decoder") " -----------------------"); + PrintAndLogEx(INFO, "-------------------------- " _CYAN_("Sector trailer decoder") " --------------------------"); PrintAndLogEx(INFO, "key A........ " _GREEN_("%s"), sprint_hex_inrow(data, 6)); PrintAndLogEx(INFO, "acr.......... " _GREEN_("%s"), sprint_hex_inrow(data + 6, 3)); PrintAndLogEx(INFO, "user / gpb... " _GREEN_("%02x"), data[9]); PrintAndLogEx(INFO, "key B........ " _GREEN_("%s"), sprint_hex_inrow(data + 10, 6)); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, " # | Access rights"); - PrintAndLogEx(INFO, "----+-----------------------------------------------------------------"); + PrintAndLogEx(INFO, ""); + PrintAndLogEx(INFO, " # | access rights"); + PrintAndLogEx(INFO, "----+-----------------------------------------------------------------------"); if (mfValidateAccessConditions(&data[6]) == false) { PrintAndLogEx(WARNING, _RED_("Invalid Access Conditions")); } + int bln = mfFirstBlockOfSector(mfSectorNum(blockno)); int blinc = (mfNumBlocksPerSector(mfSectorNum(blockno)) > 4) ? 5 : 1; for (int i = 0; i < 4; i++) { PrintAndLogEx(INFO, "%3d%c| " _YELLOW_("%s"), bln, ((blinc > 1) && (i < 3) ? '+' : ' '), mfGetAccessConditionsDesc(i, &data[6])); bln += blinc; + + if (i == 3) { + uint8_t cond = mf_get_accesscondition(i, &data[6]); + if (cond == 0 || cond == 1 || cond == 2) { + PrintAndLogEx(INFO, ""); + PrintAndLogEx(INFO, "OBS! Key B is readable, it SHALL NOT be able to authenticate on original MFC"); + } + } } - PrintAndLogEx(INFO, "----------------------------------------------------------------------"); + + + PrintAndLogEx(INFO, "----------------------------------------------------------------------------"); PrintAndLogEx(NORMAL, ""); } } diff --git a/client/src/mifare/mifare4.c b/client/src/mifare/mifare4.c index 7a3ec9f77..420c93a9e 100644 --- a/client/src/mifare/mifare4.c +++ b/client/src/mifare/mifare4.c @@ -83,6 +83,7 @@ bool mfValidateAccessConditions(const uint8_t *data) { return ((nd1 == (d1 ^ 0xF)) && (nd2 == (d2 ^ 0xF)) && (nd3 == (d3 ^ 0xF))); } + bool mfReadOnlyAccessConditions(uint8_t blockn, const uint8_t *data) { uint8_t d1 = NIBBLE_HIGH(data[1]) >> blockn; @@ -98,7 +99,6 @@ bool mfReadOnlyAccessConditions(uint8_t blockn, const uint8_t *data) { return false; } - const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data) { uint8_t d1 = NIBBLE_HIGH(data[1]) >> blockn; uint8_t d2 = NIBBLE_LOW(data[2]) >> blockn; @@ -118,9 +118,17 @@ const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data) { } }; - static char StaticNone[] = "none"; - return StaticNone; + static char none[] = "none"; + return none; } + +uint8_t mf_get_accesscondition(uint8_t blockn, const uint8_t *data) { + uint8_t d1 = NIBBLE_HIGH(data[1]) >> blockn; + uint8_t d2 = NIBBLE_LOW(data[2]) >> blockn; + uint8_t d3 = NIBBLE_HIGH(data[2]) >> blockn; + return (d1 & 0x01) << 2 | (d2 & 0x01) << 1 | (d3 & 0x01); +} + /* static int CalculateEncIVCommand(mf4Session_t *mf4session, uint8_t *iv, bool verbose) { memcpy(&iv[0], &mf4session->TI, 4); diff --git a/client/src/mifare/mifare4.h b/client/src/mifare/mifare4.h index fee12ef6e..6687930e6 100644 --- a/client/src/mifare/mifare4.h +++ b/client/src/mifare/mifare4.h @@ -73,6 +73,7 @@ int MFPGetVersion(bool activateField, bool leaveSignalON, uint8_t *dataout, int bool mfValidateAccessConditions(const uint8_t *data); bool mfReadOnlyAccessConditions(uint8_t blockn, const uint8_t *data); const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data); +uint8_t mf_get_accesscondition(uint8_t blockn, const uint8_t *data); uint8_t mfNumBlocksPerSector(uint8_t sectorNo); uint8_t mfFirstBlockOfSector(uint8_t sectorNo);