fix hf mf mad loading mad v2 sector

This commit is contained in:
iceman1001 2023-06-23 17:14:58 +02:00
parent 4b12d67632
commit 8700b1e754

View file

@ -3407,8 +3407,9 @@ static int CmdHF14AMfChk(const char *Cmd) {
CLIParamStrToBuf(arg_get_str(ctx, 12), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); CLIParamStrToBuf(arg_get_str(ctx, 12), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
CLIParserFree(ctx); CLIParserFree(ctx);
bool singleSector = blockNo > -1;
if (! singleSector) { bool singleSector = (blockNo > -1);
if (singleSector == false) {
// start from first trailer block // start from first trailer block
blockNo = 3; blockNo = 3;
} }
@ -3431,9 +3432,11 @@ static int CmdHF14AMfChk(const char *Cmd) {
} }
if (singleSector) { if (singleSector) {
size_t min_sectors_cnt = 0;
// find a MIFARE type that can accommodate the provided block number // find a MIFARE type that can accommodate the provided block number
size_t min_sectors_cnt = 0;
uint8_t s = mfSectorNum(blockNo); uint8_t s = mfSectorNum(blockNo);
if (s < MIFARE_MINI_MAXSECTOR) { if (s < MIFARE_MINI_MAXSECTOR) {
min_sectors_cnt = MIFARE_MINI_MAXSECTOR; min_sectors_cnt = MIFARE_MINI_MAXSECTOR;
} else if (s < MIFARE_1K_MAXSECTOR) { } else if (s < MIFARE_1K_MAXSECTOR) {
@ -3578,9 +3581,9 @@ out:
PrintAndLogEx(SUCCESS, _GREEN_("found keys:")); PrintAndLogEx(SUCCESS, _GREEN_("found keys:"));
//print keys //print keys
if (singleSector) // if (singleSector)
printKeyTableEx(1, e_sector, mfSectorNum(blockNo)); // printKeyTableEx(1, e_sector, mfSectorNum(blockNo));
else // else
printKeyTable(sectors_cnt, e_sector); printKeyTable(sectors_cnt, e_sector);
if (transferToEml) { if (transferToEml) {
@ -5760,6 +5763,25 @@ static int CmdHF14AMfMAD(const char *Cmd) {
MAD2DecodeAndPrint(dump + (MIFARE_1K_MAXBLOCK * MF_MAD2_SECTOR), swapmad, verbose); MAD2DecodeAndPrint(dump + (MIFARE_1K_MAXBLOCK * MF_MAD2_SECTOR), swapmad, verbose);
} }
if (aidlen == 2 || decodeholder) {
uint16_t mad[7 + 8 + 8 + 8 + 8] = {0};
size_t madlen = 0;
if (MADDecode(dump, dump + (0x10 * MIFARE_1K_MAXBLOCK), mad, &madlen, swapmad)) {
PrintAndLogEx(ERR, "can't decode MAD");
free(dump);
return PM3_ESOFT;
}
uint16_t aaid = 0x0004;
if (aidlen == 2) {
aaid = (aid[0] << 8) + aid[1];
}
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "-------- " _CYAN_("Card Holder Info 0x%04x") " --------", aaid);
MADCardHolderInfoDecode(dump, bytes_read, verbose);
}
free(dump); free(dump);
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -5795,17 +5817,34 @@ static int CmdHF14AMfMAD(const char *Cmd) {
return PM3_ESOFT; return PM3_ESOFT;
} }
got_first = true;
if (mfReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifare_mad_key, sector10) != PM3_SUCCESS) {
if (verbose) {
PrintAndLogEx(ERR, "error, read sector 0x10. card doesn't have MAD 2 or doesn't have MAD 2 on default keys");
}
got_first = false;
} else {
PrintAndLogEx(INFO, "Authentication ( " _GREEN_("ok") " )");
}
// User supplied key
if (got_first == false && keylen == 6) {
PrintAndLogEx(INFO, "Trying user specified key...");
if (mfReadSector(MF_MAD2_SECTOR, MF_KEY_A, userkey, sector10) != PM3_SUCCESS) {
if (verbose) {
PrintAndLogEx(ERR, "error, read sector 10. card doesn't have MAD 2 or the custom key is wrong");
}
} else {
PrintAndLogEx(INFO, "Authentication ( " _GREEN_("ok") " )");
}
}
MADPrintHeader(); MADPrintHeader();
bool haveMAD2 = false; bool haveMAD2 = false;
MAD1DecodeAndPrint(sector0, swapmad, verbose, &haveMAD2); MAD1DecodeAndPrint(sector0, swapmad, verbose, &haveMAD2);
if (haveMAD2) { if (haveMAD2) {
if (mfReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifare_mad_key, sector10)) {
PrintAndLogEx(ERR, "error, read sector 0x10. card doesn't have MAD or doesn't have MAD on default keys");
return PM3_ESOFT;
}
MAD2DecodeAndPrint(sector10, swapmad, verbose); MAD2DecodeAndPrint(sector10, swapmad, verbose);
} }