X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/76c7e6c36368c3fc23dc4fab1fe5852023c78fac..a61b4976bd2085bf0495855b48fcad0d9ed4572e:/client/cmdhfmf.c diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 0d4813dd..1d2de683 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -521,14 +521,12 @@ int CmdHF14AMfDump(const char *Cmd) int size = GetCardSize(); char cmdp = param_getchar(Cmd, 0); - - PrintAndLog("Got %d",size); - - return; - + if ( size > -1) - cmdp = (char)48+size; - + cmdp = (char)(48+size); + + PrintAndLog("Got %d",cmdp); + switch (cmdp) { case '0' : numSectors = 5; break; case '1' : @@ -548,7 +546,7 @@ int CmdHF14AMfDump(const char *Cmd) } if ((fin = fopen("dumpkeys.bin","rb")) == NULL) { - PrintAndLog("Could not find file dumpkeys.bin"); + PrintAndLog("Could not find file dumpkeys.bin"); return 1; } @@ -556,6 +554,7 @@ int CmdHF14AMfDump(const char *Cmd) for (sectorNo=0; sectorNo>4) | ((data[8] & 0x1)<<1) | ((data[8] & 0x10)>>2); - rights[sectorNo][1] = ((data[7] & 0x20)>>5) | ((data[8] & 0x2)<<0) | ((data[8] & 0x20)>>3); - rights[sectorNo][2] = ((data[7] & 0x40)>>6) | ((data[8] & 0x4)>>1) | ((data[8] & 0x40)>>4); - rights[sectorNo][3] = ((data[7] & 0x80)>>7) | ((data[8] & 0x8)>>2) | ((data[8] & 0x80)>>5); + rights[sectorNo][0] = ((data[7] & 0x10)>>2) | ((data[8] & 0x1)<<1) | ((data[8] & 0x10)>>4); // C1C2C3 for data area 0 + rights[sectorNo][1] = ((data[7] & 0x20)>>3) | ((data[8] & 0x2)<<0) | ((data[8] & 0x20)>>5); // C1C2C3 for data area 1 + rights[sectorNo][2] = ((data[7] & 0x40)>>4) | ((data[8] & 0x4)>>1) | ((data[8] & 0x40)>>6); // C1C2C3 for data area 2 + rights[sectorNo][3] = ((data[7] & 0x80)>>5) | ((data[8] & 0x8)>>2) | ((data[8] & 0x80)>>7); // C1C2C3 for sector trailer } else { PrintAndLog("Could not get access rights for sector %2d. Trying with defaults...", sectorNo); - rights[sectorNo][0] = rights[sectorNo][1] = rights[sectorNo][2] = rights[sectorNo][3] = 0x01; + rights[sectorNo][0] = rights[sectorNo][1] = rights[sectorNo][2] = 0x00; + rights[sectorNo][3] = 0x01; } } else { PrintAndLog("Command execute timeout when trying to read access rights for sector %2d. Trying with defaults...", sectorNo); - rights[sectorNo][0] = rights[sectorNo][1] = rights[sectorNo][2] = rights[sectorNo][3] = 0x01; + rights[sectorNo][0] = rights[sectorNo][1] = rights[sectorNo][2] = 0x00; + rights[sectorNo][3] = 0x01; } } @@ -611,12 +615,12 @@ int CmdHF14AMfDump(const char *Cmd) received = WaitForResponseTimeout(CMD_ACK,&resp,1500); } else { // data block. Check if it can be read with key A or key B uint8_t data_area = sectorNo<32?blockNo:blockNo/5; - if ((rights[sectorNo][data_area] == 3) || (rights[sectorNo][data_area] == 5)) { // only key B would work + if ((rights[sectorNo][data_area] == 0x03) || (rights[sectorNo][data_area] == 0x05)) { // only key B would work UsbCommand c = {CMD_MIFARE_READBL, {FirstBlockOfSector(sectorNo) + blockNo, 1, 0}}; memcpy(c.d.asBytes, keyB[sectorNo], 6); SendCommand(&c); received = WaitForResponseTimeout(CMD_ACK,&resp,1500); - } else if (rights[sectorNo][data_area] == 7) { // no key would work + } else if (rights[sectorNo][data_area] == 0x07) { // no key would work isOK = false; PrintAndLog("Access rights do not allow reading of sector %2d block %3d", sectorNo, blockNo); } else { // key A would work @@ -671,7 +675,6 @@ int CmdHF14AMfDump(const char *Cmd) PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks); } - fclose(fin); return 0; } @@ -1025,6 +1028,18 @@ int CmdHF14AMfNested(const char *Cmd) int CmdHF14AMfChk(const char *Cmd) { + if (strlen(Cmd)<3) { + PrintAndLog("Usage: hf mf chk |<*card memory> [t|d] [] []"); + PrintAndLog(" * - all sectors"); + PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, - 1K"); + PrintAndLog("d - write keys to binary file\n"); + PrintAndLog("t - write keys to emulator memory"); + PrintAndLog(" sample: hf mf chk 0 A 1234567890ab keys.dic"); + PrintAndLog(" hf mf chk *1 ? t"); + PrintAndLog(" hf mf chk *1 ? d"); + return 0; + } + FILE * f; char filename[256]={0}; char buf[13]; @@ -1068,16 +1083,6 @@ int CmdHF14AMfChk(const char *Cmd) num_to_bytes(defaultKeys[defaultKeyCounter], 6, (uint8_t*)(keyBlock + defaultKeyCounter * 6)); } - if (strlen(Cmd)<3) { - PrintAndLog("Usage: hf mf chk |<*card memory> [t] [] []"); - PrintAndLog(" * - all sectors"); - PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, - 1K"); - PrintAndLog("d - write keys to binary file\n"); - PrintAndLog(" sample: hf mf chk 0 A 1234567890ab keys.dic"); - PrintAndLog(" hf mf chk *1 ? t"); - return 0; - } - if (param_getchar(Cmd, 0)=='*') { blockNo = 3; switch(param_getchar(Cmd+1, 0)) { @@ -1165,11 +1170,12 @@ int CmdHF14AMfChk(const char *Cmd) keycnt++; memset(buf, 0, sizeof(buf)); } + fclose(f); } else { PrintAndLog("File: %s: not found or locked.", filename); free(keyBlock); return 1; - fclose(f); + } } } @@ -1450,6 +1456,7 @@ int CmdHF14AMfELoad(const char *Cmd) break; } PrintAndLog("File reading error."); + fclose(f); return 2; } if (strlen(buf) < 32){ @@ -1474,6 +1481,7 @@ int CmdHF14AMfELoad(const char *Cmd) if ((blockNum != 16*4) && (blockNum != 32*4 + 8*16)) { PrintAndLog("File content error. There must be 64 or 256 blocks."); + fclose(f); return 4; } PrintAndLog("Loaded %d blocks from file: %s", blockNum, filename); @@ -1606,8 +1614,8 @@ int CmdHF14AMfEKeyPrn(const char *Cmd) int CmdHF14AMfCSetUID(const char *Cmd) { uint8_t wipeCard = 0; - uint8_t uid[8]; - uint8_t oldUid[8]; + uint8_t uid[8] = {0x00}; + uint8_t oldUid[8] = {0x00}; int res; if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') { @@ -2088,49 +2096,56 @@ int GetCardSize() // NXP MIFARE Mini 0.3k - if ( (atqa && 0xff0f == 0x0004) && (sak == 0x09) ) return 0; + if ( ( (atqa & 0xff0f) == 0x0004) && (sak == 0x09) ) return 0; // MIFARE Classic 1K - if ( (atqa && 0xff0f == 0x0004) && (sak == 0x08) ) return 1; + if ( ((atqa & 0xff0f) == 0x0004) && (sak == 0x08) ) return 1; // MIFARE Classik 4K - if ( (atqa && 0xff0f == 0x0002) && (sak == 0x18) ) return 4; + if ( ((atqa & 0xff0f) == 0x0002) && (sak == 0x18) ) return 4; // SmartMX with MIFARE 1K emulation - if ( (atqa && 0xf0ff == 0x0004) ) return 1; + if ( ((atqa & 0xf0ff) == 0x0004) ) return 1; // SmartMX with MIFARE 4K emulation - if ( (atqa && 0xf0ff == 0x0002) ) return 4; + if ( ((atqa & 0xf0ff) == 0x0002) ) return 4; // Infineon MIFARE CLASSIC 1K - if ( (atqa && 0xffff == 0x0004) && (sak == 0x88) ) return 1; + if ( ((atqa & 0xffff) == 0x0004) && (sak == 0x88) ) return 1; // MFC 4K emulated by Nokia 6212 Classic - if ( (atqa && 0xffff == 0x0002) && (sak == 0x38) ) return 4; + if ( ((atqa & 0xffff) == 0x0002) && (sak == 0x38) ) return 4; // MFC 4K emulated by Nokia 6131 NFC - if ( (atqa && 0xffff == 0x0008) && (sak == 0x38) ) return 4; + if ( ((atqa & 0xffff) == 0x0008) && (sak == 0x38) ) return 4; + + PrintAndLog("BEFOOO 1K %02X", (atqa & 0xff0f)); + // MIFARE Plus (4 Byte UID or 4 Byte RID) // MIFARE Plus (7 Byte UID) if ( - (atqa && 0xffff == 0x0002) || - (atqa && 0xffff == 0x0004) || - (atqa && 0xffff == 0x0042) || - (atqa && 0xffff == 0x0044) + ((atqa & 0xffff) == 0x0002) | + ((atqa & 0xffff) == 0x0004) | + ((atqa & 0xffff) == 0x0042) | + ((atqa & 0xffff) == 0x0044) ) { switch(sak){ case 0x08: - case 0x10: + case 0x10: { //case 0x20: + PrintAndLog("2"); return 2; break; + } case 0x11: - case 0x18: + case 0x18:{ //case 0x20: + PrintAndLog("4"); return 4; break; + } } }