mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-24 07:05:40 -07:00
textual
This commit is contained in:
parent
61be7c7c30
commit
d7377e7ccc
4 changed files with 223 additions and 133 deletions
|
@ -4492,14 +4492,14 @@ static int CmdHF14AMfMAD(const char *Cmd) {
|
|||
"Checks and prints Mifare Application Directory (MAD)",
|
||||
"Usage:\n"
|
||||
"\thf mf mad -> shows MAD if exists\n"
|
||||
"\thf mf mad -a 03e1 -k ffffffffffff -b -> shows NDEF data if exists. read card with custom key and key B\n"
|
||||
"\thf mf mad -a 0004 -k ffffffffffff --dch -> decode CardHolder information\n");
|
||||
"\thf mf mad --aid 03e1 -k ffffffffffff -b -> shows NDEF data if exists. read card with custom key and key B\n"
|
||||
"\thf mf mad --dch -k ffffffffffff -> decode CardHolder information\n");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0("vV", "verbose", "show technical data"),
|
||||
arg_str0("aA", "aid", "print all sectors with specified aid", NULL),
|
||||
arg_str0("kK", "key", "key for printing sectors", NULL),
|
||||
arg_str0("", "aid", "<aid>", "print all sectors with specified aid"),
|
||||
arg_str0("kK", "key", "<key>", "key for printing sectors"),
|
||||
arg_lit0("bB", "keyb", "use key B for access printing sectors (by default: key A)"),
|
||||
arg_lit0("", "be", "(optional, BigEndian)"),
|
||||
arg_lit0("", "dch", "decode Card Holder information"),
|
||||
|
@ -4530,16 +4530,9 @@ static int CmdHF14AMfMAD(const char *Cmd) {
|
|||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("MAD Information") " -------------------------------");
|
||||
PrintAndLogEx(INFO, "---------------------------------------------------");
|
||||
|
||||
if (verbose) {
|
||||
PrintAndLogEx(SUCCESS, "Raw:");
|
||||
for (int i = 0; i < 4; i ++)
|
||||
PrintAndLogEx(INFO, "[%d] %s", i, sprint_hex(§or0[i * 16], 16));
|
||||
}
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("Mifare App Directory Information") " ----------------");
|
||||
PrintAndLogEx(INFO, "-----------------------------------------------------");
|
||||
|
||||
bool haveMAD2 = false;
|
||||
MAD1DecodeAndPrint(sector0, swapmad, verbose, &haveMAD2);
|
||||
|
@ -4561,14 +4554,21 @@ static int CmdHF14AMfMAD(const char *Cmd) {
|
|||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
// copy default NDEF key
|
||||
uint8_t akey[6] = {0};
|
||||
memcpy(akey, g_mifare_ndef_key, 6);
|
||||
|
||||
// user specified key
|
||||
if (keylen == 6) {
|
||||
memcpy(akey, key, 6);
|
||||
}
|
||||
|
||||
uint16_t aaid = 0x0004;
|
||||
if (aidlen == 2) {
|
||||
uint16_t aaid = (aid[0] << 8) + aid[1];
|
||||
|
||||
aaid = (aid[0] << 8) + aid[1];
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "-------------- " _CYAN_("AID 0x%04x") " ---------------", aaid);
|
||||
|
||||
for (int i = 0; i < madlen; i++) {
|
||||
|
@ -4587,7 +4587,8 @@ static int CmdHF14AMfMAD(const char *Cmd) {
|
|||
}
|
||||
|
||||
if (decodeholder) {
|
||||
uint16_t aaid = 0x0004;
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "-------- " _CYAN_("Card Holder Info 0x%04x") " --------", aaid);
|
||||
|
||||
uint8_t data[4096] = {0};
|
||||
|
@ -4595,6 +4596,7 @@ static int CmdHF14AMfMAD(const char *Cmd) {
|
|||
|
||||
for (int i = 0; i < madlen; i++) {
|
||||
if (aaid == mad[i]) {
|
||||
|
||||
uint8_t vsector[16 * 4] = {0};
|
||||
if (mfReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, akey, vsector)) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
@ -4611,11 +4613,17 @@ static int CmdHF14AMfMAD(const char *Cmd) {
|
|||
PrintAndLogEx(WARNING, "no Card Holder Info data");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
MADCardHolderInfoDecode(data, datalen, verbose);
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "------------ " _CYAN_("MAD sector raw") " -------------");
|
||||
for (int i = 0; i < 4; i ++)
|
||||
PrintAndLogEx(INFO, "[%d] %s", i, sprint_hex(§or0[i * 16], 16));
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -4624,14 +4632,15 @@ static int CmdHFMFNDEF(const char *Cmd) {
|
|||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf mf ndef",
|
||||
"Prints NFC Data Exchange Format (NDEF)",
|
||||
"Usage:\n\thf mf ndef -> shows NDEF data\n"
|
||||
"\thf mf ndef -a 03e1 -k ffffffffffff -b -> shows NDEF data with custom AID, key and with key B\n");
|
||||
"Usage:\n\thf mf ndef -> shows NDEF parsed data\n"
|
||||
"\thf mf ndef -vv -> shows NDEF parsed and raw data\n"
|
||||
"\thf mf ndef --aid 03e1 -k ffffffffffff -b -> shows NDEF data with custom AID, key and with key B\n");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_litn("vV", "verbose", 0, 2, "show technical data"),
|
||||
arg_str0("aA", "aid", "replace default aid for NDEF", NULL),
|
||||
arg_str0("kK", "key", "replace default key for NDEF", NULL),
|
||||
arg_str0("", "aid", "<aid>", "replace default aid for NDEF"),
|
||||
arg_str0("kK", "key", "<key>", "replace default key for NDEF"),
|
||||
arg_lit0("bB", "keyb", "use key B for access sectors (by default: key A)"),
|
||||
arg_param_end
|
||||
};
|
||||
|
@ -4664,11 +4673,15 @@ static int CmdHFMFNDEF(const char *Cmd) {
|
|||
uint8_t data[4096] = {0};
|
||||
int datalen = 0;
|
||||
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "reading MAD v1 sector");
|
||||
|
||||
if (mfReadSector(MF_MAD1_SECTOR, MF_KEY_A, (uint8_t *)g_mifare_mad_key, sector0)) {
|
||||
PrintAndLogEx(ERR, "error, read sector 0. card don't have MAD or don't have MAD on default keys");
|
||||
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mf ndef -k `") " with your custom key");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
|
||||
bool haveMAD2 = false;
|
||||
int res = MADCheck(sector0, NULL, verbose, &haveMAD2);
|
||||
if (res != PM3_SUCCESS) {
|
||||
|
@ -4677,8 +4690,12 @@ static int CmdHFMFNDEF(const char *Cmd) {
|
|||
}
|
||||
|
||||
if (haveMAD2) {
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "reading MAD v2 sector");
|
||||
|
||||
if (mfReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifare_mad_key, sector10)) {
|
||||
PrintAndLogEx(ERR, "error, read sector 0x10. card don't have MAD or don't have MAD on default keys");
|
||||
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mf ndef -k `") " with your custom key");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
}
|
||||
|
@ -4691,7 +4708,7 @@ static int CmdHFMFNDEF(const char *Cmd) {
|
|||
return res;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "data reading:");
|
||||
PrintAndLogEx(INFO, "reading data from tag");
|
||||
for (int i = 0; i < madlen; i++) {
|
||||
if (ndefAID == mad[i]) {
|
||||
uint8_t vsector[16 * 4] = {0};
|
||||
|
@ -4703,7 +4720,7 @@ static int CmdHFMFNDEF(const char *Cmd) {
|
|||
memcpy(&data[datalen], vsector, 16 * 3);
|
||||
datalen += 16 * 3;
|
||||
|
||||
PrintAndLogEx(INPLACE, ".");
|
||||
PrintAndLogEx(INPLACE, "%d", i);
|
||||
}
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
@ -4714,12 +4731,14 @@ static int CmdHFMFNDEF(const char *Cmd) {
|
|||
}
|
||||
|
||||
if (verbose2) {
|
||||
PrintAndLogEx(SUCCESS, "NDEF data:");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("MFC NDEF raw") " ----------------");
|
||||
dump_buffer(data, datalen, stdout, 1);
|
||||
}
|
||||
|
||||
NDEFDecodeAndPrint(data, datalen, verbose);
|
||||
|
||||
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mf ndef -vv`") " for more details");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -1288,16 +1288,17 @@ static int CmdHFMFPMAD(const char *Cmd) {
|
|||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf mfp mad",
|
||||
"Checks and prints Mifare Application Directory (MAD)",
|
||||
"Usage:\n\thf mfp mad -> shows MAD if exists\n"
|
||||
"Usage:\n\thf mfp mad -> shows MAD if exists\n"
|
||||
"\thf mfp mad -a 03e1 -k d3f7d3f7d3f7d3f7d3f7d3f7d3f7d3f7 -> shows NDEF data if exists\n");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0("vV", "verbose", "show technical data"),
|
||||
arg_str0("aA", "aid", "print all sectors with aid", NULL),
|
||||
arg_str0("kK", "key", "key for printing sectors", NULL),
|
||||
arg_str0("", "aid", "<aid>", "print all sectors with aid"),
|
||||
arg_str0("kK", "key", "<key>", "key for printing sectors"),
|
||||
arg_lit0("bB", "keyb", "use key B for access printing sectors (by default: key A)"),
|
||||
arg_lit0("", "be", "(optional, BigEndian)"),
|
||||
arg_lit0("", "dch", "decode Card Holder information"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
@ -1311,11 +1312,12 @@ static int CmdHFMFPMAD(const char *Cmd) {
|
|||
CLIGetHexWithReturn(ctx, 3, key, &keylen);
|
||||
bool keyB = arg_get_lit(ctx, 4);
|
||||
bool swapmad = arg_get_lit(ctx, 5);
|
||||
bool decodeholder = arg_get_lit(ctx, 6);
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (aidlen != 2 && keylen > 0) {
|
||||
PrintAndLogEx(WARNING, "do not need a key without aid");
|
||||
if (aidlen != 2 && !decodeholder && keylen > 0) {
|
||||
PrintAndLogEx(WARNING, "Using default MAD keys instead");
|
||||
}
|
||||
|
||||
uint8_t sector0[16 * 4] = {0};
|
||||
|
@ -1328,8 +1330,8 @@ static int CmdHFMFPMAD(const char *Cmd) {
|
|||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("MAD Information") " -------------------------------");
|
||||
PrintAndLogEx(INFO, "---------------------------------------------------");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("Mifare App Directory Information") " ----------------");
|
||||
PrintAndLogEx(INFO, "-----------------------------------------------------");
|
||||
|
||||
if (verbose) {
|
||||
PrintAndLogEx(SUCCESS, "Raw:");
|
||||
|
@ -1350,10 +1352,7 @@ static int CmdHFMFPMAD(const char *Cmd) {
|
|||
MAD2DecodeAndPrint(sector10, swapmad, verbose);
|
||||
}
|
||||
|
||||
if (aidlen == 2) {
|
||||
uint16_t aaid = (aid[0] << 8) + aid[1];
|
||||
PrintAndLogEx(INFO, "-------------- " _CYAN_("AID 0x%04x") " ---------------", aaid);
|
||||
|
||||
if (aidlen == 2 || decodeholder) {
|
||||
uint16_t mad[7 + 8 + 8 + 8 + 8] = {0};
|
||||
size_t madlen = 0;
|
||||
if (MADDecode(sector0, sector10, mad, &madlen, swapmad)) {
|
||||
|
@ -1361,27 +1360,66 @@ static int CmdHFMFPMAD(const char *Cmd) {
|
|||
return 10;
|
||||
}
|
||||
|
||||
// copy default NDEF key
|
||||
uint8_t akey[16] = {0};
|
||||
memcpy(akey, g_mifarep_ndef_key, 16);
|
||||
|
||||
// user specified key
|
||||
if (keylen == 16) {
|
||||
memcpy(akey, key, 16);
|
||||
}
|
||||
|
||||
for (int i = 0; i < madlen; i++) {
|
||||
if (aaid == mad[i]) {
|
||||
uint8_t vsector[16 * 4] = {0};
|
||||
if (mfpReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, akey, vsector, false)) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(ERR, "error, read sector %d error", i + 1);
|
||||
return 2;
|
||||
}
|
||||
uint16_t aaid = 0x0004;
|
||||
if (aidlen == 2) {
|
||||
aaid = (aid[0] << 8) + aid[1];
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "-------------- " _CYAN_("AID 0x%04x") " ---------------", aaid);
|
||||
|
||||
for (int j = 0; j < (verbose ? 4 : 3); j ++)
|
||||
PrintAndLogEx(NORMAL, " [%03d] %s", (i + 1) * 4 + j, sprint_hex(&vsector[j * 16], 16));
|
||||
for (int i = 0; i < madlen; i++) {
|
||||
if (aaid == mad[i]) {
|
||||
uint8_t vsector[16 * 4] = {0};
|
||||
if (mfpReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, akey, vsector, false)) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(ERR, "error, read sector %d error", i + 1);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
for (int j = 0; j < (verbose ? 4 : 3); j ++)
|
||||
PrintAndLogEx(NORMAL, " [%03d] %s", (i + 1) * 4 + j, sprint_hex(&vsector[j * 16], 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (decodeholder) {
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "-------- " _CYAN_("Card Holder Info 0x%04x") " --------", aaid);
|
||||
|
||||
uint8_t data[4096] = {0};
|
||||
int datalen = 0;
|
||||
|
||||
for (int i = 0; i < madlen; i++) {
|
||||
if (aaid == mad[i]) {
|
||||
|
||||
uint8_t vsector[16 * 4] = {0};
|
||||
if (mfReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, akey, vsector)) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(ERR, "error, read sector %d", i + 1);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
memcpy(&data[datalen], vsector, 16 * 3);
|
||||
datalen += 16 * 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (!datalen) {
|
||||
PrintAndLogEx(WARNING, "no Card Holder Info data");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
MADCardHolderInfoDecode(data, datalen, verbose);
|
||||
}
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1390,14 +1428,16 @@ static int CmdHFMFPNDEF(const char *Cmd) {
|
|||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf mfp ndef",
|
||||
"Prints NFC Data Exchange Format (NDEF)",
|
||||
"Usage:\n\thf mfp ndef -> shows NDEF data\n"
|
||||
"\thf mfp ndef -a 03e1 -k d3f7d3f7d3f7d3f7d3f7d3f7d3f7d3f7 -> shows NDEF data with custom AID and key\n");
|
||||
"Usage:\n"
|
||||
"\thf mfp ndef -> shows NDEF data\n"
|
||||
"\thf mfp ndef -vv -> shows NDEF parsed and raw data\n"
|
||||
"\thf mfp ndef -a 03e1 -k d3f7d3f7d3f7d3f7d3f7d3f7d3f7d3f7 -> shows NDEF data with custom AID and key\n");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_litn("vV", "verbose", 0, 2, "show technical data"),
|
||||
arg_str0("aA", "aid", "replace default aid for NDEF", NULL),
|
||||
arg_str0("kK", "key", "replace default key for NDEF", NULL),
|
||||
arg_str0("", "aid", "<aid>", "replace default aid for NDEF"),
|
||||
arg_str0("kK", "key", "<key>", "replace default key for NDEF"),
|
||||
arg_lit0("bB", "keyb", "use key B for access sectors (by default: key A)"),
|
||||
arg_param_end
|
||||
};
|
||||
|
@ -1430,8 +1470,12 @@ static int CmdHFMFPNDEF(const char *Cmd) {
|
|||
uint8_t data[4096] = {0};
|
||||
int datalen = 0;
|
||||
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "reading MAD v1 sector");
|
||||
|
||||
if (mfpReadSector(MF_MAD1_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector0, verbose)) {
|
||||
PrintAndLogEx(ERR, "error, read sector 0. card don't have MAD or don't have MAD on default keys");
|
||||
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mfp ndef -k `") " with your custom key");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
|
@ -1443,8 +1487,13 @@ static int CmdHFMFPNDEF(const char *Cmd) {
|
|||
}
|
||||
|
||||
if (haveMAD2) {
|
||||
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "reading MAD v2 sector");
|
||||
|
||||
if (mfpReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector10, verbose)) {
|
||||
PrintAndLogEx(ERR, "error, read sector 0x10. card don't have MAD or don't have MAD on default keys");
|
||||
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mf ndef -k `") " with your custom key");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
}
|
||||
|
@ -1457,7 +1506,7 @@ static int CmdHFMFPNDEF(const char *Cmd) {
|
|||
return res;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "data reading:");
|
||||
PrintAndLogEx(INFO, "reading data from tag");
|
||||
for (int i = 0; i < madlen; i++) {
|
||||
if (ndefAID == mad[i]) {
|
||||
uint8_t vsector[16 * 4] = {0};
|
||||
|
@ -1469,7 +1518,7 @@ static int CmdHFMFPNDEF(const char *Cmd) {
|
|||
memcpy(&data[datalen], vsector, 16 * 3);
|
||||
datalen += 16 * 3;
|
||||
|
||||
PrintAndLogEx(INPLACE, ".");
|
||||
PrintAndLogEx(INPLACE, "%d", i);
|
||||
}
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
@ -1480,11 +1529,13 @@ static int CmdHFMFPNDEF(const char *Cmd) {
|
|||
}
|
||||
|
||||
if (verbose2) {
|
||||
PrintAndLogEx(INFO, "NDEF data:");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("MFC NDEF raw") " ----------------");
|
||||
dump_buffer(data, datalen, stdout, 1);
|
||||
}
|
||||
|
||||
NDEFDecodeAndPrint(data, datalen, verbose);
|
||||
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mf ndef -vv`") " for more details");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,22 @@
|
|||
// https://www.nxp.com/docs/en/application-note/AN10787.pdf
|
||||
static json_t *mad_known_aids = NULL;
|
||||
|
||||
static const char *holder_info_type[] = {
|
||||
"Surname",
|
||||
"Given name",
|
||||
"Sex",
|
||||
"Other"
|
||||
};
|
||||
|
||||
static const char *aid_admin[] = {
|
||||
"free",
|
||||
"defect",
|
||||
"reserved",
|
||||
"additional directory info",
|
||||
"card holder info",
|
||||
"not applicable"
|
||||
};
|
||||
|
||||
static int open_mad_file(json_t **root, bool verbose) {
|
||||
|
||||
char *path;
|
||||
|
@ -45,7 +61,7 @@ static int open_mad_file(json_t **root, bool verbose) {
|
|||
}
|
||||
|
||||
if (verbose)
|
||||
PrintAndLogEx(SUCCESS, "Loaded file (%s) OK. %zu records.", path, json_array_size(*root));
|
||||
PrintAndLogEx(SUCCESS, "Loaded file " _YELLOW_("`%s`") " (%s) %zu records.", path, _GREEN_("ok"), json_array_size(*root));
|
||||
out:
|
||||
free(path);
|
||||
return retval;
|
||||
|
@ -157,9 +173,9 @@ int MADCheck(uint8_t *sector0, uint8_t *sector10, bool verbose, bool *haveMAD2)
|
|||
if (sector0 == NULL)
|
||||
return PM3_EINVARG;
|
||||
|
||||
uint8_t GPB = sector0[3 * 16 + 9];
|
||||
uint8_t GPB = sector0[3 * 16 + 9];
|
||||
if (verbose)
|
||||
PrintAndLogEx(SUCCESS, "GPB: " _GREEN_("0x%02x"), GPB);
|
||||
PrintAndLogEx(SUCCESS, "%14s " _GREEN_("0x%02x"), "GPB", GPB);
|
||||
|
||||
// DA (MAD available)
|
||||
if (!(GPB & 0x80)) {
|
||||
|
@ -167,6 +183,33 @@ int MADCheck(uint8_t *sector0, uint8_t *sector10, bool verbose, bool *haveMAD2)
|
|||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
uint8_t mad_ver = GPB & 0x03;
|
||||
if (verbose)
|
||||
PrintAndLogEx(SUCCESS, "%14s " _GREEN_("%d"), "MAD version", mad_ver);
|
||||
|
||||
// MAD version
|
||||
if ((mad_ver != 0x01) && (mad_ver != 0x02)) {
|
||||
PrintAndLogEx(ERR, "Wrong MAD version " _RED_("0x%02x"), mad_ver);
|
||||
return PM3_ESOFT;
|
||||
};
|
||||
|
||||
if (haveMAD2)
|
||||
*haveMAD2 = (mad_ver == 2);
|
||||
|
||||
int res = madCRCCheck(sector0, true, 1);
|
||||
|
||||
if (verbose && res == PM3_SUCCESS)
|
||||
PrintAndLogEx(SUCCESS, "%14s " _GREEN_("0x%02x") " (%s)", "CRC8", sector0[16], _GREEN_("ok"));
|
||||
|
||||
if (mad_ver == 2 && sector10) {
|
||||
int res2 = madCRCCheck(sector10, true, 2);
|
||||
if (res == PM3_SUCCESS)
|
||||
res = res2;
|
||||
|
||||
if (verbose && !res2)
|
||||
PrintAndLogEx(SUCCESS, "%14s " _GREEN_("0x%02x") " (%s)", "CRC8", sector10[0], _GREEN_("ok"));
|
||||
}
|
||||
|
||||
// MA (multi-application card)
|
||||
if (verbose) {
|
||||
if (GPB & 0x40)
|
||||
|
@ -174,34 +217,6 @@ int MADCheck(uint8_t *sector0, uint8_t *sector10, bool verbose, bool *haveMAD2)
|
|||
else
|
||||
PrintAndLogEx(SUCCESS, "Single application card");
|
||||
}
|
||||
|
||||
uint8_t MADVer = GPB & 0x03;
|
||||
if (verbose)
|
||||
PrintAndLogEx(SUCCESS, "MAD version: " _GREEN_("%d"), MADVer);
|
||||
|
||||
// MAD version
|
||||
if ((MADVer != 0x01) && (MADVer != 0x02)) {
|
||||
PrintAndLogEx(ERR, "Wrong MAD version: " _RED_("0x%02x"), MADVer);
|
||||
return PM3_ESOFT;
|
||||
};
|
||||
|
||||
if (haveMAD2)
|
||||
*haveMAD2 = (MADVer == 2);
|
||||
|
||||
int res = madCRCCheck(sector0, true, 1);
|
||||
|
||||
if (verbose && res == PM3_SUCCESS)
|
||||
PrintAndLogEx(SUCCESS, "CRC8-MAD1 (%s)", _GREEN_("ok"));
|
||||
|
||||
if (MADVer == 2 && sector10) {
|
||||
int res2 = madCRCCheck(sector10, true, 2);
|
||||
if (res == PM3_SUCCESS)
|
||||
res = res2;
|
||||
|
||||
if (verbose && !res2)
|
||||
PrintAndLogEx(SUCCESS, "CRC8-MAD2 (%s)", _GREEN_("ok"));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -232,83 +247,78 @@ int MADDecode(uint8_t *sector0, uint8_t *sector10, uint16_t *mad, size_t *madlen
|
|||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static const char *holder_info_type[] = {
|
||||
"Surname",
|
||||
"Given name",
|
||||
"Sex",
|
||||
"Other"
|
||||
};
|
||||
|
||||
int MADCardHolderInfoDecode(uint8_t *data, size_t dataLen, bool verbose) {
|
||||
int MADCardHolderInfoDecode(uint8_t *data, size_t datalen, bool verbose) {
|
||||
size_t idx = 0;
|
||||
while (idx < dataLen) {
|
||||
while (idx < datalen) {
|
||||
uint8_t len = data[idx] & 0x3f;
|
||||
uint8_t type = data[idx] >> 6;
|
||||
idx++;
|
||||
if (len > 0) {
|
||||
PrintAndLogEx(INFO, "%s: %.*s", holder_info_type[type], len, &data[idx]);
|
||||
PrintAndLogEx(INFO, "%14s " _GREEN_("%.*s"), holder_info_type[type], len, &data[idx]);
|
||||
idx += len;
|
||||
} else break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int MADInfoByteDecode(uint8_t *sector, bool swapmad, int MADver, bool verbose) {
|
||||
uint8_t InfoByte;
|
||||
if (MADver == 1) {
|
||||
InfoByte = sector[16 + 1] & 0x3f;
|
||||
if (InfoByte >= 0xF) {
|
||||
PrintAndLogEx(WARNING, "Invalid Info byte (MAD1) value " _YELLOW_("0x%02x"), InfoByte);
|
||||
static int MADInfoByteDecode(uint8_t *sector, bool swapmad, int mad_ver, bool verbose) {
|
||||
uint8_t info;
|
||||
if (mad_ver == 1) {
|
||||
info = sector[16 + 1] & 0x3f;
|
||||
if (info >= 0xF) {
|
||||
PrintAndLogEx(WARNING, "Invalid Info byte (MAD1) value " _YELLOW_("0x%02x"), info);
|
||||
if (verbose)
|
||||
// I understand the spec in a way that MAD1 InfoByte should not point into MAD2 sectors, @lukaskuzmiak
|
||||
PrintAndLogEx(WARNING, "MAD1 Info byte points outside of MAD1 sector space (0x%02x), report a bug?", InfoByte);
|
||||
PrintAndLogEx(WARNING, "MAD1 Info byte points outside of MAD1 sector space (0x%02x), report a bug?", info);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
} else {
|
||||
InfoByte = sector[1] & 0x3f;
|
||||
if (InfoByte == 0x10 || InfoByte >= 0x28) {
|
||||
PrintAndLogEx(WARNING, "Invalid Info byte (MAD2) value " _YELLOW_("0x%02x"), InfoByte);
|
||||
info = sector[1] & 0x3f;
|
||||
if (info == 0x10 || info >= 0x28) {
|
||||
PrintAndLogEx(WARNING, "Invalid Info byte (MAD2) value " _YELLOW_("0x%02x"), info);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
}
|
||||
|
||||
if (InfoByte) {
|
||||
PrintAndLogEx(SUCCESS, "Card publisher sector: " _MAGENTA_("0x%02x"), InfoByte);
|
||||
return InfoByte;
|
||||
} else {
|
||||
PrintAndLogEx(WARNING, "Card publisher not present " _YELLOW_("0x%02x"), InfoByte);
|
||||
return PM3_ESOFT;
|
||||
if (info) {
|
||||
return info;
|
||||
}
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
static const char *aid_admin[] = {
|
||||
"free",
|
||||
"defect",
|
||||
"reserved",
|
||||
"additional directory info",
|
||||
"card holder info",
|
||||
"not applicable"
|
||||
};
|
||||
|
||||
int MAD1DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose, bool *haveMAD2) {
|
||||
open_mad_file(&mad_known_aids, verbose);
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "------------ " _CYAN_("MAD v1 details") " -------------");
|
||||
|
||||
// check MAD1 only
|
||||
MADCheck(sector, NULL, verbose, haveMAD2);
|
||||
|
||||
int InfoByteSector = MADInfoByteDecode(sector, swapmad, 1, verbose);
|
||||
int ibs = MADInfoByteDecode(sector, swapmad, 1, verbose);
|
||||
|
||||
PrintAndLogEx(INFO, " 00 MAD 1");
|
||||
if (ibs) {
|
||||
PrintAndLogEx(SUCCESS, "Card publisher sector " _MAGENTA_("0x%02x"), ibs);
|
||||
} else {
|
||||
PrintAndLogEx(WARNING, "Card publisher " _RED_("not") " present " _YELLOW_("0x%02x"), ibs);
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "---------------- " _CYAN_("Listing") " ----------------");
|
||||
|
||||
PrintAndLogEx(INFO, " 00 MAD v1");
|
||||
uint32_t prev_aid = 0xFFFFFFFF;
|
||||
for (int i = 1; i < 16; i++) {
|
||||
uint16_t aid = madGetAID(sector, swapmad, 1, i);
|
||||
if (aid < 6) {
|
||||
PrintAndLogEx(INFO, (InfoByteSector == i) ? _MAGENTA_(" %02d [%04X] (%s)") : " %02d [%04X] (%s)", i, aid, aid_admin[aid]);
|
||||
PrintAndLogEx(INFO, (ibs == i) ? _MAGENTA_(" %02d [%04X] (%s)") : " %02d [%04X] (%s)", i, aid, aid_admin[aid]);
|
||||
} else if (prev_aid == aid) {
|
||||
PrintAndLogEx(INFO, (InfoByteSector == i) ? _MAGENTA_(" %02d [%04X] (continuation)") : " %02d [%04X] (continuation)", i, aid);
|
||||
PrintAndLogEx(INFO, (ibs == i) ? _MAGENTA_(" %02d [%04X] (continuation)") : " %02d [%04X] (continuation)", i, aid);
|
||||
} else {
|
||||
char fmt[30];
|
||||
sprintf(fmt, (InfoByteSector == i) ? _MAGENTA_(" %02d [%04X]%s") : " %02d [%04X]%s", i, aid, "%s");
|
||||
sprintf(fmt, (ibs == i) ? _MAGENTA_(" %02d [%04X]%s") : " %02d [%04X]%s", i, aid, "%s");
|
||||
print_aid_description(mad_known_aids, aid, fmt, verbose);
|
||||
prev_aid = aid;
|
||||
}
|
||||
|
@ -319,28 +329,38 @@ int MAD1DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose, bool *haveMA
|
|||
|
||||
int MAD2DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose) {
|
||||
open_mad_file(&mad_known_aids, verbose);
|
||||
PrintAndLogEx(INFO, " 16 MAD 2");
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "------------ " _CYAN_("MAD v2 details") " -------------");
|
||||
|
||||
PrintAndLogEx(INFO, " 16 MAD v2");
|
||||
|
||||
int res = madCRCCheck(sector, true, 2);
|
||||
if (verbose) {
|
||||
if (res == PM3_SUCCESS)
|
||||
PrintAndLogEx(SUCCESS, "CRC8-MAD2 (%s)", _GREEN_("ok"));
|
||||
PrintAndLogEx(SUCCESS, "CRC8 (%s)", _GREEN_("ok"));
|
||||
else
|
||||
PrintAndLogEx(WARNING, "CRC8-MAD2 (%s)", _RED_("fail"));
|
||||
PrintAndLogEx(WARNING, "CRC8 (%s)", _RED_("fail"));
|
||||
}
|
||||
|
||||
int ibs = MADInfoByteDecode(sector, swapmad, 2, verbose);
|
||||
if (ibs) {
|
||||
PrintAndLogEx(SUCCESS, "Card publisher sector " _MAGENTA_("0x%02x"), ibs);
|
||||
} else {
|
||||
PrintAndLogEx(WARNING, "Card publisher " _RED_("not") " present " _YELLOW_("0x%02x"), ibs);
|
||||
}
|
||||
|
||||
int InfoByteSector = MADInfoByteDecode(sector, swapmad, 2, verbose);
|
||||
|
||||
uint32_t prev_aid = 0xFFFFFFFF;
|
||||
for (int i = 1; i < 8 + 8 + 7 + 1; i++) {
|
||||
uint16_t aid = madGetAID(sector, swapmad, 2, i);
|
||||
if (aid < 6) {
|
||||
PrintAndLogEx(INFO, (InfoByteSector == i) ? _MAGENTA_(" %02d [%04X] (%s)") : " %02d [%04X] (%s)", i + 16, aid, aid_admin[aid]);
|
||||
PrintAndLogEx(INFO, (ibs == i) ? _MAGENTA_(" %02d [%04X] (%s)") : " %02d [%04X] (%s)", i + 16, aid, aid_admin[aid]);
|
||||
} else if (prev_aid == aid) {
|
||||
PrintAndLogEx(INFO, (InfoByteSector == i) ? _MAGENTA_(" %02d [%04X] (continuation)") : " %02d [%04X] (continuation)", i + 16, aid);
|
||||
PrintAndLogEx(INFO, (ibs == i) ? _MAGENTA_(" %02d [%04X] (continuation)") : " %02d [%04X] (continuation)", i + 16, aid);
|
||||
} else {
|
||||
char fmt[30];
|
||||
sprintf(fmt, (InfoByteSector == i) ? _MAGENTA_(" %02d [%04X]%s") : " %02d [%04X]%s", i + 16, aid, "%s");
|
||||
sprintf(fmt, (ibs == i) ? _MAGENTA_(" %02d [%04X]%s") : " %02d [%04X]%s", i + 16, aid, "%s");
|
||||
print_aid_description(mad_known_aids, aid, fmt, verbose);
|
||||
prev_aid = aid;
|
||||
}
|
||||
|
|
|
@ -437,7 +437,7 @@ int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose) {
|
|||
size_t indx = 0;
|
||||
|
||||
PrintAndLogEx(INFO, "");
|
||||
PrintAndLogEx(INFO, "NDEF parsing");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("NDEF parsing") " ----------------");
|
||||
while (indx < ndefLen) {
|
||||
|
||||
PrintAndLogEx(INFO, "-----------------------------------------------------");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue