From bd70689de23f44ec13fd4421bb6d6b75a2e6105b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 14 Dec 2019 12:45:07 +0100 Subject: [PATCH] hf mf nested: break bad loop if timeout (@uzlonewolf) --- armsrc/mifarecmd.c | 9 ++++++++- client/mifare/mifarehost.c | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index bb4fb343d..ea7e8482a 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -32,6 +32,7 @@ #include "crc16.h" #include "dbprint.h" #include "ticks.h" +#include "usb_cdc.h" // usb_poll_validate_length #ifndef HARDNESTED_AUTHENTICATION_TIMEOUT # define HARDNESTED_AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation) @@ -918,7 +919,7 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8 for (rtr = 0; rtr < 17; rtr++) { // Test if the action was cancelled - if (BUTTON_PRESS()) { + if (BUTTON_PRESS() || usb_poll_validate_length()) { isOK = -2; break; } @@ -998,6 +999,12 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8 target_nt[i] = 0; while (target_nt[i] == 0) { // continue until we have an unambiguous nonce + // Test if the action was cancelled + if (BUTTON_PRESS() || usb_poll_validate_length()) { + isOK = -2; + break; + } + // prepare next select. No need to power down the card. if (mifare_classic_halt(pcs, cuid)) { if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Halt error"); diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index e9baa7ee7..86676696d 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -24,7 +24,6 @@ #include "mfkey.h" #include "util_posix.h" // msclock - int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { uint32_t uid = 0; uint32_t nt = 0, nr = 0, ar = 0; @@ -361,7 +360,10 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, clearCommandBuffer(); SendCommandNG(CMD_HF_MIFARE_NESTED, (uint8_t *)&payload, sizeof(payload)); - if (!WaitForResponseTimeout(CMD_HF_MIFARE_NESTED, &resp, 1500)) return PM3_ETIMEOUT; + if (!WaitForResponseTimeout(CMD_HF_MIFARE_NESTED, &resp, 2000)) { + SendCommandNG(CMD_BREAK_LOOP, NULL, 0); + return PM3_ETIMEOUT; + } if (resp.status != PM3_SUCCESS) return PM3_ESOFT;