Add colour to hf mfdes command

This commit is contained in:
Daniel Underhay 2020-03-15 23:32:53 +11:00
parent 7d2e65ce91
commit daba356871
3 changed files with 105 additions and 105 deletions

View file

@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased] ## [unreleased][unreleased]
- Add colour to `hf mfdes` command (@dunderhay)
- Change type colour for `hf 14a` card types (@dunderhay)
- Add 'HINTS' command. Will turn off / on hint messages. Default mode is OFF. (@iceman1001) - Add 'HINTS' command. Will turn off / on hint messages. Default mode is OFF. (@iceman1001)
- Add colour to `hf 14a` and `hf mfu` commands (@dunderhay) - Add colour to `hf 14a` and `hf mfu` commands (@dunderhay)
- Add colour to `lf hid` commands (@dunderhay) - Add colour to `lf hid` commands (@dunderhay)

View file

@ -1323,55 +1323,55 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
} }
break; break;
case 0x01: case 0x01:
PrintAndLogEx(SUCCESS, "TYPE : NXP TNP3xxx Activision Game Appliance"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("NXP TNP3xxx Activision Game Appliance"));
break; break;
case 0x04: case 0x04:
PrintAndLogEx(SUCCESS, "TYPE : NXP MIFARE (various !DESFire !DESFire EV1)"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("NXP MIFARE (various !DESFire !DESFire EV1)"));
isMifareClassic = false; isMifareClassic = false;
isMifareDesfire = true; isMifareDesfire = true;
break; break;
case 0x08: case 0x08:
PrintAndLogEx(SUCCESS, "TYPE : NXP MIFARE CLASSIC 1k | Plus 2k SL1 | 1k Ev1"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("NXP MIFARE CLASSIC 1k | Plus 2k SL1 | 1k Ev1"));
break; break;
case 0x09: case 0x09:
PrintAndLogEx(SUCCESS, "TYPE : NXP MIFARE Mini 0.3k"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("NXP MIFARE Mini 0.3k"));
break; break;
case 0x0A: case 0x0A:
PrintAndLogEx(SUCCESS, "TYPE : FM11RF005SH (Shanghai Metro)"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("FM11RF005SH (Shanghai Metro)"));
break; break;
case 0x10: case 0x10:
PrintAndLogEx(SUCCESS, "TYPE : NXP MIFARE Plus 2k SL2"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("NXP MIFARE Plus 2k SL2"));
isMifarePlus = true; isMifarePlus = true;
break; break;
case 0x11: case 0x11:
PrintAndLogEx(SUCCESS, "TYPE : NXP MIFARE Plus 4k SL2"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("NXP MIFARE Plus 4k SL2"));
isMifarePlus = true; isMifarePlus = true;
break; break;
case 0x18: case 0x18:
PrintAndLogEx(SUCCESS, "TYPE : NXP MIFARE Classic 4k | Plus 4k SL1 | 4k Ev1"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("NXP MIFARE Classic 4k | Plus 4k SL1 | 4k Ev1"));
break; break;
case 0x20: case 0x20:
PrintAndLogEx(SUCCESS, "TYPE : NXP MIFARE DESFire 4k | DESFire EV1 2k/4k/8k | Plus 2k/4k SL3 | JCOP 31/41"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("NXP MIFARE DESFire 4k | DESFire EV1 2k/4k/8k | Plus 2k/4k SL3 | JCOP 31/41"));
isMifareClassic = false; isMifareClassic = false;
isMifareDesfire = true; isMifareDesfire = true;
isMifarePlus = true; isMifarePlus = true;
break; break;
case 0x24: case 0x24:
PrintAndLogEx(SUCCESS, "TYPE : NXP MIFARE DESFire | DESFire EV1"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("NXP MIFARE DESFire | DESFire EV1"));
isMifareClassic = false; isMifareClassic = false;
isMifareDesfire = true; isMifareDesfire = true;
break; break;
case 0x28: case 0x28:
PrintAndLogEx(SUCCESS, "TYPE : JCOP31 or JCOP41 v2.3.1"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("JCOP31 or JCOP41 v2.3.1"));
break; break;
case 0x38: case 0x38:
PrintAndLogEx(SUCCESS, "TYPE : Nokia 6212 or 6131 MIFARE CLASSIC 4K"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("Nokia 6212 or 6131 MIFARE CLASSIC 4K"));
break; break;
case 0x88: case 0x88:
PrintAndLogEx(SUCCESS, "TYPE : Infineon MIFARE CLASSIC 1K"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("Infineon MIFARE CLASSIC 1K"));
break; break;
case 0x98: case 0x98:
PrintAndLogEx(SUCCESS, "TYPE : Gemplus MPCOS"); PrintAndLogEx(SUCCESS, "TYPE: " _YELLOW_("Gemplus MPCOS"));
break; break;
default: default:
; ;
@ -1379,7 +1379,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
// Double & triple sized UID, can be mapped to a manufacturer. // Double & triple sized UID, can be mapped to a manufacturer.
if (card.uidlen > 4) { if (card.uidlen > 4) {
PrintAndLogEx(SUCCESS, "MANUFACTURER: " _GREEN_("%s"), getTagInfo(card.uid[0])); PrintAndLogEx(SUCCESS, "MANUFACTURER: " _YELLOW_("%s"), getTagInfo(card.uid[0]));
} }
// try to request ATS even if tag claims not to support it // try to request ATS even if tag claims not to support it
@ -1400,7 +1400,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
if (select_status == 2) { if (select_status == 2) {
PrintAndLogEx(INFO, "SAK incorrectly claims that card doesn't support RATS"); PrintAndLogEx(INFO, "SAK incorrectly claims that card doesn't support RATS");
} }
PrintAndLogEx(SUCCESS, " ATS : %s", sprint_hex(card.ats, card.ats_len)); PrintAndLogEx(SUCCESS, " ATS: %s", sprint_hex(card.ats, card.ats_len));
PrintAndLogEx(SUCCESS, " - TL : length is %d bytes", card.ats[0]); PrintAndLogEx(SUCCESS, " - TL : length is %d bytes", card.ats[0]);
if (card.ats[0] != card.ats_len - 2) { if (card.ats[0] != card.ats_len - 2) {
PrintAndLogEx(SUCCESS, "ATS may be corrupted. Length of ATS (%d bytes incl. 2 Bytes CRC) doesn't match TL", card.ats_len); PrintAndLogEx(SUCCESS, "ATS may be corrupted. Length of ATS (%d bytes incl. 2 Bytes CRC) doesn't match TL", card.ats_len);
@ -1626,17 +1626,17 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
if (res == 2 && verbose) if (res == 2 && verbose)
PrintAndLogEx(SUCCESS, "Static nonce: " _RED_("fail")); PrintAndLogEx(SUCCESS, "Static nonce: " _RED_("fail"));
} }
if (isMifareUltralight) { if (isMifareUltralight) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfu info`")); PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfu info`"));
} }
if (isMifarePlus) { if (isMifarePlus) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfp info`")); PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfp info`"));
} }
if (isMifareDesfire) { if (isMifareDesfire) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfdes info`")); PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfdes info`"));
} }
return select_status; return select_status;
} }

View file

@ -46,34 +46,34 @@ static int CmdHF14ADesInfo(const char *Cmd) {
break; break;
case 3: case 3:
default: default:
PrintAndLogEx(WARNING, "Command unsuccessful"); PrintAndLogEx(WARNING, _RED_("Command unsuccessful"));
break; break;
} }
return PM3_ESOFT; return PM3_ESOFT;
} }
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "-- Desfire Information --------------------------------------"); PrintAndLogEx(INFO, "-- Desfire Information --------------------------------------");
PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------");
PrintAndLogEx(NORMAL, " UID : %s", sprint_hex(resp.data.asBytes, 7)); PrintAndLogEx(SUCCESS, " UID : " _GREEN_("%s"), sprint_hex(resp.data.asBytes, 7));
PrintAndLogEx(NORMAL, " Batch number : %s", sprint_hex(resp.data.asBytes + 28, 5)); PrintAndLogEx(SUCCESS, " Batch number : " _GREEN_("%s"), sprint_hex(resp.data.asBytes + 28, 5));
PrintAndLogEx(NORMAL, " Production date : week %02x, 20%02x", resp.data.asBytes[33], resp.data.asBytes[34]); PrintAndLogEx(SUCCESS, " Production date : week %02x, 20%02x", resp.data.asBytes[33], resp.data.asBytes[34]);
PrintAndLogEx(NORMAL, " -----------------------------------------------------------"); PrintAndLogEx(INFO, " -----------------------------------------------------------");
PrintAndLogEx(NORMAL, " Hardware Information"); PrintAndLogEx(INFO, " Hardware Information");
PrintAndLogEx(NORMAL, " Vendor Id : %s", getTagInfo(resp.data.asBytes[7])); PrintAndLogEx(SUCCESS, " Vendor Id : " _YELLOW_("%s"), getTagInfo(resp.data.asBytes[7]));
PrintAndLogEx(NORMAL, " Type : 0x%02X", resp.data.asBytes[8]); PrintAndLogEx(SUCCESS, " Type : " _YELLOW_("0x%02X"), resp.data.asBytes[8]);
PrintAndLogEx(NORMAL, " Subtype : 0x%02X", resp.data.asBytes[9]); PrintAndLogEx(SUCCESS, " Subtype : " _YELLOW_("0x%02X"), resp.data.asBytes[9]);
PrintAndLogEx(NORMAL, " Version : %s", getVersionStr(resp.data.asBytes[10], resp.data.asBytes[11])); PrintAndLogEx(SUCCESS, " Version : " _YELLOW_("%s"), getVersionStr(resp.data.asBytes[10], resp.data.asBytes[11]));
PrintAndLogEx(NORMAL, " Storage size : %s", getCardSizeStr(resp.data.asBytes[12])); PrintAndLogEx(SUCCESS, " Storage size : " _YELLOW_("%s"), getCardSizeStr(resp.data.asBytes[12]));
PrintAndLogEx(NORMAL, " Protocol : %s", getProtocolStr(resp.data.asBytes[13])); PrintAndLogEx(SUCCESS, " Protocol : " _YELLOW_("%s"), getProtocolStr(resp.data.asBytes[13]));
PrintAndLogEx(NORMAL, " -----------------------------------------------------------"); PrintAndLogEx(INFO, " -----------------------------------------------------------");
PrintAndLogEx(NORMAL, " Software Information"); PrintAndLogEx(INFO, " Software Information");
PrintAndLogEx(NORMAL, " Vendor Id : %s", getTagInfo(resp.data.asBytes[14])); PrintAndLogEx(SUCCESS, " Vendor Id : " _YELLOW_("%s"), getTagInfo(resp.data.asBytes[14]));
PrintAndLogEx(NORMAL, " Type : 0x%02X", resp.data.asBytes[15]); PrintAndLogEx(SUCCESS, " Type : " _YELLOW_("0x%02X"), resp.data.asBytes[15]);
PrintAndLogEx(NORMAL, " Subtype : 0x%02X", resp.data.asBytes[16]); PrintAndLogEx(SUCCESS, " Subtype : " _YELLOW_("0x%02X"), resp.data.asBytes[16]);
PrintAndLogEx(NORMAL, " Version : %d.%d", resp.data.asBytes[17], resp.data.asBytes[18]); PrintAndLogEx(SUCCESS, " Version : " _YELLOW_("%d.%d"), resp.data.asBytes[17], resp.data.asBytes[18]);
PrintAndLogEx(NORMAL, " storage size : %s", getCardSizeStr(resp.data.asBytes[19])); PrintAndLogEx(SUCCESS, " storage size : " _YELLOW_("%s"), getCardSizeStr(resp.data.asBytes[19]));
PrintAndLogEx(NORMAL, " Protocol : %s", getProtocolStr(resp.data.asBytes[20])); PrintAndLogEx(SUCCESS, " Protocol : " _YELLOW_("%s"), getProtocolStr(resp.data.asBytes[20]));
PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------");
// Master Key settings // Master Key settings
getKeySettings(NULL); getKeySettings(NULL);
@ -87,8 +87,8 @@ static int CmdHF14ADesInfo(const char *Cmd) {
uint8_t tmp[3]; uint8_t tmp[3];
memcpy(tmp, resp.data.asBytes + 3, 3); memcpy(tmp, resp.data.asBytes + 3, 3);
PrintAndLogEx(NORMAL, " Available free memory on card : %d bytes", le24toh(tmp)); PrintAndLogEx(SUCCESS, " Available free memory on card : " _GREEN_("%d bytes"), le24toh(tmp));
PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------");
/* /*
Card Master key (CMK) 0x00 AID = 00 00 00 (card level) Card Master key (CMK) 0x00 AID = 00 00 00 (card level)
@ -168,8 +168,8 @@ void getKeySettings(uint8_t *aid) {
//memset(messStr, 0x00, 512); //memset(messStr, 0x00, 512);
if (aid == NULL) { if (aid == NULL) {
PrintAndLogEx(NORMAL, " CMK - PICC, Card Master Key settings "); PrintAndLogEx(SUCCESS, " CMK - PICC, Card Master Key settings");
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "-------------------------------------------------------------");
{ {
uint8_t data[1] = {GET_KEY_SETTINGS}; // 0x45 uint8_t data[1] = {GET_KEY_SETTINGS}; // 0x45
SendCommandOLD(CMD_HF_DESFIRE_COMMAND, INIT | DISCONNECT, sizeof(data), 0, data, sizeof(data)); SendCommandOLD(CMD_HF_DESFIRE_COMMAND, INIT | DISCONNECT, sizeof(data), 0, data, sizeof(data));
@ -177,18 +177,18 @@ void getKeySettings(uint8_t *aid) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;} if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
isOK = resp.oldarg[0] & 0xff; isOK = resp.oldarg[0] & 0xff;
if (!isOK) { if (!isOK) {
PrintAndLogEx(WARNING, " Can't select master application"); PrintAndLogEx(WARNING, _RED_(" Can't select master application"));
return; return;
} }
str = (resp.data.asBytes[3] & (1 << 3)) ? "YES" : "NO"; str = (resp.data.asBytes[3] & (1 << 3)) ? _GREEN_("YES") : _RED_("NO");
PrintAndLogEx(NORMAL, " [0x08] Configuration changeable : %s", str); PrintAndLogEx(SUCCESS, " [0x08] Configuration changeable : %s", str);
str = (resp.data.asBytes[3] & (1 << 2)) ? "NO" : "YES"; str = (resp.data.asBytes[3] & (1 << 2)) ? _RED_("NO") : _GREEN_("YES");
PrintAndLogEx(NORMAL, " [0x04] CMK required for create/delete : %s", str); PrintAndLogEx(SUCCESS, " [0x04] CMK required for create/delete : %s", str);
str = (resp.data.asBytes[3] & (1 << 1)) ? "NO" : "YES"; str = (resp.data.asBytes[3] & (1 << 1)) ? _RED_("NO") : _GREEN_("YES");
PrintAndLogEx(NORMAL, " [0x02] Directory list access with CMK : %s", str); PrintAndLogEx(SUCCESS, " [0x02] Directory list access with CMK : %s", str);
str = (resp.data.asBytes[3] & (1 << 0)) ? "YES" : "NO"; str = (resp.data.asBytes[3] & (1 << 0)) ? _GREEN_("YES") : _RED_("NO");
PrintAndLogEx(NORMAL, " [0x01] CMK is changeable : %s", str); PrintAndLogEx(SUCCESS, " [0x01] CMK is changeable : %s", str);
{ {
uint8_t data[2] = {GET_KEY_VERSION, 0}; // 0x64 uint8_t data[2] = {GET_KEY_VERSION, 0}; // 0x64
@ -198,13 +198,13 @@ void getKeySettings(uint8_t *aid) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) { return; } if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) { return; }
isOK = resp.oldarg[0] & 0xff; isOK = resp.oldarg[0] & 0xff;
if (!isOK) { if (!isOK) {
PrintAndLogEx(WARNING, " Can't read key-version"); PrintAndLogEx(WARNING, _RED_(" Can't read key-version"));
return; return;
} }
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(SUCCESS, "");
PrintAndLogEx(NORMAL, " Max number of keys : %d", resp.data.asBytes[4]); PrintAndLogEx(SUCCESS, " Max number of keys : %d", resp.data.asBytes[4]);
PrintAndLogEx(NORMAL, " Master key Version : %d (0x%02x)", resp.data.asBytes[3], resp.data.asBytes[3]); PrintAndLogEx(SUCCESS, " Master key Version : %d (0x%02x)", resp.data.asBytes[3], resp.data.asBytes[3]);
PrintAndLogEx(NORMAL, " ----------------------------------------------------------"); PrintAndLogEx(INFO, " ----------------------------------------------------------");
{ {
uint8_t data[2] = {AUTHENTICATE, 0}; // 0x0A, KEY 0 uint8_t data[2] = {AUTHENTICATE, 0}; // 0x0A, KEY 0
@ -213,7 +213,7 @@ void getKeySettings(uint8_t *aid) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;} if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
isOK = resp.data.asBytes[2] & 0xff; isOK = resp.data.asBytes[2] & 0xff;
PrintAndLogEx(NORMAL, " [0x0A] Authenticate : %s", (isOK == 0xAE) ? "NO" : "YES"); PrintAndLogEx(SUCCESS, " [0x0A] Authenticate : %s", (isOK == 0xAE) ? "NO" : _YELLOW_("YES"));
{ {
uint8_t data[2] = {AUTHENTICATE_ISO, 0}; // 0x1A, KEY 0 uint8_t data[2] = {AUTHENTICATE_ISO, 0}; // 0x1A, KEY 0
@ -222,7 +222,7 @@ void getKeySettings(uint8_t *aid) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;} if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
isOK = resp.data.asBytes[2] & 0xff; isOK = resp.data.asBytes[2] & 0xff;
PrintAndLogEx(NORMAL, " [0x1A] Authenticate ISO : %s", (isOK == 0xAE) ? "NO" : "YES"); PrintAndLogEx(SUCCESS, " [0x1A] Authenticate ISO : %s", (isOK == 0xAE) ? "NO" : _YELLOW_("YES"));
{ {
uint8_t data[2] = {AUTHENTICATE_AES, 0}; // 0xAA, KEY 0 uint8_t data[2] = {AUTHENTICATE_AES, 0}; // 0xAA, KEY 0
@ -231,12 +231,12 @@ void getKeySettings(uint8_t *aid) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;} if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
isOK = resp.data.asBytes[2] & 0xff; isOK = resp.data.asBytes[2] & 0xff;
PrintAndLogEx(NORMAL, " [0xAA] Authenticate AES : %s", (isOK == 0xAE) ? "NO" : "YES"); PrintAndLogEx(SUCCESS, " [0xAA] Authenticate AES : %s", (isOK == 0xAE) ? "NO" : _YELLOW_("YES"));
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "-------------------------------------------------------------");
PrintAndLogEx(NORMAL, " ----------------------------------------------------------");
} else { } else {
PrintAndLogEx(NORMAL, " AMK - Application Master Key settings"); PrintAndLogEx(SUCCESS, " AMK - Application Master Key settings");
PrintAndLogEx(INFO, " ----------------------------------------------------------");
// SELECT AID // SELECT AID
{ {
@ -245,12 +245,12 @@ void getKeySettings(uint8_t *aid) {
SendCommandMIX(CMD_HF_DESFIRE_COMMAND, INIT | CLEARTRACE, sizeof(data), 0, data, sizeof(data)); SendCommandMIX(CMD_HF_DESFIRE_COMMAND, INIT | CLEARTRACE, sizeof(data), 0, data, sizeof(data));
} }
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
PrintAndLogEx(WARNING, " Timed-out"); PrintAndLogEx(WARNING, _RED_(" Timed-out"));
return; return;
} }
isOK = resp.oldarg[0] & 0xff; isOK = resp.oldarg[0] & 0xff;
if (!isOK) { if (!isOK) {
PrintAndLogEx(WARNING, " Can't select AID: %s", sprint_hex(aid, 3)); PrintAndLogEx(WARNING, " Can't select AID: " _RED_("%s"), sprint_hex(aid, 3));
return; return;
} }
@ -265,7 +265,7 @@ void getKeySettings(uint8_t *aid) {
} }
isOK = resp.oldarg[0] & 0xff; isOK = resp.oldarg[0] & 0xff;
if (!isOK) { if (!isOK) {
PrintAndLogEx(WARNING, " Can't read Application Master key settings"); PrintAndLogEx(WARNING, _RED_(" Can't read Application Master key settings"));
} else { } else {
// Access rights. // Access rights.
uint8_t rights = (resp.data.asBytes[3] >> 4 & 0xff); uint8_t rights = (resp.data.asBytes[3] >> 4 & 0xff);
@ -283,18 +283,18 @@ void getKeySettings(uint8_t *aid) {
str = "Authentication with the specified key is necessary to change any key. A change key and a PICC master key (CMK) can only be changed after authentication with the master key. For keys other then the master or change key, an authentication with the same key is needed."; str = "Authentication with the specified key is necessary to change any key. A change key and a PICC master key (CMK) can only be changed after authentication with the master key. For keys other then the master or change key, an authentication with the same key is needed.";
break; break;
} }
PrintAndLogEx(NORMAL, "Changekey Access rights"); PrintAndLogEx(SUCCESS, "Changekey Access rights");
PrintAndLogEx(NORMAL, "-- %s", str); PrintAndLogEx(SUCCESS, "-- " _GREEN_("%s"), str);
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(SUCCESS, "");
// same as CMK // same as CMK
str = (resp.data.asBytes[3] & (1 << 3)) ? "YES" : "NO"; str = (resp.data.asBytes[3] & (1 << 3)) ? "YES" : "NO";
PrintAndLogEx(NORMAL, " 0x08 Configuration changeable : %s", str); PrintAndLogEx(SUCCESS, " 0x08 Configuration changeable : %s", str);
str = (resp.data.asBytes[3] & (1 << 2)) ? "NO" : "YES"; str = (resp.data.asBytes[3] & (1 << 2)) ? "NO" : "YES";
PrintAndLogEx(NORMAL, " 0x04 AMK required for create/delete : %s", str); PrintAndLogEx(SUCCESS, " 0x04 AMK required for create/delete : %s", str);
str = (resp.data.asBytes[3] & (1 << 1)) ? "NO" : "YES"; str = (resp.data.asBytes[3] & (1 << 1)) ? "NO" : "YES";
PrintAndLogEx(NORMAL, " 0x02 Directory list access with AMK : %s", str); PrintAndLogEx(SUCCESS, " 0x02 Directory list access with AMK : %s", str);
str = (resp.data.asBytes[3] & (1 << 0)) ? "YES" : "NO"; str = (resp.data.asBytes[3] & (1 << 0)) ? "YES" : "NO";
PrintAndLogEx(NORMAL, " 0x01 AMK is changeable : %s", str); PrintAndLogEx(SUCCESS, " 0x01 AMK is changeable : %s", str);
} }
// KEY VERSION - AMK // KEY VERSION - AMK
@ -304,7 +304,7 @@ void getKeySettings(uint8_t *aid) {
} }
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
PrintAndLogEx(WARNING, " Timed-out"); PrintAndLogEx(WARNING, _RED_(" Timed-out"));
return; return;
} }
@ -316,10 +316,9 @@ void getKeySettings(uint8_t *aid) {
//numOfKeys = MAX_NUM_KEYS; //numOfKeys = MAX_NUM_KEYS;
} else { } else {
numOfKeys = resp.data.asBytes[4]; numOfKeys = resp.data.asBytes[4];
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(SUCCESS, " Max number of keys : %d", numOfKeys);
PrintAndLogEx(NORMAL, " Max number of keys : %d", numOfKeys); PrintAndLogEx(SUCCESS, " Application Master key Version : %d (0x%02x)", resp.data.asBytes[3], resp.data.asBytes[3]);
PrintAndLogEx(NORMAL, " Application Master key Version : %d (0x%02x)", resp.data.asBytes[3], resp.data.asBytes[3]); PrintAndLogEx(INFO, "-------------------------------------------------------------");
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
} }
// LOOP over numOfKeys that we got before. // LOOP over numOfKeys that we got before.
@ -349,12 +348,12 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
isOK = resp.oldarg[0] & 0xff; isOK = resp.oldarg[0] & 0xff;
if (!isOK) { if (!isOK) {
PrintAndLogEx(NORMAL, "Command unsuccessful"); PrintAndLogEx(WARNING, _RED_("Command unsuccessful"));
return PM3_ESOFT; return PM3_ESOFT;
} }
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "-- Desfire Enumerate Applications ---------------------------"); PrintAndLogEx(SUCCESS, "-- Desfire Enumerate Applications ---------------------------");
PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------");
PacketResponseNG respAid; PacketResponseNG respAid;
PacketResponseNG respFiles; PacketResponseNG respFiles;
@ -363,7 +362,7 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
int max = resp.oldarg[1] - 3 - 2; int max = resp.oldarg[1] - 3 - 2;
for (int i = 3; i <= max; i += 3) { for (int i = 3; i <= max; i += 3) {
PrintAndLogEx(NORMAL, " Aid %d : %02X %02X %02X ", num, resp.data.asBytes[i], resp.data.asBytes[i + 1], resp.data.asBytes[i + 2]); PrintAndLogEx(SUCCESS, " Aid %d : %02X %02X %02X ", num, resp.data.asBytes[i], resp.data.asBytes[i + 1], resp.data.asBytes[i + 2]);
num++; num++;
aid[0] = resp.data.asBytes[i]; aid[0] = resp.data.asBytes[i];
@ -379,12 +378,12 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
} }
if (!WaitForResponseTimeout(CMD_ACK, &respAid, 1500)) { if (!WaitForResponseTimeout(CMD_ACK, &respAid, 1500)) {
PrintAndLogEx(WARNING, " Timed-out"); PrintAndLogEx(WARNING, _RED_(" Timed-out"));
continue; continue;
} }
isOK = respAid.data.asBytes[2] & 0xff; isOK = respAid.data.asBytes[2] & 0xff;
if (isOK != 0x00) { if (isOK != 0x00) {
PrintAndLogEx(WARNING, " Can't select AID: %s", sprint_hex(resp.data.asBytes + i, 3)); PrintAndLogEx(WARNING, " Can't select AID: " _RED_("%s"), sprint_hex(resp.data.asBytes + i, 3));
continue; continue;
} }
@ -395,16 +394,16 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
} }
if (!WaitForResponseTimeout(CMD_ACK, &respFiles, 1500)) { if (!WaitForResponseTimeout(CMD_ACK, &respFiles, 1500)) {
PrintAndLogEx(WARNING, " Timed-out"); PrintAndLogEx(WARNING, _RED_(" Timed-out"));
continue; continue;
} else { } else {
isOK = respFiles.data.asBytes[2] & 0xff; isOK = respFiles.data.asBytes[2] & 0xff;
if (!isOK) { if (!isOK) {
PrintAndLogEx(WARNING, " Can't get file ids "); PrintAndLogEx(WARNING, _RED_(" Can't get file ids "));
} else { } else {
int respfileLen = resp.oldarg[1] - 3 - 2; int respfileLen = resp.oldarg[1] - 3 - 2;
for (int j = 0; j < respfileLen; ++j) { for (int j = 0; j < respfileLen; ++j) {
PrintAndLogEx(NORMAL, " Fileid %d :", resp.data.asBytes[j + 3]); PrintAndLogEx(SUCCESS, " Fileid %d :", resp.data.asBytes[j + 3]);
} }
} }
} }
@ -416,21 +415,21 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
} }
if (!WaitForResponseTimeout(CMD_ACK, &respFiles, 1500)) { if (!WaitForResponseTimeout(CMD_ACK, &respFiles, 1500)) {
PrintAndLogEx(WARNING, " Timed-out"); PrintAndLogEx(WARNING, _RED_(" Timed-out"));
continue; continue;
} else { } else {
isOK = respFiles.data.asBytes[2] & 0xff; isOK = respFiles.data.asBytes[2] & 0xff;
if (!isOK) { if (!isOK) {
PrintAndLogEx(WARNING, " Can't get ISO file ids "); PrintAndLogEx(WARNING, _RED_(" Can't get ISO file ids"));
} else { } else {
int respfileLen = resp.oldarg[1] - 3 - 2; int respfileLen = resp.oldarg[1] - 3 - 2;
for (int j = 0; j < respfileLen; ++j) { for (int j = 0; j < respfileLen; ++j) {
PrintAndLogEx(NORMAL, " ISO Fileid %d :", resp.data.asBytes[j + 3]); PrintAndLogEx(SUCCESS, " ISO Fileid %d :", resp.data.asBytes[j + 3]);
} }
} }
} }
} }
PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -457,8 +456,8 @@ static int CmdHF14ADesAuth(const char *Cmd) {
PrintAndLogEx(NORMAL, " 1 = DES 2 = 3DES 3 = 3K3DES 4 = AES"); PrintAndLogEx(NORMAL, " 1 = DES 2 = 3DES 3 = 3K3DES 4 = AES");
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf mfdes auth 1 1 0 11223344"); PrintAndLogEx(NORMAL, _YELLOW_(" hf mfdes auth 1 1 0 11223344"));
PrintAndLogEx(NORMAL, " hf mfdes auth 3 4 0 404142434445464748494a4b4c4d4e4f"); PrintAndLogEx(NORMAL, _YELLOW_(" hf mfdes auth 3 4 0 404142434445464748494a4b4c4d4e4f"));
return PM3_SUCCESS; return PM3_SUCCESS;
} }
uint8_t cmdAuthMode = param_get8(Cmd, 0); uint8_t cmdAuthMode = param_get8(Cmd, 0);
@ -531,14 +530,14 @@ static int CmdHF14ADesAuth(const char *Cmd) {
if (isOK) { if (isOK) {
uint8_t *session_key = resp.data.asBytes; uint8_t *session_key = resp.data.asBytes;
PrintAndLogEx(NORMAL, " Key :%s", sprint_hex(key, keylength)); PrintAndLogEx(SUCCESS, " Key : " _GREEN_("%s"), sprint_hex(key, keylength));
PrintAndLogEx(NORMAL, " SESSION :%s", sprint_hex(session_key, keylength)); PrintAndLogEx(SUCCESS, " SESSION : " _GREEN_("%s"), sprint_hex(session_key, keylength));
PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------");
//PrintAndLogEx(NORMAL, " Expected :B5 21 9E E8 1A A7 49 9D 21 96 68 7E 13 97 38 56"); //PrintAndLogEx(NORMAL, " Expected :B5 21 9E E8 1A A7 49 9D 21 96 68 7E 13 97 38 56");
} else { } else {
PrintAndLogEx(NORMAL, "Client command failed."); PrintAndLogEx(WARNING, _RED_("Client command failed."));
} }
PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -564,4 +563,3 @@ int CmdHFMFDes(const char *Cmd) {
clearCommandBuffer(); clearCommandBuffer();
return CmdsParse(CommandTable, Cmd); return CmdsParse(CommandTable, Cmd);
} }