chg: 'hf search' - add FeliCa detection

This commit is contained in:
iceman1001 2019-10-17 21:58:57 +02:00
commit 9fdc29e91c
2 changed files with 49 additions and 43 deletions

View file

@ -70,6 +70,8 @@ static int usage_hf_tune() {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
#define PROMPT_CLEARLINE PrintAndLogEx(INPLACE, " ")
int CmdHFSearch(const char *Cmd) { int CmdHFSearch(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0)); char cmdp = tolower(param_getchar(Cmd, 0));
@ -77,6 +79,7 @@ int CmdHFSearch(const char *Cmd) {
PrintAndLogEx(INFO, "Checking for known tags...\n"); PrintAndLogEx(INFO, "Checking for known tags...\n");
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, "Searching for ThinFilm tag..."); PrintAndLogEx(INPLACE, "Searching for ThinFilm tag...");
if (IfPm3NfcBarcode()) { if (IfPm3NfcBarcode()) {
if (infoThinFilm(false) == PM3_SUCCESS) { if (infoThinFilm(false) == PM3_SUCCESS) {
@ -85,6 +88,7 @@ int CmdHFSearch(const char *Cmd) {
} }
} }
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, "Searching for ISO14443-A tag..."); PrintAndLogEx(INPLACE, "Searching for ISO14443-A tag...");
if (IfPm3Iso14443a()) { if (IfPm3Iso14443a()) {
if (infoHF14A(false, false) > 0) { if (infoHF14A(false, false) > 0) {
@ -93,6 +97,7 @@ int CmdHFSearch(const char *Cmd) {
} }
} }
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, "Searching for ISO15693 tag..."); PrintAndLogEx(INPLACE, "Searching for ISO15693 tag...");
if (IfPm3Iso15693()) { if (IfPm3Iso15693()) {
if (readHF15Uid(false) == 1) { if (readHF15Uid(false) == 1) {
@ -104,6 +109,7 @@ int CmdHFSearch(const char *Cmd) {
DropField(); DropField();
} }
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, "Searching for LEGIC tag..."); PrintAndLogEx(INPLACE, "Searching for LEGIC tag...");
if (IfPm3Legicrf()) { if (IfPm3Legicrf()) {
if (readLegicUid(false) == PM3_SUCCESS) { if (readLegicUid(false) == PM3_SUCCESS) {
@ -112,6 +118,7 @@ int CmdHFSearch(const char *Cmd) {
} }
} }
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, "Searching for Topaz tag..."); PrintAndLogEx(INPLACE, "Searching for Topaz tag...");
if (IfPm3Iso14443a()) { if (IfPm3Iso14443a()) {
if (readTopazUid() == PM3_SUCCESS) { if (readTopazUid() == PM3_SUCCESS) {
@ -120,7 +127,17 @@ int CmdHFSearch(const char *Cmd) {
} }
} }
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, "Searching for FeliCa tag...");
if (IfPm3Felica()) {
if (readFelicaUid(false) == PM3_SUCCESS) {
PrintAndLogEx(NORMAL, "\nValid " _GREEN_("ISO18092 / FeliCa tag") " found\n");
return PM3_SUCCESS;
}
}
// 14b and iclass is the longest test (put last) // 14b and iclass is the longest test (put last)
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, "Searching for ISO14443-B tag..."); PrintAndLogEx(INPLACE, "Searching for ISO14443-B tag...");
if (IfPm3Iso14443a()) { if (IfPm3Iso14443a()) {
if (readHF14B(false) == 1) { if (readHF14B(false) == 1) {
@ -129,6 +146,7 @@ int CmdHFSearch(const char *Cmd) {
} }
} }
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, "Searching for iClass / PicoPass tag..."); PrintAndLogEx(INPLACE, "Searching for iClass / PicoPass tag...");
if (IfPm3Iclass()) { if (IfPm3Iclass()) {
if (readIclass(false, false) == 1) { if (readIclass(false, false) == 1) {
@ -137,17 +155,6 @@ int CmdHFSearch(const char *Cmd) {
} }
} }
// PrintAndLogEx(INPLACE, "Searching for FeliCa tag...");
//if (IfPm3Felica()) {
// ans = CmdHFFelicaReader("s");
// if (ans) {
// PrintAndLogEx(NORMAL, "\nValid " _GREEN_("ISO18092 / FeliCa tag") " found\n");
// return ans;
// }
//}
PrintAndLogEx(INPLACE, "No known/supported 13.56 MHz tags found"); PrintAndLogEx(INPLACE, "No known/supported 13.56 MHz tags found");
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
return PM3_ESOFT; return PM3_ESOFT;

View file

@ -36,7 +36,7 @@ static int usage_hf_felica_sim(void) {
PrintAndLogEx(NORMAL, " v : (Optional) Verbose"); PrintAndLogEx(NORMAL, " v : (Optional) Verbose");
PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf felica sim t 1 "); PrintAndLogEx(NORMAL, " hf felica sim t 1 ");
return 0; return PM3_SUCCESS;
} }
*/ */
@ -48,7 +48,7 @@ static int usage_hf_felica_sniff(void) {
PrintAndLogEx(NORMAL, " t triggers to skip (decimal)"); PrintAndLogEx(NORMAL, " t triggers to skip (decimal)");
PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf felica sniff s 1000"); PrintAndLogEx(NORMAL, " hf felica sniff s 1000");
return 0; return PM3_SUCCESS;
} }
static int usage_hf_felica_simlite(void) { static int usage_hf_felica_simlite(void) {
PrintAndLogEx(NORMAL, "\n Emulating ISO/18092 FeliCa Lite tag \n"); PrintAndLogEx(NORMAL, "\n Emulating ISO/18092 FeliCa Lite tag \n");
@ -58,7 +58,7 @@ static int usage_hf_felica_simlite(void) {
PrintAndLogEx(NORMAL, " uid : UID in hexsymbol"); PrintAndLogEx(NORMAL, " uid : UID in hexsymbol");
PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf felica litesim 11223344556677"); PrintAndLogEx(NORMAL, " hf felica litesim 11223344556677");
return 0; return PM3_SUCCESS;
} }
static int usage_hf_felica_dumplite(void) { static int usage_hf_felica_dumplite(void) {
PrintAndLogEx(NORMAL, "\n Dump ISO/18092 FeliCa Lite tag \n"); PrintAndLogEx(NORMAL, "\n Dump ISO/18092 FeliCa Lite tag \n");
@ -68,7 +68,7 @@ static int usage_hf_felica_dumplite(void) {
PrintAndLogEx(NORMAL, " h : This help"); PrintAndLogEx(NORMAL, " h : This help");
PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf felica litedump"); PrintAndLogEx(NORMAL, " hf felica litedump");
return 0; return PM3_SUCCESS;
} }
static int usage_hf_felica_raw(void) { static int usage_hf_felica_raw(void) {
PrintAndLogEx(NORMAL, "Usage: hf felica raw [-h] [-r] [-c] [-p] [-a] <0A 0B 0C ... hex>"); PrintAndLogEx(NORMAL, "Usage: hf felica raw [-h] [-r] [-c] [-p] [-a] <0A 0B 0C ... hex>");
@ -78,32 +78,30 @@ static int usage_hf_felica_raw(void) {
PrintAndLogEx(NORMAL, " -p leave the signal field ON after receive"); PrintAndLogEx(NORMAL, " -p leave the signal field ON after receive");
PrintAndLogEx(NORMAL, " -a active signal field ON without select"); PrintAndLogEx(NORMAL, " -a active signal field ON without select");
PrintAndLogEx(NORMAL, " -s active signal field ON with select"); PrintAndLogEx(NORMAL, " -s active signal field ON with select");
return 0; return PM3_SUCCESS;
} }
static int usage_hf_felica_dump(void) { static int usage_hf_felica_dump(void) {
PrintAndLogEx(NORMAL, "Usage: hf felica dump [-h] <outputfile>"); PrintAndLogEx(NORMAL, "Usage: hf felica dump [-h] <outputfile>");
PrintAndLogEx(NORMAL, " -h this help"); PrintAndLogEx(NORMAL, " -h this help");
return 0; return PM3_SUCCESS;
} }
static int CmdHFFelicaList(const char *Cmd) { static int CmdHFFelicaList(const char *Cmd) {
(void)Cmd; // Cmd is not used so far (void)Cmd; // Cmd is not used so far
//PrintAndLogEx(NORMAL, "Deprecated command, use 'hf list felica' instead"); //PrintAndLogEx(NORMAL, "Deprecated command, use 'hf list felica' instead");
CmdTraceList("felica"); CmdTraceList("felica");
return 0; return PM3_SUCCESS;
} }
static int CmdHFFelicaReader(const char *Cmd) { static int CmdHFFelicaReader(const char *Cmd) {
bool verbose = !(Cmd[0] == 's' || Cmd[0] == 'S'); bool verbose = !(Cmd[0] == 's' || Cmd[0] == 'S');
readFelicaUid(verbose); return readFelicaUid(verbose);
return 0;
} }
static int CmdHFFelicaDump(const char *Cmd) { static int CmdHFFelicaDump(const char *Cmd) {
if (strlen(Cmd) < 1) return usage_hf_felica_dump(); if (strlen(Cmd) < 1) return usage_hf_felica_dump();
dump(*Cmd); return dump(*Cmd);
return 0;
} }
// simulate iso18092 / FeliCa tag // simulate iso18092 / FeliCa tag
@ -169,7 +167,7 @@ static int CmdHFFelicaSim(const char *Cmd) {
while (!kbd_enter_pressed()) { while (!kbd_enter_pressed()) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue; if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue;
} }
return 0; return PM3_SUCCESS;
} }
*/ */
@ -206,7 +204,7 @@ static int CmdHFFelicaSniff(const char *Cmd) {
clearCommandBuffer(); clearCommandBuffer();
SendCommandMIX(CMD_HF_FELICA_SNIFF, samples2skip, triggers2skip, 0, NULL, 0); SendCommandMIX(CMD_HF_FELICA_SNIFF, samples2skip, triggers2skip, 0, NULL, 0);
return 0; return PM3_SUCCESS;
} }
// uid hex // uid hex
@ -219,7 +217,7 @@ static int CmdHFFelicaSimLite(const char *Cmd) {
clearCommandBuffer(); clearCommandBuffer();
SendCommandMIX(CMD_HF_FELICALITE_SIMULATE, uid, 0, 0, NULL, 0); SendCommandMIX(CMD_HF_FELICALITE_SIMULATE, uid, 0, 0, NULL, 0);
return 0; return PM3_SUCCESS;
} }
static void printSep() { static void printSep() {
@ -392,35 +390,35 @@ static int CmdHFFelicaDumpLite(const char *Cmd) {
if (kbd_enter_pressed()) { if (kbd_enter_pressed()) {
PrintAndLogEx(WARNING, "\n[!] aborted via keyboard!\n"); PrintAndLogEx(WARNING, "\n[!] aborted via keyboard!\n");
DropField(); DropField();
return 1; return PM3_EOPABORTED;
} }
if (timeout > 100) { if (timeout > 100) {
PrintAndLogEx(WARNING, "timeout while waiting for reply."); PrintAndLogEx(WARNING, "timeout while waiting for reply.");
DropField(); DropField();
return 1; return PM3_ETIMEOUT;
} }
} }
if (resp.oldarg[0] == 0) { if (resp.oldarg[0] == 0) {
PrintAndLogEx(WARNING, "\nButton pressed. Aborted."); PrintAndLogEx(WARNING, "\nButton pressed. Aborted.");
return 1; return PM3_EOPABORTED;
} }
uint32_t tracelen = resp.oldarg[1]; uint32_t tracelen = resp.oldarg[1];
if (tracelen == 0) { if (tracelen == 0) {
PrintAndLogEx(WARNING, "\nNo trace data! Maybe not a FeliCa Lite card?"); PrintAndLogEx(WARNING, "\nNo trace data! Maybe not a FeliCa Lite card?");
return 1; return PM3_ESOFT;
} }
uint8_t *trace = calloc(tracelen, sizeof(uint8_t)); uint8_t *trace = calloc(tracelen, sizeof(uint8_t));
if (trace == NULL) { if (trace == NULL) {
PrintAndLogEx(WARNING, "Cannot allocate memory for trace"); PrintAndLogEx(WARNING, "Cannot allocate memory for trace");
return 1; return PM3_EMALLOC;
} }
if (!GetFromDevice(BIG_BUF, trace, tracelen, 0, NULL, 0, NULL, 2500, false)) { if (!GetFromDevice(BIG_BUF, trace, tracelen, 0, NULL, 0, NULL, 2500, false)) {
PrintAndLogEx(WARNING, "command execution time out"); PrintAndLogEx(WARNING, "command execution time out");
free(trace); free(trace);
return 0; return PM3_ETIMEOUT;
} }
PrintAndLogEx(SUCCESS, "Recorded Activity (trace len = %"PRIu64" bytes)", tracelen); PrintAndLogEx(SUCCESS, "Recorded Activity (trace len = %"PRIu64" bytes)", tracelen);
@ -435,7 +433,7 @@ static int CmdHFFelicaDumpLite(const char *Cmd) {
printSep(); printSep();
free(trace); free(trace);
return 0; return PM3_SUCCESS;
} }
static void waitCmdFelica(uint8_t iSelect) { static void waitCmdFelica(uint8_t iSelect) {
@ -524,7 +522,7 @@ static int CmdHFFelicaCmdRaw(const char *Cmd) {
continue; continue;
} }
PrintAndLogEx(WARNING, "Invalid char on input"); PrintAndLogEx(WARNING, "Invalid char on input");
return 0; return PM3_EINVARG;
} }
if (crc && datalen > 0 && datalen < sizeof(data) - 2) { if (crc && datalen > 0 && datalen < sizeof(data) - 2) {
@ -565,7 +563,7 @@ static int CmdHFFelicaCmdRaw(const char *Cmd) {
waitCmdFelica(0); waitCmdFelica(0);
} }
} }
return 0; return PM3_SUCCESS;
} }
int readFelicaUid(bool verbose) { int readFelicaUid(bool verbose) {
@ -576,7 +574,7 @@ int readFelicaUid(bool verbose) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
if (verbose) PrintAndLogEx(WARNING, "FeliCa card select failed"); if (verbose) PrintAndLogEx(WARNING, "FeliCa card select failed");
//SendCommandMIX(CMD_HF_FELICA_COMMAND, 0, 0, 0, NULL, 0); //SendCommandMIX(CMD_HF_FELICA_COMMAND, 0, 0, 0, NULL, 0);
return 0; return PM3_ESOFT;
} }
felica_card_select_t card; felica_card_select_t card;
@ -587,19 +585,20 @@ int readFelicaUid(bool verbose) {
case 1: { case 1: {
if (verbose) if (verbose)
PrintAndLogEx(WARNING, "card timeout"); PrintAndLogEx(WARNING, "card timeout");
break; return PM3_ETIMEOUT;
} }
case 2: { case 2: {
if (verbose) if (verbose)
PrintAndLogEx(WARNING, "card answered wrong"); PrintAndLogEx(WARNING, "card answered wrong");
break; return PM3_ESOFT;
} }
case 3: { case 3: {
if (verbose) if (verbose)
PrintAndLogEx(WARNING, "CRC check failed"); PrintAndLogEx(WARNING, "CRC check failed");
break; return PM3_ESOFT;
} }
case 0: { case 0: {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "FeliCa tag info"); PrintAndLogEx(SUCCESS, "FeliCa tag info");
PrintAndLogEx(NORMAL, "IDm %s", sprint_hex(card.IDm, sizeof(card.IDm))); PrintAndLogEx(NORMAL, "IDm %s", sprint_hex(card.IDm, sizeof(card.IDm)));
@ -614,18 +613,18 @@ int readFelicaUid(bool verbose) {
break; break;
} }
} }
return status; return PM3_SUCCESS;
} }
int dump(const char *Cmd) { int dump(const char *Cmd) {
clearCommandBuffer(); clearCommandBuffer();
char ctmp = tolower(param_getchar(Cmd, 0)); char ctmp = tolower(param_getchar(Cmd, 0));
if (ctmp == 'h') return usage_hf_felica_dumplite(); if (ctmp == 'h') return usage_hf_felica_dumplite();
// TODO FINISH THIS METHOD // TODO FINISH THIS METHOD
PrintAndLogEx(SUCCESS, "NOT IMPLEMENTED YET!"); PrintAndLogEx(SUCCESS, "NOT IMPLEMENTED YET!");
return 0; return PM3_SUCCESS;
} }
static command_t CommandTable[] = { static command_t CommandTable[] = {
@ -644,7 +643,7 @@ static command_t CommandTable[] = {
static int CmdHelp(const char *Cmd) { static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far (void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable); CmdsHelp(CommandTable);
return 0; return PM3_SUCCESS;
} }
int CmdHFFelica(const char *Cmd) { int CmdHFFelica(const char *Cmd) {