From f840dc810b3ce25d33503520d4bf34e9a7b999e7 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 31 Dec 2023 09:35:42 +0100 Subject: [PATCH] made keytype instead of fixed keyB. would help in situations keyB is readable... --- armsrc/appmain.c | 3 ++- armsrc/mifarecmd.c | 4 ++-- armsrc/mifarecmd.h | 2 +- client/src/cmdhfmf.c | 6 +++--- client/src/mifare/mifarehost.c | 8 ++++---- client/src/mifare/mifarehost.h | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 263238ff9..be7cb018d 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1736,10 +1736,11 @@ static void PacketReceived(PacketCommandNG *packet) { struct p { uint8_t is_mfc; + uint8_t keytype; uint8_t key[6]; } PACKED; struct p *payload = (struct p *) packet->data.asBytes; - MifareCIdent(payload->is_mfc, payload->key); + MifareCIdent(payload->is_mfc, payload->keytype, payload->key); break; } // Gen 3 magic cards diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 4174b69ed..9c15e2458 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -2420,7 +2420,7 @@ static void mf_reset_card(void) { iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); } -void MifareCIdent(bool is_mfc, uint8_t *key) { +void MifareCIdent(bool is_mfc, uint8_t keytype, uint8_t *key) { // variables uint8_t rec[1] = {0x00}; uint8_t recpar[1] = {0x00}; @@ -2570,7 +2570,7 @@ void MifareCIdent(bool is_mfc, uint8_t *key) { pcs = &mpcs; uint64_t tmpkey = bytes_to_num(key, 6); - if (mifare_classic_authex(pcs, cuid, 0, MF_KEY_B, tmpkey, AUTH_FIRST, NULL, NULL) == 0) { + if (mifare_classic_authex(pcs, cuid, 0, keytype, tmpkey, AUTH_FIRST, NULL, NULL) == 0) { uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE] = {0x00}; uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE] = {0x00}; if ((mifare_sendcmd_short(pcs, 1, ISO14443A_CMD_WRITEBLOCK, 0, receivedAnswer, receivedAnswerPar, NULL) == 1) && (receivedAnswer[0] == 0x0A)) { diff --git a/armsrc/mifarecmd.h b/armsrc/mifarecmd.h index 5a360e221..aefc4e760 100644 --- a/armsrc/mifarecmd.h +++ b/armsrc/mifarecmd.h @@ -47,7 +47,7 @@ int MifareECardLoadExt(uint8_t sectorcnt, uint8_t keytype); // MFC GEN1a /1b void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain); // Work with "magic Chinese" card void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain); -void MifareCIdent(bool is_mfc, uint8_t *key); // is "magic chinese" card? +void MifareCIdent(bool is_mfc, uint8_t keytype, uint8_t *key); // is "magic chinese" card? void MifareHasStaticNonce(void); // Has the tag a static nonce? void MifareHasStaticEncryptedNonce(uint8_t block_no, uint8_t key_type, uint8_t *key); // Has the tag a static encrypted nonce? diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index 742db52b0..e0dbac7f5 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -8923,7 +8923,7 @@ static int CmdHF14AMfInfo(const char *Cmd) { int sectorsCnt = 1; uint8_t *keyBlock = NULL; uint32_t keycnt = 0; - res = mfLoadKeys(&keyBlock, &keycnt, NULL, 0, NULL, 0); + res = mfLoadKeys(&keyBlock, &keycnt, key, MIFARE_KEY_SIZE, NULL, 0); if (res != PM3_SUCCESS) { return res; } @@ -8973,8 +8973,8 @@ static int CmdHF14AMfInfo(const char *Cmd) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "--- " _CYAN_("Magic Tag Information")); - if (detect_mf_magic(true, e_sector[0].Key[MF_KEY_B]) == 0) { - if (detect_mf_magic(true, e_sector[0].Key[MF_KEY_A]) == 0) { + if (detect_mf_magic(true, MF_KEY_B, e_sector[0].Key[MF_KEY_B]) == 0) { + if (detect_mf_magic(true, MF_KEY_A, e_sector[0].Key[MF_KEY_A]) == 0) { PrintAndLogEx(INFO, ""); } } diff --git a/client/src/mifare/mifarehost.c b/client/src/mifare/mifarehost.c index f487f5900..56313aa55 100644 --- a/client/src/mifare/mifarehost.c +++ b/client/src/mifare/mifarehost.c @@ -1373,7 +1373,7 @@ returns: */ int detect_classic_static_encrypted_nonce(uint8_t block_no, uint8_t key_type, uint8_t *key) { clearCommandBuffer(); - uint8_t cdata[1 + 1 + MIFARE_KEY_SIZE] = {0}; + uint8_t cdata[1 + 1 + MIFARE_KEY_SIZE] = { 0 }; cdata[0] = block_no; cdata[1] = key_type; memcpy(&cdata[2], key, MIFARE_KEY_SIZE); @@ -1390,13 +1390,13 @@ int detect_classic_static_encrypted_nonce(uint8_t block_no, uint8_t key_type, ui } /* try to see if card responses to "Chinese magic backdoor" commands. */ -int detect_mf_magic(bool is_mfc, uint64_t key) { +int detect_mf_magic(bool is_mfc, uint8_t key_type, uint64_t key) { uint8_t isMagic = 0; PacketResponseNG resp; clearCommandBuffer(); - uint8_t payload[1 + MIFARE_KEY_SIZE] = { is_mfc }; - num_to_bytes(key, MIFARE_KEY_SIZE, payload + 1); + uint8_t payload[1 + 1 + MIFARE_KEY_SIZE] = { is_mfc, key_type }; + num_to_bytes(key, MIFARE_KEY_SIZE, payload + 2); SendCommandNG(CMD_HF_MIFARE_CIDENT, payload, sizeof(payload)); if (WaitForResponseTimeout(CMD_HF_MIFARE_CIDENT, &resp, 1500)) { diff --git a/client/src/mifare/mifarehost.h b/client/src/mifare/mifarehost.h index 972353b08..f71a9436d 100644 --- a/client/src/mifare/mifarehost.h +++ b/client/src/mifare/mifarehost.h @@ -101,7 +101,7 @@ int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int detect_classic_prng(void); int detect_classic_nackbug(bool verbose); -int detect_mf_magic(bool is_mfc, uint64_t key); +int detect_mf_magic(bool is_mfc, uint8_t key_type, uint64_t key); int detect_classic_static_nonce(void); int detect_classic_static_encrypted_nonce(uint8_t block_no, uint8_t key_type, uint8_t *key); bool detect_mfc_ev1_signature(void);