Add: hf thinfilm info - support to read and decode Kovio Thinfilm NCT tags

This commit is contained in:
iceman1001
2019-08-01 09:39:33 -04:00
parent f6befc235f
commit fbff51c88d
12 changed files with 404 additions and 8 deletions

View File

@@ -130,7 +130,7 @@ CORESRCS = uart_posix.c \
crc16.c \
comms.c
CMDSRCS = crapto1/crapto1.c \
CMDSRCS = crapto1/crapto1.c \
crapto1/crypto1.c \
mifare/mfkey.c \
tea.c \
@@ -199,6 +199,7 @@ CMDSRCS = crapto1/crapto1.c \
cmdhftopaz.c \
cmdhffido.c \
cmdhffelica.c \
cmdhfthinfilm.c \
cmdhw.c \
cmdlf.c \
cmdlfawid.c \

View File

@@ -54,6 +54,11 @@ int CmdHFSearch(const char *Cmd) {
PrintAndLogEx(INFO, "Checking for known tags...\n");
if (infoThinFilm() == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Thinfilm tag") " found\n");
return 1;
}
if (infoHF14A(false, false) > 0) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO14443-A tag") " found\n");
return 1;
@@ -160,6 +165,7 @@ static command_t CommandTable[] = {
{"mfdes", CmdHFMFDes, AlwaysAvailable, "{ MIFARE Desfire RFIDs... }"},
{"topaz", CmdHFTopaz, AlwaysAvailable, "{ TOPAZ (NFC Type 1) RFIDs... }"},
{"fido", CmdHFFido, AlwaysAvailable, "{ FIDO and FIDO2 authenticators... }"},
{"thinfilm", CmdHFThinfilm, AlwaysAvailable, "{ Thinfilm RFIDs... }"},
{"list", CmdTraceList, AlwaysAvailable, "List protocol data in trace buffer"},
{"tune", CmdHFTune, IfPm3Present, "Continuously measure HF antenna tuning"},
{"search", CmdHFSearch, AlwaysAvailable, "Search for known HF tags [preliminary]"},

View File

@@ -31,6 +31,7 @@
#include "cmdhftopaz.h" // TOPAZ
#include "cmdhffelica.h" // ISO18092 / FeliCa
#include "cmdhffido.h" // FIDO authenticators
#include "cmdhfthinfilm.h" // Thinfilm
#include "cmdtrace.h" // trace list
int CmdHF(const char *Cmd);

147
client/cmdhfthinfilm.c Normal file
View File

@@ -0,0 +1,147 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2019 iceman
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Thinfilm commands
//-----------------------------------------------------------------------------
#include "cmdhfthinfilm.h"
static int CmdHelp(const char *Cmd);
static int usage_thinfilm_info(void) {
PrintAndLogEx(NORMAL, "Usage: hf thin info [h]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf thin info");
return PM3_SUCCESS;
}
// Printing function based upon the code in libnfc
// ref
// https://github.com/nfc-tools/libnfc/blob/master/utils/nfc-barcode.c
static int print_barcode(uint8_t *barcode, const size_t barcode_len) {
PrintAndLogEx(SUCCESS, " Manufacturer : "_YELLOW_("%s") "[0x%02X]", (barcode[0] == 0xB7) ? "Thinfilm" : "unknown", barcode[0] );
PrintAndLogEx(SUCCESS, " Data format : "_YELLOW_("%02X"), barcode[1]);
PrintAndLogEx(SUCCESS, " Raw data : "_YELLOW_("%s"), sprint_hex(barcode, barcode_len) );
char s[45];
memset(s, 0x00, sizeof(s));
switch (barcode[1]) {
case 0:
printf("Data Format Field: Reserved for allocation by tag manufacturer\n");
return PM3_SUCCESS;
case 1:
snprintf(s, sizeof(s), "http://www." );
break;
case 2:
snprintf(s, sizeof(s), "https://www.");
break;
case 3:
snprintf(s, sizeof(s), "http://");
break;
case 4:
snprintf(s, sizeof(s), "https://");
break;
case 5:
PrintAndLogEx(SUCCESS, "EPC: %s", sprint_hex(barcode + 2, 12) );
return PM3_SUCCESS;
default:
PrintAndLogEx(SUCCESS, "Data Format Field: unknown (%02X)", barcode[1]);
PrintAndLogEx(SUCCESS, "Data:" _YELLOW_("%s"), sprint_hex(barcode + 2, barcode_len - 2) );
return PM3_SUCCESS;
}
snprintf(s + strlen(s), barcode_len - 1, (const char*)&barcode[2] , barcode_len - 2);
for (uint8_t i = 0; i < strlen(s); i++) {
// terminate string
if (s[i] == 0xFE) {
s[i] = 0;
break;
}
}
PrintAndLogEx(SUCCESS, " Decoded NFC URL : "_YELLOW_("%s"), s);
return PM3_SUCCESS;
}
static int CmdHfThinFilmInfo(const char *Cmd) {
uint8_t cmdp = 0;
bool errors = false;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) {
case 'h':
return usage_thinfilm_info();
default:
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = true;
break;
}
}
//Validations
if (errors) {
usage_thinfilm_info();
return PM3_EINVARG;
}
return infoThinFilm();
}
int infoThinFilm(void) {
clearCommandBuffer();
SendCommandNG(CMD_THINFILM_READ, NULL, 0);
PacketResponseNG resp;
if (!WaitForResponseTimeout(CMD_THINFILM_READ, &resp, 1500)) {
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
return PM3_ETIMEOUT;
}
if ( resp.status == PM3_SUCCESS ) {
print_barcode( resp.data.asBytes, resp.length - 2);
}
return resp.status;
}
static int CmdHfThinFilmSim(const char *Cmd) {
PrintAndLogEx(INFO, "To be implemented");
return PM3_ENOTIMPL;
}
static int CmdHfThinFilmList(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdTraceList("14a");
return PM3_SUCCESS;
}
static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"info", CmdHfThinFilmInfo, IfPm3Flash, "Tag information"},
{"list", CmdHfThinFilmList, AlwaysAvailable, "List ISO 14443A / Thinfilm history - not correct"},
{"sim", CmdHfThinFilmSim, IfPm3Flash, "Fake Thinfilm tag"},
{NULL, NULL, NULL, NULL}
};
static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return PM3_SUCCESS;
}
int CmdHFThinfilm(const char *Cmd) {
clearCommandBuffer();
return CmdsParse(CommandTable, Cmd);
}

28
client/cmdhfthinfilm.h Normal file
View File

@@ -0,0 +1,28 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2019 iceman
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Thinfilm commands
//-----------------------------------------------------------------------------
#ifndef CMDHFTHINFILM_H__
#define CMDHFTHINFILM_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "proxmark3.h"
#include "ui.h"
#include "cmdparser.h"
#include "util.h"
#include "cmdhf.h" // list cmd
int infoThinFilm(void);
int CmdHFThinfilm(const char *Cmd);
#endif