X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/26fdb4ab49f74415b43363d999063261ed4cb9da..13d8c68d8615974c54315d6ae7bba26b66a61131:/client/cmdhfmf.c diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 742b7b3b..1a29f871 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -259,15 +259,10 @@ int CmdHF14AMfDump1k(const char *Cmd) { int i, j; - uint8_t keyType = 0; - uint8_t c[3][4]; uint8_t keyA[16][6]; uint8_t keyB[16][6]; uint8_t rights[16][4]; - uint8_t isOK = 0; - uint8_t *data = NULL; - FILE *fin; FILE *fout; @@ -330,7 +325,6 @@ int CmdHF14AMfDump1k(const char *Cmd) for (i=0 ; i<16 ; i++) { for (j=0 ; j<4 ; j++) { - if (j == 3){ UsbCommand c = {CMD_MIFARE_READBL, {i*4 + j, 0, 0}}; memcpy(c.d.asBytes, keyA[i], 6); @@ -358,6 +352,20 @@ int CmdHF14AMfDump1k(const char *Cmd) if (resp != NULL) { uint8_t isOK = resp->arg[0] & 0xff; uint8_t *data = resp->d.asBytes; + if (j == 3) { + data[0] = (keyA[i][0]); + data[1] = (keyA[i][1]); + data[2] = (keyA[i][2]); + data[3] = (keyA[i][3]); + data[4] = (keyA[i][4]); + data[5] = (keyA[i][5]); + data[10] = (keyB[i][0]); + data[11] = (keyB[i][1]); + data[12] = (keyB[i][2]); + data[13] = (keyB[i][3]); + data[14] = (keyB[i][4]); + data[15] = (keyB[i][5]); + } if (isOK) { fwrite ( data, 1, 16, fout ); } @@ -381,20 +389,15 @@ int CmdHF14AMfRestore1k(const char *Cmd) { int i,j; - uint8_t blockNo = 0; uint8_t keyType = 0; uint8_t key[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t keyA[16][6]; uint8_t keyB[16][6]; - char cmdp = 0x00; - FILE *fdump; FILE *fkeys; - FILE *fdebug = fopen("debug.bin","wb"); - if ((fdump = fopen("dumpdata.bin","rb")) == NULL) { PrintAndLog("Could not find file dump.bin"); return 1; @@ -411,7 +414,7 @@ int CmdHF14AMfRestore1k(const char *Cmd) fread(keyB[i], 1, 6, fkeys); } - PrintAndLog("going..."); + PrintAndLog("Restoring dumpdata.bin to card"); for (i=0 ; i<16 ; i++) { for( j=0 ; j<4 ; j++) { @@ -435,7 +438,17 @@ int CmdHF14AMfRestore1k(const char *Cmd) bldata[15] = (keyB[i][5]); } - PrintAndLog("writing to block %2d: %s confirm?", i*4+j, sprint_hex(bldata, 16)); + PrintAndLog("Writing to block %2d: %s", i*4+j, sprint_hex(bldata, 16)); + + /* + PrintAndLog("Writing to block %2d: %s Confirm? [Y,N]", i*4+j, sprint_hex(bldata, 16)); + + scanf("%c",&ch); + if ((ch != 'y') && (ch != 'Y')){ + PrintAndLog("Aborting !"); + return 1; + } + */ memcpy(c.d.asBytes + 10, bldata, 16); SendCommand(&c); @@ -472,6 +485,8 @@ int CmdHF14AMfNested(const char *Cmd) int createDumpFile = 0; FILE *fkeys; + uint8_t standart[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; char cmdp, ctmp; @@ -524,10 +539,12 @@ int CmdHF14AMfNested(const char *Cmd) } ctmp = param_getchar(Cmd, 4); - if (ctmp == 't' || ctmp == 'T') transferToEml = 1; + if (ctmp == 't' || ctmp == 'T') transferToEml = 1; + else if (ctmp == 'd' || ctmp == 'D') createDumpFile = 1; + ctmp = param_getchar(Cmd, 6); transferToEml |= (ctmp == 't' || ctmp == 'T'); - createDumpFile |= (ctmp == 'd' || ctmp == 'D'); + transferToEml |= (ctmp == 'd' || ctmp == 'D'); PrintAndLog("--block no:%02x key type:%02x key:%s etrans:%d", blockNo, keyType, sprint_hex(key, 6), transferToEml); if (cmdp == 'o') @@ -563,8 +580,8 @@ int CmdHF14AMfNested(const char *Cmd) } else { PrintAndLog("No valid key found"); } - } else // ------------------------------------ multiple sectors working - { + } + else { // ------------------------------------ multiple sectors working blDiff = blockNo % 4; PrintAndLog("Block shift=%d", blDiff); e_sector = calloc(SectorsCnt, sizeof(sector)); @@ -592,7 +609,6 @@ int CmdHF14AMfNested(const char *Cmd) } } - // nested sectors iterations = 0; PrintAndLog("nested..."); @@ -639,17 +655,31 @@ int CmdHF14AMfNested(const char *Cmd) } } + // Create dump file if (createDumpFile) { if ((fkeys = fopen("dumpkeys.bin","wb")) == NULL) { - rintAndLog("Could not create file keys.bin"); + PrintAndLog("Could not create file keys.bin"); free(e_sector); return 1; } + PrintAndLog("Printing keys to bynary file dumpkeys.bin..."); for(i=0; i<16; i++) { - fwrite ( e_sector[i].Key[0], sizeof(e_sector[i].Key[0]), 1, fkeys ); + if (e_sector[i].foundKey[0]){ + num_to_bytes(e_sector[i].Key[0], 6, tempkey); + fwrite ( tempkey, 1, 6, fkeys ); + } + else{ + fwrite ( &standart, 1, 6, fkeys ); + } } for(i=0; i<16; i++) { - fwrite ( e_sector[i].Key[1], sizeof(e_sector[i].Key[1]), 1, fkeys ); + if (e_sector[i].foundKey[1]){ + num_to_bytes(e_sector[i].Key[1], 6, tempkey); + fwrite ( tempkey, 1, 6, fkeys ); + } + else{ + fwrite ( &standart, 1, 6, fkeys ); + } } fclose(fkeys); }