chg: 'hf iclass chk' - different output and break the twice-loop when found.

This commit is contained in:
iceman1001 2017-12-15 15:37:00 +01:00
commit 76fc2cbc2b

View file

@ -755,15 +755,15 @@ void Calc_wb_mac(uint8_t blockno, uint8_t *data, uint8_t *div_key, uint8_t MAC[4
static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool verbose) { static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool verbose) {
UsbCommand resp; UsbCommand resp;
UsbCommand c = {CMD_READER_ICLASS, {0}}; UsbCommand c = {CMD_READER_ICLASS, {0}};
c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE | FLAG_ICLASS_READER_CC | FLAG_ICLASS_READER_ONE_TRY; c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE | FLAG_ICLASS_READER_CC | FLAG_ICLASS_READER_ONE_TRY;
if (use_credit_key) if (use_credit_key)
c.arg[0] |= FLAG_ICLASS_READER_CEDITKEY; c.arg[0] |= FLAG_ICLASS_READER_CEDITKEY;
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK,&resp,4500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) {
PrintAndLog("Command execute timeout"); PrintAndLog("Command execute timeout");
return false; return false;
} }
@ -771,16 +771,16 @@ static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool v
uint8_t isOK = resp.arg[0] & 0xff; uint8_t isOK = resp.arg[0] & 0xff;
uint8_t *data = resp.d.asBytes; uint8_t *data = resp.d.asBytes;
memcpy(CSN,data,8); memcpy(CSN, data, 8);
if (CCNR!=NULL) if (CCNR != NULL)
memcpy(CCNR,data+16,8); memcpy(CCNR, data+16, 8);
if(isOK > 0) { if (isOK > 0) {
if (verbose) PrintAndLog("CSN: %s",sprint_hex(CSN,8)); if (verbose) PrintAndLog("CSN: %s",sprint_hex(CSN,8));
} }
if(isOK <= 1){ if (isOK <= 1){
PrintAndLog("Failed to obtain CC! Aborting..."); PrintAndLog("Failed to obtain CC! Aborting...");
return false; return false;
} }
@ -808,7 +808,7 @@ static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool u
memcpy(d.d.asBytes, MAC, 4); memcpy(d.d.asBytes, MAC, 4);
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&d); SendCommand(&d);
if (!WaitForResponseTimeout(CMD_ACK,&resp,4500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) {
if (verbose) PrintAndLog("Auth Command execute timeout"); if (verbose) PrintAndLog("Auth Command execute timeout");
return false; return false;
} }
@ -1355,7 +1355,7 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite,
int CmdHFiClass_ReadBlock(const char *Cmd) { int CmdHFiClass_ReadBlock(const char *Cmd) {
uint8_t blockno=0; uint8_t blockno=0;
uint8_t keyType = 0x88; //debit key uint8_t keyType = 0x88; //debit key
uint8_t KEY[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; uint8_t KEY[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uint8_t keyNbr = 0; uint8_t keyNbr = 0;
uint8_t dataLen = 0; uint8_t dataLen = 0;
char tempStr[50] = {0}; char tempStr[50] = {0};
@ -1897,33 +1897,25 @@ int CmdHFiClassCheckKeys(const char *Cmd) {
memcpy(key, keyBlock + 8 * c , 8); memcpy(key, keyBlock + 8 * c , 8);
// debit key. try twice // debit key. try twice
if ( !found_debit ) { for (int foo = 0; foo < 2 && !found_debit; foo++) {
for (int foo = 0; foo < 2; foo++) { if (!select_and_auth(key, mac, div_key, false, elite, rawkey, false))
if (!select_and_auth(key, mac, div_key, false, elite, rawkey, false)) continue;
continue;
// key found. // key found.
PrintAndLog("Found debit key %s || div_key %s", PrintAndLog("\n--------------------------------------------------------");
sprint_hex(key, 8), PrintAndLog(" Found AA1 debit key\t\t[%s]", sprint_hex(key, 8));
sprint_hex(div_key, 8) found_debit = true;
);
found_debit = true;
}
} }
// credit key. try twice // credit key. try twice
if ( !found_credit ) { for (int foo = 0; foo < 2 && !found_credit; foo++) {
for (int foo = 0; foo < 2; foo++) { if (!select_and_auth(key, mac, div_key, true, elite, rawkey, false))
if (!select_and_auth(key, mac, div_key, true, elite, rawkey, false)) continue;
continue;
// key found // key found
PrintAndLog("Found credit key %s || div_key %s", PrintAndLog("\n--------------------------------------------------------");
sprint_hex(key, 8), PrintAndLog(" Found AA2 credit key\t\t[%s]", sprint_hex(key, 8));
sprint_hex(div_key, 8) found_credit = true;
);
found_credit = true;
}
} }
// both keys found. // both keys found.