mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-06 16:27:22 +08:00
Merge pull request #181 from brianpow/PrintAndLogDevice
migrate PrintfAndLog() to PrintAndLogDevice()
This commit is contained in:
commit
d1a029dc33
8 changed files with 107 additions and 105 deletions
|
@ -626,14 +626,14 @@ int CmdHFiClassELoad(const char *Cmd) {
|
|||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
if (fsize < 0) {
|
||||
PrintfAndLog("[-] error, when getting filesize");
|
||||
PrintAndLogDevice(WARNING, "error, when getting filesize");
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t *dump = malloc(fsize);
|
||||
if (!dump) {
|
||||
PrintfAndLog("[-] error, cannot allocate memory ");
|
||||
PrintAndLogDevice(WARNING, "error, cannot allocate memory ");
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
@ -645,7 +645,7 @@ int CmdHFiClassELoad(const char *Cmd) {
|
|||
//Validate
|
||||
|
||||
if (bytes_read < fsize) {
|
||||
PrintfAndLog("[-] error, could only read %d bytes (should be %d)", bytes_read, fsize );
|
||||
PrintAndLogDevice(WARNING, "error, could only read %d bytes (should be %d)", bytes_read, fsize );
|
||||
free(dump);
|
||||
return 1;
|
||||
}
|
||||
|
@ -1545,7 +1545,7 @@ int CmdHFiClass_loclass(const char *Cmd) {
|
|||
errors += testMAC();
|
||||
errors += doKeyTests(0);
|
||||
errors += testElite();
|
||||
if (errors) PrintfAndLog("[!] There were errors!!!");
|
||||
if (errors) PrintAndLogDevice(WARNING, "There were errors!!!");
|
||||
return errors;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -264,7 +264,7 @@ void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_ke
|
|||
#ifndef ON_DEVICE
|
||||
int testMAC()
|
||||
{
|
||||
PrintfAndLog("[+] Testing MAC calculation...");
|
||||
PrintAndLogDevice(SUCCESS, "Testing MAC calculation...");
|
||||
|
||||
//From the "dismantling.IClass" paper:
|
||||
uint8_t cc_nr[] = {0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0,0,0,0};
|
||||
|
@ -277,11 +277,11 @@ int testMAC()
|
|||
|
||||
if(memcmp(calculated_mac, correct_MAC,4) == 0)
|
||||
{
|
||||
PrintfAndLog("[+] MAC calculation OK!");
|
||||
PrintAndLogDevice(SUCCESS, "MAC calculation OK!");
|
||||
|
||||
}else
|
||||
{
|
||||
PrintfAndLog("[+] FAILED: MAC calculation failed:");
|
||||
PrintAndLogDevice(FAILED, "FAILED: MAC calculation failed:");
|
||||
printarr(" Calculated_MAC", calculated_mac, 4);
|
||||
printarr(" Correct_MAC ", correct_MAC, 4);
|
||||
return 1;
|
||||
|
|
|
@ -169,7 +169,7 @@ void printarr(char * name, uint8_t* arr, int len)
|
|||
cx += snprintf(output+cx,outsize-cx,"0x%02x,",*(arr+i));//5 bytes per byte
|
||||
}
|
||||
cx += snprintf(output+cx,outsize-cx,"};");
|
||||
PrintfAndLog(output);
|
||||
PrintAndLogDevice(NORMAL, output);
|
||||
free(output);
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ void printvar(char * name, uint8_t* arr, int len)
|
|||
cx += snprintf(output+cx,outsize-cx,"%02x",*(arr+i));//2 bytes per byte
|
||||
}
|
||||
|
||||
PrintfAndLog(output);
|
||||
PrintAndLogDevice(NORMAL, output);
|
||||
free(output);
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ void printarr_human_readable(char * title, uint8_t* arr, int len)
|
|||
cx += snprintf(output+cx,outsize-cx,"\n%02x| ", i );
|
||||
cx += snprintf(output+cx,outsize-cx, "%02x ",*(arr+i));
|
||||
}
|
||||
PrintfAndLog(output);
|
||||
PrintAndLogDevice(NORMAL, output);
|
||||
free(output);
|
||||
}
|
||||
|
||||
|
@ -231,14 +231,14 @@ int testBitStream()
|
|||
}
|
||||
if(memcmp(input, output, sizeof(input)) == 0)
|
||||
{
|
||||
PrintfAndLog(" Bitstream test 1 ok");
|
||||
PrintAndLogDevice(SUCCESS, " Bitstream test 1 ok");
|
||||
}else
|
||||
{
|
||||
PrintfAndLog(" Bitstream test 1 failed");
|
||||
PrintAndLogDevice(FAILED, " Bitstream test 1 failed");
|
||||
uint8_t i;
|
||||
for(i = 0 ; i < sizeof(input) ; i++)
|
||||
{
|
||||
PrintfAndLog(" IN %02x, OUT %02x", input[i], output[i]);
|
||||
PrintAndLogDevice(NORMAL, " IN %02x, OUT %02x", input[i], output[i]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -265,14 +265,14 @@ int testReversedBitstream()
|
|||
}
|
||||
if(memcmp(input, output, sizeof(input)) == 0)
|
||||
{
|
||||
PrintfAndLog(" Bitstream test 2 ok");
|
||||
PrintAndLogDevice(SUCCESS, " Bitstream test 2 ok");
|
||||
}else
|
||||
{
|
||||
PrintfAndLog(" Bitstream test 2 failed");
|
||||
PrintAndLogDevice(FAILED, " Bitstream test 2 failed");
|
||||
uint8_t i;
|
||||
for(i = 0 ; i < sizeof(input) ; i++)
|
||||
{
|
||||
PrintfAndLog(" IN %02x, MIDDLE: %02x, OUT %02x", input[i],reverse[i], output[i]);
|
||||
PrintAndLogDevice(NORMAL, " IN %02x, MIDDLE: %02x, OUT %02x", input[i],reverse[i], output[i]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ int testReversedBitstream()
|
|||
|
||||
int testCipherUtils(void)
|
||||
{
|
||||
PrintfAndLog("[+] Testing some internals...");
|
||||
PrintAndLogDevice(INFO, "Testing some internals...");
|
||||
int retval = 0;
|
||||
retval |= testBitStream();
|
||||
retval |= testReversedBitstream();
|
||||
|
|
|
@ -221,7 +221,7 @@ void hash2(uint8_t *key64, uint8_t *outp_keytable) {
|
|||
// Once again, key is on iclass-format
|
||||
desencrypt_iclass(key64, key64_negated, z[0]);
|
||||
|
||||
// PrintfAndLog("\nHigh security custom key (Kcus):");
|
||||
// PrintAndLogDevice(NORMAL, "\n"); PrintAndLogDevice(NORMAL, "High security custom key (Kcus):");
|
||||
// printvar("z0 ", z[0],8);
|
||||
|
||||
uint8_t y[8][8]={{0},{0}};
|
||||
|
@ -324,10 +324,10 @@ int bruteforceItem(dumpdata item, uint16_t keytable[]) {
|
|||
keytable[key_index[i]] |= BEING_CRACKED;
|
||||
|
||||
if (numbytes_to_recover > 3) {
|
||||
PrintfAndLog("[-] The CSN requires > 3 byte bruteforce, not supported");
|
||||
PrintAndLogDevice(FAILED, "The CSN requires > 3 byte bruteforce, not supported");
|
||||
printvar("[-] CSN", item.csn, 8);
|
||||
printvar("[-] HASH1", key_index, 8);
|
||||
PrintfAndLog("");
|
||||
PrintAndLogDevice(NORMAL, "");
|
||||
//Before we exit, reset the 'BEING_CRACKED' to zero
|
||||
keytable[bytes_to_recover[0]] &= ~BEING_CRACKED;
|
||||
keytable[bytes_to_recover[1]] &= ~BEING_CRACKED;
|
||||
|
@ -350,9 +350,9 @@ int bruteforceItem(dumpdata item, uint16_t keytable[]) {
|
|||
*/
|
||||
|
||||
uint32_t endmask = 1 << 8*numbytes_to_recover;
|
||||
PrintfAndLog("----------------------------");
|
||||
PrintAndLogDevice(NORMAL, "----------------------------");
|
||||
for (i =0 ; i < numbytes_to_recover && numbytes_to_recover > 1; i++)
|
||||
PrintfAndLog("[+] Bruteforcing byte %d", bytes_to_recover[i]);
|
||||
PrintAndLogDevice(INFO, "Bruteforcing byte %d", bytes_to_recover[i]);
|
||||
|
||||
while (!found && !(brute & endmask)) {
|
||||
|
||||
|
@ -383,7 +383,7 @@ int bruteforceItem(dumpdata item, uint16_t keytable[]) {
|
|||
if (memcmp(calculated_MAC, item.mac, 4) == 0) {
|
||||
printf("\r\n");
|
||||
for (i =0 ; i < numbytes_to_recover; i++) {
|
||||
PrintfAndLog("[=] %d: 0x%02x", bytes_to_recover[i], 0xFF & keytable[bytes_to_recover[i]]);
|
||||
PrintAndLogDevice(INFO, "%d: 0x%02x", bytes_to_recover[i], 0xFF & keytable[bytes_to_recover[i]]);
|
||||
}
|
||||
found = true;
|
||||
break;
|
||||
|
@ -399,7 +399,7 @@ int bruteforceItem(dumpdata item, uint16_t keytable[]) {
|
|||
}
|
||||
|
||||
if (!found) {
|
||||
PrintfAndLog("\n[!] Failed to recover %d bytes using the following CSN", numbytes_to_recover);
|
||||
PrintAndLogDevice(NORMAL, "\n"); PrintAndLogDevice(WARNING, "Failed to recover %d bytes using the following CSN", numbytes_to_recover);
|
||||
printvar("[!] CSN", item.csn, 8);
|
||||
errors++;
|
||||
|
||||
|
@ -409,7 +409,7 @@ int bruteforceItem(dumpdata item, uint16_t keytable[]) {
|
|||
keytable[bytes_to_recover[i]] |= CRACK_FAILED;
|
||||
}
|
||||
} else {
|
||||
//PrintfAndLog("[+] DES calcs: %u", brute);
|
||||
//PrintAndLogDevice(SUCCESS, "DES calcs: %u", brute);
|
||||
for (i=0; i < numbytes_to_recover; i++){
|
||||
keytable[bytes_to_recover[i]] &= 0xFF;
|
||||
keytable[bytes_to_recover[i]] |= CRACKED;
|
||||
|
@ -464,7 +464,7 @@ int calculateMasterKey(uint8_t first16bytes[], uint64_t master_key[] ){
|
|||
|
||||
des_setkey_enc( &ctx_e, key64_stdformat );
|
||||
des_crypt_ecb(&ctx_e, key64_negated, result);
|
||||
PrintfAndLog("\n[+] -- High security custom key (Kcus) --");
|
||||
PrintAndLogDevice(NORMAL, "\n"); PrintAndLogDevice(SUCCESS, "-- High security custom key (Kcus) --");
|
||||
printvar("[+] Standard format ", key64_stdformat, 8);
|
||||
printvar("[+] iClass format ", key64, 8);
|
||||
|
||||
|
@ -472,10 +472,10 @@ int calculateMasterKey(uint8_t first16bytes[], uint64_t master_key[] ){
|
|||
memcpy(master_key, key64, 8);
|
||||
|
||||
if (memcmp(z_0,result,4) != 0) {
|
||||
PrintfAndLog("[!] Failed to verify calculated master key (k_cus)! Something is wrong.");
|
||||
PrintAndLogDevice(WARNING, "Failed to verify calculated master key (k_cus)! Something is wrong.");
|
||||
return 1;
|
||||
} else {
|
||||
PrintfAndLog("\n[+] Key verified ok!\n");
|
||||
PrintAndLogDevice(NORMAL, "\n"); PrintAndLogDevice(SUCCESS, "Key verified ok!\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -501,7 +501,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) {
|
|||
}
|
||||
free(attack);
|
||||
|
||||
PrintfAndLog("[+] time: %" PRIu64 " seconds", (msclock()-t1)/1000);
|
||||
PrintAndLogDevice(SUCCESS, "time: %" PRIu64 " seconds", (msclock()-t1)/1000);
|
||||
|
||||
// Pick out the first 16 bytes of the keytable.
|
||||
// The keytable is now in 16-bit ints, where the upper 8 bits
|
||||
|
@ -513,7 +513,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) {
|
|||
first16bytes[i] = keytable[i] & 0xFF;
|
||||
|
||||
if (!(keytable[i] & CRACKED))
|
||||
PrintfAndLog("[!] error, we are missing byte %d, custom key calculation will fail...", i);
|
||||
PrintAndLogDevice(WARNING, "error, we are missing byte %d, custom key calculation will fail...", i);
|
||||
}
|
||||
errors += calculateMasterKey(first16bytes, NULL);
|
||||
return errors;
|
||||
|
@ -528,7 +528,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) {
|
|||
int bruteforceFile(const char *filename, uint16_t keytable[]) {
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if (!f) {
|
||||
PrintfAndLog("[!] Failed to read from file '%s'", filename);
|
||||
PrintAndLogDevice(WARNING, "Failed to read from file '%s'", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -537,7 +537,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) {
|
|||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
if (fsize < 0) {
|
||||
PrintfAndLog("[!] Error, when getting filesize");
|
||||
PrintAndLogDevice(WARNING, "Error, when getting filesize");
|
||||
if (f) fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) {
|
|||
if (f) fclose(f);
|
||||
|
||||
if (bytes_read < fsize) {
|
||||
PrintfAndLog("[!] Error, could only read %d bytes (should be %d)", bytes_read, fsize );
|
||||
PrintAndLogDevice(WARNING, "Error, could only read %d bytes (should be %d)", bytes_read, fsize );
|
||||
}
|
||||
|
||||
uint8_t res = bruteforceDump(dump, fsize, keytable);
|
||||
|
@ -576,7 +576,7 @@ int _testBruteforce() {
|
|||
int errors = 0;
|
||||
if (true) {
|
||||
// First test
|
||||
PrintfAndLog("[+] Testing crack from dumpfile...");
|
||||
PrintAndLogDevice(INFO, "Testing crack from dumpfile...");
|
||||
|
||||
/**
|
||||
Expected values for the dumpfile:
|
||||
|
@ -603,7 +603,7 @@ int _testBruteforce() {
|
|||
} else if (fileExists("client/loclass/iclass_dump.bin")){
|
||||
errors |= bruteforceFile("client/loclass/iclass_dump.bin", keytable);
|
||||
} else {
|
||||
PrintfAndLog("[!] Error: The file iclass_dump.bin was not found!");
|
||||
PrintAndLogDevice(WARNING, "Error: The file iclass_dump.bin was not found!");
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
|
@ -618,20 +618,20 @@ int _test_iclass_key_permutation() {
|
|||
permutekey_rev(testcase_output, testcase_output_rev);
|
||||
|
||||
if (memcmp(testcase_output, testcase_output_correct,8) != 0) {
|
||||
PrintfAndLog("[!] Error with iclass key permute!");
|
||||
PrintAndLogDevice(WARNING, "Error with iclass key permute!");
|
||||
printarr("testcase_output", testcase_output, 8);
|
||||
printarr("testcase_output_correct", testcase_output_correct, 8);
|
||||
return 1;
|
||||
|
||||
}
|
||||
if (memcmp(testcase, testcase_output_rev, 8) != 0) {
|
||||
PrintfAndLog("[!] Error with reverse iclass key permute");
|
||||
PrintAndLogDevice(WARNING, "Error with reverse iclass key permute");
|
||||
printarr("testcase", testcase, 8);
|
||||
printarr("testcase_output_rev", testcase_output_rev, 8);
|
||||
return 1;
|
||||
}
|
||||
|
||||
PrintfAndLog("[+] Iclass key permutation OK!");
|
||||
PrintAndLogDevice(SUCCESS, "Iclass key permutation OK!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -642,7 +642,7 @@ int _testHash1() {
|
|||
hash1(csn, k);
|
||||
|
||||
if (memcmp(k,expected,8) != 0) {
|
||||
PrintfAndLog("[!] Error with hash1!");
|
||||
PrintAndLogDevice(WARNING, "Error with hash1!");
|
||||
printarr("calculated", k, 8);
|
||||
printarr("expected", expected, 8);
|
||||
return 1;
|
||||
|
@ -651,8 +651,8 @@ int _testHash1() {
|
|||
}
|
||||
|
||||
int testElite() {
|
||||
PrintfAndLog("[+] Testing iClass Elite functinality...");
|
||||
PrintfAndLog("[+] Testing hash2");
|
||||
PrintAndLogDevice(INFO, "Testing iClass Elite functinality...");
|
||||
PrintAndLogDevice(INFO, "Testing hash2");
|
||||
uint8_t k_cus[8] = {0x5B,0x7C,0x62,0xC4,0x91,0xC1,0x1B,0x39};
|
||||
|
||||
/**
|
||||
|
@ -676,13 +676,13 @@ int testElite() {
|
|||
hash2(k_cus, keytable);
|
||||
printarr_human_readable("Hash2", keytable, 128);
|
||||
if (keytable[3] == 0xA1 && keytable[0x30] == 0xA3 && keytable[0x6F] == 0x95) {
|
||||
PrintfAndLog("[+] Hash2 looks fine...");
|
||||
PrintAndLogDevice(SUCCESS, "Hash2 looks fine...");
|
||||
}
|
||||
|
||||
int errors = 0 ;
|
||||
PrintfAndLog("[+] Testing hash1...");
|
||||
PrintAndLogDevice(INFO, "Testing hash1...");
|
||||
errors += _testHash1();
|
||||
PrintfAndLog("[+] Testing key diversification ...");
|
||||
PrintAndLogDevice(INFO, "Testing key diversification ...");
|
||||
errors +=_test_iclass_key_permutation();
|
||||
errors += _testBruteforce();
|
||||
return errors;
|
||||
|
|
|
@ -77,14 +77,14 @@ int saveFile(const char *preferredName, const char *suffix, const void* data, si
|
|||
/*Opening file for writing in binary mode*/
|
||||
FILE *f = fopen(fileName, "wb");
|
||||
if (!f) {
|
||||
PrintfAndLog("[!] file not found or locked. '%s'", fileName);
|
||||
PrintAndLogDevice(WARNING, "file not found or locked. '%s'", fileName);
|
||||
free(fileName);
|
||||
return 1;
|
||||
}
|
||||
fwrite(data, 1, datalen, f);
|
||||
fflush(f);
|
||||
fclose(f);
|
||||
PrintfAndLog("[+] saved %u bytes to binary file %s", datalen, fileName);
|
||||
PrintAndLogDevice(SUCCESS, "saved %u bytes to binary file %s", datalen, fileName);
|
||||
free(fileName);
|
||||
return 0;
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ int saveFileEML(const char *preferredName, const char *suffix, uint8_t* data, si
|
|||
/*Opening file for writing in text mode*/
|
||||
FILE *f = fopen(fileName, "w+");
|
||||
if (!f) {
|
||||
PrintfAndLog("[!] file not found or locked. '%s'", fileName);
|
||||
PrintAndLogDevice(WARNING, "file not found or locked. '%s'", fileName);
|
||||
retval = 1;
|
||||
goto out;
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ int saveFileEML(const char *preferredName, const char *suffix, uint8_t* data, si
|
|||
}
|
||||
fflush(f);
|
||||
fclose(f);
|
||||
PrintfAndLog("[+] saved %d blocks to text file %s", blocks, fileName);
|
||||
PrintAndLogDevice(SUCCESS, "saved %d blocks to text file %s", blocks, fileName);
|
||||
|
||||
out:
|
||||
free(fileName);
|
||||
|
@ -147,17 +147,17 @@ out:
|
|||
* write also to a logfile. When doing so, just delete this function.
|
||||
* @param fmt
|
||||
*/
|
||||
void PrintfAndLog(char *fmt, ...)
|
||||
void PrintAndLogDevice(logLevel_t level, char *fmt, ...)
|
||||
{
|
||||
char buffer[2048] = {0};
|
||||
va_list args;
|
||||
va_start(args,fmt);
|
||||
vsprintf (buffer,fmt, args);
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||
va_end(args);
|
||||
PrintAndLog(buffer);
|
||||
PrintAndLogEx(level, buffer);
|
||||
}
|
||||
#else //if we're on ARM
|
||||
void PrintfAndLog(char *fmt,...)
|
||||
void PrintAndLogDevice(logLevel_t level, char *fmt,...)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
#ifndef ON_DEVICE
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "../ui.h"
|
||||
|
||||
/**
|
||||
* @brief Utility function to save data to a binary file. This method takes a preferred name, but if that
|
||||
* file already exists, it tries with another name until it finds something suitable.
|
||||
|
@ -84,5 +86,5 @@ int fileExists(const char *filename);
|
|||
* write also to a logfile. When doing so, just point this function to use PrintAndLog
|
||||
* @param fmt
|
||||
*/
|
||||
void PrintfAndLog(char *fmt, ...);
|
||||
void PrintAndLogDevice(logLevel_t level, char *fmt, ...);
|
||||
#endif // FILEUTILS_H
|
||||
|
|
|
@ -227,7 +227,7 @@ void printbegin() {
|
|||
if (debug_print < 2)
|
||||
return;
|
||||
|
||||
PrintfAndLog(" | x| y|z0|z1|z2|z3|z4|z5|z6|z7|");
|
||||
PrintAndLogDevice(NORMAL, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|");
|
||||
}
|
||||
|
||||
void printState(char* desc, uint64_t c)
|
||||
|
@ -295,7 +295,7 @@ void hash0(uint64_t c, uint8_t k[8])
|
|||
if(x & 1) //Check if x7 is 1
|
||||
p = ~p;
|
||||
|
||||
if(debug_print >= 2) PrintfAndLog("p:%02x", p);
|
||||
if(debug_print >= 2) PrintAndLogDevice(DEBUG, "p:%02x", p);
|
||||
|
||||
BitstreamIn p_in = { &p, 8,0 };
|
||||
uint8_t outbuffer[] = {0,0,0,0,0,0,0,0};
|
||||
|
@ -448,7 +448,7 @@ int testDES(Testcase testcase, des_context ctx_enc, des_context ctx_dec)
|
|||
if(memcmp(testcase.uid,decrypted,8) != 0)
|
||||
{
|
||||
//Decryption fail
|
||||
PrintfAndLog("Encryption <-> Decryption FAIL");
|
||||
PrintAndLogDevice(FAILED, "Encryption <-> Decryption FAIL");
|
||||
printarr("Input", testcase.uid, 8);
|
||||
printarr("Decrypted", decrypted, 8);
|
||||
retval = 1;
|
||||
|
@ -457,7 +457,7 @@ int testDES(Testcase testcase, des_context ctx_enc, des_context ctx_dec)
|
|||
if(memcmp(des_encrypted_csn,testcase.t_key,8) != 0)
|
||||
{
|
||||
//Encryption fail
|
||||
PrintfAndLog("Encryption != Expected result");
|
||||
PrintAndLogDevice(FAILED, "Encryption != Expected result");
|
||||
printarr("Output", des_encrypted_csn, 8);
|
||||
printarr("Expected", testcase.t_key, 8);
|
||||
retval = 1;
|
||||
|
@ -468,7 +468,7 @@ int testDES(Testcase testcase, des_context ctx_enc, des_context ctx_dec)
|
|||
if(memcmp(div_key, testcase.div_key ,8) != 0)
|
||||
{
|
||||
//Key diversification fail
|
||||
PrintfAndLog("Div key != expected result");
|
||||
PrintAndLogDevice(FAILED, "Div key != expected result");
|
||||
printarr(" csn ", testcase.uid,8);
|
||||
printarr("{csn} ", des_encrypted_csn,8);
|
||||
printarr("hash0 ", div_key, 8);
|
||||
|
@ -493,13 +493,13 @@ void des_checkParity(uint8_t* key) {
|
|||
bool parity = des_getParityBitFromKey(key[i]);
|
||||
if (parity != (key[i] & 0x1)) {
|
||||
fails++;
|
||||
PrintfAndLog("[+] parity1 fail, byte %d [%02x] was %d, should be %d", i, key[i], (key[i] & 0x1), parity);
|
||||
PrintAndLogDevice(FAILED, "parity1 fail, byte %d [%02x] was %d, should be %d", i, key[i], (key[i] & 0x1), parity);
|
||||
}
|
||||
}
|
||||
if(fails)
|
||||
PrintfAndLog("[+] parity fails: %d", fails);
|
||||
PrintAndLogDevice(FAILED, "parity fails: %d", fails);
|
||||
else
|
||||
PrintfAndLog("[+] Key syntax is with parity bits inside each byte");
|
||||
PrintAndLogDevice(SUCCESS, "Key syntax is with parity bits inside each byte");
|
||||
}
|
||||
|
||||
Testcase testcases[] ={
|
||||
|
@ -578,15 +578,15 @@ int testKeyDiversificationWithMasterkeyTestcases() {
|
|||
int i;
|
||||
uint8_t empty[8]={0};
|
||||
|
||||
PrintfAndLog("[+] Testing encryption/decryption");
|
||||
PrintAndLogDevice(INFO, "Testing encryption/decryption");
|
||||
|
||||
for (i = 0; memcmp(testcases+i, empty, 8); i++)
|
||||
error += testDES(testcases[i], ctx_enc, ctx_dec);
|
||||
|
||||
if (error)
|
||||
PrintfAndLog("[+] %d errors occurred (%d testcases)", error, i);
|
||||
PrintAndLogDevice(FAILED, "%d errors occurred (%d testcases)", error, i);
|
||||
else
|
||||
PrintfAndLog("[+] Hashing seems to work (%d testcases)", i);
|
||||
PrintAndLogDevice(SUCCESS, "Hashing seems to work (%d testcases)", i);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -598,7 +598,7 @@ uint64_t testCryptedCSN(uint64_t crypted_csn, uint64_t expected)
|
|||
{
|
||||
int retval = 0;
|
||||
uint8_t result[8] = {0};
|
||||
if(debug_print) PrintfAndLog("debug_print %d", debug_print);
|
||||
if(debug_print) PrintAndLogDevice(DEBUG, "debug_print %d", debug_print);
|
||||
if(debug_print) print64bits(" {csn} ", crypted_csn );
|
||||
|
||||
uint64_t crypted_csn_swapped = swapZvalues(crypted_csn);
|
||||
|
@ -611,12 +611,12 @@ uint64_t testCryptedCSN(uint64_t crypted_csn, uint64_t expected)
|
|||
|
||||
if(resultbyte != expected ) {
|
||||
if(debug_print) {
|
||||
PrintfAndLog("\n[+] FAIL!");
|
||||
PrintAndLogDevice(NORMAL, "\n"); PrintAndLogDevice(FAILED, "FAIL!");
|
||||
print64bits(" expected " , expected );
|
||||
}
|
||||
retval = 1;
|
||||
} else {
|
||||
if (debug_print) PrintfAndLog(" [OK]");
|
||||
if (debug_print) PrintAndLogDevice(SUCCESS, "[OK]");
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
@ -635,7 +635,7 @@ int testDES2(uint64_t csn, uint64_t expected) {
|
|||
print64bits(" expected ", expected );
|
||||
|
||||
if( expected == crypt_csn ) {
|
||||
PrintfAndLog("[+] OK");
|
||||
PrintAndLogDevice(SUCCESS, "OK");
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
|
@ -650,13 +650,13 @@ int testDES2(uint64_t csn, uint64_t expected) {
|
|||
int doTestsWithKnownInputs() {
|
||||
// KSel from http://www.proxmark.org/forum/viewtopic.php?pid=10977#p10977
|
||||
int errors = 0;
|
||||
PrintfAndLog("[+] Testing DES encryption");
|
||||
PrintAndLogDevice(SUCCESS, "Testing DES encryption");
|
||||
uint8_t key[8] = {0x6c,0x8d,0x44,0xf9,0x2a,0x2d,0x01,0xbf};
|
||||
|
||||
des_setkey_enc( &ctx_enc, key);
|
||||
testDES2(0xbbbbaaaabbbbeeee,0xd6ad3ca619659e6b);
|
||||
|
||||
PrintfAndLog("[+] Testing hashing algorithm");
|
||||
PrintAndLogDevice(SUCCESS, "Testing hashing algorithm");
|
||||
|
||||
errors += testCryptedCSN(0x0102030405060708,0x0bdd6512073c460a);
|
||||
errors += testCryptedCSN(0x1020304050607080,0x0208211405f3381f);
|
||||
|
@ -669,9 +669,9 @@ int doTestsWithKnownInputs() {
|
|||
errors += testCryptedCSN(0x14e2adfc5bb7e134,0x6ac90c6508bd9ea3);
|
||||
|
||||
if (errors)
|
||||
PrintfAndLog("[+] %d errors occurred (9 testcases)", errors);
|
||||
PrintAndLogDevice(FAILED, "%d errors occurred (9 testcases)", errors);
|
||||
else
|
||||
PrintfAndLog("[+] Hashing seems to work (9 testcases)" );
|
||||
PrintAndLogDevice(SUCCESS, "Hashing seems to work (9 testcases)" );
|
||||
return errors;
|
||||
}
|
||||
|
||||
|
@ -693,10 +693,10 @@ static bool readKeyFile(uint8_t key[8]) {
|
|||
int doKeyTests(uint8_t debuglevel) {
|
||||
debug_print = debuglevel;
|
||||
|
||||
PrintfAndLog("[+] Checking if the master key is present (iclass_key.bin)...");
|
||||
PrintAndLogDevice(INFO, "Checking if the master key is present (iclass_key.bin)...");
|
||||
uint8_t key[8] = {0};
|
||||
if (readKeyFile(key)) {
|
||||
PrintfAndLog("[+] Master key not present, will not be able to do all testcases");
|
||||
PrintAndLogDevice(FAILED, "Master key not present, will not be able to do all testcases");
|
||||
} else {
|
||||
|
||||
//Test if it's the right key...
|
||||
|
@ -706,19 +706,19 @@ int doKeyTests(uint8_t debuglevel) {
|
|||
j += key[i];
|
||||
|
||||
if (j != 185) {
|
||||
PrintfAndLog("[+] A key was loaded, but it does not seem to be the correct one. Aborting these tests");
|
||||
PrintAndLogDevice(INFO, "A key was loaded, but it does not seem to be the correct one. Aborting these tests");
|
||||
} else {
|
||||
PrintfAndLog("[+] Key present");
|
||||
PrintfAndLog("[+] Checking key parity...");
|
||||
PrintAndLogDevice(SUCCESS, "Key present");
|
||||
PrintAndLogDevice(SUCCESS, "Checking key parity...");
|
||||
des_checkParity(key);
|
||||
des_setkey_enc( &ctx_enc, key);
|
||||
des_setkey_dec( &ctx_dec, key);
|
||||
// Test hashing functions
|
||||
PrintfAndLog("[+] The following tests require the correct 8-byte master key");
|
||||
PrintAndLogDevice(SUCCESS, "The following tests require the correct 8-byte master key");
|
||||
testKeyDiversificationWithMasterkeyTestcases();
|
||||
}
|
||||
}
|
||||
PrintfAndLog("[+] Testing key diversification with non-sensitive keys...");
|
||||
PrintAndLogDevice(SUCCESS, "Testing key diversification with non-sensitive keys...");
|
||||
doTestsWithKnownInputs();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -56,42 +56,42 @@ int unitTests()
|
|||
errors += testElite();
|
||||
if(errors)
|
||||
{
|
||||
PrintfAndLog("OBS! There were errors!!!");
|
||||
PrintAndLogDevice(NORMAL, "OBS! There were errors!!!");
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
int showHelp()
|
||||
{
|
||||
PrintfAndLog("Usage: loclass [options]");
|
||||
PrintfAndLog("Options:");
|
||||
PrintfAndLog("-t Perform self-test");
|
||||
PrintfAndLog("-h Show this help");
|
||||
PrintfAndLog("-f <filename> Bruteforce iclass dumpfile");
|
||||
PrintfAndLog(" An iclass dumpfile is assumed to consist of an arbitrary number of malicious CSNs, and their protocol responses");
|
||||
PrintfAndLog(" The binary format of the file is expected to be as follows: ");
|
||||
PrintfAndLog(" <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>");
|
||||
PrintfAndLog(" <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>");
|
||||
PrintfAndLog(" <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>");
|
||||
PrintfAndLog(" ... totalling N*24 bytes");
|
||||
PrintfAndLog(" Check iclass_dump.bin for an example");
|
||||
PrintAndLogDevice(NORMAL, "Usage: loclass [options]");
|
||||
PrintAndLogDevice(NORMAL, "Options:");
|
||||
PrintAndLogDevice(NORMAL, "-t Perform self-test");
|
||||
PrintAndLogDevice(NORMAL, "-h Show this help");
|
||||
PrintAndLogDevice(NORMAL, "-f <filename> Bruteforce iclass dumpfile");
|
||||
PrintAndLogDevice(NORMAL, " An iclass dumpfile is assumed to consist of an arbitrary number of malicious CSNs, and their protocol responses");
|
||||
PrintAndLogDevice(NORMAL, " The binary format of the file is expected to be as follows: ");
|
||||
PrintAndLogDevice(NORMAL, " <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>");
|
||||
PrintAndLogDevice(NORMAL, " <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>");
|
||||
PrintAndLogDevice(NORMAL, " <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>");
|
||||
PrintAndLogDevice(NORMAL, " ... totalling N*24 bytes");
|
||||
PrintAndLogDevice(NORMAL, " Check iclass_dump.bin for an example");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
PrintfAndLog("IClass Cipher version 1.2, Copyright (C) 2014 Martin Holst Swende\n");
|
||||
PrintfAndLog("Comes with ABSOLUTELY NO WARRANTY");
|
||||
PrintfAndLog("Released as GPLv2\n");
|
||||
PrintfAndLog("WARNING");
|
||||
PrintfAndLog("");
|
||||
PrintfAndLog("THIS TOOL IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. ");
|
||||
PrintfAndLog("");
|
||||
PrintfAndLog("USAGE OF THIS TOOL IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL ");
|
||||
PrintfAndLog("PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, ");
|
||||
PrintfAndLog("AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. ");
|
||||
PrintfAndLog("");
|
||||
PrintfAndLog("THIS TOOL SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. ");
|
||||
PrintAndLogDevice(NORMAL, "IClass Cipher version 1.2, Copyright (C) 2014 Martin Holst Swende\n");
|
||||
PrintAndLogDevice(NORMAL, "Comes with ABSOLUTELY NO WARRANTY");
|
||||
PrintAndLogDevice(NORMAL, "Released as GPLv2\n");
|
||||
PrintAndLogDevice(NORMAL, "WARNING");
|
||||
PrintAndLogDevice(NORMAL, "");
|
||||
PrintAndLogDevice(NORMAL, "THIS TOOL IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. ");
|
||||
PrintAndLogDevice(NORMAL, "");
|
||||
PrintAndLogDevice(NORMAL, "USAGE OF THIS TOOL IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL ");
|
||||
PrintAndLogDevice(NORMAL, "PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, ");
|
||||
PrintAndLogDevice(NORMAL, "AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. ");
|
||||
PrintAndLogDevice(NORMAL, "");
|
||||
PrintAndLogDevice(NORMAL, "THIS TOOL SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. ");
|
||||
|
||||
|
||||
char *fileName = NULL;
|
||||
|
|
Loading…
Reference in a new issue