#define MAX_UL_BLOCKS 0x0f
#define MAX_ULC_BLOCKS 0x2f
-#define MAX_ULEV1a_BLOCKS 0x0b
+#define MAX_ULEV1a_BLOCKS 0x12
#define MAX_ULEV1b_BLOCKS 0x20
#define MAX_NTAG_213 0x2c
#define MAX_NTAG_215 0x86
{0x32,0x0C,0x16,0x17}, // PACK 0x80,0x80 -- AMiiboo (sniffed)
};
+#define MAX_UL_TYPES 13
+uint16_t UL_TYPES_ARRAY[MAX_UL_TYPES] = {UNKNOWN, UL, UL_C, UL_EV1_48, UL_EV1_128,
+ NTAG, NTAG_213, NTAG_215, NTAG_216, MY_D, MY_D_NFC, MY_D_MOVE, MY_D_MOVE_NFC};
+uint8_t UL_MEMORY_ARRAY[MAX_UL_TYPES] = {MAX_UL_BLOCKS, MAX_UL_BLOCKS, MAX_ULC_BLOCKS,
+ MAX_ULEV1a_BLOCKS, MAX_ULEV1b_BLOCKS, MAX_NTAG_213, MAX_NTAG_213, MAX_NTAG_215,
+ MAX_NTAG_216, MAX_UL_BLOCKS, MAX_UL_BLOCKS, MAX_UL_BLOCKS, MAX_UL_BLOCKS};
+
+
static int CmdHelp(const char *Cmd);
char* getProductTypeStr( uint8_t id){
PrintAndLog(" BCC1 : %02X - crc should be %02X", data[8], crc1 );
PrintAndLog(" Internal : %02X - %s default", data[9], (data[9]==0x48)?"":"not" );
- PrintAndLog(" Lock : %s - %s", sprint_hex(data+10, 2),printBits( 2, data+10) );
- PrintAndLog("OneTimePad : %s ", sprint_hex(data + 12, 4));
- PrintAndLog("");
+ PrintAndLog(" Lock : %s - %s",
+ sprint_hex(data+10, 2),
+ printBits(2, data+10)
+ );
+ PrintAndLog("OneTimePad : %s - %s\n",
+ sprint_hex(data + 12, 4),
+ printBits(4, data+12)
+ );
return 0;
}
PrintAndLog(" deskey1 [45/0x2D]: %s [%.4s]", sprint_hex(data+4 ,4),data+4);
PrintAndLog(" deskey2 [46/0x2E]: %s [%.4s]", sprint_hex(data+8 ,4),data+8);
PrintAndLog(" deskey2 [47/0x2F]: %s [%.4s]", sprint_hex(data+12,4),data+12);
- PrintAndLog("\n 3des key : %s", sprint_hex(SwapEndian64(data, 16), 16));
+ PrintAndLog("\n 3des key : %s", sprint_hex(SwapEndian64(data, 16, 8), 16));
return 0;
}
uint8_t datalen = 0;
uint8_t authenticationkey[16] = {0x00};
uint8_t pack[4] = {0,0,0,0};
+ int len=0;
while(param_getchar(Cmd, cmdp) != 0x00)
{
}
if ( hasAuthKey ) {
- if ((tagtype & UL_C))
- try3DesAuthentication(authenticationkey);
- else
- ulev1_requestAuthentication(authenticationkey, pack, sizeof(pack));
+ if ((tagtype & UL_C)) {
+ ul_switch_off_field();
+ //will select card automatically
+ if (try3DesAuthentication(authenticationkey, false) != 1) {
+ ul_switch_off_field();
+ PrintAndLog("Error: Authentication Failed UL-C");
+ return 0;
+ }
+ } else {
+ len = ulev1_requestAuthentication(authenticationkey, pack, sizeof(pack));
+ if (len < 1) {
+ if (!len) ul_switch_off_field();
+ PrintAndLog("Error: Authentication Failed UL-EV1/NTAG");
+ return 0;
+ }
+ }
}
+
// read pages 0,1,2,4 (should read 4pages)
status = ul_read(0, data, sizeof(data));
if ( status == -1 ){
if ( hasAuthKey ) return 1;
PrintAndLog("Trying some default 3des keys");
- ul_switch_off_field();
+ ul_switch_off_field(); //will select again in try3DesAuth...
for (uint8_t i = 0; i < KEYS_3DES_COUNT; ++i ){
key = default_3des_keys[i];
- if (try3DesAuthentication(key) == 1){
+ if (try3DesAuthentication(key, true) == 1){
PrintAndLog("Found default 3des key: "); //%s", sprint_hex(key,16));
- ulc_print_3deskey(SwapEndian64(key,16));
+ uint8_t keySwap[16];
+ memcpy(keySwap, SwapEndian64(key,16,8), 16);
+ ulc_print_3deskey(keySwap);
return 1;
- }
+ }
}
+ return 1; //return even if key not found (UL_C is done)
}
}
if ( authlim == 0 ){
PrintAndLog("\n--- Known EV1/NTAG passwords.");
- int len=0; //if len goes to -1 the connection will be turned off.
for (uint8_t i = 0; i < 3; ++i ){
key = default_pwd_pack[i];
if ( len > -1 ){
len = ulev1_requestAuthentication(key, pack, sizeof(pack));
- PrintAndLog("Found a default password: %s || Pack: %02X %02X",sprint_hex(key, 4), pack[0], pack[1]);
- break;
+ if (len == 1) {
+ PrintAndLog("Found a default password: %s || Pack: %02X %02X",sprint_hex(key, 4), pack[0], pack[1]);
+ break;
+ }
}
}
if (len > -1) ul_switch_off_field();
PrintAndLog("It autodetects card type.\n");
PrintAndLog("Usage: hf mfu dump s k <key> n <filename w/o .bin>");
PrintAndLog(" Options : ");
- PrintAndLog(" k <key> : Enter key for authentication");
- PrintAndLog(" n <FN > : Enter filename w/o .bin to save the dump as");
- PrintAndLog(" s : Swap entered key's endianness for auth");
+ PrintAndLog(" k <key> : key for authentication [UL-C 16bytes, EV1/NTAG 4bytes]");
+ PrintAndLog(" l : swap entered key's endianness for auth");
+ PrintAndLog(" n <FN > : filename w/o .bin to save the dump as");
+ PrintAndLog(" p <Pg > : starting Page number to manually set a page to start the dump at");
+ PrintAndLog(" q <qty> : number of Pages to manually set how many pages to dump");
+
PrintAndLog("");
PrintAndLog(" sample : hf mfu dump");
PrintAndLog(" : hf mfu dump n myfile");
FILE *fout;
char filename[FILE_PATH_SIZE] = {0x00};
char *fnameptr = filename;
- char *str = "Dumping Ultralight%s%s Card Data...";
+ //char *str = "Dumping Ultralight%s%s Card Data...";
uint8_t *lockbytes_t = NULL;
uint8_t lockbytes[2] = {0x00};
uint8_t *lockbytes_t2 = NULL;
size_t fileNlen = 0;
bool errors = false;
bool swapEndian = false;
+ bool manualPages = false;
+ uint8_t startPage = 0;
+ char tempStr[50];
while(param_getchar(Cmd, cmdp) != 0x00)
{
return usage_hf_mfu_dump();
case 'k':
case 'K':
- dataLen = param_gethex(Cmd, cmdp+1, data, 32);
- if (dataLen) {
- errors = true;
- } else {
- memcpy(key, data, 16);
- }
+ dataLen = param_getstr(Cmd, cmdp+1, tempStr);
+ if (dataLen == 32) //ul-c
+ errors = param_gethex(tempStr, 0, key, dataLen);
+ else if (dataLen == 8) //ev1/ntag
+ errors = param_gethex(tempStr, 0, key, dataLen);
+ else
+ errors = true;
+
+ if (!errors)
+ memcpy(key, data, dataLen/2);
+
cmdp += 2;
hasPwd = true;
break;
+ case 'l':
+ case 'L':
+ swapEndian = true;
+ cmdp++;
+ break;
case 'n':
case 'N':
fileNlen = param_getstr(Cmd, cmdp+1, filename);
if (fileNlen > FILE_PATH_SIZE-5) fileNlen = FILE_PATH_SIZE-5;
cmdp += 2;
break;
- case 's':
- swapEndian = true;
- cmdp++;
+ case 'p':
+ case 'P':
+ startPage = param_get8(Cmd, cmdp+1);
+ manualPages = true;
+ cmdp += 2;
+ break;
+ case 'q':
+ case 'Q':
+ Pages = param_get8(Cmd, cmdp+1);
+ cmdp += 2;
+ manualPages = true;
break;
default:
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
//Validations
if(errors) return usage_hf_mfu_dump();
- if (swapEndian)
- keyPtr = SwapEndian64(data, 16);
+ if (swapEndian && dataLen == 32)
+ keyPtr = SwapEndian64(data, 16, 8);
TagTypeUL_t tagtype = GetHF14AMfU_Type();
if (tagtype == UL_ERROR) return -1;
- if ( tagtype & UL ) {
- Pages = 16;
- PrintAndLog(str,"", (tagtype & MAGIC)?" (magic)":"" );
- }
- else if ( tagtype & UL_C ) {
- Pages = 44;
- PrintAndLog(str,"-C", (tagtype & MAGIC)?" (magic)":"" );
- }
- else if ( tagtype & UL_EV1_48 ) {
- Pages = 18;
- PrintAndLog(str," EV1_48","");
- }
- else if ( tagtype & UL_EV1_128 ) {
- Pages = 32;
- PrintAndLog(str," EV1_128","");
- } else {
- Pages = 16;
- PrintAndLog("Dumping unknown Ultralight, using default values.");
- }
+ if (!manualPages)
+ for (uint8_t idx = 0; idx < MAX_UL_TYPES; idx++)
+ if (tagtype & UL_TYPES_ARRAY[idx])
+ Pages = UL_MEMORY_ARRAY[idx]+1;
- UsbCommand c = {CMD_MIFAREUC_READCARD, {0,Pages}};
+ ul_print_type(tagtype, 0);
+ PrintAndLog("Reading tag memory...");
+
+ UsbCommand c = {CMD_MIFAREUC_READCARD, {startPage,Pages}};
if ( hasPwd ) {
- c.arg[2] = 1;
- memcpy(c.d.asBytes, key, 16);
+ if (tagtype & UL_C)
+ c.arg[2] = 1; //UL_C auth
+ else
+ c.arg[2] = 2; //UL_EV1/NTAG auth
+
+ memcpy(c.d.asBytes, key, dataLen/2);
}
SendCommand(&c);
UsbCommand resp;
}
// Load bottom lockbytes if available
+ // HOW DOES THIS APPLY TO EV1 and/or NTAG???
if ( Pages == 44 ) {
lockbytes_t2 = data + (40*4);
lockbytes2[0] = lockbytes_t2[2];
}
// add keys
- if (hasPwd){
+ if (hasPwd && dataLen == 32){ //UL_C
memcpy(data + Pages*4, key, 16);
Pages += 4;
- }
+ }
+ //TODO add key MEM location for other tags
+
for (i = 0; i < Pages; ++i) {
if ( i < 3 ) {
PrintAndLog("Block %02x:%s ", i,sprint_hex(data + i * 4, 4));
sprintf(fnameptr,"%02X%02X%02X%02X%02X%02X%02X.bin",
data[0],data[1], data[2], data[4],data[5],data[6], data[7]);
} else {
- sprintf(fnameptr + fileNlen," .bin");
+ sprintf(fnameptr + fileNlen,".bin");
}
if ((fout = fopen(filename,"wb")) == NULL) {
}
uint8_t *key = default_3des_keys[keyNo];
- if (try3DesAuthentication(key)>0)
+ if (try3DesAuthentication(key, true) > 0)
PrintAndLog("Authentication successful. 3des key: %s",sprint_hex(key, 16));
else
PrintAndLog("Authentication failed");
return 0;
}
-int try3DesAuthentication( uint8_t *key){
+int try3DesAuthentication( uint8_t *key, bool switch_off_field ){
- uint32_t cuid = 0;
+ //uint32_t cuid = 0;
des3_context ctx = { 0 };
if ( !WaitForResponseTimeout(CMD_ACK, &resp, 1500) ) return -1;
if ( !(resp.arg[0] & 0xff) ) return -2;
- cuid = resp.arg[1];
+ //cuid = resp.arg[1];
memcpy(enc_random_b,resp.d.asBytes+1,8);
des3_set2key_dec(&ctx, key);
//Auth2
c.cmd = CMD_MIFAREUC_AUTH2;
- c.arg[0] = cuid;
+ c.arg[0] = switch_off_field;
memcpy(c.d.asBytes, rnd_ab, 16);
SendCommand(&c);
hasPwd = TRUE;
}
}
- //uint8_t *key2 = SwapEndian64(key, 16);
+ //uint8_t *key2 = SwapEndian64(key, 16, 8);
//Read Block
UsbCommand c = {CMD_MIFAREU_READBL, {blockNo}};