From f3a63767ed22d34afc6e914f9ee6e2351b93a6f1 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 15:55:52 +0200 Subject: [PATCH] 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 --- client/cmdhficlass.c | 4 +-- client/loclass/elite_crack.c | 47 +++++++++++++++--------------------- client/loclass/ikeys.c | 38 ++++++++++------------------- 3 files changed, 34 insertions(+), 55 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 52c3ff21c..bd937fe17 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -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; diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index 735e3c3df..bc474fc21 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -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; } diff --git a/client/loclass/ikeys.c b/client/loclass/ikeys.c index 53f7848de..f53f80221 100644 --- a/client/loclass/ikeys.c +++ b/client/loclass/ikeys.c @@ -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 {