Add MIFARE Plus commands in trace list

This commit is contained in:
DidierA committed 2023-07-19 21:15:07 +02:00
1 parent 0d682da676
commit b314d1ef1c
7 files changed
+300 -12

No files matched your search

+224
View File
@@ -1196,6 +1196,230 @@ void annotateMfDesfire(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
}
}
}
// codes for which no data is interpreted, returns the message to print.
const char *mfpGetAnnotationForCode(uint8_t code) {
struct mfp_code_msg {
uint8_t code;
const char *annotation;
} messages[] = {
{ MFP_GETVERSION, "GET VERSION"},
{ MFP_ADDITIONALFRAME, "NEXT FRAME"},
{ MFP_AUTHENTICATENONFIRST, "FOLLOWING AUTH"},
{ MFP_AUTHENTICATECONTINUE, "SECOND AUTH STEP"},
{ MFP_RESETAUTH, "RESET AUTH"},
{ MFP_COMMITPERSO, "COMMIT PERSO"},
{ MFP_VCSUPPORTLASTISOL3, "CHECK VIRTUAL CARD"},
{ MFP_ISOSELECT, "SELECT VIRTUAL CARD"},
{ MFP_SETCONFIGSL1, "SET CONFIG SL1"},
{ MFP_MF_PERSONALIZEUIDUSAGE, "PERSONALIZE UID USAGE"},
{ MFP_READ_SIG, "READ SIGNATURE"},
{ MFDES_PREPARE_PC, "PREPARE PROXIMITY CHECK"},
{ MFDES_PROXIMITY_CHECK, "PROXIMITY CHECK"},
{ MFDES_VERIFY_PC, "VERIFY PROXIMITY CHECK"},
{ 0, NULL}
} ;
for (struct mfp_code_msg *p=messages ; p->annotation != NULL ; p++) {
if (p->code == code) {
return p->annotation ;
}
}
return NULL ;
}
// MIFARE Plus
void annotateMfPlus(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
// If we are in Mifare Classic Authenticated mode, all the work has already be done elsewhere
if ((MifareAuthState != masNone) && (MifareAuthState != masError)) {
return ;
}
// it's basically a ISO14443a tag, so try annotation from there
if (applyIso14443a(exp, size, cmd, cmdsize, false) == PM3_SUCCESS) {
return ;
}
// ok this part is copy paste from annotateMfDesfire, it seems to work for MIFARE Plus also
if (((cmd[0] & 0xC0) == 0x00) && (cmdsize > 2)) {
// PCB [CID] [NAD] [INF] CRC CRC
int pos = 1;
if ((cmd[0] & 0x08) == 0x08) // cid byte following
pos++;
if ((cmd[0] & 0x04) == 0x04) // nad byte following
pos++;
for (uint8_t i = 0; i < 2; i++, pos++) {
bool found_annotation = true;
uint8_t *data = cmd + pos + 1;
// if the byte prior to the command is 90 the command is wrapped, so data starts 3 bytes later
if (i > 0 && cmd[pos - 1] == 0x90) {
data += 3;
}
uint8_t data_size = 0;
if (cmdsize > (data - cmd)) {
data_size = cmdsize - (data - cmd);
}
// Messages for commands that do not need args are treated first
const char *annotation = mfpGetAnnotationForCode(cmd[pos]) ;
if (annotation != NULL) {
snprintf(exp, size, "%s", annotation) ;
break ;
}
switch (cmd[pos]) {
case MFP_AUTHENTICATEFIRST:
case MFP_AUTHENTICATEFIRST_VARIANT:
if (data_size > 1) {
// key : uint16_t uKeyNum = 0x4000 + sectorNum * 2 + (keyB ? 1 : 0);
uint16_t uKeyNum = MemLeToUint2byte(data) ;
snprintf(exp, size, "FIRST AUTH (Keynr 0x%04X: %c sector %d)", uKeyNum, uKeyNum & 0x0001 ? 'B' : 'A', (uKeyNum - 0x4000)/2 );
} else {
snprintf(exp, size, "FIRST AUTH") ;
}
break;
case MFP_WRITEPERSO:
if (data_size > 1) {
uint16_t uKeyNum = MemLeToUint2byte(data) ;
snprintf(exp, size, "WRITE PERSO (Keynr 0x%04X)", uKeyNum);
} else {
snprintf(exp, size, "WRITE PERSO");
}
break;
case MFP_READENCRYPTEDNOMAC_MACED:
case MFP_READENCRYPTEDMAC_MACED:
case MFP_READENCRYPTEDNOMAC_UNMACED:
case MFP_READENCRYPTEDMAC_UNMACED:
if (data_size > 2) {
uint16_t uBlockNum = MemLeToUint2byte(data) ;
uint8_t uQty = data[2] ;
if (uQty != 1) {
snprintf(exp, size, "READ ENCRYPTED(%u-%u)", uBlockNum, uBlockNum+uQty-1);
} else {
snprintf(exp, size, "READ ENCRYPTED(%u)", uBlockNum);
}
} else {
snprintf(exp, size, "READ ENCRYPTED ?");
}
break;
case MFP_READPLAINNOMAC_MACED:
case MFP_READPLAINMAC_MACED:
case MFP_READPLAINNOMAC_UNMACED:
case MFP_READPLAINMAC_UNMACED:
if (data_size > 2) {
uint16_t uBlockNum = MemLeToUint2byte(data) ;
uint8_t uQty = data[2] ;
if (uQty != 1) {
snprintf(exp, size, "READ PLAIN(%u-%u)", uBlockNum, uBlockNum+uQty-1);
} else {
snprintf(exp, size, "READ PLAIN(%u)", uBlockNum);
}
} else {
snprintf(exp, size, "READ PLAIN ?");
}
break;
case MFP_WRITEPLAINNOMAC :
case MFP_WRITEPLAINMAC :
if (data_size > 1) {
uint16_t uBlockNum = MemLeToUint2byte(data) ;
snprintf(exp, size, "WRITE PLAIN(%u)", uBlockNum);
} else {
snprintf(exp, size, "WRITE PLAIN ?");
}
break;
case MFP_WRITEENCRYPTEDNOMAC:
case MFP_WRITEENCRYPTEDMAC :
if (data_size > 1) {
uint16_t uBlockNum = MemLeToUint2byte(data) ;
snprintf(exp, size, "WRITE ENCRYPTED(%u)", uBlockNum);
} else {
snprintf(exp, size, "WRITE ENCRYPTED ?");
}
break;
case MFP_INCREMENTNOMAC :
case MFP_INCREMENTMAC :
if (data_size > 1) {
uint16_t uBlockNum = MemLeToUint2byte(data) ;
snprintf(exp, size, "INCREMENT(%u)", uBlockNum);
} else {
snprintf(exp, size, "INCREMENT ?");
}
break;
case MFP_DECREMENTNOMAC :
case MFP_DECREMENTMAC :
if (data_size > 1) {
uint16_t uBlockNum = MemLeToUint2byte(data) ;
snprintf(exp, size, "DECREMENT(%u)", uBlockNum);
} else {
snprintf(exp, size, "DECREMENT ?");
}
break;
case MFP_TRANSFERNOMAC :
case MFP_TRANSFERMAC :
if (data_size > 1) {
uint16_t uBlockNum = MemLeToUint2byte(data) ;
snprintf(exp, size, "TRANSFER(%u)", uBlockNum);
} else {
snprintf(exp, size, "TRANSFER ?");
}
break;
case MFP_INCREMENTTRANSFERNOMAC:
case MFP_INCREMENTTRANSFERMAC :
if (data_size > 1) {
uint16_t uBlockNum = MemLeToUint2byte(data) ;
snprintf(exp, size, "INCREMENT, TRANSFER(%u)", uBlockNum);
} else {
snprintf(exp, size, "INCREMENT, TRANSFER ?");
}
break;
case MFP_DECREMENTTRANSFERNOMAC:
case MFP_DECREMENTTRANSFERMAC :
if (data_size > 1) {
uint16_t uBlockNum = MemLeToUint2byte(data) ;
snprintf(exp, size, "DECREMENT, TRANSFER(%u)", uBlockNum);
} else {
snprintf(exp, size, "DECREMENT, TRANSFER ?");
}
break;
case MFP_RESTORENOMAC :
case MFP_RESTOREMAC :
if (data_size > 1) {
uint16_t uBlockNum = MemLeToUint2byte(data) ;
snprintf(exp, size, "RESTORE(%u)", uBlockNum);
} else {
snprintf(exp, size, "RESTORE ?");
}
break;
default:
found_annotation = false;
break;
}
if (found_annotation) {
break;
}
}
} else {
// anything else
snprintf(exp, size, "?");
}
}
/**
06 00 = INITIATE