hf seos info: Try to print more information

This commit is contained in:
Antonio Vázquez Blanco committed 2026-10-21 15:05:53 +02:00
1 parent 0b9597e8f3
commit 3a57bb112c
5 files changed
+172 -95

No files matched your search

+103 -93
View File
@@ -2933,6 +2933,107 @@ static void get_compact_tlv(uint8_t *d, uint8_t n) {
}
}
// selects every AID in aidlist.json, returns how many were found
int hf14a_aid_search(bool verbose) {
PrintAndLogEx(INFO, "-------------------- " _CYAN_("AID Search") " --------------------");
json_t *root = AIDSearchInit(verbose);
if (root == NULL) {
return 0;
}
int found = 0;
bool ActivateField = true;
for (size_t elmindx = 0; elmindx < json_array_size(root); elmindx++) {
if (kbd_enter_pressed()) {
break;
}
json_t *data = AIDSearchGetElm(root, elmindx);
uint8_t vaid[200] = {0};
int vaidlen = 0;
if ((AIDGetFromElm(data, vaid, sizeof(vaid), &vaidlen) == false) || (vaidlen == 0)) {
continue;
}
if (AIDSeenBefore(root, vaid, (size_t)vaidlen, elmindx)) {
continue;
}
uint16_t sw = 0;
uint8_t result[1024] = {0};
size_t resultlen = 0;
int res = Iso7816Select(CC_CONTACTLESS, ActivateField, true, vaid, vaidlen, result, sizeof(result), &resultlen, &sw);
ActivateField = false;
if (res) {
continue;
}
uint8_t dfname[200] = {0};
size_t dfnamelen = 0;
if (resultlen > 3) {
struct tlvdb *tlv = tlvdb_parse_multi(result, resultlen);
if (tlv) {
// 0x84 Dedicated File (DF) Name
const struct tlv *dfnametlv = tlvdb_get_tlv(tlvdb_find_full(tlv, 0x84));
if (dfnametlv) {
dfnamelen = dfnametlv->len;
memcpy(dfname, dfnametlv->value, dfnamelen);
}
tlvdb_free(tlv);
}
}
if (sw == ISO7816_OK || sw == ISO7816_INVALID_DF || sw == ISO7816_FILE_TERMINATED) {
if (sw == ISO7816_OK) {
if (verbose) PrintAndLogEx(SUCCESS, "Application ( " _GREEN_("ok") " )");
} else {
if (verbose) PrintAndLogEx(WARNING, "Application ( " _RED_("blocked") " )");
}
uint8_t response_for_match[1026] = {0};
size_t response_for_match_len = resultlen;
memcpy(response_for_match, result, MIN(resultlen, sizeof(response_for_match)));
if ((response_for_match_len + 2) <= sizeof(response_for_match)) {
response_for_match[response_for_match_len] = sw >> 8;
response_for_match[response_for_match_len + 1] = sw & 0xff;
response_for_match_len += 2;
}
PrintAIDDescriptionEx(root, sprint_hex_inrow(vaid, vaidlen), response_for_match, response_for_match_len, verbose);
if (dfnamelen) {
if (dfnamelen == vaidlen) {
if (memcmp(dfname, vaid, vaidlen) == 0) {
if (verbose) PrintAndLogEx(INFO, "(DF) Name found and equal to AID");
} else {
PrintAndLogEx(INFO, "(DF) Name not equal to AID: " _YELLOW_("%s"), sprint_hex_inrow(dfname, dfnamelen));
PrintAIDDescriptionBuf(root, dfname, dfnamelen, verbose);
}
} else {
PrintAndLogEx(INFO, "(DF) Name not equal to AID: " _YELLOW_("%s"), sprint_hex_inrow(dfname, dfnamelen));
PrintAIDDescriptionBuf(root, dfname, dfnamelen, verbose);
}
} else {
if (verbose) PrintAndLogEx(INFO, "(DF) Name not found");
}
if (verbose) PrintAndLogEx(SUCCESS, "----------------------------------------------------");
found++;
}
}
DropField();
if (verbose == false && found) {
PrintAndLogEx(INFO, "----------------------------------------------------");
}
AIDSearchFree(root);
return found;
}
int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
uint8_t dbg_curr = DBG_NONE;
@@ -3415,99 +3516,8 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
}
if (do_aid_search) {
PrintAndLogEx(INFO, "-------------------- " _CYAN_("AID Search") " --------------------");
json_t *root = AIDSearchInit(verbose);
if (root != NULL) {
bool found = false;
bool ActivateField = true;
for (size_t elmindx = 0; elmindx < json_array_size(root); elmindx++) {
if (kbd_enter_pressed()) {
break;
}
json_t *data = AIDSearchGetElm(root, elmindx);
uint8_t vaid[200] = {0};
int vaidlen = 0;
if ((AIDGetFromElm(data, vaid, sizeof(vaid), &vaidlen) == false) || (vaidlen == 0)) {
continue;
}
if (AIDSeenBefore(root, vaid, (size_t)vaidlen, elmindx)) {
continue;
}
uint16_t sw = 0;
uint8_t result[1024] = {0};
size_t resultlen = 0;
res = Iso7816Select(CC_CONTACTLESS, ActivateField, true, vaid, vaidlen, result, sizeof(result), &resultlen, &sw);
ActivateField = false;
if (res) {
continue;
}
uint8_t dfname[200] = {0};
size_t dfnamelen = 0;
if (resultlen > 3) {
struct tlvdb *tlv = tlvdb_parse_multi(result, resultlen);
if (tlv) {
// 0x84 Dedicated File (DF) Name
const struct tlv *dfnametlv = tlvdb_get_tlv(tlvdb_find_full(tlv, 0x84));
if (dfnametlv) {
dfnamelen = dfnametlv->len;
memcpy(dfname, dfnametlv->value, dfnamelen);
}
tlvdb_free(tlv);
}
}
if (sw == ISO7816_OK || sw == ISO7816_INVALID_DF || sw == ISO7816_FILE_TERMINATED) {
if (sw == ISO7816_OK) {
if (verbose) PrintAndLogEx(SUCCESS, "Application ( " _GREEN_("ok") " )");
} else {
if (verbose) PrintAndLogEx(WARNING, "Application ( " _RED_("blocked") " )");
}
uint8_t response_for_match[1026] = {0};
size_t response_for_match_len = resultlen;
memcpy(response_for_match, result, MIN(resultlen, sizeof(response_for_match)));
if ((response_for_match_len + 2) <= sizeof(response_for_match)) {
response_for_match[response_for_match_len] = sw >> 8;
response_for_match[response_for_match_len + 1] = sw & 0xff;
response_for_match_len += 2;
}
PrintAIDDescriptionEx(root, sprint_hex_inrow(vaid, vaidlen), response_for_match, response_for_match_len, verbose);
if (dfnamelen) {
if (dfnamelen == vaidlen) {
if (memcmp(dfname, vaid, vaidlen) == 0) {
if (verbose) PrintAndLogEx(INFO, "(DF) Name found and equal to AID");
} else {
PrintAndLogEx(INFO, "(DF) Name not equal to AID: " _YELLOW_("%s"), sprint_hex_inrow(dfname, dfnamelen));
PrintAIDDescriptionBuf(root, dfname, dfnamelen, verbose);
}
} else {
PrintAndLogEx(INFO, "(DF) Name not equal to AID: " _YELLOW_("%s"), sprint_hex_inrow(dfname, dfnamelen));
PrintAIDDescriptionBuf(root, dfname, dfnamelen, verbose);
}
} else {
if (verbose) PrintAndLogEx(INFO, "(DF) Name not found");
}
if (verbose) PrintAndLogEx(SUCCESS, "----------------------------------------------------");
found = true;
isEMV = true;
}
}
DropField();
if (verbose == false && found) {
PrintAndLogEx(INFO, "----------------------------------------------------");
}
if (hf14a_aid_search(verbose) > 0) {
isEMV = true;
}
}
+1
View File
@@ -88,6 +88,7 @@ int hf14a_getconfig(hf14a_config_t *config);
int hf14a_setconfig(hf14a_config_t *config, bool verbose);
int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search);
int infoHF14A4Applications(bool verbose);
int hf14a_aid_search(bool verbose);
const char *getTagInfo(uint8_t uid);
int Hf14443_4aGetCardData(iso14a_card_select_t *card);
int ExchangeAPDU14a(const uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
+66 -1
View File
@@ -36,6 +36,7 @@
#include "wiegand_formats.h"
#include "wiegand_formatutils.h"
#include "iso7816/apduinfo.h" // GetAPDUCodeDescription
#include "iso7816/iso7816core.h" // Iso7816Select
#include "crypto/asn1utils.h" // ASN1 decode / print
#include "crypto/libpcrypto.h" // AES decrypt
#include "commonutil.h" // get_sw
@@ -1674,10 +1675,69 @@ static int seos_load_keys(char *filename) {
return PM3_SUCCESS;
}
static void seos_print_aid_status(const uint8_t *aid, int aid_len) {
uint8_t response[PM3_CMD_DATA_SIZE] = {0};
size_t resplen = 0;
uint16_t sw = 0;
// fresh activation, an already selected applet may answer the SELECT itself
Iso7816Select(CC_CONTACTLESS, true, true, (uint8_t *)aid, aid_len, response, sizeof(response), &resplen, &sw);
// sw stays 0 when the card did not answer
if (sw == ISO7816_OK) {
PrintAndLogEx(SUCCESS, "%s ( " _GREEN_("ok") " )", sprint_hex_inrow(aid, aid_len));
} else if (sw != 0) {
PrintAndLogEx(INFO, "%s ( %04X - %s )", sprint_hex_inrow(aid, aid_len), sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
} else {
PrintAndLogEx(FAILED, "%s ( " _RED_("no answer") " )", sprint_hex_inrow(aid, aid_len));
}
}
static int seos_print_card(const uint8_t *custom_aid, int custom_aid_len) {
iso14a_card_select_t card;
int res = SelectCard14443A_4(false, true, &card);
if (res != PM3_SUCCESS) {
DropField();
return res;
}
PrintAndLogEx(INFO, "--- " _CYAN_("Card") " ---------------------------");
PrintAndLogEx(SUCCESS, "UID.............................. " _YELLOW_("%s"), sprint_hex(card.uid, card.uidlen));
PrintAndLogEx(SUCCESS, "ATQA............................. " _YELLOW_("%02X %02X"), card.atqa[1], card.atqa[0]);
PrintAndLogEx(SUCCESS, "SAK.............................. " _YELLOW_("%02X"), card.sak);
// ats_len includes CRC
if (card.ats_len > 2) {
PrintAndLogEx(SUCCESS, "ATS.............................. " _YELLOW_("%s"), sprint_hex(card.ats, card.ats_len - 2));
}
// SAK b4: MIFARE Classic, b5: 4K
if ((card.sak & 0x08) == 0x08) {
PrintAndLogEx(SUCCESS, "MIFARE Classic emulation......... " _YELLOW_("%s"), ((card.sak & 0x10) == 0x10) ? "4K" : "1K");
} else {
PrintAndLogEx(SUCCESS, "MIFARE Classic emulation......... " _YELLOW_("none"));
}
PrintAndLogEx(INFO, "--- " _CYAN_("SEOS AIDs") " ---------------------------");
if (custom_aid_len > 0) {
seos_print_aid_status(custom_aid, custom_aid_len);
} else {
for (size_t i = 0; i < ARRAYLEN(known_seos_aids); i++) {
uint8_t aid[MAX_SEOS_AID_LEN] = {0};
int aid_len = 0;
param_gethex_to_eol(known_seos_aids[i], 0, aid, sizeof(aid), &aid_len);
seos_print_aid_status(aid, aid_len);
}
}
DropField();
hf14a_aid_search(false);
return PM3_SUCCESS;
}
static int CmdHfSeosInfo(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf seos info",
"Requests the unauthenticated information from the default ADF of a SEOS card\n"
"Prints the card's UID, ATQA, SAK, ATS and MIFARE Classic emulation, which SEOS AIDs it answers\n"
"and which aidlist.json AIDs it has, then\n"
"requests the unauthenticated information from the default ADF of a SEOS card\n"
"- If the card is a SEOS card\n"
"- Are static RND.ICC keys used (can detect SEOS default keyset)\n"
"- What encryption and hashing algorithm is use\n\n"
@@ -1725,6 +1785,11 @@ static int CmdHfSeosInfo(const char *Cmd) {
if (res != PM3_SUCCESS) {
return res;
}
res = seos_print_card(aid, aid_len);
if (res != PM3_SUCCESS) {
return res;
}
return seos_select(aid, aid_len, privacy_key_index, auth_key_index);
}