From cdbef43f1a018abb3cf2c40d13d4c79d1be8d219 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 11 Feb 2021 23:09:45 +0100 Subject: [PATCH] hf jooki write - may work... --- CHANGELOG.md | 1 + client/src/cmdhfjooki.c | 46 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f3ead0f4..9547aba77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Added `hf jooki` commands (@iceman1001) - Changed `wiegand encode` - format param is now optional, w/o it will try encode all formats (@iceman1001) - Fix cppchecker warnings (@iceman1001) - Added `trace list -t mf` - now can use external dictionary keys file diff --git a/client/src/cmdhfjooki.c b/client/src/cmdhfjooki.c index 8a5b0772a..c6bae2e09 100644 --- a/client/src/cmdhfjooki.c +++ b/client/src/cmdhfjooki.c @@ -308,11 +308,12 @@ static int CmdHF14AJookiWrite(const char *Cmd) { void *argtable[] = { arg_param_begin, arg_str1("d", "data", "", "bytes"), + arg_str0("p", "pwd", "", "password for authentication (EV1/NTAG 4 bytes)"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); int dlen = 0; - uint8_t data[100] = {0x00}; + uint8_t data[52] = {0x00}; memset(data, 0x0, sizeof(data)); int res = CLIParamHexToBuf(arg_get_str(ctx, 1), data, sizeof(data), &dlen); if (res) { @@ -321,7 +322,50 @@ static int CmdHF14AJookiWrite(const char *Cmd) { return PM3_EINVARG; } + + int plen = 0; + uint8_t pwd[4] = {0x00}; + CLIGetHexWithReturn(ctx, 2, pwd, &plen); + CLIParserFree(ctx); + + if (dlen != 52) { + PrintAndLogEx(ERR, "Wrong data length. Expected 52 got %d", dlen); + return PM3_EINVARG; + } + + bool has_pwd = false; + if (plen == 4) { + has_pwd = true; + } + + // 0 - no authentication + // 2 - pwd (4 bytes) + uint8_t keytype = 0, blockno = 4, i = 0; + + while ((i * 4) < dlen) { + + uint8_t cmddata[8] = {0}; + memcpy(cmddata, data + (i * 4), 4); + if (has_pwd) { + memcpy(cmddata + 4, pwd, 4); + keytype = 2; + } + clearCommandBuffer(); + SendCommandMIX(CMD_HF_MIFAREU_WRITEBL, blockno, keytype, 0, cmddata, sizeof(cmddata)); + + PacketResponseNG resp; + if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { + uint8_t isOK = resp.oldarg[0] & 0xff; + PrintAndLogEx(SUCCESS, "block %d, data %s ( %s )", blockno, sprint_hex_inrow(cmddata, sizeof(cmddata)), isOK ? _GREEN_("ok") : _RED_("fail")); + } else { + PrintAndLogEx(WARNING, "Command execute timeout"); + } + + blockno++; + i++; + } + return PM3_SUCCESS; }