From 8e199d4c9e67197fb8576132e8f8c056287d6514 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 20 Feb 2019 15:51:55 +0200 Subject: [PATCH 1/4] add get ATR to cmdsmartcard --- client/cmdsmartcard.c | 21 +++++++++++++-------- client/cmdsmartcard.h | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index 23b2b8b3c..9496b5445 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -292,7 +292,10 @@ static int PrintATR(uint8_t *atr, size_t atrlen) { return 0; } -static bool smart_select(bool silent) { +bool smart_select(bool silent, smart_card_atr_t *atr) { + if (atr) + memset(atr, 0, sizeof(smart_card_atr_t)); + UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}}; clearCommandBuffer(); SendCommand(&c); @@ -308,12 +311,14 @@ static bool smart_select(bool silent) { return false; } - if (!silent) { - smart_card_atr_t card; - memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t)); - + smart_card_atr_t card; + memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t)); + + if (atr) + memcpy(atr, &card, sizeof(smart_card_atr_t)); + + if (!silent) PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len)); - } return true; } @@ -518,7 +523,7 @@ int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leave *dataoutlen = 0; if (activateCard) - smart_select(false); + smart_select(false, NULL); PrintAndLogEx(DEBUG, "APDU SC"); @@ -1017,7 +1022,7 @@ int CmdSmartBruteforceSFI(const char *Cmd) { return 1; PrintAndLogEx(INFO, "Selecting card"); - if ( !smart_select(false) ) + if ( !smart_select(false, NULL) ) return 1; char* caid = NULL; diff --git a/client/cmdsmartcard.h b/client/cmdsmartcard.h index cffaeff98..00bc41ff4 100644 --- a/client/cmdsmartcard.h +++ b/client/cmdsmartcard.h @@ -33,6 +33,7 @@ extern int CmdSmartUpgrade(const char* cmd); extern int CmdSmartInfo(const char* cmd); extern int CmdSmartReader(const char *Cmd); +extern bool smart_select(bool silent, smart_card_atr_t *atr); extern int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen); extern int usage_sm_raw(void); From fe66f0fac4f9b6e61b81ac979e43a953f3c6a46b Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 20 Feb 2019 15:52:26 +0200 Subject: [PATCH 2/4] added contact to `emv scan` --- client/emv/cmdemv.c | 49 ++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index e2988e1e7..de86d5343 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -1382,12 +1382,6 @@ int CmdEMVScan(const char *cmd) { SetAPDULogging(showAPDU); - // TODO - if (channel == ECC_CONTACT) { - PrintAndLogEx(ERR, "Do not use contact interface. Exit."); - return 1; - } - // current path + file name if (!strstr(crelfname, ".json")) strcat(crelfname, ".json"); @@ -1411,23 +1405,35 @@ int CmdEMVScan(const char *cmd) { } // drop field at start - DropFieldEx( channel ); - - // iso 14443 select - PrintAndLogEx(NORMAL, "--> GET UID, ATS."); - - iso14a_card_select_t card; - if (Hf14443_4aGetCardData(&card)) { - return 2; - } + if (channel == ECC_CONTACTLESS) + DropFieldEx( channel ); JsonSaveStr(root, "$.File.Created", "proxmark3 `emv scan`"); - JsonSaveStr(root, "$.Card.Communication", "iso14443-4a"); - JsonSaveBufAsHex(root, "$.Card.UID", (uint8_t *)&card.uid, card.uidlen); - JsonSaveHex(root, "$.Card.ATQA", card.atqa[0] + (card.atqa[1] << 2), 2); - JsonSaveHex(root, "$.Card.SAK", card.sak, 0); - JsonSaveBufAsHex(root, "$.Card.ATS", (uint8_t *)card.ats, card.ats_len); + if (channel == ECC_CONTACTLESS) { + // iso 14443 select + PrintAndLogEx(NORMAL, "--> GET UID, ATS."); + + iso14a_card_select_t card; + if (Hf14443_4aGetCardData(&card)) { + return 2; + } + + + JsonSaveStr(root, "$.Card.Contactless.Communication", "iso14443-4a"); + JsonSaveBufAsHex(root, "$.Card.Contactless.UID", (uint8_t *)&card.uid, card.uidlen); + JsonSaveHex(root, "$.Card.Contactless.ATQA", card.atqa[0] + (card.atqa[1] << 2), 2); + JsonSaveHex(root, "$.Card.Contactless.SAK", card.sak, 0); + JsonSaveBufAsHex(root, "$.Card.Contactless.ATS", (uint8_t *)card.ats, card.ats_len); + } else { + PrintAndLogEx(NORMAL, "--> GET ATR."); + + smart_card_atr_t card; + smart_select(true, &card); + + JsonSaveStr(root, "$.Card.Contact.Communication", "iso7816"); + JsonSaveBufAsHex(root, "$.Card.Contact.ATR", (uint8_t *)card.atr, card.atr_len); + } // init applets list tree const char *al = "Applets list"; @@ -1642,7 +1648,8 @@ int CmdEMVScan(const char *cmd) { // free tlv object tlvdb_free(tlvRoot); - DropFieldEx( channel ); + if (channel == ECC_CONTACTLESS) + DropFieldEx( channel ); res = json_dump_file(root, fname, JSON_INDENT(2)); if (res) { From ed991e76b4dd638ced3f32485068f84a2a18f528 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 20 Feb 2019 16:04:08 +0200 Subject: [PATCH 3/4] add print error if smart card functionality not defined --- client/emv/cmdemv.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index de86d5343..6f5917b8d 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -792,6 +792,14 @@ int CmdEMVExec(const char *cmd) { uint8_t psenum = (channel == ECC_CONTACT) ? 1 : 2; CLIParserFree(); +#ifndef WITH_SMARTCARD + // not compiled with smartcard functionality, we need to exit + if ( channel == ECC_CONTACT ) { + PrintAndLogEx(WARNING, "PM3 Client is not compiled with support for SMARTCARD. Exiting."); + return 0; + } +#endif + SetAPDULogging(showAPDU); // init applets list tree @@ -1380,6 +1388,14 @@ int CmdEMVScan(const char *cmd) { CLIGetStrWithReturn(12, relfname, &relfnamelen); CLIParserFree(); +#ifndef WITH_SMARTCARD + // not compiled with smartcard functionality, we need to exit + if ( channel == ECC_CONTACT ) { + PrintAndLogEx(WARNING, "PM3 Client is not compiled with support for SMARTCARD. Exiting."); + return 0; + } +#endif + SetAPDULogging(showAPDU); // current path + file name @@ -1418,7 +1434,6 @@ int CmdEMVScan(const char *cmd) { if (Hf14443_4aGetCardData(&card)) { return 2; } - JsonSaveStr(root, "$.Card.Contactless.Communication", "iso14443-4a"); JsonSaveBufAsHex(root, "$.Card.Contactless.UID", (uint8_t *)&card.uid, card.uidlen); @@ -1702,6 +1717,7 @@ int CmdEMVRoca(const char *cmd) { if (arg_get_lit(2)) channel = ECC_CONTACT; PrintChannel(channel); + CLIParserFree(); #ifndef WITH_SMARTCARD // not compiled with smartcard functionality, we need to exit From 12582df97657f9fbf7ad8fae431ec5034cd93409 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 20 Feb 2019 16:05:32 +0200 Subject: [PATCH 4/4] fix macro --- client/emv/cmdemv.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index 6f5917b8d..3e36a4ae6 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -1421,8 +1421,7 @@ int CmdEMVScan(const char *cmd) { } // drop field at start - if (channel == ECC_CONTACTLESS) - DropFieldEx( channel ); + DropFieldEx( channel ); JsonSaveStr(root, "$.File.Created", "proxmark3 `emv scan`"); @@ -1663,8 +1662,7 @@ int CmdEMVScan(const char *cmd) { // free tlv object tlvdb_free(tlvRoot); - if (channel == ECC_CONTACTLESS) - DropFieldEx( channel ); + DropFieldEx( channel ); res = json_dump_file(root, fname, JSON_INDENT(2)); if (res) {