verbose..

This commit is contained in:
iceman1001 2020-07-13 20:58:24 +02:00
commit 4493153dbb
3 changed files with 42 additions and 56 deletions

View file

@ -918,7 +918,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
if (errors || cmdp < 1) return usage_hf_iclass_decrypt(); 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) { if (have_key == false && use_sc == false) {
int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen); 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(); 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) { if (have_key == false && use_sc == false) {
size_t keylen = 0; 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) { 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. // return data.
struct p { struct p {
bool isOK; bool isOK;
@ -1822,23 +1821,18 @@ static int iclass_read_block(uint8_t *KEY, uint8_t blockno, uint8_t keyType, boo
} PACKED; } PACKED;
struct p *result = NULL; struct p *result = NULL;
do {
// block 0,1 should always be able to read, and block 5 on some cards. // block 0,1 should always be able to read, and block 5 on some cards.
if (auth || blockno >= 2) { if (auth || blockno >= 2) {
uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00}; uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00};
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 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) { if (select_and_auth(KEY, MAC, div_key, (keyType == 0x18), elite, rawkey, verbose) == false) {
numberAuthRetries--; return PM3_ESOFT;
DropField();
continue;
} }
} else { } else {
uint8_t CSN[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 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}; 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) { if (select_only(CSN, CCNR, (keyType == 0x18), verbose) == false) {
numberAuthRetries--; return PM3_ESOFT;
DropField();
continue;
} }
} }
@ -1854,29 +1848,24 @@ static int iclass_read_block(uint8_t *KEY, uint8_t blockno, uint8_t keyType, boo
if (resp.status != PM3_SUCCESS) { if (resp.status != PM3_SUCCESS) {
if (verbose) PrintAndLogEx(ERR, "failed to communicate with card"); if (verbose) PrintAndLogEx(ERR, "failed to communicate with card");
DropField();
return PM3_EWRONGANSWER; return PM3_EWRONGANSWER;
} }
result = (struct p *)resp.data.asBytes; result = (struct p *)resp.data.asBytes;
if (result->isOK) if (result->isOK == false)
break; return PM3_ESOFT;
} while (numberAuthRetries);
DropField(); 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))); PrintAndLogEx(SUCCESS, "block %02X: " _GREEN_("%s"), blockno, sprint_hex(result->blockdata, sizeof(result->blockdata)));
if (memcmp(result->blockdata, empty, 8) == 0) if (memcmp(result->blockdata, empty, 8) == 0)
return PM3_SUCCESS; return PM3_SUCCESS;
bool use_sc = IsCryptoHelperPresent(); if (blockno < 6 || blockno > 7)
return PM3_SUCCESS;
bool use_sc = IsCryptoHelperPresent(verbose);
if (use_sc == false) if (use_sc == false)
return PM3_SUCCESS; return PM3_SUCCESS;
@ -1887,8 +1876,6 @@ static int iclass_read_block(uint8_t *KEY, uint8_t blockno, uint8_t keyType, boo
break; break;
} }
case 7: { case 7: {
// case 8:
// case 9: {
PrintAndLogEx(INFO, "Trying to decrypt..."); PrintAndLogEx(INFO, "Trying to decrypt...");
uint8_t dec_data[8]; 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); mid = bytes_to_num(dec_data, 4);
bot = bytes_to_num(dec_data + 4, 4); bot = bytes_to_num(dec_data + 4, 4);
PrintAndLogEx(INFO, "Block 7 binary"); PrintAndLogEx(INFO, "Binary");
char hexstr[8 + 1] = {0}; char hexstr[8 + 1] = {0};
hex_to_buffer((uint8_t *)hexstr, dec_data, 8, sizeof(hexstr) - 1, 0, 0, true); 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(SUCCESS, "%s", binstr + i);
PrintAndLogEx(INFO, "Wiegand decode"); PrintAndLogEx(INFO, "-----------------------------------------------------------------");
wiegand_message_t packed = initialize_message_object(top, mid, bot); wiegand_message_t packed = initialize_message_object(top, mid, bot);
HIDTryUnpack(&packed, true); HIDTryUnpack(&packed, true);
PrintAndLogEx(INFO, "-----------------------------------------------------------------"); PrintAndLogEx(INFO, "-----------------------------------------------------------------");

View file

@ -22,7 +22,7 @@
static uint8_t cmd[] = {0x96, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static uint8_t cmd[] = {0x96, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// look for CryptoHelper // look for CryptoHelper
bool IsCryptoHelperPresent(void) { bool IsCryptoHelperPresent(bool verbose) {
if (IfPm3Smartcard()) { if (IfPm3Smartcard()) {
int resp_len = 0; int resp_len = 0;
@ -31,14 +31,13 @@ bool IsCryptoHelperPresent(void) {
ExchangeAPDUSC(true, version, sizeof(version), true, true, resp, sizeof(resp), &resp_len); ExchangeAPDUSC(true, version, sizeof(version), true, true, resp, sizeof(resp), &resp_len);
if (strstr("CryptoHelper", (char *)resp) == 0) { if (strstr("CryptoHelper", (char *)resp) == 0) {
if (verbose) {
PrintAndLogEx(INFO, "Found smart card helper"); PrintAndLogEx(INFO, "Found smart card helper");
}
return true; return true;
} else {
return false;
} }
} else {
return false;
} }
return false;
} }
static bool executeCrypto(uint8_t ins, uint8_t *src, uint8_t *dest) { static bool executeCrypto(uint8_t ins, uint8_t *src, uint8_t *dest) {

View file

@ -14,7 +14,7 @@
#include <ctype.h> #include <ctype.h>
#include "common.h" #include "common.h"
bool IsCryptoHelperPresent(void); bool IsCryptoHelperPresent(bool verbose);
bool Encrypt(uint8_t *src, uint8_t *dest); bool Encrypt(uint8_t *src, uint8_t *dest);
bool Decrypt(uint8_t *src, uint8_t *dest); bool Decrypt(uint8_t *src, uint8_t *dest);
void DecodeBlock6(uint8_t *src); void DecodeBlock6(uint8_t *src);