From 2a4a9745c95ec70f494ff803236f241fbfc0956b Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 4 Nov 2019 21:18:37 +0200 Subject: [PATCH] aid search works --- client/aidsearch.c | 51 ++++++++++++++++++++++++++++++---------------- client/aidsearch.h | 2 ++ client/cmdhf14a.c | 34 ++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/client/aidsearch.c b/client/aidsearch.c index d139eebea..04aec92a5 100644 --- a/client/aidsearch.c +++ b/client/aidsearch.c @@ -102,37 +102,51 @@ bool aidCompare(const char *aidlarge, const char *aidsmall) { return false; } +bool AIDGetFromElm(json_t *data, uint8_t *aid, size_t aidmaxlen, int *aidlen) { + *aidlen = 0; + const char *hexaid = jsonStrGet(data, "AID"); + if (hexaid == NULL || strlen(hexaid) == 0) + return false; + + int res = param_gethex_to_eol(hexaid, 0, aid, aidmaxlen, aidlen); + if (res) + return false; + + return true; +} + int PrintAIDDescription(char *aid, bool verbose) { int retval = PM3_SUCCESS; - int elmindx = 0; json_t *root = AIDSearchInit(); - json_t *data = AIDSearchGetElm(root, elmindx); - if (data == NULL) + if (root == NULL) goto out; - while (aidCompare(jsonStrGet(data, "AID"), aid)) { - elmindx++; - if (elmindx > json_array_size(root)) - goto out; - data = AIDSearchGetElm(root, elmindx); - + json_t *elm = NULL; + for (int elmindx = 0; elmindx < json_array_size(root); elmindx++) { + json_t *data = AIDSearchGetElm(root, elmindx); if (data == NULL) - goto out; + continue; + if (aidCompare(jsonStrGet(data, "AID"), aid)) { + elm = data; + break; + } } + if (elm == NULL) + goto out; + // print here - const char *vaid = jsonStrGet(data, "AID"); - const char *vendor = jsonStrGet(data, "Vendor"); - const char *name = jsonStrGet(data, "Name"); - const char *country = jsonStrGet(data, "Country"); - const char *description = jsonStrGet(data, "Description"); - const char *type = jsonStrGet(data, "Type"); + const char *vaid = jsonStrGet(elm, "AID"); + const char *vendor = jsonStrGet(elm, "Vendor"); + const char *name = jsonStrGet(elm, "Name"); + const char *country = jsonStrGet(elm, "Country"); + const char *description = jsonStrGet(elm, "Description"); + const char *type = jsonStrGet(elm, "Type"); if (!verbose) { PrintAndLogEx(SUCCESS, "AID %s | %s | %s", vaid, vendor, name); } else { - PrintAndLogEx(NORMAL, "----------------------------------------"); PrintAndLogEx(SUCCESS, "Input AID: %s", aid); if (aid) PrintAndLogEx(SUCCESS, "Found AID: %s", vaid); @@ -153,4 +167,7 @@ out: return retval; } +int PrintAIDDescriptionBuf(uint8_t *aid, size_t aidlen, bool verbose) { + return PrintAIDDescription(sprint_hex_inrow(aid, aidlen), verbose); +} diff --git a/client/aidsearch.h b/client/aidsearch.h index c8ad8e1ad..4e6eaf8f9 100644 --- a/client/aidsearch.h +++ b/client/aidsearch.h @@ -19,8 +19,10 @@ #include int PrintAIDDescription(char *aid, bool verbose); +int PrintAIDDescriptionBuf(uint8_t *aid, size_t aidlen, bool verbose); json_t *AIDSearchInit(); json_t *AIDSearchGetElm(json_t *root, int elmindx); +bool AIDGetFromElm(json_t *data, uint8_t *aid, size_t aidmaxlen, int *aidlen); int AIDSearchFree(); #endif \ No newline at end of file diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 39167056a..2d2b90178 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -1496,7 +1496,39 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { } if (do_aid_search) { - PrintAIDDescription("315041592E5359532E4444463031", true); + int elmindx = 0; + json_t *root = AIDSearchInit(); + if (root != NULL) { + bool ActivateField = true; + for (elmindx = 0; elmindx < json_array_size(root); elmindx++) { + json_t *data = AIDSearchGetElm(root, elmindx); + uint8_t vaid[200] = {0}; + int vaidlen = 0; + if (!AIDGetFromElm(data, vaid, sizeof(vaid), &vaidlen) || !vaidlen) + continue; + + uint16_t sw = 0; + uint8_t result[1024] = {0}; + size_t resultlen = 0; + int res = EMVSelect(ECC_CONTACTLESS, ActivateField, true, vaid, vaidlen, result, sizeof(result), &resultlen, &sw, NULL); + ActivateField = false; + if (res) + continue; + + if (sw == 0x9000) { + PrintAndLogEx(NORMAL, "------------- Application OK -----------"); + PrintAndLogEx(NORMAL, "res: %s", sprint_hex(result, resultlen)); + PrintAIDDescriptionBuf(vaid, vaidlen, true); + } + + if (sw == 0x6283 || sw == 0x6285) { + PrintAndLogEx(NORMAL, "----------- Application blocked --------"); + PrintAIDDescriptionBuf(vaid, vaidlen, true); + } + + } + DropField(); + } } } else { PrintAndLogEx(INFO, "proprietary non iso14443-4 card found, RATS not supported");