mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
FIX: 'hf mf chk' / 'hf mf fchk' - t/d param bug. Now it is not place dependent and can also read several dictionary files :)
This commit is contained in:
parent
2abcce598a
commit
d5ce45bae7
1 changed files with 138 additions and 121 deletions
113
client/cmdhfmf.c
113
client/cmdhfmf.c
|
@ -1200,6 +1200,7 @@ int CmdHF14AMfChk_fast(const char *Cmd) {
|
||||||
uint8_t *keyBlock = NULL, *p;
|
uint8_t *keyBlock = NULL, *p;
|
||||||
uint8_t sectorsCnt = 1;
|
uint8_t sectorsCnt = 1;
|
||||||
int i, keycnt = 0;
|
int i, keycnt = 0;
|
||||||
|
int clen = 0;
|
||||||
int transferToEml = 0, createDumpFile = 0;
|
int transferToEml = 0, createDumpFile = 0;
|
||||||
uint32_t keyitems = MIFARE_DEFAULTKEYS_SIZE;
|
uint32_t keyitems = MIFARE_DEFAULTKEYS_SIZE;
|
||||||
|
|
||||||
|
@ -1220,35 +1221,46 @@ int CmdHF14AMfChk_fast(const char *Cmd) {
|
||||||
default: sectorsCnt = 16;
|
default: sectorsCnt = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctmp = param_getchar(Cmd, 1);
|
for (i = 1; param_getchar(Cmd, i); i++) {
|
||||||
if (ctmp == 't' || ctmp == 'T') transferToEml = 1;
|
|
||||||
else if (ctmp == 'd' || ctmp == 'D') createDumpFile = 1;
|
|
||||||
|
|
||||||
for (i = transferToEml || createDumpFile; param_getchar(Cmd, 1 + i); i++) {
|
ctmp = param_getchar(Cmd, i);
|
||||||
if (!param_gethex(Cmd, 1 + i, keyBlock + 6 * keycnt, 12)) {
|
clen = param_getlength(Cmd, i);
|
||||||
|
|
||||||
|
if (clen == 12) {
|
||||||
|
|
||||||
|
if ( param_gethex(Cmd, i, keyBlock + 6 * keycnt, 12) ){
|
||||||
|
PrintAndLog("[-] not hex, skipping");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ( keyitems - keycnt < 2) {
|
if ( keyitems - keycnt < 2) {
|
||||||
p = realloc(keyBlock, 6 * (keyitems += 64));
|
p = realloc(keyBlock, 6 * (keyitems += 64));
|
||||||
if (!p) {
|
if (!p) {
|
||||||
PrintAndLog("Cannot allocate memory for Keys");
|
PrintAndLog("[-] Cannot allocate memory for Keys");
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
keyBlock = p;
|
keyBlock = p;
|
||||||
}
|
}
|
||||||
PrintAndLog("[%2d] key %02x%02x%02x%02x%02x%02x", keycnt,
|
PrintAndLog("[%2d] key %s", keycnt, sprint_hex( (keyBlock + 6*keycnt), 6 ) );
|
||||||
(keyBlock + 6*keycnt)[0],(keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2],
|
|
||||||
(keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4], (keyBlock + 6*keycnt)[5], 6);
|
|
||||||
keycnt++;
|
keycnt++;
|
||||||
|
} else if ( clen == 1) {
|
||||||
|
if (ctmp == 't' || ctmp == 'T') { transferToEml = 1; continue; }
|
||||||
|
if (ctmp == 'd' || ctmp == 'D') { createDumpFile = 1; continue; }
|
||||||
} else {
|
} else {
|
||||||
// May be a dic file
|
// May be a dic file
|
||||||
if ( param_getstr(Cmd, 1 + i, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE ) {
|
if ( param_getstr(Cmd, i, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE ) {
|
||||||
PrintAndLog("File name too long");
|
PrintAndLog("[-] Filename too long");
|
||||||
free(keyBlock);
|
continue;
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (f = fopen( filename , "r")) ) {
|
f = fopen( filename, "r");
|
||||||
|
if ( !f ){
|
||||||
|
PrintAndLog("[-] File: %s: not found or locked.", filename);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read file
|
||||||
while( fgets(buf, sizeof(buf), f) ){
|
while( fgets(buf, sizeof(buf), f) ){
|
||||||
if (strlen(buf) < 12 || buf[11] == '\n')
|
if (strlen(buf) < 12 || buf[11] == '\n')
|
||||||
continue;
|
continue;
|
||||||
|
@ -1258,7 +1270,7 @@ int CmdHF14AMfChk_fast(const char *Cmd) {
|
||||||
if( buf[0]=='#' ) continue; //The line start with # is comment, skip
|
if( buf[0]=='#' ) continue; //The line start with # is comment, skip
|
||||||
|
|
||||||
if (!isxdigit(buf[0])){
|
if (!isxdigit(buf[0])){
|
||||||
PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf);
|
PrintAndLog("[-] File content error. '%s' must include 12 HEX symbols",buf);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1266,7 +1278,7 @@ int CmdHF14AMfChk_fast(const char *Cmd) {
|
||||||
if ( keyitems - keycnt < 2) {
|
if ( keyitems - keycnt < 2) {
|
||||||
p = realloc(keyBlock, 6 * (keyitems += 64));
|
p = realloc(keyBlock, 6 * (keyitems += 64));
|
||||||
if (!p) {
|
if (!p) {
|
||||||
PrintAndLog("Cannot allocate memory for default keys");
|
PrintAndLog("[-] Cannot allocate memory for default keys");
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -1281,11 +1293,6 @@ int CmdHF14AMfChk_fast(const char *Cmd) {
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
PrintAndLog("[+] Loaded %2d keys from %s", keycnt, filename);
|
PrintAndLog("[+] Loaded %2d keys from %s", keycnt, filename);
|
||||||
} else {
|
|
||||||
PrintAndLog("File: %s: not found or locked.", filename);
|
|
||||||
free(keyBlock);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1393,8 +1400,7 @@ out:
|
||||||
|
|
||||||
int CmdHF14AMfChk(const char *Cmd) {
|
int CmdHF14AMfChk(const char *Cmd) {
|
||||||
|
|
||||||
char ctmp = 0x00;
|
char ctmp = param_getchar(Cmd, 0);
|
||||||
ctmp = param_getchar(Cmd, 0);
|
|
||||||
if (strlen(Cmd) < 3 || ctmp == 'h' || ctmp == 'H') return usage_hf14_chk();
|
if (strlen(Cmd) < 3 || ctmp == 'h' || ctmp == 'H') return usage_hf14_chk();
|
||||||
|
|
||||||
FILE * f;
|
FILE * f;
|
||||||
|
@ -1409,6 +1415,7 @@ int CmdHF14AMfChk(const char *Cmd) {
|
||||||
uint32_t keyitems = MIFARE_DEFAULTKEYS_SIZE;
|
uint32_t keyitems = MIFARE_DEFAULTKEYS_SIZE;
|
||||||
uint64_t key64 = 0;
|
uint64_t key64 = 0;
|
||||||
uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
|
int clen = 0;
|
||||||
int transferToEml = 0;
|
int transferToEml = 0;
|
||||||
int createDumpFile = 0;
|
int createDumpFile = 0;
|
||||||
int i, res, keycnt = 0;
|
int i, res, keycnt = 0;
|
||||||
|
@ -1427,12 +1434,14 @@ int CmdHF14AMfChk(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctmp = param_getchar(Cmd, 1);
|
ctmp = param_getchar(Cmd, 1);
|
||||||
|
clen = param_getlength(Cmd, 1);
|
||||||
|
if (clen == 1) {
|
||||||
switch (ctmp) {
|
switch (ctmp) {
|
||||||
case 'a': case 'A':
|
case 'a': case 'A':
|
||||||
keyType = !0;
|
keyType = 0;
|
||||||
break;
|
break;
|
||||||
case 'b': case 'B':
|
case 'b': case 'B':
|
||||||
keyType = !1;
|
keyType = 1;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
keyType = 2;
|
keyType = 2;
|
||||||
|
@ -1442,35 +1451,48 @@ int CmdHF14AMfChk(const char *Cmd) {
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
ctmp = param_getchar(Cmd, 2);
|
for (i = 2; param_getchar(Cmd, i); i++) {
|
||||||
if (ctmp == 't' || ctmp == 'T') transferToEml = 1;
|
|
||||||
else if (ctmp == 'd' || ctmp == 'D') createDumpFile = 1;
|
ctmp = param_getchar(Cmd, i);
|
||||||
|
clen = param_getlength(Cmd, i);
|
||||||
|
|
||||||
|
if (clen == 12) {
|
||||||
|
|
||||||
|
if ( param_gethex(Cmd, i, keyBlock + 6 * keycnt, 12) ){
|
||||||
|
PrintAndLog("[-] not hex, skipping");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = transferToEml || createDumpFile; param_getchar(Cmd, 2 + i); i++) {
|
|
||||||
if (!param_gethex(Cmd, 2 + i, keyBlock + 6 * keycnt, 12)) {
|
|
||||||
if ( keyitems - keycnt < 2) {
|
if ( keyitems - keycnt < 2) {
|
||||||
p = realloc(keyBlock, 6 * (keyitems += 64));
|
p = realloc(keyBlock, 6 * (keyitems += 64));
|
||||||
if (!p) {
|
if (!p) {
|
||||||
PrintAndLog("Cannot allocate memory for Keys");
|
PrintAndLog("[-] cannot allocate memory for Keys");
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
keyBlock = p;
|
keyBlock = p;
|
||||||
}
|
}
|
||||||
PrintAndLog("key[%2d] %02x%02x%02x%02x%02x%02x", keycnt,
|
PrintAndLog("[%2d] key %s", keycnt, sprint_hex( (keyBlock + 6*keycnt), 6 ) );;
|
||||||
(keyBlock + 6*keycnt)[0],(keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2],
|
|
||||||
(keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4], (keyBlock + 6*keycnt)[5], 6);
|
|
||||||
keycnt++;
|
keycnt++;
|
||||||
|
} else if ( clen == 1 ) {
|
||||||
|
if (ctmp == 't' || ctmp == 'T') { transferToEml = 1; continue; }
|
||||||
|
if (ctmp == 'd' || ctmp == 'D') { createDumpFile = 1; continue; }
|
||||||
} else {
|
} else {
|
||||||
// May be a dic file
|
// May be a dic file
|
||||||
if ( param_getstr(Cmd, 2 + i, filename, sizeof(filename)) >= FILE_PATH_SIZE ) {
|
if ( param_getstr(Cmd, i, filename, sizeof(filename)) >= FILE_PATH_SIZE ) {
|
||||||
PrintAndLog("File name too long");
|
PrintAndLog("[-] File name too long");
|
||||||
free(keyBlock);
|
continue;
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (f = fopen( filename , "r")) ) {
|
f = fopen( filename , "r");
|
||||||
|
if ( !f ) {
|
||||||
|
PrintAndLog("[-] File: %s: not found or locked.", filename);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// load keys from dictionary file
|
||||||
while( fgets(buf, sizeof(buf), f) ){
|
while( fgets(buf, sizeof(buf), f) ){
|
||||||
if (strlen(buf) < 12 || buf[11] == '\n')
|
if (strlen(buf) < 12 || buf[11] == '\n')
|
||||||
continue;
|
continue;
|
||||||
|
@ -1479,8 +1501,9 @@ int CmdHF14AMfChk(const char *Cmd) {
|
||||||
|
|
||||||
if( buf[0]=='#' ) continue; //The line start with # is comment, skip
|
if( buf[0]=='#' ) continue; //The line start with # is comment, skip
|
||||||
|
|
||||||
|
// codesmell, only checks first char?
|
||||||
if (!isxdigit(buf[0])){
|
if (!isxdigit(buf[0])){
|
||||||
PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf);
|
PrintAndLog("[-] File content error. '%s' must include 12 HEX symbols",buf);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1489,7 +1512,7 @@ int CmdHF14AMfChk(const char *Cmd) {
|
||||||
if ( keyitems - keycnt < 2) {
|
if ( keyitems - keycnt < 2) {
|
||||||
p = realloc(keyBlock, 6 * (keyitems += 64));
|
p = realloc(keyBlock, 6 * (keyitems += 64));
|
||||||
if (!p) {
|
if (!p) {
|
||||||
PrintAndLog("Cannot allocate memory for defKeys");
|
PrintAndLog("[-] Cannot allocate memory for defKeys");
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -1503,13 +1526,7 @@ int CmdHF14AMfChk(const char *Cmd) {
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
PrintAndLog("Loaded %2d keys from %s", keycnt, filename);
|
PrintAndLog("[+] Loaded %2d keys from %s", keycnt, filename);
|
||||||
} else {
|
|
||||||
PrintAndLog("File: %s: not found or locked.", filename);
|
|
||||||
free(keyBlock);
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue