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 += testElite();
if (errors) PrintAndLogEx(ERR, "There were errors!!!");
return errors;
return PM3_ESOFT;
}
return PM3_SUCCESS;
}
@ -1971,7 +1971,7 @@ static int CmdHFiClassManageKeys(const char *Cmd) {
case 'n':
keyNbr = param_get8(Cmd, cmdp + 1);
if (keyNbr >= ICLASS_KEYS_MAX) {
PrintAndLogEx(ERR, "Invalid block number, MAX is "_YELLOW_("%d"), ICLASS_KEYS_MAX);
PrintAndLogEx(ERR, "Invalid block number, MAX is " _YELLOW_("%d"), ICLASS_KEYS_MAX);
errors = true;
}
cmdp += 2;

View file

@ -569,39 +569,30 @@ int bruteforceFileNoKeys(const char *filename) {
// TEST CODE BELOW
// ----------------------------------------------------------------------------
static int _testBruteforce() {
int errors = 0;
if (true) {
// First test
PrintAndLogEx(INFO, "Testing crack from dumpfile...");
/**
Expected values for the dumpfile:
High Security Key Table
PrintAndLogEx(INFO, "Testing crack from dumpfile...");
00 F1 35 59 A1 0D 5A 26 7F 18 60 0B 96 8A C0 25 C1
10 BF A1 3B B0 FF 85 28 75 F2 1F C6 8F 0E 74 8F 21
20 14 7A 55 16 C8 A9 7D B3 13 0C 5D C9 31 8D A9 B2
30 A3 56 83 0F 55 7E DE 45 71 21 D2 6D C1 57 1C 9C
40 78 2F 64 51 42 7B 64 30 FA 26 51 76 D3 E0 FB B6
50 31 9F BF 2F 7E 4F 94 B4 BD 4F 75 91 E3 1B EB 42
60 3F 88 6F B8 6C 2C 93 0D 69 2C D5 20 3C C1 61 95
70 43 08 A0 2F FE B3 26 D7 98 0B 34 7B 47 70 A0 AB
/**
Expected values for the dumpfile:
High Security Key Table
**** The 64-bit HS Custom Key Value = 5B7C62C491C11B39 ****
**/
uint16_t keytable[128] = {0};
00 F1 35 59 A1 0D 5A 26 7F 18 60 0B 96 8A C0 25 C1
10 BF A1 3B B0 FF 85 28 75 F2 1F C6 8F 0E 74 8F 21
20 14 7A 55 16 C8 A9 7D B3 13 0C 5D C9 31 8D A9 B2
30 A3 56 83 0F 55 7E DE 45 71 21 D2 6D C1 57 1C 9C
40 78 2F 64 51 42 7B 64 30 FA 26 51 76 D3 E0 FB B6
50 31 9F BF 2F 7E 4F 94 B4 BD 4F 75 91 E3 1B EB 42
60 3F 88 6F B8 6C 2C 93 0D 69 2C D5 20 3C C1 61 95
70 43 08 A0 2F FE B3 26 D7 98 0B 34 7B 47 70 A0 AB
//Test a few variants
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!");
}
**** The 64-bit HS Custom Key Value = 5B7C62C491C11B39 ****
**/
uint16_t keytable[128] = {0};
int errors = bruteforceFile("iclass_dump.bin", keytable);
if (errors) {
PrintAndLogEx(ERR, "Error: The file " _YELLOW_("iclass_dump.bin") "was not found!");
}
return errors;
}

View file

@ -654,33 +654,21 @@ static int doTestsWithKnownInputs() {
return errors;
}
static bool readKeyFile(uint8_t key[8]) {
bool retval = false;
//Test a few variants
char filename[30] = {0};
static bool readKeyFile(uint8_t* key, size_t keylen) {
if (fileExists("iclass_key.bin")) {
sprintf(filename, "%s.bin", "iclass_key");
} else if (fileExists("loclass/iclass_key.bin")) {
sprintf(filename, "%s.bin", "loclass/iclass_key");
} else if (fileExists("client/loclass/iclass_key.bin")) {
sprintf(filename, "%s.bin", "client/loclass/iclass_key");
size_t len = 0;
uint8_t *keyptr = NULL;
if ( loadFile_safe("iclass_key.bin", "", (void**)&keyptr, &len) != PM3_SUCCESS ) {
return false;
}
if (strlen(filename) == 0)
return retval;
FILE *f = fopen(filename, "rb");
if (!f)
return retval;
size_t bytes_read = fread(key, sizeof(uint8_t), 8, f);
if (bytes_read == 8)
retval = true;
fclose(f);
return retval;
if ( keylen != len ) {
return false;
}
memcpy(key, keyptr, keylen );
return true;
}
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)...");
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");
} else {