add static encrypted nonce detection

This commit is contained in:
merlokk committed 2023-12-11 21:24:26 +02:00
1 parent d352f9d44e
commit 91892bc1bf
9 files changed
+125 -10

No files matched your search

+6 -2
View File
@@ -8875,7 +8875,7 @@ static int CmdHF14AMfInfo(const char *Cmd) {
PrintAndLogEx(SUCCESS, "ATQA: " _GREEN_("%02X %02X"), card.atqa[1], card.atqa[0]);
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%" PRIu64 "]"), card.sak, resp.oldarg[0]);
if (setDeviceDebugLevel(DBG_NONE, false) != PM3_SUCCESS)
if (setDeviceDebugLevel(verbose ? DBG_INFO : DBG_NONE, false) != PM3_SUCCESS)
return PM3_EFAILED;
PrintAndLogEx(INFO, "--- " _CYAN_("Backdoors Information") "---------------------");
@@ -8951,7 +8951,11 @@ static int CmdHF14AMfInfo(const char *Cmd) {
// detect static encrypted nonce
if (keyType != 0xff) {
res = detect_classic_static_encrypted_nonce(0, keyType, key); // TODO: add block number to the config
if (res == NONCE_STATIC)
PrintAndLogEx(SUCCESS, "Static nested nonce: " _YELLOW_("yes"));
if (res == NONCE_STATIC_ENC)
PrintAndLogEx(SUCCESS, "Static encrypted nonce: " _YELLOW_("yes"));
}
if (do_nack_test)
+27
View File
@@ -1349,6 +1349,33 @@ int detect_classic_static_nonce(void) {
return NONCE_FAIL;
}
/* Detect Mifare Classic static encrypted nonce
detects special magic cards that has a static / fixed nonce
returns:
0 = nonce ok
1 = has static/fixed nonce
2 = cmd failed
3 = has encrypted nonce
*/
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};
cdata[0] = block_no;
cdata[1] = key_type;
memcpy(&cdata[2], key, MIFARE_KEY_SIZE);
SendCommandNG(CMD_HF_MIFARE_STATIC_ENCRYPTED_NONCE, cdata, sizeof(cdata));
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_HF_MIFARE_STATIC_ENCRYPTED_NONCE, &resp, 1000)) {
if (resp.status == PM3_ESOFT)
return NONCE_FAIL;
return resp.data.asBytes[0];
}
return NONCE_FAIL;
}
/* try to see if card responses to "Chinese magic backdoor" commands. */
int detect_mf_magic(bool is_mfc) {
+1
View File
@@ -102,6 +102,7 @@ int detect_classic_prng(void);
int detect_classic_nackbug(bool verbose);
int detect_mf_magic(bool is_mfc);
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);
int read_mfc_ev1_signature(uint8_t *signature);