chg: 'hf iclass loclass t' - now uses loadfile_safe. However the iclass_key.bin and iclass_dump.bin must be in the new folder structure

This commit is contained in:
iceman1001 2019-08-29 15:55:52 +02:00
parent d3124d7f4b
commit f3a63767ed
3 changed files with 34 additions and 55 deletions

View file

@ -1662,7 +1662,7 @@ static int CmdHFiClass_loclass(const char *Cmd) {
errors += doKeyTests(0); errors += doKeyTests(0);
errors += testElite(); errors += testElite();
if (errors) PrintAndLogEx(ERR, "There were errors!!!"); if (errors) PrintAndLogEx(ERR, "There were errors!!!");
return errors; return PM3_ESOFT;
} }
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -569,9 +569,7 @@ int bruteforceFileNoKeys(const char *filename) {
// TEST CODE BELOW // TEST CODE BELOW
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
static int _testBruteforce() { static int _testBruteforce() {
int errors = 0;
if (true) {
// First test
PrintAndLogEx(INFO, "Testing crack from dumpfile..."); PrintAndLogEx(INFO, "Testing crack from dumpfile...");
/** /**
@ -590,18 +588,11 @@ static int _testBruteforce() {
**** The 64-bit HS Custom Key Value = 5B7C62C491C11B39 **** **** The 64-bit HS Custom Key Value = 5B7C62C491C11B39 ****
**/ **/
uint16_t keytable[128] = {0}; uint16_t keytable[128] = {0};
int errors = bruteforceFile("iclass_dump.bin", keytable);
//Test a few variants if (errors) {
if (fileExists("iclass_dump.bin")) {
errors |= bruteforceFile("iclass_dump.bin", keytable);
} else if (fileExists("loclass/iclass_dump.bin")) {
errors |= bruteforceFile("loclass/iclass_dump.bin", keytable);
} else if (fileExists("client/loclass/iclass_dump.bin")) {
errors |= bruteforceFile("client/loclass/iclass_dump.bin", keytable);
} else {
PrintAndLogEx(ERR, "Error: The file " _YELLOW_("iclass_dump.bin") "was not found!"); PrintAndLogEx(ERR, "Error: The file " _YELLOW_("iclass_dump.bin") "was not found!");
} }
}
return errors; return errors;
} }

View file

@ -654,33 +654,21 @@ static int doTestsWithKnownInputs() {
return errors; return errors;
} }
static bool readKeyFile(uint8_t key[8]) {
bool retval = false;
//Test a few variants static bool readKeyFile(uint8_t* key, size_t keylen) {
char filename[30] = {0};
if (fileExists("iclass_key.bin")) { size_t len = 0;
sprintf(filename, "%s.bin", "iclass_key"); uint8_t *keyptr = NULL;
} else if (fileExists("loclass/iclass_key.bin")) { if ( loadFile_safe("iclass_key.bin", "", (void**)&keyptr, &len) != PM3_SUCCESS ) {
sprintf(filename, "%s.bin", "loclass/iclass_key"); return false;
} else if (fileExists("client/loclass/iclass_key.bin")) {
sprintf(filename, "%s.bin", "client/loclass/iclass_key");
} }
if (strlen(filename) == 0) if ( keylen != len ) {
return retval; return false;
}
FILE *f = fopen(filename, "rb"); memcpy(key, keyptr, keylen );
if (!f) return true;
return retval;
size_t bytes_read = fread(key, sizeof(uint8_t), 8, f);
if (bytes_read == 8)
retval = true;
fclose(f);
return retval;
} }
int doKeyTests(uint8_t debuglevel) { int doKeyTests(uint8_t debuglevel) {
@ -688,7 +676,7 @@ int doKeyTests(uint8_t debuglevel) {
PrintAndLogEx(INFO, "Checking if the master key is present (iclass_key.bin)..."); PrintAndLogEx(INFO, "Checking if the master key is present (iclass_key.bin)...");
uint8_t key[8] = {0}; uint8_t key[8] = {0};
if (!readKeyFile(key)) { if (readKeyFile(key, sizeof(key)) == false) {
PrintAndLogEx(FAILED, "Master key not present, will not be able to do all testcases"); PrintAndLogEx(FAILED, "Master key not present, will not be able to do all testcases");
} else { } else {