From 01af87e6d7bbb6342c7983c0f67585b30be9487f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 2 Oct 2020 18:06:21 +0200 Subject: [PATCH] hf 14b sniff, sim, info, - now uses cliparser --- armsrc/appmain.c | 3 +- armsrc/iso14443b.c | 12 +++--- armsrc/iso14443b.h | 2 +- client/src/cmdhf14b.c | 91 +++++++++++++++++++++++-------------------- 4 files changed, 56 insertions(+), 52 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 42161d738..2c6ace8ee 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1126,11 +1126,10 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_ISO14443B_SIMULATE: { - SimulateIso14443bTag(packet->oldarg[0]); + SimulateIso14443bTag(packet->data.asBytes); break; } case CMD_HF_ISO14443B_COMMAND: { - //SendRawCommand14443B(packet->oldarg[0],packet->oldarg[1],packet->oldarg[2],packet->data.asBytes); SendRawCommand14443B_Ex(packet); break; } diff --git a/armsrc/iso14443b.c b/armsrc/iso14443b.c index e4fe67a64..ccbe06e5c 100644 --- a/armsrc/iso14443b.c +++ b/armsrc/iso14443b.c @@ -530,7 +530,7 @@ static void TransmitFor14443b_AsTag(uint8_t *response, uint16_t len) { // Main loop of simulated tag: receive commands from reader, decide what // response to send, and send it. //----------------------------------------------------------------------------- -void SimulateIso14443bTag(uint32_t pupi) { +void SimulateIso14443bTag(uint8_t *pupi) { LED_A_ON(); // the only commands we understand is WUPB, AFI=0, Select All, N=1: @@ -553,15 +553,15 @@ void SimulateIso14443bTag(uint32_t pupi) { 0x5e, 0xd7 }; - // response to HLTB and ATTRIB - static const uint8_t respOK[] = {0x00, 0x78, 0xF0}; - // ...PUPI/UID supplied from user. Adjust ATQB response accordingly - if (pupi > 0) { - num_to_bytes(pupi, 4, respATQB + 1); + if (memcmp("\x00\x00\x00\x00", pupi, 4) != 0) { + memcpy(respATQB + 1, pupi, 4); AddCrc14B(respATQB, 12); } + // response to HLTB and ATTRIB + static const uint8_t respOK[] = {0x00, 0x78, 0xF0}; + // setup device. FpgaDownloadAndGo(FPGA_BITSTREAM_HF); diff --git a/armsrc/iso14443b.h b/armsrc/iso14443b.h index 3fde4ffe0..7e5023e1b 100644 --- a/armsrc/iso14443b.h +++ b/armsrc/iso14443b.h @@ -32,7 +32,7 @@ int iso14443b_apdu(uint8_t const *msg, size_t msg_len, bool send_chaining, uint8 int iso14443b_select_card(iso14b_card_select_t *card); int iso14443b_select_card_srx(iso14b_card_select_t *card); -void SimulateIso14443bTag(uint32_t pupi); +void SimulateIso14443bTag(uint8_t *pupi); void AcquireRawAdcSamplesIso14443b(uint32_t parameter); void ReadSTMemoryIso14443b(uint16_t numofblocks); void SniffIso14443b(void); diff --git a/client/src/cmdhf14b.c b/client/src/cmdhf14b.c index a1be64ffd..dd90a4e39 100644 --- a/client/src/cmdhf14b.c +++ b/client/src/cmdhf14b.c @@ -34,35 +34,6 @@ bool apdu_in_framing_enable = true; static int CmdHelp(const char *Cmd); -static int usage_hf_14b_info(void) { - PrintAndLogEx(NORMAL, "Usage: hf 14b info [h] [s]"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " s silently"); - PrintAndLogEx(NORMAL, "Example:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf 14b info")); - return PM3_SUCCESS; -} -static int usage_hf_14b_reader(void) { - PrintAndLogEx(NORMAL, "Usage: hf 14b reader [h] [v]"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " v verbose"); - PrintAndLogEx(NORMAL, "Example:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf 14b reader")); - return PM3_SUCCESS; -} -static int usage_hf_14b_sim(void) { - PrintAndLogEx(NORMAL, "Emulating ISO/IEC 14443 type B tag with 4 UID / PUPI"); - PrintAndLogEx(NORMAL, "Usage: hf 14b sim [h] u "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " u 4byte UID/PUPI"); - PrintAndLogEx(NORMAL, "Example:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf 14b sim")); - PrintAndLogEx(NORMAL, _YELLOW_(" hf 14b sim u 11223344")); - return PM3_SUCCESS; -} static int usage_hf_14b_read_srx(void) { PrintAndLogEx(NORMAL, "Usage: hf 14b sriread [h] <1|2>"); PrintAndLogEx(NORMAL, "Options:"); @@ -158,16 +129,29 @@ static int CmdHF14BList(const char *Cmd) { } static int CmdHF14BSim(const char *Cmd) { - char cmdp = tolower(param_getchar(Cmd, 0)); - if (cmdp == 'h') return usage_hf_14b_sim(); - - uint32_t pupi = 0; - if (cmdp == 'u') { - pupi = param_get32ex(Cmd, 1, 0, 16); - } + + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf 14b sim", + "Simulate a ISO/IEC 14443 type B tag with 4 byte UID / PUPI", + "hf 14b sim\n" + "hf 14b sim -u 11AA33BB" + ); + + void *argtable[] = { + arg_param_begin, + arg_strx0("u", "uid", "hex", "4byte UID/PUPI"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + + uint8_t pupi[4]; + int n = 0; + CLIParamHexToBuf(arg_get_str(ctx, 1), pupi, sizeof(pupi), &n); + CLIParserFree(ctx); clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443B_SIMULATE, pupi, 0, 0, NULL, 0); + SendCommandNG(CMD_HF_ISO14443B_SIMULATE, pupi, sizeof(pupi)); + return PM3_SUCCESS; } @@ -722,10 +706,20 @@ static bool HF14B_ST_Info(bool verbose) { // menu command to get and print all info known about any known 14b tag static int CmdHF14Binfo(const char *Cmd) { - char cmdp = tolower(param_getchar(Cmd, 0)); - if (cmdp == 'h') return usage_hf_14b_info(); + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf 14b info", + "Tag information for ISO/IEC 14443 type B based tags", + "hf 14b info\n" + ); - bool verbose = !(cmdp == 's'); + void *argtable[] = { + arg_param_begin, + arg_lit0("v", "verbose", "verbose"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool verbose = arg_get_lit(ctx, 1); + CLIParserFree(ctx); return infoHF14B(verbose); } @@ -938,9 +932,20 @@ static bool HF14B_other_reader(bool verbose) { // menu command to get and print general info about all known 14b chips static int CmdHF14BReader(const char *Cmd) { - char cmdp = tolower(param_getchar(Cmd, 0)); - if (cmdp == 'h') return usage_hf_14b_reader(); - bool verbose = (cmdp == 'v'); + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf 14b reader", + "Act as a 14443B reader to identify a tag", + "hf 14b reader\n" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("v", "verbose", "verbose"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool verbose = arg_get_lit(ctx, 1); + CLIParserFree(ctx); return readHF14B(verbose); }