diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 72b573324..967f0d6df 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -1600,12 +1600,46 @@ static int CmdHF14aDesMAD(const char *Cmd) { AppListS AppList = {0}; DesfireFillAppList(&dctx, &PICCInfo, AppList, false, false); // no deep scan, no scan files + if (PICCInfo.freemem == 0xffffffff) + PrintAndLogEx(SUCCESS, "Applications count: " _GREEN_("%zu") " free memory " _YELLOW_("n/a"), PICCInfo.appCount); + else + PrintAndLogEx(SUCCESS, "Applications count: " _GREEN_("%zu") " free memory " _GREEN_("%d") " bytes", PICCInfo.appCount, PICCInfo.freemem); + + if ((PICCInfo.keySettings & (1 << 1)) == 0) + PrintAndLogEx(WARNING, "Directory list access with CMK : " _RED_("Enabled") ". Try to read mad with Card Master Key("); + // print zone - DesfirePrintPICCInfo(&dctx, &PICCInfo); - DesfirePrintAppList(&dctx, &PICCInfo, AppList); - - - + PrintAndLogEx(SUCCESS, "------------------------------------ " _CYAN_("MAD") " -------------------------------------"); + bool foundFFFFFF = false; + for (int i = 0; i < PICCInfo.appCount; i++) { + if (AppList[i].appNum == 0xffffff) { + foundFFFFFF = true; + break; + } + } + + if (foundFFFFFF) { + res = DesfireSelectAIDHexNoFieldOn(&dctx, 0xffffff); + if (res == PM3_SUCCESS) { + + + } else { + PrintAndLogEx(WARNING, _RED_("Can't select") " issuer information app (0xffffff)."); + } + } else { + PrintAndLogEx(WARNING, "Issuer information " _RED_("not found") " on the card."); + } + + size_t madappcount = 0; + for (int i = 0; i < PICCInfo.appCount; i++) { + if ((AppList[i].appNum & 0xf00000) == 0xf00000) { + DesfirePrintMADAID(AppList[i].appNum, verbose); + madappcount++; + } + } + + if (madappcount == 0) + PrintAndLogEx(SUCCESS, "There is no MAD applications on the card"); DropField(); return PM3_SUCCESS; diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index dd9928983..5a9456edc 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -837,6 +837,23 @@ int DesfireSelectAIDHexNoFieldOn(DesfireContext *ctx, uint32_t aid) { return res; } +void DesfirePrintMADAID(uint32_t appid, bool verbose) { + uint8_t aid[3] = {0}; + DesfireAIDUintToByte(appid, aid); + if ((aid[2] >> 4) != 0xF) + return; + + uint16_t short_aid = ((aid[2] & 0xF) << 12) | (aid[1] << 4) | (aid[0] >> 4); + + PrintAndLogEx(SUCCESS, "MIFARE Classic ID (MAD) " _YELLOW_("%04X") " AID %06x MAD AID Cluster 0x%02X " _YELLOW_("%s"), + short_aid, + appid, + short_aid >> 8, + nxp_cluster_to_text(short_aid >> 8)); + if (verbose) + MADDFDecodeAndPrint(short_aid); +} + void DesfirePrintAIDFunctions(uint32_t appid) { uint8_t aid[3] = {0}; DesfireAIDUintToByte(appid, aid); diff --git a/client/src/mifare/desfirecore.h b/client/src/mifare/desfirecore.h index c912f6239..92a3df99c 100644 --- a/client/src/mifare/desfirecore.h +++ b/client/src/mifare/desfirecore.h @@ -165,6 +165,7 @@ int DesfireSelectAID(DesfireContext *ctx, uint8_t *aid1, uint8_t *aid2); int DesfireSelectAIDHex(DesfireContext *ctx, uint32_t aid1, bool select_two, uint32_t aid2); int DesfireSelectAIDHexNoFieldOn(DesfireContext *ctx, uint32_t aid); void DesfirePrintAIDFunctions(uint32_t appid); +void DesfirePrintMADAID(uint32_t appid, bool verbose); int DesfireGetCardUID(DesfireContext *ctx);