]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
chg 'hf mf chk':
authorpwpiwi <pwpiwi@users.noreply.github.com>
Sat, 10 Aug 2019 21:30:47 +0000 (23:30 +0200)
committerGitHub <noreply@github.com>
Sat, 10 Aug 2019 21:30:47 +0000 (23:30 +0200)
* don't repeatedly clear trace while running (PR 243 by @mceloff from https://github.com/RfidResearchGroup/proxmark3)
* standard LED handling
* better check for key file syntax
* get rid of "res" column when printing the result. Show unknown keys more prominent as "     ?     "

armsrc/mifarecmd.c
client/cmdhfmf.c

index a3807cf7150adefc05f534aedf19302f52ae74bc..8fe502ca3135c6d184cabcac2677fb5b41202e76 100644 (file)
@@ -980,16 +980,17 @@ void MifareChkKeys(uint16_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
        uint8_t set14aTimeout = (arg1 >> 8) & 0xff;\r
        uint8_t keyCount = arg2;\r
 \r
+       LED_A_ON();\r
+\r
        // clear debug level\r
        int OLD_MF_DBGLEVEL = MF_DBGLEVEL;\r
        MF_DBGLEVEL = MF_DBG_NONE;\r
 \r
-       LED_A_ON();\r
-       LED_B_OFF();\r
-       LED_C_OFF();\r
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
 \r
-       if (clearTrace) clear_trace();\r
+       if (clearTrace) {\r
+               clear_trace();\r
+       }\r
        set_tracing(true);\r
 \r
        if (set14aTimeout){\r
@@ -1001,30 +1002,28 @@ void MifareChkKeys(uint16_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
                uint8_t sectorCnt = blockNo;\r
                int res = MifareMultisectorChk(datain, keyCount, sectorCnt, keyType, OLD_MF_DBGLEVEL, &keyIndex);\r
 \r
-               LED_B_ON();\r
                if (res >= 0) {\r
                        cmd_send(CMD_ACK, 1, 0, 0, keyIndex, 80);\r
                } else {\r
                        cmd_send(CMD_ACK, 0, 0, 0, NULL, 0);\r
                }\r
-               LED_B_OFF();\r
        } else {        \r
                int res = MifareChkBlockKeys(datain, keyCount, blockNo, keyType, OLD_MF_DBGLEVEL);\r
                \r
-               LED_B_ON();\r
                if (res > 0) {\r
                        cmd_send(CMD_ACK, 1, 0, 0, datain + (res - 1) * 6, 6);\r
                } else {\r
                        cmd_send(CMD_ACK, 0, 0, 0, NULL, 0);\r
                }\r
-               LED_B_OFF();\r
        }\r
 \r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
-       LEDsoff();\r
+       LED_D_OFF();\r
 \r
        // restore debug level\r
        MF_DBGLEVEL = OLD_MF_DBGLEVEL;\r
+       \r
+       LED_A_OFF();\r
 }\r
 \r
 //-----------------------------------------------------------------------------\r
index a4461e37b9bf76f40b94cfbef9a8899ecfe708aa..c38e276ed51515d75ed8ef342feb1df3a26b34cb 100644 (file)
@@ -1099,16 +1099,17 @@ int CmdHF14AMfChk(const char *Cmd)
 \r
        if (param_getchar(Cmd, 0)=='*') {\r
                SectorsCnt = ParamCardSizeSectors(param_getchar(Cmd + 1, 0));\r
-       }\r
-       else {   \r
+       } else {   \r
                blockNo = param_get8(Cmd, 0);\r
                // Singe Key check, so Set Sector count to cover sectors (1 to sector that contains the block)\r
                // 1 and 2 Cards : Sector = blockNo/4 + 1\r
                // Sectors  0 - 31  :  4 blocks per sector : Blocks 0 - 127\r
                // Sectors 32 - 39  : 16 blocks per sector : Blocks 128 - 255 (4K)\r
-               if (blockNo < 128) SectorsCnt =       (blockNo     / 4) + 1;\r
-               else                                     SectorsCnt = 32 + ((blockNo-128)/16) + 1;\r
-\r
+               if (blockNo < 128) {\r
+                       SectorsCnt = (blockNo / 4) + 1;\r
+               } else {\r
+                       SectorsCnt = 32 + ((blockNo-128)/16) + 1;\r
+               }\r
                singleBlock  = true;              // Set flag for single key check\r
        }\r
 \r
@@ -1143,7 +1144,7 @@ int CmdHF14AMfChk(const char *Cmd)
        param3InUse = transferToEml | createDumpFile | (btimeout14a != MF_CHKKEYS_DEFTIMEOUT);\r
 \r
        PrintAndLog("--chk keys. sectors:%2d, block no:%3d, key type:%c, eml:%c, dmp=%c checktimeout=%d us",\r
-                       SectorsCnt, blockNo, keyType?'B':'A', transferToEml?'y':'n', createDumpFile?'y':'n', ((int)btimeout14a * 10000) / 106);\r
+                       SectorsCnt, blockNo, keyType==0?'A':keyType==1?'B':'?', transferToEml?'y':'n', createDumpFile?'y':'n', ((int)btimeout14a * 10000) / 106);\r
 \r
        for (i = param3InUse; param_getchar(Cmd, 2 + i); i++) {\r
                if (!param_gethex(Cmd, 2 + i, keyBlock + 6 * keycnt, 12)) {\r
@@ -1168,8 +1169,8 @@ int CmdHF14AMfChk(const char *Cmd)
                                return 2;\r
                        }\r
 \r
-                       if ( (f = fopen( filename , "r")) ) {\r
-                               while( fgets(buf, sizeof(buf), f) ){\r
+                       if ((f = fopen( filename , "r"))) {\r
+                               while (fgets(buf, sizeof(buf), f)) {\r
                                        if (strlen(buf) < 12 || buf[11] == '\n')\r
                                                continue;\r
 \r
@@ -1177,14 +1178,20 @@ int CmdHF14AMfChk(const char *Cmd)
 \r
                                        if( buf[0]=='#' ) continue; //The line start with # is comment, skip\r
 \r
-                                       if (!isxdigit((unsigned char)buf[0])){\r
-                                               PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf);\r
+                                       bool content_error = false;\r
+                                       for (int i = 0; i < 12; i++) {\r
+                                               if (!isxdigit((unsigned char)buf[i])) {\r
+                                                       content_error = true;\r
+                                               }\r
+                                       }\r
+                                       if (content_error) {\r
+                                               PrintAndLog("File content error. '%s' must include 12 HEX symbols", buf);\r
                                                continue;\r
                                        }\r
 \r
                                        buf[12] = 0;\r
 \r
-                                       if ( stKeyBlock - keycnt < 2) {\r
+                                       if (stKeyBlock - keycnt < 2) {\r
                                                p = realloc(keyBlock, 6*(stKeyBlock+=10));\r
                                                if (!p) {\r
                                                        PrintAndLog("Cannot allocate memory for defKeys");\r
@@ -1232,8 +1239,9 @@ int CmdHF14AMfChk(const char *Cmd)
        }\r
        printf("\n");\r
 \r
-       bool            foundAKey = false;\r
-       uint32_t        max_keys  = keycnt > USB_CMD_DATA_SIZE / 6 ? USB_CMD_DATA_SIZE / 6 : keycnt;\r
+       bool foundAKey = false;\r
+       bool clearTraceLog = true;\r
+       uint32_t max_keys  = keycnt > USB_CMD_DATA_SIZE / 6 ? USB_CMD_DATA_SIZE / 6 : keycnt;\r
 \r
        // !SingleKey, so all key check (if SectorsCnt > 0)\r
        if (!singleBlock) { \r
@@ -1242,7 +1250,8 @@ int CmdHF14AMfChk(const char *Cmd)
                for (uint32_t c = 0; c < keycnt; c += max_keys) {\r
 \r
                        uint32_t size = keycnt-c > max_keys ? max_keys : keycnt-c;\r
-                       res = mfCheckKeysSec(SectorsCnt, keyType, btimeout14a, true, size, &keyBlock[6 * c], e_sector); // timeout is (ms * 106)/10 or us*0.0106\r
+                       res = mfCheckKeysSec(SectorsCnt, keyType, btimeout14a, clearTraceLog, size, &keyBlock[6 * c], e_sector); // timeout is (ms * 106)/10 or us*0.0106\r
+                       clearTraceLog = false;\r
 \r
                        if (res != 1) {\r
                                if (!res) {\r
@@ -1259,10 +1268,11 @@ int CmdHF14AMfChk(const char *Cmd)
        } else { \r
                int keyAB = keyType;\r
                do {\r
-                       for (uint32_t c = 0; c < keycnt; c+=max_keys) {\r
+                       for (uint32_t c = 0; c < keycnt; c += max_keys) {\r
 \r
                                uint32_t size = keycnt-c > max_keys ? max_keys : keycnt-c;\r
                                res = mfCheckKeys(blockNo, keyAB & 0x01, true, size, &keyBlock[6 * c], &key64);\r
+                               clearTraceLog = false;\r
 \r
                                if (res != 1) {\r
                                        if (!res) {      \r
@@ -1285,20 +1295,25 @@ int CmdHF14AMfChk(const char *Cmd)
 \r
        // print result\r
        if (foundAKey) {\r
-               if (SectorsCnt) {\r
-                       PrintAndLog("");\r
-                       PrintAndLog("|---|----------------|---|----------------|---|");\r
-                       PrintAndLog("|sec|key A           |res|key B           |res|");\r
-                       PrintAndLog("|---|----------------|---|----------------|---|");\r
-                       for (i = 0; i < SectorsCnt; i++) {\r
-                       // If a block key check, only print a line if a key was found.\r
-                if (!singleBlock || (e_sector[i].foundKey[0]) || (e_sector[i].foundKey[1]) ){ \r
-                    PrintAndLog("|%03d|  %012" PRIx64 "  | %d |  %012" PRIx64 "  | %d |", i,\r
-                        e_sector[i].Key[0], e_sector[i].foundKey[0], e_sector[i].Key[1], e_sector[i].foundKey[1]);\r
-                }\r
+               PrintAndLog("");\r
+               PrintAndLog("|---|----------------|----------------|");\r
+               PrintAndLog("|sec|key A           |key B           |");\r
+               PrintAndLog("|---|----------------|----------------|");\r
+               for (i = 0; i < SectorsCnt; i++) {\r
+                       // If a block key check, only print a line if a key was found.\r
+                       if (!singleBlock || e_sector[i].foundKey[0] || e_sector[i].foundKey[1]) {\r
+                               char keyAString[13] = "      ?     ";\r
+                               char keyBString[13] = "      ?     ";\r
+                               if (e_sector[i].foundKey[0]) {\r
+                                       sprintf(keyAString, "%012" PRIx64, e_sector[i].Key[0]);\r
+                               }\r
+                               if (e_sector[i].foundKey[1]) {\r
+                                       sprintf(keyBString, "%012" PRIx64, e_sector[i].Key[1]);\r
+                               }\r
+                               PrintAndLog("|%03d|  %s  |  %s  |", i, keyAString, keyBString);\r
                        }\r
-                       PrintAndLog("|---|----------------|---|----------------|---|");\r
                }\r
+               PrintAndLog("|---|----------------|----------------|");\r
        } else {\r
                PrintAndLog("");\r
                PrintAndLog("No valid keys found.");\r
@@ -1347,6 +1362,7 @@ int CmdHF14AMfChk(const char *Cmd)
        return 0;\r
 }\r
 \r
+\r
 void readerAttack(nonces_t ar_resp[], bool setEmulatorMem, bool doStandardAttack) {\r
        #define ATTACK_KEY_COUNT 7 // keep same as define in iso14443a.c -> Mifare1ksim()\r
                                                           // cannot be more than 7 or it will overrun c.d.asBytes(512)\r
Impressum, Datenschutz