diff --git a/armsrc/appmain.c b/armsrc/appmain.c index b44dbc5c5..587347390 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1295,7 +1295,7 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_MFU_OTP_TEAROFF: { - MifareU_Otp_Tearoff(); + MifareU_Otp_Tearoff(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes); break; } case CMD_HF_MIFARE_STATIC_NONCE: { diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index a8f829144..0266af633 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -2423,12 +2423,14 @@ void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain) { // // Tear-off attack against MFU. // - Moebius et al -void MifareU_Otp_Tearoff() { - -// should the -// optional time be configurable via client side? +void MifareU_Otp_Tearoff(uint8_t arg0, uint32_t arg1, uint8_t *datain) { + uint8_t blockNo = arg0; + uint32_t tearOffTime = arg1; + uint8_t data_fullwrite[4] = {0x00}; + uint8_t data_testwrite[4] = {0x00}; + memcpy(data_fullwrite, datain, 4); + memcpy(data_testwrite, datain + 4, 4); // optional authentication before? -// optional data to be written? if (DBGLEVEL >= DBG_ERROR) DbpString("Preparing OTP tear-off"); @@ -2439,46 +2441,26 @@ void MifareU_Otp_Tearoff() { StartTicks(); -#define OTP_TEAR_OFF_TIME 1000 -#define OTP_BLK_NO 3 - // write cmd to send, include CRC // 1b write, 1b block, 4b data, 2 crc - uint8_t cmd[] = {MIFARE_ULC_WRITE, OTP_BLK_NO, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0}; + uint8_t cmd[] = {MIFARE_ULC_WRITE, blockNo, data_testwrite[0], data_testwrite[1], data_testwrite[2], data_testwrite[3], 0, 0}; -// User specific data to write? -// memcpy(block + 2, blockData, 4); + MifareUWriteBlock(blockNo, 0, data_fullwrite); AddCrc14A(cmd, sizeof(cmd) - 2); - if (DBGLEVEL >= DBG_ERROR) DbpString("Transmitting"); - // anticollision / select card if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) { if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card"); OnError(1); return; }; - - /* - // UL-EV1 / NTAG authentication - if (usePwd) { - uint8_t pwd[4] = {0x00}; - memcpy(pwd, datain + 4, 4); - uint8_t pack[4] = {0, 0, 0, 0}; - if (!mifare_ul_ev1_auth(pwd, pack)) { - OnError(1); - return; - } - } - */ - // send ReaderTransmit(cmd, sizeof(cmd), NULL); // Wait before cutting power. aka tear-off LED_D_ON(); - WaitUS(OTP_TEAR_OFF_TIME); + WaitUS(tearOffTime); switch_off(); reply_ng(CMD_HF_MFU_OTP_TEAROFF, PM3_SUCCESS, NULL, 0); diff --git a/armsrc/mifarecmd.h b/armsrc/mifarecmd.h index 91adba3b1..a4bf2b30b 100644 --- a/armsrc/mifarecmd.h +++ b/armsrc/mifarecmd.h @@ -59,6 +59,6 @@ void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain); void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain); // Tear-off test for MFU -void MifareU_Otp_Tearoff(); +void MifareU_Otp_Tearoff(uint8_t arg0, uint32_t arg1, uint8_t *datain); #endif diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index fcac8d137..a3e256cff 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -235,13 +235,21 @@ static int usage_hf_mfu_pwdgen(void) { } static int usage_hf_mfu_otp_tearoff(void) { - PrintAndLogEx(NORMAL, "Tear-off test against OTP block on MFU tags."); - PrintAndLogEx(NORMAL, "Usage: hf mfu otptear [h]"); + PrintAndLogEx(NORMAL, "Tear-off test against OTP block (no 3) on MFU tags - More help sooner or later\n"); + PrintAndLogEx(NORMAL, "Usage: hf mfu otptear b i l s \n"); PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : this help"); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf mfu otptear")); + PrintAndLogEx(NORMAL, " b : (optional) block to run the test - default block: 8 (not OTP for safety)"); + PrintAndLogEx(NORMAL, " i