ADD: analyse nuid - generates NUID 4byte from a UID 7byte. Mifare Classic Ev1 has this option as a activation sequences. This NUID is also used for authenticate (cuid), not the block0 data.

ref: http://www.gorferay.com/mifare-and-handling-of-uids/
This commit is contained in:
iceman1001 2017-03-10 09:48:36 +01:00
commit 905c55de2b
4 changed files with 71 additions and 7 deletions

View file

@ -68,6 +68,18 @@ int usage_analyse_hid(void){
PrintAndLog(" analyse hid r 0123456789abcdef"); PrintAndLog(" analyse hid r 0123456789abcdef");
return 0; return 0;
} }
int usage_analyse_nuid(void){
PrintAndLog("Generate 4byte NUID from 7byte UID");
PrintAndLog("");
PrintAndLog("Usage: analyse hid [h] <bytes>");
PrintAndLog("Options:");
PrintAndLog(" h This help");
PrintAndLog(" <bytes> input bytes (14 hexsymbols)");
PrintAndLog("");
PrintAndLog("Samples:");
PrintAndLog(" analyse nuid 11223344556677");
return 0;
}
static uint8_t calculateLRC( uint8_t* bytes, uint8_t len) { static uint8_t calculateLRC( uint8_t* bytes, uint8_t len) {
uint8_t LRC = 0; uint8_t LRC = 0;
@ -521,6 +533,53 @@ int CmdAnalyseHid(const char *Cmd){
return 0; return 0;
} }
void generate4bNUID(uint8_t *uid, uint8_t *nuid){
uint16_t crc;
uint8_t first, second;
ComputeCrc14443(CRC_14443_A, uid, 3, &first, &second);
nuid[0] |= (second & 0xE0) | 0xF;
nuid[1] = first;
crc = first;
crc |= second << 8;
UpdateCrc14443(uid[3], &crc);
UpdateCrc14443(uid[4], &crc);
UpdateCrc14443(uid[5], &crc);
UpdateCrc14443(uid[6], &crc);
nuid[2] = (crc >> 8) & 0xFF ;
nuid[3] = crc & 0xFF;
}
int CmdAnalyseNuid(const char *Cmd){
uint8_t nuid[4] = {0};
uint8_t uid[7] = {0};
int len = 0;
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) == 0|| cmdp == 'h' || cmdp == 'H') return usage_analyse_nuid();
/* selftest UID 040D681AB52281 -> NUID 8F430FEF */
if (cmdp == 't' || cmdp == 'T') {
memcpy(uid, "\x04\x0d\x68\x1a\xb5\x22\x81", 7);
generate4bNUID(uid, nuid);
if ( 0 == memcmp(nuid, "\x8f\x43\x0f\xef", 4))
printf("Selftest OK\n");
else
printf("Selftest Failed\n");
return 0;
}
param_gethex_ex(Cmd, 0, uid, &len);
if ( len%2 || len != 14) return usage_analyse_nuid();
generate4bNUID(uid, nuid);
printf("UID | %s \n", sprint_hex(uid, 7));
printf("NUID | %s \n", sprint_hex(nuid, 4));
return 0;
}
static command_t CommandTable[] = { static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help"}, {"help", CmdHelp, 1, "This help"},
{"lcr", CmdAnalyseLCR, 1, "Generate final byte for XOR LRC"}, {"lcr", CmdAnalyseLCR, 1, "Generate final byte for XOR LRC"},
@ -531,6 +590,7 @@ static command_t CommandTable[] = {
{"lfsr", CmdAnalyseLfsr, 1, "LFSR tests"}, {"lfsr", CmdAnalyseLfsr, 1, "LFSR tests"},
{"a", CmdAnalyseA, 1, "num bits test"}, {"a", CmdAnalyseA, 1, "num bits test"},
{"hid", CmdAnalyseHid, 1, "Permute function from 'heart of darkness' paper"}, {"hid", CmdAnalyseHid, 1, "Permute function from 'heart of darkness' paper"},
{"nuid", CmdAnalyseNuid, 1, "create NUID from 7byte UID"},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };

View file

@ -18,15 +18,17 @@
#include "ui.h" // PrintAndLog #include "ui.h" // PrintAndLog
#include "util.h" #include "util.h"
#include "crc.h" #include "crc.h"
#include "../common/iso15693tools.h" #include "iso15693tools.h" //
#include "iso14443crc.h" // crc 14a
#include "tea.h" #include "tea.h"
#include "../include/legic_prng.h" #include "legic_prng.h"
#include "loclass/elite_crack.h" #include "loclass/elite_crack.h"
int usage_analyse_lcr(void); int usage_analyse_lcr(void);
int usage_analyse_checksum(void); int usage_analyse_checksum(void);
int usage_analyse_crc(void); int usage_analyse_crc(void);
int usage_analyse_hid(void); int usage_analyse_hid(void);
int usage_analyse_nuid(void);
int CmdAnalyse(const char *Cmd); int CmdAnalyse(const char *Cmd);
int CmdAnalyseLCR(const char *Cmd); int CmdAnalyseLCR(const char *Cmd);
@ -36,4 +38,5 @@ int CmdAnalyseCRC(const char *Cmd);
int CmdAnalyseTEASelfTest(const char *Cmd); int CmdAnalyseTEASelfTest(const char *Cmd);
int CmdAnalyseLfsr(const char *Cmd); int CmdAnalyseLfsr(const char *Cmd);
int CmdAnalyseHid(const char *Cmd); int CmdAnalyseHid(const char *Cmd);
int CmdAnalyseNuid(const char *Cmd);
#endif #endif

View file

@ -8,7 +8,7 @@
#include "iso14443crc.h" #include "iso14443crc.h"
static unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc) unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc)
{ {
ch = (ch ^ (unsigned char) ((*lpwCrc) & 0x00FF)); ch = (ch ^ (unsigned char) ((*lpwCrc) & 0x00FF));
ch = (ch ^ (ch << 4)); ch = (ch ^ (ch << 4));

View file

@ -18,6 +18,7 @@
#define CRC_14443_B 0xFFFF /* ISO/IEC 13239 (formerly ISO/IEC 3309) */ #define CRC_14443_B 0xFFFF /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
#define CRC_ICLASS 0xE012 /* ICLASS PREFIX */ #define CRC_ICLASS 0xE012 /* ICLASS PREFIX */
unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc);
void ComputeCrc14443(int CrcType, void ComputeCrc14443(int CrcType,
const unsigned char *Data, int Length, const unsigned char *Data, int Length,
unsigned char *TransmitFirst, unsigned char *TransmitFirst,