From 57778a46308a250f4c9b1516aa8ca251d4e09cc5 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 6 Mar 2017 19:11:08 +0100 Subject: [PATCH] CHG: renamed struct sector -> sector_t CHG: defines on armside CHG: #define WIN32 -> _WIN32 CHG: started to enhance "hf mf chkkeys" REM: removed some duplicates etc in default keys. --- armsrc/appmain.c | 1 + armsrc/apps.h | 1 - armsrc/mifarecmd.c | 22 ++++++++++++++---- armsrc/optimized_cipher.h | 3 +-- client/cmdhfmf.c | 14 +++++------ client/cmdhfmf.h | 4 +--- client/hid-flasher/proxendian.h | 2 +- client/hid-flasher/sleep.h | 2 +- client/lualibs/mf_default_keys.lua | 37 ++++++++++++++++-------------- client/mifarehost.c | 6 +++-- client/mifarehost.h | 2 +- client/scripts/mfkeys.lua | 11 ++++++++- 12 files changed, 64 insertions(+), 41 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index d976febc..bcff7476 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -9,6 +9,7 @@ // The main application code. This is the first thing called after start.c // executes. //----------------------------------------------------------------------------- +#include #include "usb_cdc.h" #include "proxmark3.h" #include "apps.h" diff --git a/armsrc/apps.h b/armsrc/apps.h index 0cb375e6..4f1b622a 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -29,7 +29,6 @@ extern "C" { #include "pcf7931.h" #include "desfire.h" #include "iso14443b.h" -//#include "iso14443a.h" #include "emvcard.h" extern int rsamples; // = 0; diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 2ab076b6..1e398bc8 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -956,9 +956,13 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *dat // //----------------------------------------------------------------------------- void MifareChkKeys(uint16_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) { - uint8_t blockNo = arg0 & 0xff; - uint8_t keyType = (arg0 >> 8) & 0xff; - bool clearTrace = arg1; +#define STD_SEARCH 1 +#define EXT_SEARCH 2 + + uint8_t blockNo = arg0 & 0xFF; + uint8_t keyType = (arg0 >> 8) & 0xFF; + uint8_t searchType = (arg1 >> 8 ) & 0xFF; + bool clearTrace = arg1 & 0xFF; uint8_t keyCount = arg2; uint64_t ui64Key = 0; @@ -1026,8 +1030,16 @@ void MifareChkKeys(uint16_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) { continue; } - isOK = 1; - break; + + // found a key. + // + //if ( searchType == EXT_SEARCH) { + + //} + //else { + isOK = 1; + break; + //} } LED_B_ON(); diff --git a/armsrc/optimized_cipher.h b/armsrc/optimized_cipher.h index 6f428bf5..7398069f 100644 --- a/armsrc/optimized_cipher.h +++ b/armsrc/optimized_cipher.h @@ -2,8 +2,7 @@ #define OPTIMIZED_CIPHER_H #include -#include -#include +#include #include /** diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index ede88cb7..793863b0 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -721,7 +721,7 @@ int CmdHF14AMfRestore(const char *Cmd) { int CmdHF14AMfNested(const char *Cmd) { int i, j, res, iterations; - sector *e_sector = NULL; + sector_t *e_sector = NULL; uint8_t blockNo = 0; uint8_t keyType = 0; uint8_t trgBlockNo = 0; @@ -823,7 +823,7 @@ int CmdHF14AMfNested(const char *Cmd) { time_t start, end; time(&start); - e_sector = calloc(SectorsCnt, sizeof(sector)); + e_sector = calloc(SectorsCnt, sizeof(sector_t)); if (e_sector == NULL) return 1; //test current key and additional standard keys first @@ -1083,7 +1083,7 @@ int CmdHF14AMfChk(const char *Cmd) { uint8_t *keyBlock = NULL, *p; uint8_t stKeyBlock = 20; - sector *e_sector = NULL; + sector_t *e_sector = NULL; int i, res; int keycnt = 0; @@ -1230,7 +1230,7 @@ int CmdHF14AMfChk(const char *Cmd) { } // initialize storage for found keys - e_sector = calloc(SectorsCnt, sizeof(sector)); + e_sector = calloc(SectorsCnt, sizeof(sector_t)); if (e_sector == NULL) { free(keyBlock); return 1; @@ -1362,13 +1362,13 @@ int CmdHF14AMfChk(const char *Cmd) { return 0; } -sector *k_sector = NULL; +sector_t *k_sector = NULL; uint8_t k_sectorsCount = 16; static void emptySectorTable(){ // initialize storage for found keys if (k_sector == NULL) - k_sector = calloc(k_sectorsCount, sizeof(sector)); + k_sector = calloc(k_sectorsCount, sizeof(sector_t)); if (k_sector == NULL) return; @@ -1720,7 +1720,7 @@ int CmdHF14AMfKeyBrute(const char *Cmd) { return 0; } -void printKeyTable( uint8_t sectorscnt, sector *e_sector ){ +void printKeyTable( uint8_t sectorscnt, sector_t *e_sector ){ PrintAndLog("|---|----------------|---|----------------|---|"); PrintAndLog("|sec|key A |res|key B |res|"); PrintAndLog("|---|----------------|---|----------------|---|"); diff --git a/client/cmdhfmf.h b/client/cmdhfmf.h index 26df2df4..e102dbd0 100644 --- a/client/cmdhfmf.h +++ b/client/cmdhfmf.h @@ -16,14 +16,12 @@ #include #include #include "proxmark3.h" - #include "iso14443crc.h" #include "data.h" #include "ui.h" #include "cmdparser.h" #include "common.h" #include "util.h" -//#include "mifarehost.h" #include "mifare.h" // nonces_t struct #include "cmdhfmfhard.h" #include "nonce2key/nonce2key.h" @@ -63,5 +61,5 @@ int CmdHf14MfDecryptBytes(const char *Cmd); void showSectorTable(void); void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose); -void printKeyTable( uint8_t sectorscnt, sector *e_sector ); +void printKeyTable( uint8_t sectorscnt, sector_t *e_sector ); #endif diff --git a/client/hid-flasher/proxendian.h b/client/hid-flasher/proxendian.h index 4a386a0d..4f5a4519 100644 --- a/client/hid-flasher/proxendian.h +++ b/client/hid-flasher/proxendian.h @@ -13,7 +13,7 @@ #include -#ifdef WIN32 +#ifdef _WIN32 # define HOST_LITTLE_ENDIAN #else # include diff --git a/client/hid-flasher/sleep.h b/client/hid-flasher/sleep.h index 81f4e060..62d9f4d1 100644 --- a/client/hid-flasher/sleep.h +++ b/client/hid-flasher/sleep.h @@ -11,7 +11,7 @@ #ifndef SLEEP_H__ #define SLEEP_H__ -#ifdef WIN32 +#ifdef _WIN32 #include #define sleep(n) Sleep(1000 * n) #define msleep(n) Sleep(n) diff --git a/client/lualibs/mf_default_keys.lua b/client/lualibs/mf_default_keys.lua index 28f56ea8..9a496b19 100644 --- a/client/lualibs/mf_default_keys.lua +++ b/client/lualibs/mf_default_keys.lua @@ -181,27 +181,27 @@ local _keys = { hotel system cards, http://www.proxmark.org/forum/viewtopic.php?id=2430 --]] - '44ab09010845', - '85fed980ea5a', + '44ab09010845', + '85fed980ea5a', - --[[ - VIGIK1 - --]] - '314B49474956', - '564c505f4d41', + --[[ + VIGIK1 + --]] + '314B49474956', + '564c505f4d41', - --[[ - BCARD keyB - --]] - 'f4a9ef2afc6d', + --[[ + BCARD keyB + --]] + 'f4a9ef2afc6d', - --[[ - --]] - 'a9f953def0a3', + --[[ + --]] + 'a9f953def0a3', - --[[ - mystery Key A and B for Mifare 1k EV1 (S50) Sector 17! - --]] + --[[ + mystery Key A and B for Mifare 1k EV1 (S50) Sector 17! + --]] '75ccb59c9bed', '4b791bea7bcc', @@ -451,6 +451,9 @@ local _keys = { '0ffbf65b5a14', 'c5cfe06d9ea3', 'c0dece673829', + --[[ + --]] + 'a56c2df9a26d', } --- diff --git a/client/mifarehost.c b/client/mifarehost.c index d1bfa69a..5d39221f 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -192,8 +192,10 @@ out: } int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){ - *key = 0; - UsbCommand c = {CMD_MIFARE_CHKKEYS, { (blockNo | (keyType<<8)), clear_trace, keycnt}}; +#define STD_SEARCH 1 +#define EXT_SEARCH 2 + *key = 0; + UsbCommand c = {CMD_MIFARE_CHKKEYS, { (blockNo | (keyType << 8)), ((EXT_SEARCH << 8) | clear_trace), keycnt}}; memcpy(c.d.asBytes, keyBlock, 6 * keycnt); clearCommandBuffer(); SendCommand(&c); diff --git a/client/mifarehost.h b/client/mifarehost.h index 4f6b984a..e172bd39 100644 --- a/client/mifarehost.h +++ b/client/mifarehost.h @@ -58,7 +58,7 @@ typedef struct { typedef struct { uint64_t Key[2]; int foundKey[2]; -} sector; +} sector_t; extern int compar_int(const void * a, const void * b); extern char logHexFileName[FILE_PATH_SIZE]; diff --git a/client/scripts/mfkeys.lua b/client/scripts/mfkeys.lua index 804b6115..937c9172 100644 --- a/client/scripts/mfkeys.lua +++ b/client/scripts/mfkeys.lua @@ -30,6 +30,7 @@ If you want to add more, just put them inside /lualibs/mf_default_keys.lua\n"):f Arguments: -h : this help + -p : print keys ]] local TIMEOUT = 10000 -- 10 seconds @@ -179,12 +180,20 @@ local function dumptofile(results) file:close() end end +local function printkeys() + for i=0,#keys do + print(i,keys[i]) + + end + print ('Number of keys: '..#keys) +end local function main( args) -- Arguments for the script - for o, a in getopt.getopt(args, 'h') do + for o, a in getopt.getopt(args, 'hp') do if o == "h" then return help() end + if o == "p" then return printkeys() end end result, err = reader.read1443a() -- 2.39.2