X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/f885043422facc34eb6a5b3c3767f8ac25338157..ba39db376c12c945f3ba1bc0ad5b8cc188e21d6f:/client/cmdhfmf.c diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 6ddf845a..a840969e 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -31,6 +31,8 @@ int usage_hf14_mf1ksim(void){ PrintAndLog(" n (Optional) Automatically exit simulation after blocks have been read by reader. 0 = infinite"); PrintAndLog(" i (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted"); PrintAndLog(" x (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)"); + PrintAndLog(" e (Optional) Fill simulator keys from what we crack"); + PrintAndLog(" v (Optional) Show maths used for cracking reader. Useful for debugging."); PrintAndLog("samples:"); PrintAndLog(" hf mf sim u 0a0a0a0a"); PrintAndLog(" hf mf sim u 11223344556677"); @@ -475,6 +477,7 @@ int CmdHF14AMfDump(const char *Cmd) { if ( bytes_read == 0) { PrintAndLog("File reading error."); fclose(fin); + fin = NULL; return 2; } } @@ -485,12 +488,14 @@ int CmdHF14AMfDump(const char *Cmd) { if ( bytes_read == 0) { PrintAndLog("File reading error."); fclose(fin); + fin = NULL; return 2; } } fclose(fin); - + fin = NULL; + PrintAndLog("|-----------------------------------------|"); PrintAndLog("|------ Reading sector access bits...-----|"); PrintAndLog("|-----------------------------------------|"); @@ -596,6 +601,7 @@ int CmdHF14AMfDump(const char *Cmd) { uint16_t numblocks = FirstBlockOfSector(numSectors - 1) + NumBlocksPerSector(numSectors - 1); fwrite(carddata, 1, 16*numblocks, fout); fclose(fout); + fout = NULL; PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks); } @@ -644,6 +650,7 @@ int CmdHF14AMfRestore(const char *Cmd) { if ( bytes_read == 0) { PrintAndLog("File reading error (dumpkeys.bin)."); fclose(fkeys); + fkeys = NULL; return 2; } } @@ -653,6 +660,7 @@ int CmdHF14AMfRestore(const char *Cmd) { if ( bytes_read == 0) { PrintAndLog("File reading error (dumpkeys.bin)."); fclose(fkeys); + fkeys = NULL; return 2; } } @@ -673,6 +681,7 @@ int CmdHF14AMfRestore(const char *Cmd) { if ( bytes_read == 0) { PrintAndLog("File reading error (dumpdata.bin)."); fclose(fdump); + fdump = NULL; return 2; } @@ -708,6 +717,7 @@ int CmdHF14AMfRestore(const char *Cmd) { } fclose(fdump); + fdump = NULL; return 0; } @@ -1355,7 +1365,7 @@ int CmdHF14AMfChk(const char *Cmd) { #define ATTACK_KEY_COUNT 8 sector *k_sector = NULL; uint8_t k_sectorsCount = 16; -void readerAttack(nonces_t data[], bool setEmulatorMem) { +void readerAttack(nonces_t data[], bool setEmulatorMem, bool verbose) { // initialize storage for found keys if (k_sector == NULL) @@ -1376,8 +1386,10 @@ void readerAttack(nonces_t data[], bool setEmulatorMem) { 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)) { + + // We can probably skip this, mfkey32v2 is more reliable. +#ifdef HFMF_TRYMFK32 + if (tryMfk32(data[i], &key, verbose)) { PrintAndLog("Found Key%s for sector %02d: [%012"llx"]" , (data[i].keytype) ? "B" : "A" , data[i].sector @@ -1392,22 +1404,43 @@ void readerAttack(nonces_t data[], bool 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 + , ((data[i].sector)*4) + 3 , sprint_hex( memBlock, sizeof(memBlock)) ); + mfEmlSetMem( memBlock, ((data[i].sector)*4) + 3, 1); } - break; + continue; } +#endif //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 - // ); - // } + if (tryMfk32_moebius(data[i+ATTACK_KEY_COUNT], &key, verbose)) { + uint8_t sectorNum = data[i+ATTACK_KEY_COUNT].sector; + uint8_t keyType = data[i+ATTACK_KEY_COUNT].keytype; + + PrintAndLog("M-Found Key%s for sector %02d: [%012"llx"]" + , keyType ? "B" : "A" + , sectorNum + , key + ); + + k_sector[sectorNum].Key[keyType] = key; + k_sector[sectorNum].foundKey[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[sectorNum].Key[0], 6, memBlock); + num_to_bytes( k_sector[sectorNum].Key[1], 6, memBlock+10); + PrintAndLog("Setting Emulator Memory Block %02d: [%s]" + , (sectorNum*4) + 3 + , sprint_hex( memBlock, sizeof(memBlock)) + ); + mfEmlSetMem( memBlock, (sectorNum*4) + 3, 1); + } + continue; + } + } } } @@ -1417,11 +1450,14 @@ int CmdHF14AMf1kSim(const char *Cmd) { uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t exitAfterNReads = 0; uint8_t flags = (FLAG_UID_IN_EMUL | FLAG_4B_UID_IN_DATA); - int uidlen = 0; + int uidlen = 0; bool setEmulatorMem = false; uint8_t cmdp = 0; bool errors = false; + // If set to true, we should show our workings when doing NR_AR_ATTACK. + bool verbose = false; + while(param_getchar(Cmd, cmdp) != 0x00) { switch(param_getchar(Cmd, cmdp)) { case 'e': @@ -1453,6 +1489,11 @@ int CmdHF14AMf1kSim(const char *Cmd) { } cmdp +=2; break; + case 'v': + case 'V': + verbose = true; + cmdp++; + break; case 'x': case 'X': flags |= FLAG_NR_AR_ATTACK; @@ -1492,12 +1533,13 @@ int CmdHF14AMf1kSim(const char *Cmd) { if ( (resp.arg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD ) break; memcpy( data, resp.d.asBytes, sizeof(data) ); - readerAttack(data, setEmulatorMem); + readerAttack(data, setEmulatorMem, verbose); } if (k_sector != NULL) { printKeyTable(k_sectorsCount, k_sector ); free(k_sector); + k_sector = NULL; } } return 0;