2011-06-07 20:35:52 +08:00
|
|
|
// Merlok, 2011
|
|
|
|
// people from mifare@nethemba.com, 2010
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// High frequency ISO14443A commands
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2016-08-01 04:00:49 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
2016-10-30 03:42:46 +08:00
|
|
|
|
|
|
|
#include "proxmark3.h" // time_t
|
2016-08-01 04:00:49 +08:00
|
|
|
//#include "radixsort.h"
|
2011-06-07 20:35:52 +08:00
|
|
|
#include "common.h"
|
|
|
|
#include "cmdmain.h"
|
|
|
|
#include "ui.h"
|
|
|
|
#include "data.h"
|
|
|
|
#include "util.h"
|
2016-08-01 04:00:49 +08:00
|
|
|
//#include "nonce2key/nonce2key.h"
|
2011-06-07 20:35:52 +08:00
|
|
|
#include "nonce2key/crapto1.h"
|
2012-07-17 19:41:56 +08:00
|
|
|
#include "iso14443crc.h"
|
2015-11-10 04:46:15 +08:00
|
|
|
#include "protocols.h"
|
2011-06-07 20:35:52 +08:00
|
|
|
|
|
|
|
#define NESTED_SECTOR_RETRY 10
|
|
|
|
|
2012-07-16 22:49:51 +08:00
|
|
|
// mifare tracer flags
|
2015-11-10 04:46:15 +08:00
|
|
|
#define TRACE_IDLE 0x00
|
|
|
|
#define TRACE_AUTH1 0x01
|
|
|
|
#define TRACE_AUTH2 0x02
|
|
|
|
#define TRACE_AUTH_OK 0x03
|
|
|
|
#define TRACE_READ_DATA 0x04
|
|
|
|
#define TRACE_WRITE_OK 0x05
|
|
|
|
#define TRACE_WRITE_DATA 0x06
|
|
|
|
#define TRACE_ERROR 0xFF
|
2012-07-16 22:49:51 +08:00
|
|
|
|
2016-08-01 04:00:49 +08:00
|
|
|
typedef struct {
|
|
|
|
union {
|
|
|
|
struct Crypto1State *slhead;
|
|
|
|
uint64_t *keyhead;
|
|
|
|
} head;
|
|
|
|
union {
|
|
|
|
struct Crypto1State *sltail;
|
|
|
|
uint64_t *keytail;
|
|
|
|
} tail;
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t uid;
|
|
|
|
uint32_t blockNo;
|
|
|
|
uint32_t keyType;
|
|
|
|
uint32_t nt;
|
|
|
|
uint32_t ks1;
|
|
|
|
} StateList_t;
|
|
|
|
|
2011-06-07 20:35:52 +08:00
|
|
|
typedef struct {
|
|
|
|
uint64_t Key[2];
|
|
|
|
int foundKey[2];
|
|
|
|
} sector;
|
|
|
|
|
2016-08-01 04:00:49 +08:00
|
|
|
extern int compar_int(const void * a, const void * b);
|
2015-01-21 04:58:53 +08:00
|
|
|
extern char logHexFileName[FILE_PATH_SIZE];
|
2012-07-16 22:49:51 +08:00
|
|
|
|
2013-09-15 17:33:17 +08:00
|
|
|
int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * ResultKeys, bool calibrate);
|
2015-07-13 04:58:16 +08:00
|
|
|
int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key);
|
2016-08-08 23:49:30 +08:00
|
|
|
int mfKeyBrute(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint64_t *resultkey);
|
2012-07-17 19:28:12 +08:00
|
|
|
|
2011-06-18 02:39:54 +08:00
|
|
|
int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount);
|
|
|
|
int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount);
|
2015-10-05 00:01:33 +08:00
|
|
|
int mfEmlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth);
|
2012-07-17 19:28:12 +08:00
|
|
|
|
2015-11-10 04:46:15 +08:00
|
|
|
int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, uint8_t wipecard);
|
|
|
|
int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, uint8_t params);
|
2012-07-05 22:05:01 +08:00
|
|
|
int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params);
|
2012-07-17 19:28:12 +08:00
|
|
|
|
2016-04-18 19:18:02 +08:00
|
|
|
int mfTraceInit(uint8_t *tuid, uint8_t uidlen, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile);
|
2014-12-16 14:41:07 +08:00
|
|
|
int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile);
|
2012-07-17 19:28:12 +08:00
|
|
|
|
|
|
|
int isTraceCardEmpty(void);
|
|
|
|
int isBlockEmpty(int blockN);
|
|
|
|
int isBlockTrailer(int blockN);
|
2016-04-18 19:18:02 +08:00
|
|
|
int loadTraceCard(uint8_t *tuid, uint8_t uidlen);
|
2012-07-17 19:28:12 +08:00
|
|
|
int saveTraceCard(void);
|
2015-10-08 05:00:46 +08:00
|
|
|
int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int len);
|