From 4493153dbb7a674c3ab504b8c9da47ab067a1948 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 13 Jul 2020 20:58:24 +0200 Subject: [PATCH] verbose.. --- client/src/cmdhficlass.c | 85 +++++++++++++++++----------------------- common/cardhelper.c | 11 +++--- common/cardhelper.h | 2 +- 3 files changed, 42 insertions(+), 56 deletions(-) diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 8bdde6592..b4fc7dcb2 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -918,7 +918,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) { if (errors || cmdp < 1) return usage_hf_iclass_decrypt(); - bool use_sc = IsCryptoHelperPresent(); + bool use_sc = IsCryptoHelperPresent(true); if (have_key == false && use_sc == false) { int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen); @@ -1092,7 +1092,7 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) { if (errors || cmdp < 1) return usage_hf_iclass_encrypt(); - bool use_sc = IsCryptoHelperPresent(); + bool use_sc = IsCryptoHelperPresent(true); if (have_key == false && use_sc == false) { size_t keylen = 0; @@ -1814,7 +1814,6 @@ static int CmdHFiClassCloneTag(const char *Cmd) { static int iclass_read_block(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, bool rawkey, bool verbose, bool auth) { - int numberAuthRetries = ICLASS_AUTH_RETRY; // return data. struct p { bool isOK; @@ -1822,61 +1821,51 @@ static int iclass_read_block(uint8_t *KEY, uint8_t blockno, uint8_t keyType, boo } PACKED; struct p *result = NULL; - do { - // block 0,1 should always be able to read, and block 5 on some cards. - if (auth || blockno >= 2) { - uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00}; - uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if (select_and_auth(KEY, MAC, div_key, (keyType == 0x18), elite, rawkey, verbose) == false) { - numberAuthRetries--; - DropField(); - continue; - } - } else { - uint8_t CSN[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t CCNR[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if (select_only(CSN, CCNR, (keyType == 0x18), verbose) == false) { - numberAuthRetries--; - DropField(); - continue; - } + // block 0,1 should always be able to read, and block 5 on some cards. + if (auth || blockno >= 2) { + uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00}; + uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + if (select_and_auth(KEY, MAC, div_key, (keyType == 0x18), elite, rawkey, verbose) == false) { + return PM3_ESOFT; } - - PacketResponseNG resp; - clearCommandBuffer(); - SendCommandNG(CMD_HF_ICLASS_READBL, (uint8_t *)&blockno, sizeof(uint8_t)); - - if (WaitForResponseTimeout(CMD_HF_ICLASS_READBL, &resp, 2000) == 0) { - if (verbose) PrintAndLogEx(WARNING, "Command execute timeout"); - DropField(); - return PM3_ETIMEOUT; + } else { + uint8_t CSN[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t CCNR[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + if (select_only(CSN, CCNR, (keyType == 0x18), verbose) == false) { + return PM3_ESOFT; } + } - if (resp.status != PM3_SUCCESS) { - if (verbose) PrintAndLogEx(ERR, "failed to communicate with card"); - DropField(); - return PM3_EWRONGANSWER; - } + PacketResponseNG resp; + clearCommandBuffer(); + SendCommandNG(CMD_HF_ICLASS_READBL, (uint8_t *)&blockno, sizeof(uint8_t)); - result = (struct p *)resp.data.asBytes; - if (result->isOK) - break; + if (WaitForResponseTimeout(CMD_HF_ICLASS_READBL, &resp, 2000) == 0) { + if (verbose) PrintAndLogEx(WARNING, "Command execute timeout"); + DropField(); + return PM3_ETIMEOUT; + } - } while (numberAuthRetries); + if (resp.status != PM3_SUCCESS) { + if (verbose) PrintAndLogEx(ERR, "failed to communicate with card"); + return PM3_EWRONGANSWER; + } + + result = (struct p *)resp.data.asBytes; + if (result->isOK == false) + return PM3_ESOFT; DropField(); - if (numberAuthRetries == 0) { - PrintAndLogEx(ERR, "failed to authenticate and read block"); - return PM3_ESOFT; - } - PrintAndLogEx(SUCCESS, "block %02X: " _GREEN_("%s"), blockno, sprint_hex(result->blockdata, sizeof(result->blockdata))); if (memcmp(result->blockdata, empty, 8) == 0) return PM3_SUCCESS; - bool use_sc = IsCryptoHelperPresent(); + if (blockno < 6 || blockno > 7) + return PM3_SUCCESS; + + bool use_sc = IsCryptoHelperPresent(verbose); if (use_sc == false) return PM3_SUCCESS; @@ -1887,8 +1876,6 @@ static int iclass_read_block(uint8_t *KEY, uint8_t blockno, uint8_t keyType, boo break; } case 7: { -// case 8: -// case 9: { PrintAndLogEx(INFO, "Trying to decrypt..."); uint8_t dec_data[8]; @@ -1902,7 +1889,7 @@ static int iclass_read_block(uint8_t *KEY, uint8_t blockno, uint8_t keyType, boo mid = bytes_to_num(dec_data, 4); bot = bytes_to_num(dec_data + 4, 4); - PrintAndLogEx(INFO, "Block 7 binary"); + PrintAndLogEx(INFO, "Binary"); char hexstr[8 + 1] = {0}; hex_to_buffer((uint8_t *)hexstr, dec_data, 8, sizeof(hexstr) - 1, 0, 0, true); @@ -1914,7 +1901,7 @@ static int iclass_read_block(uint8_t *KEY, uint8_t blockno, uint8_t keyType, boo PrintAndLogEx(SUCCESS, "%s", binstr + i); - PrintAndLogEx(INFO, "Wiegand decode"); + PrintAndLogEx(INFO, "-----------------------------------------------------------------"); wiegand_message_t packed = initialize_message_object(top, mid, bot); HIDTryUnpack(&packed, true); PrintAndLogEx(INFO, "-----------------------------------------------------------------"); diff --git a/common/cardhelper.c b/common/cardhelper.c index 03af2d799..fbdaf2002 100644 --- a/common/cardhelper.c +++ b/common/cardhelper.c @@ -22,7 +22,7 @@ static uint8_t cmd[] = {0x96, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // look for CryptoHelper -bool IsCryptoHelperPresent(void) { +bool IsCryptoHelperPresent(bool verbose) { if (IfPm3Smartcard()) { int resp_len = 0; @@ -31,14 +31,13 @@ bool IsCryptoHelperPresent(void) { ExchangeAPDUSC(true, version, sizeof(version), true, true, resp, sizeof(resp), &resp_len); if (strstr("CryptoHelper", (char *)resp) == 0) { - PrintAndLogEx(INFO, "Found smart card helper"); + if (verbose) { + PrintAndLogEx(INFO, "Found smart card helper"); + } return true; - } else { - return false; } - } else { - return false; } + return false; } static bool executeCrypto(uint8_t ins, uint8_t *src, uint8_t *dest) { diff --git a/common/cardhelper.h b/common/cardhelper.h index fcdd73cfe..eaf7ff38f 100644 --- a/common/cardhelper.h +++ b/common/cardhelper.h @@ -14,7 +14,7 @@ #include #include "common.h" -bool IsCryptoHelperPresent(void); +bool IsCryptoHelperPresent(bool verbose); bool Encrypt(uint8_t *src, uint8_t *dest); bool Decrypt(uint8_t *src, uint8_t *dest); void DecodeBlock6(uint8_t *src);