mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-07-31 03:50:45 -07:00
hf iclass chk/lookup: load dic with searchFile and fail when errors in args
This commit is contained in:
parent
4ddc3d61d5
commit
2a1e6dff80
2 changed files with 66 additions and 56 deletions
|
@ -244,8 +244,8 @@ static int usage_hf_iclass_chk(void) {
|
||||||
PrintAndLogEx(NORMAL, " e elite");
|
PrintAndLogEx(NORMAL, " e elite");
|
||||||
PrintAndLogEx(NORMAL, " c credit key (if not use, default is debit)");
|
PrintAndLogEx(NORMAL, " c credit key (if not use, default is debit)");
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
PrintAndLogEx(NORMAL, "Examples:");
|
||||||
PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic");
|
PrintAndLogEx(NORMAL, " hf iclass chk f iclass_default_keys");
|
||||||
PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic e");
|
PrintAndLogEx(NORMAL, " hf iclass chk f iclass_default_keys e");
|
||||||
return PM3_SUCCESS;;
|
return PM3_SUCCESS;;
|
||||||
}
|
}
|
||||||
static int usage_hf_iclass_lookup(void) {
|
static int usage_hf_iclass_lookup(void) {
|
||||||
|
@ -260,8 +260,8 @@ static int usage_hf_iclass_lookup(void) {
|
||||||
PrintAndLogEx(NORMAL, " r raw");
|
PrintAndLogEx(NORMAL, " r raw");
|
||||||
PrintAndLogEx(NORMAL, " e elite");
|
PrintAndLogEx(NORMAL, " e elite");
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
PrintAndLogEx(NORMAL, "Examples:");
|
||||||
PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic");
|
PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f iclass_default_keys");
|
||||||
PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic e");
|
PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f iclass_default_keys e");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
static int usage_hf_iclass_permutekey(void) {
|
static int usage_hf_iclass_permutekey(void) {
|
||||||
|
@ -2059,9 +2059,9 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
|
||||||
|
|
||||||
// load keys into keyblock
|
// load keys into keyblock
|
||||||
int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt);
|
int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt);
|
||||||
if (res > 0) {
|
if (res != PM3_SUCCESS) {
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
return PM3_EFILE;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre = calloc(keycnt, sizeof(iclass_premac_t));
|
pre = calloc(keycnt, sizeof(iclass_premac_t));
|
||||||
|
@ -2312,33 +2312,33 @@ static int CmdHFiClassLookUp(const char *Cmd) {
|
||||||
PrintAndLogEx(SUCCESS, "MAC_TAG | %s", sprint_hex(MAC_TAG, sizeof(MAC_TAG)));
|
PrintAndLogEx(SUCCESS, "MAC_TAG | %s", sprint_hex(MAC_TAG, sizeof(MAC_TAG)));
|
||||||
|
|
||||||
int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt);
|
int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt);
|
||||||
if (res > 0) {
|
if (res != PM3_SUCCESS) {
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
return 1;
|
return res;
|
||||||
}
|
}
|
||||||
//iclass_prekey_t
|
//iclass_prekey_t
|
||||||
prekey = calloc(keycnt, sizeof(iclass_prekey_t));
|
prekey = calloc(keycnt, sizeof(iclass_prekey_t));
|
||||||
if (!prekey) {
|
if (!prekey) {
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
return 1;
|
return PM3_EMALLOC;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(FAILED, "Generating diversified keys and MAC");
|
PrintAndLogEx(INFO, "Generating diversified keys and MAC");
|
||||||
res = GenerateFromKeyFile(CSN, CCNR, use_raw, use_elite, keyBlock, keycnt, prekey);
|
res = GenerateFromKeyFile(CSN, CCNR, use_raw, use_elite, keyBlock, keycnt, prekey);
|
||||||
if (res > 0) {
|
if (res != PM3_SUCCESS) {
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
free(prekey);
|
free(prekey);
|
||||||
return 1;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(FAILED, "Sorting");
|
PrintAndLogEx(INFO, "Sorting");
|
||||||
|
|
||||||
// sort mac list.
|
// sort mac list.
|
||||||
qsort(prekey, keycnt, sizeof(iclass_prekey_t), cmp_uint32);
|
qsort(prekey, keycnt, sizeof(iclass_prekey_t), cmp_uint32);
|
||||||
|
|
||||||
//PrintPreCalc(prekey, keycnt);
|
//PrintPreCalc(prekey, keycnt);
|
||||||
|
|
||||||
PrintAndLogEx(FAILED, "Searching");
|
PrintAndLogEx(INFO, "Searching");
|
||||||
iclass_prekey_t *item;
|
iclass_prekey_t *item;
|
||||||
iclass_prekey_t lookup;
|
iclass_prekey_t lookup;
|
||||||
memcpy(lookup.mac, MAC_TAG, 4);
|
memcpy(lookup.mac, MAC_TAG, 4);
|
||||||
|
@ -2377,10 +2377,19 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) {
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
int keyitems = 0;
|
int keyitems = 0;
|
||||||
|
|
||||||
if (!(f = fopen(filename, "r"))) {
|
|
||||||
PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename);
|
char *dict_path;
|
||||||
return 1;
|
int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic");
|
||||||
|
if (res != PM3_SUCCESS) {
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
f = fopen(dict_path, "r");
|
||||||
|
if (!f) {
|
||||||
|
PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", dict_path);
|
||||||
|
free(dict_path);
|
||||||
|
return PM3_EFILE;
|
||||||
|
}
|
||||||
|
free(dict_path);
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), f)) {
|
while (fgets(buf, sizeof(buf), f)) {
|
||||||
if (strlen(buf) < 16 || buf[15] == '\n')
|
if (strlen(buf) < 16 || buf[15] == '\n')
|
||||||
|
@ -2396,7 +2405,8 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) {
|
||||||
// doesn't this only test first char only?
|
// doesn't this only test first char only?
|
||||||
if (!isxdigit(buf[0])) {
|
if (!isxdigit(buf[0])) {
|
||||||
PrintAndLogEx(ERR, "file content error. '%s' must include 16 HEX symbols", buf);
|
PrintAndLogEx(ERR, "file content error. '%s' must include 16 HEX symbols", buf);
|
||||||
continue;
|
fclose(f);
|
||||||
|
return PM3_EFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// null terminator (skip the rest of the line)
|
// null terminator (skip the rest of the line)
|
||||||
|
@ -2406,7 +2416,7 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) {
|
||||||
if (!p) {
|
if (!p) {
|
||||||
PrintAndLogEx(ERR, "cannot allocate memory for default keys");
|
PrintAndLogEx(ERR, "cannot allocate memory for default keys");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 2;
|
return PM3_EMALLOC;
|
||||||
}
|
}
|
||||||
*keys = p;
|
*keys = p;
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ p : EPURSE
|
||||||
m : macs
|
m : macs
|
||||||
e : elite
|
e : elite
|
||||||
|
|
||||||
pm3 --> hf iclass lookup u 010a0ffff7ff12e0 p feffffffffffffff m 66348979153c41b9 f dictionaries/iclass_default_keys.dic e
|
pm3 --> hf iclass lookup u 010a0ffff7ff12e0 p feffffffffffffff m 66348979153c41b9 f iclass_default_keys e
|
||||||
```
|
```
|
||||||
|
|
||||||
## Mifare
|
## Mifare
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue