From b403c300910c62cbacf95be213efdc6ed8ed85d1 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 29 Oct 2016 21:42:46 +0200 Subject: [PATCH] FIX: the time_t calls under mingw needs a #define _USE_32BIT_TIME_T 1 to be correct. It seems to work in "hf mf mifare" but not in "hf mf hardnested" --- client/cmdanalyse.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ client/cmdanalyse.h | 4 +++- client/cmdhfmfhard.c | 23 +++++++++++++--------- client/cmdhfmfhard.h | 7 ++----- client/mifarehost.h | 4 ++-- client/proxmark3.h | 16 +++++++++++----- client/uart.h | 1 + client/ui.h | 10 +++++++++- client/util.h | 3 +-- 9 files changed, 88 insertions(+), 25 deletions(-) diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index e7a638ee..fb084f43 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -8,6 +8,7 @@ // Analyse bytes commands //----------------------------------------------------------------------------- #include "cmdanalyse.h" +#include "nonce2key/nonce2key.h" static int CmdHelp(const char *Cmd); @@ -124,6 +125,29 @@ static uint8_t calcSumNibbleSubOnes( uint8_t* bytes, uint8_t len, uint32_t mask) return ~calcSumNibbleSub(bytes, len, mask); } +// measuring LFSR maximum length +int CmdAnalyseLfsr(const char *Cmd){ + + uint16_t start_state = 0; /* Any nonzero start state will work. */ + uint16_t lfsr = start_state; + //uint32_t period = 0; + + uint8_t iv = param_get8ex(Cmd, 0, 0, 16); + uint8_t find = param_get8ex(Cmd, 1, 0, 16); + + printf("LEGIC LFSR IV 0x%02X: \n", iv); + printf(" bit# | lfsr | ^0x40 | 0x%02X ^ lfsr \n",find); + + for (uint8_t i = 0x01; i < 0x30; i += 1) { + //period = 0; + legic_prng_init(iv); + legic_prng_forward(i); + lfsr = legic_prng_get_bits(12); + + printf(" %02X | %03X | %03X | %03X \n",i, lfsr, 0x40 ^ lfsr, find ^ lfsr); + } + return 0; +} int CmdAnalyseLCR(const char *Cmd) { uint8_t data[50]; char cmdp = param_getchar(Cmd, 0); @@ -284,6 +308,25 @@ int CmdAnalyseTEASelfTest(const char *Cmd){ return 0; } +int CmdAnalyseA(const char *Cmd){ + +// uid(2e086b1a) nt(230736f6) par(0000000000000000) ks(0b0008000804000e) nr(000000000) +// uid(2e086b1a) nt(230736f6) par(0000000000000000) ks(0e0b0e0b090c0d02) nr(000000001) +// uid(2e086b1a) nt(230736f6) par(0000000000000000) ks(0e05060e01080b08) nr(000000002) + uint32_t uid = 0x2e086b1a, nt = 0x230736f6, nr = 0x000000001; + uint64_t ks_list = 0x0e0b0e0b090c0d02, r_key = 0; + + nonce2key_ex(0, 0 , uid, nt, nr, ks_list, &r_key); + + nr = 0x000000002; + ks_list = 0x0e05060e01080b08; + nonce2key_ex(0, 0 , uid, nt, nr, ks_list, &r_key); + + printf("Found valid key: %012"llx" \n", r_key); + return 0; +} + + static command_t CommandTable[] = { {"help", CmdHelp, 1, "This help"}, {"lcr", CmdAnalyseLCR, 1, "Generate final byte for XOR LRC"}, @@ -291,6 +334,8 @@ static command_t CommandTable[] = { {"chksum", CmdAnalyseCHKSUM, 1, "Checksum with adding, masking and one's complement"}, {"dates", CmdAnalyseDates, 1, "Look for datestamps in a given array of bytes"}, {"tea", CmdAnalyseTEASelfTest, 1, "Crypto TEA test"}, + {"lfsr", CmdAnalyseLfsr, 1, "LFSR tests"}, + {"a", CmdAnalyseA, 1, "num bits test"}, {NULL, NULL, 0, NULL} }; diff --git a/client/cmdanalyse.h b/client/cmdanalyse.h index ec05cee2..4103a2b9 100644 --- a/client/cmdanalyse.h +++ b/client/cmdanalyse.h @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2010 iZsh +// Copyright (C) 2016 iceman // // This code is licensed to you under the terms of the GNU GPL, version 2 or, // at your option, any later version. See the LICENSE.txt file for the text of @@ -20,6 +20,7 @@ #include "crc.h" #include "../common/iso15693tools.h" #include "tea.h" +#include "../include/legic_prng.h" int usage_analyse_lcr(void); int usage_analyse_checksum(void); @@ -31,4 +32,5 @@ int CmdAnalyseCHKSUM(const char *Cmd); int CmdAnalyseDates(const char *Cmd); int CmdAnalyseCRC(const char *Cmd); int CmdAnalyseTEASelfTest(const char *Cmd); +int CmdAnalyseLfsr(const char *Cmd); #endif diff --git a/client/cmdhfmfhard.c b/client/cmdhfmfhard.c index fb576441..a6b8bc51 100644 --- a/client/cmdhfmfhard.c +++ b/client/cmdhfmfhard.c @@ -1275,7 +1275,7 @@ static bool TestIfKeyExists(uint64_t key) } count += (p_odd - p->states[ODD_STATE]) * (p_even - p->states[EVEN_STATE]); if (found_odd && found_even) { - PrintAndLog("Key Found after testing %lld (2^%1.1f) out of %lld (2^%1.1f) keys. ", + PrintAndLog("\nKey Found after testing %lld (2^%1.1f) out of %lld (2^%1.1f) keys. ", count, log(count)/log(2), maximum_states, @@ -1698,8 +1698,10 @@ static bool brute_force(void) if (maximum_states == 0) return false; // prevent keyspace reduction error (2^-inf) PrintAndLog("Brute force phase starting."); - time_t start, end; - time(&start); + +// clock_t time1 = clock(); + time_t start1, end1; + time(&start1); keys_found = 0; foundkey = 0; @@ -1746,11 +1748,16 @@ static bool brute_force(void) pthread_join(threads[i], 0); } - time(&end); - unsigned long elapsed_time = difftime(end, start); + time(&end1); + unsigned long elapsed_time = difftime(end1, start1); + // time1 = clock() - time1; + // if ( time1 > 0 ) { + // ((float)time1)/CLOCKS_PER_SEC + // } if (keys_found && TestIfKeyExists(foundkey)) { - PrintAndLog("Success! Tested %"PRIu32" states, found %u keys after %u seconds", total_states_tested, keys_found, elapsed_time); + printf("ICE: %u | %u | %u \n", start1, end1, elapsed_time); + PrintAndLog("Success! Found %u keys after %u seconds", keys_found, elapsed_time); PrintAndLog("\nFound key: %012"PRIx64"\n", foundkey); ret = true; } else { @@ -1850,6 +1857,4 @@ int mfnestedhard(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBloc candidates = NULL; } return 0; -} - - +} \ No newline at end of file diff --git a/client/cmdhfmfhard.h b/client/cmdhfmfhard.h index 72cc850a..a12875ac 100644 --- a/client/cmdhfmfhard.h +++ b/client/cmdhfmfhard.h @@ -11,23 +11,20 @@ #ifndef CMDHFMFHARD_H__ #define CMDHFMFHARD_H__ -#include "sleep.h" #include #include #include #include #include #include -#include "proxmark3.h" +#include "proxmark3.h" // time_t , PRIu32 +#include "sleep.h" #include "cmdmain.h" #include "ui.h" #include "util.h" #include "nonce2key/crapto1.h" #include "nonce2key/crypto1_bs.h" #include "parity.h" -#ifdef __WIN32 - #include -#endif // don't include for APPLE/mac which has malloc stuff elsewhere. #ifndef __APPLE__ #include diff --git a/client/mifarehost.h b/client/mifarehost.h index 1593c390..754cc483 100644 --- a/client/mifarehost.h +++ b/client/mifarehost.h @@ -13,9 +13,9 @@ #include #include #include -#include "proxmark3.h" + +#include "proxmark3.h" // time_t //#include "radixsort.h" -#include #include "common.h" #include "cmdmain.h" #include "ui.h" diff --git a/client/proxmark3.h b/client/proxmark3.h index 89cac878..87cf3e74 100644 --- a/client/proxmark3.h +++ b/client/proxmark3.h @@ -12,20 +12,26 @@ #ifndef PROXMARK3_H__ #define PROXMARK3_H__ +// Handle platform specific includes #ifdef __WIN32 // for MINGW32 environments - #define _USE_32BIT_TIME_T 1 -#endif + #define _USE_32BIT_TIME_T 1 + #include + #include +#else + #include +#endif + #define __STDC_FORMAT_MACROS 1 #include +#include "usb_cmd.h" + +#define lu PRIu32 #define lx PRIx32 #define llx PRIx64 #define lli PRIi64 #define llu PRIu64 #define hhu PRIu8 - -#include "usb_cmd.h" - #define PROXPROMPT "pm3 --> " void SendCommand(UsbCommand *c); diff --git a/client/uart.h b/client/uart.h index d520e7f4..33248fb2 100644 --- a/client/uart.h +++ b/client/uart.h @@ -54,6 +54,7 @@ typedef unsigned char byte_t; #include #include #else + #include #include #endif diff --git a/client/ui.h b/client/ui.h index 8d6c21b5..6891a821 100644 --- a/client/ui.h +++ b/client/ui.h @@ -16,11 +16,19 @@ #include #include #include -#include #include #include #include #include + +// Handle platform specific includes +#ifndef _WIN32 + #include +#else + #include + #include +#endif + #include "loclass/cipherutils.h" #include "util.h" #include "cmdmain.h" diff --git a/client/util.h b/client/util.h index f81d7d88..7a2fd46f 100644 --- a/client/util.h +++ b/client/util.h @@ -13,10 +13,9 @@ #include #include #include -#include #include // math.pow +#include "proxmark3.h" // time_t #include "data.h" // for FILE_PATH_SIZE -#include "proxmark3.h" #ifndef BITMASK # define BITMASK(X) (1 << (X)) -- 2.39.2