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
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;
} }
@ -1971,7 +1971,7 @@ static int CmdHFiClassManageKeys(const char *Cmd) {
case 'n': case 'n':
keyNbr = param_get8(Cmd, cmdp + 1); keyNbr = param_get8(Cmd, cmdp + 1);
if (keyNbr >= ICLASS_KEYS_MAX) { 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; errors = true;
} }
cmdp += 2; cmdp += 2;

View file

@ -569,39 +569,30 @@ 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...");
Expected values for the dumpfile:
High Security Key Table
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 Expected values for the dumpfile:
20 14 7A 55 16 C8 A9 7D B3 13 0C 5D C9 31 8D A9 B2 High Security Key Table
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
**** The 64-bit HS Custom Key Value = 5B7C62C491C11B39 **** 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
uint16_t keytable[128] = {0}; 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 **** The 64-bit HS Custom Key Value = 5B7C62C491C11B39 ****
if (fileExists("iclass_dump.bin")) { **/
errors |= bruteforceFile("iclass_dump.bin", keytable); uint16_t keytable[128] = {0};
} else if (fileExists("loclass/iclass_dump.bin")) { int errors = bruteforceFile("iclass_dump.bin", keytable);
errors |= bruteforceFile("loclass/iclass_dump.bin", keytable); if (errors) {
} else if (fileExists("client/loclass/iclass_dump.bin")) { PrintAndLogEx(ERR, "Error: The file " _YELLOW_("iclass_dump.bin") "was not found!");
errors |= bruteforceFile("client/loclass/iclass_dump.bin", keytable);
} else {
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");
if (!f) memcpy(key, keyptr, keylen );
return retval; return true;
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 {