diff --git a/client/src/cmdhfcipurse.c b/client/src/cmdhfcipurse.c index 379b88b1e..4f6cf68f7 100644 --- a/client/src/cmdhfcipurse.c +++ b/client/src/cmdhfcipurse.c @@ -533,7 +533,8 @@ static int CmdHFCipurseReadFile(const char *Cmd) { CLIParserInit(&ctx, "hf cipurse read", "Read file by file ID with key ID and key. If no key is supplied, default key of 737373...7373 will be used", "hf cipurse read --fid 2ff7 -> Authenticate with keyID 1, read file with id 2ff7\n" - "hf cipurse read -n 2 -k 65656565656565656565656565656565 --fid 2ff7 -> Authenticate keyID 2 and read file\n"); + "hf cipurse read -n 2 -k 65656565656565656565656565656565 --fid 2ff7 -> Authenticate keyID 2 and read file\n" + "hf cipurse read --aid 4144204631 --fid 0102 -> read file with id 0102 from application 4144204631\n"); void *argtable[] = { arg_param_begin, @@ -541,6 +542,7 @@ static int CmdHFCipurseReadFile(const char *Cmd) { arg_lit0("v", "verbose", "show technical data"), arg_int0("n", NULL, "", "key ID"), arg_str0("k", "key", "", "Auth key"), + arg_str0(NULL, "aid", "", "application ID (AID)"), arg_str0(NULL, "fid", "", "file ID"), arg_int0("o", "offset", "", "offset for reading data from file"), arg_lit0(NULL, "noauth", "read file without authentication"), @@ -559,17 +561,20 @@ static int CmdHFCipurseReadFile(const char *Cmd) { CipurseChannelSecurityLevel sresp = CPSMACed; uint8_t key[CIPURSE_AES_KEY_LENGTH] = {0}; + uint8_t aid[16] = {0}; + size_t aidLen = 0; + bool useAID = false; uint16_t fileId = defaultFileId; bool useFID = false; - int res = CLIParseCommandParameters(ctx, 4, 0, 5, 8, 9, key, NULL, NULL, NULL, &fileId, &useFID, &sreq, &sresp); + int res = CLIParseCommandParameters(ctx, 4, 5, 6, 9, 10, key, aid, &aidLen, &useAID, &fileId, &useFID, &sreq, &sresp); if (res || useFID == false) { CLIParserFree(ctx); return PM3_EINVARG; } - size_t offset = arg_get_int_def(ctx, 6, 0); + size_t offset = arg_get_int_def(ctx, 7, 0); - bool noAuth = arg_get_lit(ctx, 7); + bool noAuth = arg_get_lit(ctx, 8); SetAPDULogging(APDULogging); @@ -579,15 +584,17 @@ static int CmdHFCipurseReadFile(const char *Cmd) { uint16_t sw = 0; uint8_t buf[APDU_RES_LEN] = {0}; - res = CIPURSESelect(true, true, buf, sizeof(buf), &len, &sw); + res = CIPURSESelectAID(true, true, aid, aidLen, buf, sizeof(buf), &len, &sw); if (res != 0 || sw != 0x9000) { - PrintAndLogEx(ERR, "Cipurse select " _RED_("error") ". Card returns 0x%04x", sw); + PrintAndLogEx(ERR, "Cipurse select application " _CYAN_("%s") " ( " _RED_("error") " ). Card returns 0x%04x", sprint_hex_inrow(aid, aidLen), sw); DropField(); return PM3_ESOFT; } - if (verbose) + if (verbose) { + PrintAndLogEx(INFO, "Cipurse select application " _CYAN_("%s") " ( " _GREEN_("ok") " )", sprint_hex_inrow(aid, aidLen)); PrintAndLogEx(INFO, "File id " _YELLOW_("%x") " offset " _YELLOW_("%zu") " key id " _YELLOW_("%d") " key " _YELLOW_("%s"), fileId, offset, keyId, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)); + } if (noAuth == false) { bool bres = CIPURSEChannelAuthenticate(keyId, key, verbose); @@ -605,7 +612,7 @@ static int CmdHFCipurseReadFile(const char *Cmd) { res = CIPURSESelectFile(fileId, buf, sizeof(buf), &len, &sw); if (res != 0 || sw != 0x9000) { if (verbose == false) - PrintAndLogEx(ERR, "File select " _RED_("ERROR") ". Card returns 0x%04x", sw); + PrintAndLogEx(ERR, "File select ( " _RED_("error") " ). Card returns 0x%04x", sw); DropField(); return PM3_ESOFT; } @@ -1280,6 +1287,7 @@ static int CmdHFCipurseDefault(const char *Cmd) { memcpy(defaultKey, ckey, CIPURSE_AES_KEY_LENGTH); uint8_t aid[CIPURSE_MAX_AID_LENGTH] = CIPURSE_DEFAULT_AID; memcpy(defaultAID, aid, CIPURSE_MAX_AID_LENGTH); + defaultAIDLength = 5; } defaultKeyId = arg_get_int_def(ctx, 2, defaultKeyId);