mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
ADD: @donwan581 select keytype for the darkside attack.
This commit is contained in:
parent
6b23be6b7e
commit
df007486f5
10 changed files with 205 additions and 90 deletions
|
@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
|
||||||
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
|
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
|
||||||
|
|
||||||
## [unreleased][unreleased]
|
## [unreleased][unreleased]
|
||||||
|
- 'lf t55xx recoverpw' - adds a new password recovery using bitflips and partial flips if password write went bad. (alexgrin)
|
||||||
|
- 'hf legic' - added improved legic data mapping. (jason)
|
||||||
|
- 'hf mf mifare' - added possibility to target key A|B (douniwan5788)
|
||||||
- 'analyse lcr' - added a new main command group, to help analysing bytes & bits & nibbles. (iceman)
|
- 'analyse lcr' - added a new main command group, to help analysing bytes & bits & nibbles. (iceman)
|
||||||
- 'lf nedap' - added identification of a NEDAP tag. (iceman)
|
- 'lf nedap' - added identification of a NEDAP tag. (iceman)
|
||||||
- 'lf viking clone' - fixed a bug. (iceman)
|
- 'lf viking clone' - fixed a bug. (iceman)
|
||||||
|
|
|
@ -1100,7 +1100,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
|
||||||
EPA_PACE_Replay(c);
|
EPA_PACE_Replay(c);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_MIFARE:
|
case CMD_READER_MIFARE:
|
||||||
ReaderMifare(c->arg[0], c->arg[1]);
|
ReaderMifare(c->arg[0], c->arg[1], c->arg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_READBL:
|
case CMD_MIFARE_READBL:
|
||||||
MifareReadBlock(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareReadBlock(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
||||||
|
|
|
@ -98,14 +98,14 @@ void TurnReadLFOn();
|
||||||
void EM4xReadWord(uint8_t Address, uint32_t Pwd, uint8_t PwdMode);
|
void EM4xReadWord(uint8_t Address, uint32_t Pwd, uint8_t PwdMode);
|
||||||
void EM4xWriteWord(uint32_t Data, uint8_t Address, uint32_t Pwd, uint8_t PwdMode);
|
void EM4xWriteWord(uint32_t Data, uint8_t Address, uint32_t Pwd, uint8_t PwdMode);
|
||||||
|
|
||||||
/// iso14443.h
|
/// iso14443b.h
|
||||||
void SimulateIso14443bTag(uint32_t pupi);
|
void SimulateIso14443bTag(uint32_t pupi);
|
||||||
void AcquireRawAdcSamplesIso14443b(uint32_t parameter);
|
void AcquireRawAdcSamplesIso14443b(uint32_t parameter);
|
||||||
void ReadSTMemoryIso14443b(uint8_t numofblocks);
|
void ReadSTMemoryIso14443b(uint8_t numofblocks);
|
||||||
void RAMFUNC SnoopIso14443b(void);
|
void RAMFUNC SnoopIso14443b(void);
|
||||||
void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]);
|
void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]);
|
||||||
|
|
||||||
/// iso14443a.h
|
// iso14443a.h
|
||||||
void RAMFUNC SniffIso14443a(uint8_t param);
|
void RAMFUNC SniffIso14443a(uint8_t param);
|
||||||
void SimulateIso14443aTag(int tagType, int flags, byte_t* data);
|
void SimulateIso14443aTag(int tagType, int flags, byte_t* data);
|
||||||
void ReaderIso14443a(UsbCommand * c);
|
void ReaderIso14443a(UsbCommand * c);
|
||||||
|
@ -114,16 +114,11 @@ void ReaderIso14443a(UsbCommand * c);
|
||||||
void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *parity);
|
void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *parity);
|
||||||
void iso14a_set_trigger(bool enable);
|
void iso14a_set_trigger(bool enable);
|
||||||
|
|
||||||
void RAMFUNC SniffMifare(uint8_t param);
|
// epa.h
|
||||||
|
|
||||||
/// epa.h
|
|
||||||
void EPA_PACE_Collect_Nonce(UsbCommand * c);
|
void EPA_PACE_Collect_Nonce(UsbCommand * c);
|
||||||
void EPA_PACE_Replay(UsbCommand *c);
|
void EPA_PACE_Replay(UsbCommand *c);
|
||||||
|
|
||||||
// mifarecmd.h
|
// mifarecmd.h
|
||||||
//void ReaderMifare(bool first_try);
|
|
||||||
void ReaderMifare(bool first_try, uint8_t block );
|
|
||||||
int32_t dist_nt(uint32_t nt1, uint32_t nt2);
|
|
||||||
void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *data);
|
void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *data);
|
||||||
void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||||
void MifareUC_Auth(uint8_t arg0, uint8_t *datain);
|
void MifareUC_Auth(uint8_t arg0, uint8_t *datain);
|
||||||
|
@ -148,33 +143,37 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain);
|
||||||
void OnSuccessMagic();
|
void OnSuccessMagic();
|
||||||
void OnErrorMagic(uint8_t reason);
|
void OnErrorMagic(uint8_t reason);
|
||||||
|
|
||||||
|
int32_t dist_nt(uint32_t nt1, uint32_t nt2);
|
||||||
|
void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype );
|
||||||
|
void RAMFUNC SniffMifare(uint8_t param);
|
||||||
|
|
||||||
//desfire
|
//desfire
|
||||||
void Mifare_DES_Auth1(uint8_t arg0,uint8_t *datain);
|
void Mifare_DES_Auth1(uint8_t arg0,uint8_t *datain);
|
||||||
void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain);
|
void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain);
|
||||||
|
|
||||||
// mifaredesfire.h
|
// mifaredesfire.h
|
||||||
bool InitDesfireCard();
|
bool InitDesfireCard();
|
||||||
void MifareSendCommand(uint8_t arg0,uint8_t arg1, uint8_t *datain);
|
void MifareSendCommand(uint8_t arg0,uint8_t arg1, uint8_t *datain);
|
||||||
void MifareDesfireGetInformation();
|
void MifareDesfireGetInformation();
|
||||||
void MifareDES_Auth1(uint8_t arg0,uint8_t arg1,uint8_t arg2, uint8_t *datain);
|
void MifareDES_Auth1(uint8_t arg0,uint8_t arg1,uint8_t arg2, uint8_t *datain);
|
||||||
void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t * datain);
|
void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t * datain);
|
||||||
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout);
|
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout);
|
||||||
size_t CreateAPDU( uint8_t *datain, size_t len, uint8_t *dataout);
|
size_t CreateAPDU( uint8_t *datain, size_t len, uint8_t *dataout);
|
||||||
void OnSuccess();
|
void OnSuccess();
|
||||||
void OnError(uint8_t reason);
|
void OnError(uint8_t reason);
|
||||||
|
|
||||||
|
|
||||||
// desfire_crypto.h
|
// desfire_crypto.h
|
||||||
void *mifare_cryto_preprocess_data (desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings);
|
void *mifare_cryto_preprocess_data (desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings);
|
||||||
void *mifare_cryto_postprocess_data (desfiretag_t tag, void *data, size_t *nbytes, int communication_settings);
|
void *mifare_cryto_postprocess_data (desfiretag_t tag, void *data, size_t *nbytes, int communication_settings);
|
||||||
void mifare_cypher_single_block (desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size);
|
void mifare_cypher_single_block (desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size);
|
||||||
void mifare_cypher_blocks_chained (desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation);
|
void mifare_cypher_blocks_chained (desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation);
|
||||||
size_t key_block_size (const desfirekey_t key);
|
size_t key_block_size (const desfirekey_t key);
|
||||||
size_t padded_data_length (const size_t nbytes, const size_t block_size);
|
size_t padded_data_length (const size_t nbytes, const size_t block_size);
|
||||||
size_t maced_data_length (const desfirekey_t key, const size_t nbytes);
|
size_t maced_data_length (const desfirekey_t key, const size_t nbytes);
|
||||||
size_t enciphered_data_length (const desfiretag_t tag, const size_t nbytes, int communication_settings);
|
size_t enciphered_data_length (const desfiretag_t tag, const size_t nbytes, int communication_settings);
|
||||||
void cmac_generate_subkeys (desfirekey_t key);
|
void cmac_generate_subkeys (desfirekey_t key);
|
||||||
void cmac (const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac);
|
void cmac (const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac);
|
||||||
|
|
||||||
/// iso15693.h
|
/// iso15693.h
|
||||||
void RecordRawAdcSamplesIso15693(void);
|
void RecordRawAdcSamplesIso15693(void);
|
||||||
|
@ -199,7 +198,6 @@ void iClass_Dump(uint8_t blockno, uint8_t numblks);
|
||||||
void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data);
|
void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data);
|
||||||
void iClass_ReadCheck(uint8_t blockNo, uint8_t keyType);
|
void iClass_ReadCheck(uint8_t blockNo, uint8_t keyType);
|
||||||
|
|
||||||
|
|
||||||
// hitag2.h
|
// hitag2.h
|
||||||
void SnoopHitag(uint32_t type);
|
void SnoopHitag(uint32_t type);
|
||||||
void SimulateHitagTag(bool tag_mem_supplied, byte_t* data);
|
void SimulateHitagTag(bool tag_mem_supplied, byte_t* data);
|
||||||
|
@ -211,13 +209,13 @@ void ReadHitagS(hitag_function htf, hitag_data* htd);
|
||||||
void WritePageHitagS(hitag_function htf, hitag_data* htd,int page);
|
void WritePageHitagS(hitag_function htf, hitag_data* htd,int page);
|
||||||
void check_challenges(bool file_given, byte_t* data);
|
void check_challenges(bool file_given, byte_t* data);
|
||||||
|
|
||||||
|
|
||||||
// cmd.h
|
// cmd.h
|
||||||
bool cmd_receive(UsbCommand* cmd);
|
bool cmd_receive(UsbCommand* cmd);
|
||||||
bool cmd_send(uint32_t cmd, uint32_t arg0, uint32_t arg1, uint32_t arg2, void* data, size_t len);
|
bool cmd_send(uint32_t cmd, uint32_t arg0, uint32_t arg1, uint32_t arg2, void* data, size_t len);
|
||||||
|
|
||||||
/// util.h
|
// util.h
|
||||||
void HfSnoop(int , int);
|
void HfSnoop(int , int);
|
||||||
|
|
||||||
//EMV functions emvcmd.h
|
//EMV functions emvcmd.h
|
||||||
void EMVTransaction(void);
|
void EMVTransaction(void);
|
||||||
void EMVgetUDOL(void);
|
void EMVgetUDOL(void);
|
||||||
|
|
|
@ -2175,8 +2175,9 @@ int32_t dist_nt(uint32_t nt1, uint32_t nt2) {
|
||||||
// Cloning MiFare Classic Rail and Building Passes, Anywhere, Anytime"
|
// Cloning MiFare Classic Rail and Building Passes, Anywhere, Anytime"
|
||||||
// (article by Nicolas T. Courtois, 2009)
|
// (article by Nicolas T. Courtois, 2009)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void ReaderMifare(bool first_try, uint8_t block ) {
|
void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype ) {
|
||||||
uint8_t mf_auth[] = { MIFARE_AUTH_KEYA, block, 0x00, 0x00 };
|
|
||||||
|
uint8_t mf_auth[] = { keytype, block, 0x00, 0x00 };
|
||||||
uint8_t mf_nr_ar[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
uint8_t mf_nr_ar[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||||
uint8_t uid[10] = {0,0,0,0,0,0,0,0,0,0};
|
uint8_t uid[10] = {0,0,0,0,0,0,0,0,0,0};
|
||||||
uint8_t par_list[8] = {0,0,0,0,0,0,0,0};
|
uint8_t par_list[8] = {0,0,0,0,0,0,0,0};
|
||||||
|
@ -2209,13 +2210,14 @@ void ReaderMifare(bool first_try, uint8_t block ) {
|
||||||
#define PRNG_SEQUENCE_LENGTH (1 << 16)
|
#define PRNG_SEQUENCE_LENGTH (1 << 16)
|
||||||
#define MAX_UNEXPECTED_RANDOM 4 // maximum number of unexpected (i.e. real) random numbers when trying to sync. Then give up.
|
#define MAX_UNEXPECTED_RANDOM 4 // maximum number of unexpected (i.e. real) random numbers when trying to sync. Then give up.
|
||||||
#define MAX_SYNC_TRIES 32
|
#define MAX_SYNC_TRIES 32
|
||||||
|
|
||||||
|
AppendCrc14443a(mf_auth, 2);
|
||||||
|
|
||||||
BigBuf_free(); BigBuf_Clear_ext(false);
|
BigBuf_free(); BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
clear_trace();
|
||||||
set_tracing(TRUE);
|
set_tracing(TRUE);
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
|
||||||
|
|
||||||
AppendCrc14443a(mf_auth, 2);
|
|
||||||
|
|
||||||
if (first_try) {
|
if (first_try) {
|
||||||
sync_time = GetCountSspClk() & 0xfffffff8;
|
sync_time = GetCountSspClk() & 0xfffffff8;
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
#ifndef BITMASK
|
#ifndef BITMASK
|
||||||
# define BITMASK(X) (1 << (X))
|
# define BITMASK(X) (1 << (X))
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef ARRAYLEN
|
||||||
|
# define ARRAYLEN(x) (sizeof(x)/sizeof((x)[0]))
|
||||||
|
#endif
|
||||||
|
|
||||||
void print_result(char *name, uint8_t *buf, size_t len);
|
void print_result(char *name, uint8_t *buf, size_t len);
|
||||||
size_t nbytes(size_t nbits);
|
size_t nbytes(size_t nbits);
|
||||||
|
|
|
@ -176,7 +176,16 @@ int CmdAnalyseCRC(const char *Cmd) {
|
||||||
PrintAndLog("LEGIC: CRC8 : %X (0xC6 expected)", legic8);
|
PrintAndLog("LEGIC: CRC8 : %X (0xC6 expected)", legic8);
|
||||||
PrintAndLog("MAXIM: CRC8 : %X (0xA1 expected)", CRC8Maxim(dataStr, sizeof(dataStr)));
|
PrintAndLog("MAXIM: CRC8 : %X (0xA1 expected)", CRC8Maxim(dataStr, sizeof(dataStr)));
|
||||||
PrintAndLog("DNP : CRC16: %X (0x82EA expected)", CRC16_DNP(dataStr, sizeof(dataStr)));
|
PrintAndLog("DNP : CRC16: %X (0x82EA expected)", CRC16_DNP(dataStr, sizeof(dataStr)));
|
||||||
PrintAndLog("CCITT: CRC16: %X (0xE5CC expected)", CRC16_CCITT(dataStr, sizeof(dataStr)));
|
PrintAndLog("CCITT: CRC16: %X (0xE5CC expected)", CRC16_CCITT(dataStr, sizeof(dataStr)));
|
||||||
|
|
||||||
|
PrintAndLog("ICLASS org: CRC16: %X (0x expected)",iclass_crc16( (char*)dataStr, sizeof(dataStr)));
|
||||||
|
PrintAndLog("ICLASS ice: CRC16: %X (0x expected)",CRC16_ICLASS(dataStr, sizeof(dataStr)));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t dataStr1234[] = { 0x1,0x2,0x3,0x4};
|
||||||
|
PrintAndLog("ISO15693 org: : CRC16: %X (0xF0B8 expected)", Iso15693Crc(dataStr1234, sizeof(dataStr1234)));
|
||||||
|
PrintAndLog("ISO15693 ice: : CRC16: %X (0xF0B8 expected)", CRC16_Iso15693(dataStr1234, sizeof(dataStr1234)));
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "ui.h" // PrintAndLog
|
#include "ui.h" // PrintAndLog
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
|
#include "../common/iso15693tools.h"
|
||||||
|
|
||||||
int usage_analyse_lcr(void);
|
int usage_analyse_lcr(void);
|
||||||
int usage_analyse_checksum(void);
|
int usage_analyse_checksum(void);
|
||||||
|
|
186
client/cmdhfmf.c
186
client/cmdhfmf.c
|
@ -9,18 +9,18 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "cmdhfmf.h"
|
#include "cmdhfmf.h"
|
||||||
#include "cmdhfmfhard.h"
|
|
||||||
#include "nonce2key/nonce2key.h"
|
|
||||||
|
|
||||||
static int CmdHelp(const char *Cmd);
|
static int CmdHelp(const char *Cmd);
|
||||||
int usage_hf14_mifare(void){
|
int usage_hf14_mifare(void){
|
||||||
PrintAndLog("Usage: hf mf mifare [h] <block number>");
|
PrintAndLog("Usage: hf mf mifare [h] <block number> <A|B>");
|
||||||
PrintAndLog("options:");
|
PrintAndLog("options:");
|
||||||
PrintAndLog(" h this help");
|
PrintAndLog(" h this help");
|
||||||
PrintAndLog(" <block number> (Optional) target other key A than block 0.");
|
PrintAndLog(" <block number> (Optional) target other block");
|
||||||
|
PrintAndLog(" <A|B> (optional) target key type");
|
||||||
PrintAndLog("samples:");
|
PrintAndLog("samples:");
|
||||||
PrintAndLog(" hf mf mifare");
|
PrintAndLog(" hf mf mifare");
|
||||||
PrintAndLog(" hf mf mifare 16");
|
PrintAndLog(" hf mf mifare 16");
|
||||||
|
PrintAndLog(" hf mf mifare 16 B");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int usage_hf14_mf1ksim(void){
|
int usage_hf14_mf1ksim(void){
|
||||||
|
@ -132,13 +132,18 @@ int CmdHF14AMifare(const char *Cmd) {
|
||||||
uint64_t par_list = 0, ks_list = 0, r_key = 0;
|
uint64_t par_list = 0, ks_list = 0, r_key = 0;
|
||||||
int16_t isOK = 0;
|
int16_t isOK = 0;
|
||||||
int tmpchar;
|
int tmpchar;
|
||||||
uint8_t blockNo = 0;
|
uint8_t blockNo = 0, keytype = MIFARE_AUTH_KEYA;
|
||||||
|
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if ( cmdp == 'H' || cmdp == 'h') return usage_hf14_mifare();
|
if ( cmdp == 'H' || cmdp == 'h') return usage_hf14_mifare();
|
||||||
|
|
||||||
blockNo = param_get8(Cmd, 0);
|
blockNo = param_get8(Cmd, 0);
|
||||||
UsbCommand c = {CMD_READER_MIFARE, {true, blockNo, 0}};
|
|
||||||
|
cmdp = param_getchar(Cmd, 1);
|
||||||
|
if (cmdp == 'B' || cmdp == 'b')
|
||||||
|
keytype = MIFARE_AUTH_KEYB;
|
||||||
|
|
||||||
|
UsbCommand c = {CMD_READER_MIFARE, {true, blockNo, keytype}};
|
||||||
|
|
||||||
// message
|
// message
|
||||||
printf("-------------------------------------------------------------------------\n");
|
printf("-------------------------------------------------------------------------\n");
|
||||||
|
@ -1315,45 +1320,121 @@ int CmdHF14AMfChk(const char *Cmd) {
|
||||||
PrintAndLog("");
|
PrintAndLog("");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#define ATTACK_KEY_COUNT 8
|
||||||
|
sector *k_sector = NULL;
|
||||||
|
uint8_t k_sectorsCount = 16;
|
||||||
|
void readerAttack(nonces_t data[], bool setEmulatorMem) {
|
||||||
|
|
||||||
|
// initialize storage for found keys
|
||||||
|
if (k_sector == NULL);
|
||||||
|
k_sector = calloc(k_sectorsCount, sizeof(sector));
|
||||||
|
if (k_sector == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint64_t key = 0;
|
||||||
|
|
||||||
|
// empty e_sector
|
||||||
|
for(int i = 0; i < k_sectorsCount; ++i){
|
||||||
|
k_sector[i].Key[0] = 0xffffffffffff;
|
||||||
|
k_sector[i].Key[1] = 0xffffffffffff;
|
||||||
|
k_sector[i].foundKey[0] = FALSE;
|
||||||
|
k_sector[i].foundKey[1] = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("enter reader attack\n");
|
||||||
|
for (uint8_t i = 0; i < ATTACK_KEY_COUNT; ++i) {
|
||||||
|
if (data[i].ar2 > 0) {
|
||||||
|
|
||||||
|
if (tryMfk32(data[i], &key)) {
|
||||||
|
PrintAndLog("Found Key%s for sector %02d: [%012"llx"]"
|
||||||
|
, (data[i].keytype) ? "B" : "A"
|
||||||
|
, data[i].sector
|
||||||
|
, key
|
||||||
|
);
|
||||||
|
|
||||||
|
k_sector[i].Key[data[i].keytype] = key;
|
||||||
|
k_sector[i].foundKey[data[i].keytype] = TRUE;
|
||||||
|
|
||||||
|
//set emulator memory for keys
|
||||||
|
if (setEmulatorMem) {
|
||||||
|
uint8_t memBlock[16] = {0,0,0,0,0,0, 0xff, 0x0F, 0x80, 0x69, 0,0,0,0,0,0};
|
||||||
|
num_to_bytes( k_sector[i].Key[0], 6, memBlock);
|
||||||
|
num_to_bytes( k_sector[i].Key[1], 6, memBlock+10);
|
||||||
|
mfEmlSetMem( memBlock, i*4 + 3, 1);
|
||||||
|
PrintAndLog("Setting Emulator Memory Block %02d: [%s]"
|
||||||
|
, i*4 + 3
|
||||||
|
, sprint_hex( memBlock, sizeof(memBlock))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//moebius attack
|
||||||
|
// if (tryMfk32_moebius(data[i+ATTACK_KEY_COUNT], &key)) {
|
||||||
|
// PrintAndLog("M-Found Key%s for sector %02d: [%012"llx"]"
|
||||||
|
// ,(data[i+ATTACK_KEY_COUNT].keytype) ? "B" : "A"
|
||||||
|
// , data[i+ATTACK_KEY_COUNT].sector
|
||||||
|
// , key
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int CmdHF14AMf1kSim(const char *Cmd) {
|
int CmdHF14AMf1kSim(const char *Cmd) {
|
||||||
|
|
||||||
uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
uint8_t exitAfterNReads = 0;
|
uint8_t exitAfterNReads = 0;
|
||||||
uint8_t flags = (FLAG_UID_IN_EMUL | FLAG_4B_UID_IN_DATA);
|
uint8_t flags = (FLAG_UID_IN_EMUL | FLAG_4B_UID_IN_DATA);
|
||||||
int uidlen = 0;
|
int uidlen = 0;
|
||||||
uint8_t pnr = 0;
|
bool setEmulatorMem = false;
|
||||||
uint8_t cmdp = param_getchar(Cmd, 0);
|
uint8_t cmdp = 0;
|
||||||
|
bool errors = false;
|
||||||
|
|
||||||
if (cmdp == 'h' || cmdp == 'H') return usage_hf14_mf1ksim();
|
while(param_getchar(Cmd, cmdp) != 0x00) {
|
||||||
|
switch(param_getchar(Cmd, cmdp)) {
|
||||||
cmdp = param_getchar(Cmd, pnr);
|
case 'e':
|
||||||
if (cmdp == 'u' || cmdp == 'U') {
|
case 'E':
|
||||||
param_gethex_ex(Cmd, pnr+1, uid, &uidlen);
|
setEmulatorMem = true;
|
||||||
switch(uidlen){
|
cmdp++;
|
||||||
case 20: flags = FLAG_10B_UID_IN_DATA; break;
|
break;
|
||||||
case 14: flags = FLAG_7B_UID_IN_DATA; break;
|
case 'h':
|
||||||
case 8: flags = FLAG_4B_UID_IN_DATA; break;
|
case 'H':
|
||||||
default: return usage_hf14_mf1ksim();
|
return usage_hf14_mf1ksim();
|
||||||
|
case 'i':
|
||||||
|
case 'I':
|
||||||
|
flags |= FLAG_INTERACTIVE;
|
||||||
|
cmdp++;
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
case 'N':
|
||||||
|
exitAfterNReads = param_get8(Cmd, cmdp+1);
|
||||||
|
cmdp += 2;
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
case 'U':
|
||||||
|
param_gethex_ex(Cmd, cmdp+1, uid, &uidlen);
|
||||||
|
switch(uidlen) {
|
||||||
|
case 20: flags = FLAG_10B_UID_IN_DATA; break;
|
||||||
|
case 14: flags = FLAG_7B_UID_IN_DATA; break;
|
||||||
|
case 8: flags = FLAG_4B_UID_IN_DATA; break;
|
||||||
|
default: return usage_hf14_mf1ksim();
|
||||||
|
}
|
||||||
|
cmdp +=2;
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
case 'X':
|
||||||
|
flags |= FLAG_NR_AR_ATTACK;
|
||||||
|
cmdp++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||||
|
errors = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
pnr +=2;
|
if(errors) break;
|
||||||
}
|
|
||||||
|
|
||||||
cmdp = param_getchar(Cmd, pnr);
|
|
||||||
if (cmdp == 'n' || cmdp == 'N') {
|
|
||||||
exitAfterNReads = param_get8(Cmd, pnr+1);
|
|
||||||
pnr += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdp = param_getchar(Cmd, pnr);
|
|
||||||
if (cmdp == 'i' || cmdp == 'I' ) {
|
|
||||||
flags |= FLAG_INTERACTIVE;
|
|
||||||
pnr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdp = param_getchar(Cmd, pnr);
|
|
||||||
if (cmdp == 'x' || cmdp == 'X') {
|
|
||||||
flags |= FLAG_NR_AR_ATTACK;
|
|
||||||
}
|
}
|
||||||
|
//Validations
|
||||||
|
if(errors) return usage_hf14_mf1ksim();
|
||||||
|
|
||||||
PrintAndLog(" uid:%s, numreads:%d, flags:%d (0x%02x) "
|
PrintAndLog(" uid:%s, numreads:%d, flags:%d (0x%02x) "
|
||||||
, (uidlen == 0 ) ? "N/A" : sprint_hex(uid, uidlen>>1)
|
, (uidlen == 0 ) ? "N/A" : sprint_hex(uid, uidlen>>1)
|
||||||
|
@ -1367,24 +1448,24 @@ int CmdHF14AMf1kSim(const char *Cmd) {
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
if(flags & FLAG_INTERACTIVE) {
|
if(flags & FLAG_INTERACTIVE) {
|
||||||
uint8_t data[32];
|
|
||||||
uint64_t key;
|
|
||||||
UsbCommand resp;
|
|
||||||
PrintAndLog("Press pm3-button or send another cmd to abort simulation");
|
PrintAndLog("Press pm3-button or send another cmd to abort simulation");
|
||||||
|
|
||||||
|
nonces_t data[ATTACK_KEY_COUNT*2];
|
||||||
|
UsbCommand resp;
|
||||||
|
|
||||||
while( !ukbhit() ){
|
while( !ukbhit() ){
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500) ) continue;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500) ) continue;
|
||||||
|
|
||||||
if ( !(flags & FLAG_NR_AR_ATTACK) ) break;
|
if ( !(flags & FLAG_NR_AR_ATTACK) ) break;
|
||||||
if ( (resp.arg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD ) break;
|
if ( (resp.arg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD ) break;
|
||||||
|
|
||||||
memset(data, 0x00, sizeof(data));
|
memcpy( data, resp.d.asBytes, sizeof(data) );
|
||||||
int len = (resp.arg[1] > sizeof(data)) ? sizeof(data) : resp.arg[1];
|
readerAttack(data, setEmulatorMem);
|
||||||
|
}
|
||||||
memcpy(data, resp.d.asBytes, len);
|
|
||||||
key = 0;
|
if (k_sector != NULL) {
|
||||||
bool found = tryMfk32(data, &key);
|
printKeyTable(k_sectorsCount, k_sector );
|
||||||
found ^= tryMfk32_moebius(data, &key);
|
free(k_sector);
|
||||||
if ( found ) break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1548,7 +1629,7 @@ int CmdHF14AMfSniff(const char *Cmd){
|
||||||
int CmdHF14AMfDbg(const char *Cmd) {
|
int CmdHF14AMfDbg(const char *Cmd) {
|
||||||
|
|
||||||
char ctmp = param_getchar(Cmd, 0);
|
char ctmp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) < 1 || ctmp == 'h'|| ctmp == 'H') return usage_hf14_dbg();
|
if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_hf14_dbg();
|
||||||
|
|
||||||
uint8_t dbgMode = param_get8ex(Cmd, 0, 0, 10);
|
uint8_t dbgMode = param_get8ex(Cmd, 0, 0, 10);
|
||||||
if (dbgMode > 4) return usage_hf14_dbg();
|
if (dbgMode > 4) return usage_hf14_dbg();
|
||||||
|
@ -1572,7 +1653,6 @@ void printKeyTable( uint8_t sectorscnt, sector *e_sector ){
|
||||||
}
|
}
|
||||||
|
|
||||||
// EMULATOR COMMANDS
|
// EMULATOR COMMANDS
|
||||||
|
|
||||||
int CmdHF14AMfEGet(const char *Cmd)
|
int CmdHF14AMfEGet(const char *Cmd)
|
||||||
{
|
{
|
||||||
uint8_t blockNo = 0;
|
uint8_t blockNo = 0;
|
||||||
|
@ -1586,7 +1666,7 @@ int CmdHF14AMfEGet(const char *Cmd)
|
||||||
|
|
||||||
blockNo = param_get8(Cmd, 0);
|
blockNo = param_get8(Cmd, 0);
|
||||||
|
|
||||||
PrintAndLog(" ");
|
PrintAndLog("");
|
||||||
if (!mfEmlGetMem(data, blockNo, 1)) {
|
if (!mfEmlGetMem(data, blockNo, 1)) {
|
||||||
PrintAndLog("data[%3d]:%s", blockNo, sprint_hex(data, 16));
|
PrintAndLog("data[%3d]:%s", blockNo, sprint_hex(data, 16));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,7 +22,10 @@
|
||||||
#include "cmdparser.h"
|
#include "cmdparser.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "mifarehost.h"
|
//#include "mifarehost.h"
|
||||||
|
#include "mifare.h" // nonces_t struct
|
||||||
|
#include "cmdhfmfhard.h"
|
||||||
|
#include "nonce2key/nonce2key.h"
|
||||||
|
|
||||||
int CmdHFMF(const char *Cmd);
|
int CmdHFMF(const char *Cmd);
|
||||||
|
|
||||||
|
@ -56,5 +59,6 @@ int CmdHF14AMfCLoad(const char* cmd);
|
||||||
int CmdHF14AMfCSave(const char* cmd);
|
int CmdHF14AMfCSave(const char* cmd);
|
||||||
int CmdHf14MfDecryptBytes(const char *Cmd);
|
int CmdHf14MfDecryptBytes(const char *Cmd);
|
||||||
|
|
||||||
|
void readerAttack(nonces_t data[], bool setEmulatorMem);
|
||||||
void printKeyTable( uint8_t sectorscnt, sector *e_sector );
|
void printKeyTable( uint8_t sectorscnt, sector *e_sector );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,12 +24,15 @@
|
||||||
#ifndef ROTR
|
#ifndef ROTR
|
||||||
# define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
|
# define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MIN
|
#ifndef MIN
|
||||||
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
#ifndef MAX
|
#ifndef MAX
|
||||||
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Byte swapping
|
||||||
#ifndef BSWAP_32
|
#ifndef BSWAP_32
|
||||||
# define BSWAP_32(x) \
|
# define BSWAP_32(x) \
|
||||||
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
|
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
|
||||||
|
@ -39,11 +42,13 @@
|
||||||
# define BSWAP_16(x) ((( ((x) & 0xFF00 ) >> 8))| ( (((x) & 0x00FF) << 8)))
|
# define BSWAP_16(x) ((( ((x) & 0xFF00 ) >> 8))| ( (((x) & 0x00FF) << 8)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Boolean
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
#define EVEN 0
|
#define EVEN 0
|
||||||
#define ODD 1
|
#define ODD 1
|
||||||
|
|
||||||
|
// Nibble logic
|
||||||
#ifndef NIBBLE_HIGH
|
#ifndef NIBBLE_HIGH
|
||||||
# define NIBBLE_HIGH(b) ( (b & 0xF0) >> 4 )
|
# define NIBBLE_HIGH(b) ( (b & 0xF0) >> 4 )
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,6 +62,7 @@
|
||||||
# define SWAP_NIBBLE(b) ( (NIBBLE_LOW(b)<< 4) | NIBBLE_HIGH(b))
|
# define SWAP_NIBBLE(b) ( (NIBBLE_LOW(b)<< 4) | NIBBLE_HIGH(b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Binary Encoded Digit
|
||||||
#ifndef BCD2DEC
|
#ifndef BCD2DEC
|
||||||
# define BCD2DEC(bcd) HornerScheme(bcd, 0x10, 10)
|
# define BCD2DEC(bcd) HornerScheme(bcd, 0x10, 10)
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,6 +70,15 @@
|
||||||
# define DEC2BCD(dec) HornerScheme(dec, 10, 0x10)
|
# define DEC2BCD(dec) HornerScheme(dec, 10, 0x10)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// used for save/load files
|
||||||
|
#ifndef FILE_PATH_SIZE
|
||||||
|
# define FILE_PATH_SIZE 1000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ARRAYLEN
|
||||||
|
# define ARRAYLEN(x) (sizeof(x)/sizeof((x)[0]))
|
||||||
|
#endif
|
||||||
|
|
||||||
int ukbhit(void);
|
int ukbhit(void);
|
||||||
|
|
||||||
void AddLogLine(char *fileName, char *extData, char *c);
|
void AddLogLine(char *fileName, char *extData, char *c);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue