diff --git a/CHANGELOG.md b/CHANGELOG.md index ed09b06ec..3e05dc1a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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... ## [unreleased][unreleased] + - Changed `emv reader -v` - now can decode track1 data if found (@iceman1001) - Added `emv reader` - act as a EMV reader (@iceman1001) - Added support for Apple Wallet NFC Passes with the Value Added Services protocol implementation (@gm3197) - Fix compiling liblua on iOS (@The-SamminAter) diff --git a/client/src/emv/cmdemv.c b/client/src/emv/cmdemv.c index 1f57acbb1..169c24b69 100644 --- a/client/src/emv/cmdemv.c +++ b/client/src/emv/cmdemv.c @@ -75,7 +75,67 @@ static void PrintChannel(Iso7816CommandChannel channel) { } } -static int emv_parse_card_details(uint8_t *response, size_t reslen) { +static int emv_parse_track1(const uint8_t *d, size_t n, bool verbose){ + if (d == NULL || n < 10) { + return PM3_EINVARG; + } + if (verbose == false) { + return PM3_SUCCESS; + } + + // sanity checks + if (d[0] != 'B') { + return PM3_EINVARG; + } + + // decoder + char delim[2] = "^"; + char *tmp = str_ndup((const char*)d, n); + + uint8_t i = 0; + char *token = strtok(tmp, delim); + while (token != NULL) { + + switch(i) { + case 0: + PrintAndLogEx(INFO, "PAN............ %c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c", + token[1], token[2],token[3], token[4], + token[5], token[6],token[7], token[8], + token[9], token[10],token[11], token[12], + token[13], token[14],token[15], token[16] + ); + break; + case 1: + PrintAndLogEx(INFO, "CardHolder..... %s", token); + break; + case 2: + if (strlen(token) < 17) { + break; + } + PrintAndLogEx(INFO, "Expiry date.... %.*s", 4, token); + token += 4; + + PrintAndLogEx(INFO, "Service code... %.*s", 3, token); + token += 3; + + PrintAndLogEx(INFO, "Unknown........ %.*s", 4, token); + token += 4; + + PrintAndLogEx(INFO, "CVV / iCvv..... %.*s", 3, token); + token +=3; + + PrintAndLogEx(INFO, "Trailing....... %s", token); + break; + default: + break; + } + token = strtok(0, delim); + i++; + } + return PM3_SUCCESS; +} + +static int emv_parse_card_details(uint8_t *response, size_t reslen, bool verbose) { struct tlvdb *root = tlvdb_parse_multi(response, reslen); if (root == NULL) { @@ -196,6 +256,7 @@ static int emv_parse_card_details(uint8_t *response, size_t reslen) { const struct tlv *track1_tlv = tlvdb_get_tlv(track1_full); if (track1_tlv->len) { PrintAndLogEx(INFO, "Track 1.............. " _YELLOW_("%s"), sprint_ascii(track1_tlv->value, track1_tlv->len)); + emv_parse_track1(track1_tlv->value, track1_tlv->len, verbose); } } @@ -2282,6 +2343,7 @@ static int CmdEMVReader(const char *Cmd) { void *argtable[] = { arg_param_begin, arg_lit0("w", "wired", "Send data via contact (iso7816) interface. (def: Contactless interface)"), + arg_lit0("v", "verbose", "verbose"), arg_lit0("@", NULL, "continuous reader mode"), arg_param_end }; @@ -2293,15 +2355,14 @@ static int CmdEMVReader(const char *Cmd) { } uint8_t psenum = (channel == CC_CONTACT) ? 1 : 2; - - bool continuous = arg_get_lit(ctx, 2); + bool verbose = arg_get_lit(ctx, 2); + bool continuous = arg_get_lit(ctx, 3); CLIParserFree(ctx); if (continuous) { PrintAndLogEx(INFO, "Press " _GREEN_("Enter") " to exit"); } - uint8_t AID[APDU_AID_LEN] = {0}; size_t AIDlen = 0; uint8_t buf[APDU_RES_LEN] = {0}; @@ -2353,7 +2414,7 @@ static int CmdEMVReader(const char *Cmd) { } // decode application parts - emv_parse_card_details(buf, len); + emv_parse_card_details(buf, len, verbose); for (TransactionType_t tt = TT_MSD; tt < TT_END; tt++) { @@ -2383,7 +2444,7 @@ static int CmdEMVReader(const char *Cmd) { ProcessGPOResponseFormat1(tlvRoot, buf, len, false); - emv_parse_card_details(buf, len); + emv_parse_card_details(buf, len, verbose); if (tlvdb_get(tlvRoot, 0x77, NULL)) { break; @@ -2412,7 +2473,7 @@ static int CmdEMVReader(const char *Cmd) { if (res) { continue; } - emv_parse_card_details(buf, len); + emv_parse_card_details(buf, len, verbose); } } }