From c57a9d2d7048367d89393280510f0a678df4fc87 Mon Sep 17 00:00:00 2001 From: merlokk Date: Wed, 11 Oct 2017 18:20:30 +0300 Subject: [PATCH] hf mf nested. added key check after we have found a key. --- armsrc/mifarecmd.c | 2 -- client/cmdhfmf.c | 52 +++------------------------------------------- 2 files changed, 3 insertions(+), 51 deletions(-) diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 45e53dac..58aadda6 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -978,11 +978,9 @@ void MifareChkKeys(uint16_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) set_tracing(true); if (multisectorCheck) { - Dbprintf("multisector"); TKeyIndex keyIndex = {0}; uint8_t sectorCnt = blockNo; int res = MifareMultisectorChk(datain, keyCount, sectorCnt, keyType, OLD_MF_DBGLEVEL, &keyIndex); - Dbprintf("[0][0]=%d [0][13]=%d [0][15]=%d [1][15]=%d ", keyIndex[0][0], keyIndex[0][13], keyIndex[0][15], keyIndex[1][15]); LED_B_ON(); if (res >= 0) { diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 899207c4..eb45316e 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -742,6 +742,9 @@ int CmdHF14AMfNested(const char *Cmd) PrintAndLog("Found valid key:%012" PRIx64, key64); e_sector[sectorNo].foundKey[trgKeyType] = 1; e_sector[sectorNo].Key[trgKeyType] = key64; + + // try to check this key as a key to the other sectors + mfCheckKeysSec(SectorsCnt, 2, true, 1, keyBlock, e_sector); } } } @@ -751,55 +754,6 @@ int CmdHF14AMfNested(const char *Cmd) PrintAndLog("\n\n-----------------------------------------------\nNested statistic:\nIterations count: %d", iterations); PrintAndLog("Time in nested: %1.3f (%1.3f sec per key)", ((float)(msclock() - msclock1))/1000.0, ((float)(msclock() - msclock1))/iterations/1000.0); - // check if we have unrecognized keys - bool notFoundKeys = false; - for (i = 0; i < SectorsCnt; i++) { - for (j = 0; j < 2; j++) { - if (!e_sector[i].foundKey[j]) { - notFoundKeys = true; - break; - } - } - if (notFoundKeys) break; - } - - if (notFoundKeys) { - PrintAndLog("-----------------------------------------------\n"); - PrintAndLog("We have unrecognized keys. Trying to check if we have this keys on key buffer..."); - - // fill keyBlock with known keys - int cnt = 0; - for (i = 0; i < SectorsCnt; i++) { - for (j = 0; j < 2; j++) { - if (e_sector[i].foundKey[j]) { - // try to insert key to keyBlock - if (cnt < NESTED_KEY_COUNT) { - - // search for dublicates - bool dubl = false; - for (int v = 0; v < NESTED_KEY_COUNT; v++) { - if (e_sector[i].Key[j] == bytes_to_num((uint8_t*)(keyBlock + v * 6), 6)) { - dubl = true; - break; - } - } - - // insert - if (!dubl) { - num_to_bytes(e_sector[i].Key[j], 6, (uint8_t*)(keyBlock + cnt * 6)); - cnt++; - } - } - } - } - } - - // try to auth with known keys to not recognized sectors keys - PrintAndLog("Testing keys. Sector count=%d known keys count:%d", SectorsCnt, cnt); - mfCheckKeysSec(SectorsCnt, 2, true, cnt, keyBlock, e_sector); - - } // if (notFoundKeys) - // print result PrintAndLog("|---|----------------|---|----------------|---|"); PrintAndLog("|sec|key A |res|key B |res|");