mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
make style
This commit is contained in:
parent
99159b3cda
commit
2022df1068
12 changed files with 199 additions and 198 deletions
|
@ -1134,7 +1134,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_HF_MIFARE_EML_LOAD: {
|
case CMD_HF_MIFARE_EML_LOAD: {
|
||||||
mfc_eload_t *payload = (mfc_eload_t *) packet->data.asBytes;
|
mfc_eload_t *payload = (mfc_eload_t *) packet->data.asBytes;
|
||||||
MifareECardLoadExt(payload->sectorcnt, payload->keytype);
|
MifareECardLoadExt(payload->sectorcnt, payload->keytype);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ static int g_wait = 300;
|
||||||
static int timeout = 2900;
|
static int timeout = 2900;
|
||||||
static uint32_t time_rdr = 0;
|
static uint32_t time_rdr = 0;
|
||||||
static uint32_t time_delta = 0;
|
static uint32_t time_delta = 0;
|
||||||
static uint32_t time_delta_wait = 0;
|
static uint32_t time_delta_wait = 0;
|
||||||
static uint32_t time_response = 0;
|
static uint32_t time_response = 0;
|
||||||
|
|
||||||
static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay);
|
static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay);
|
||||||
|
@ -1875,15 +1875,15 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples,
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep tx buffer in a defined state anyway.
|
// keep tx buffer in a defined state anyway.
|
||||||
/*
|
/*
|
||||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||||
AT91C_BASE_SSC->SSC_THR = 0x00;
|
AT91C_BASE_SSC->SSC_THR = 0x00;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// Wait for byte be become available in rx holding register
|
// Wait for byte be become available in rx holding register
|
||||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||||
|
|
||||||
if ( GetCountSspClk() - foo > timeout) return false;
|
if (GetCountSspClk() - foo > timeout) return false;
|
||||||
// if (c >= timeout) return false;
|
// if (c >= timeout) return false;
|
||||||
|
|
||||||
c++;
|
c++;
|
||||||
|
@ -1896,7 +1896,7 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples,
|
||||||
if (ManchesterDecoding_iclass(b & 0x0f)) {
|
if (ManchesterDecoding_iclass(b & 0x0f)) {
|
||||||
if (samples)
|
if (samples)
|
||||||
*samples = c << 3;
|
*samples = c << 3;
|
||||||
|
|
||||||
time_response = GetCountSspClk() - foo;
|
time_response = GetCountSspClk() - foo;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1959,7 +1959,7 @@ bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *re
|
||||||
// since its called with fixed sized arrays
|
// since its called with fixed sized arrays
|
||||||
|
|
||||||
// update/write commadn takes 4ms to 15ms before responding
|
// update/write commadn takes 4ms to 15ms before responding
|
||||||
if ( command[0] == ICLASS_CMD_UPDATE )
|
if (command[0] == ICLASS_CMD_UPDATE)
|
||||||
g_wait = 15000;
|
g_wait = 15000;
|
||||||
|
|
||||||
uint8_t got_n = ReaderReceiveIClass(resp);
|
uint8_t got_n = ReaderReceiveIClass(resp);
|
||||||
|
|
|
@ -1523,33 +1523,33 @@ OUT:
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
|
|
||||||
// special trick ecfill
|
|
||||||
if (use_flashmem && foundkeys == allkeys) {
|
|
||||||
|
|
||||||
uint8_t block[16] = {0};
|
|
||||||
for (int i = 0; i < sectorcnt; i++) {
|
|
||||||
|
|
||||||
uint8_t blockno;
|
|
||||||
if (i < 32) {
|
|
||||||
blockno = (i * 4) ^ 0x3;
|
|
||||||
} else {
|
|
||||||
blockno = (32 * 4 + (i - 32) * 16) ^ 0xF;
|
|
||||||
}
|
|
||||||
// get ST
|
|
||||||
emlGetMem(block, blockno, 1);
|
|
||||||
|
|
||||||
memcpy(block, k_sector[i].keyA, 6);
|
// special trick ecfill
|
||||||
memcpy(block + 10, k_sector[i].keyB, 6);
|
if (use_flashmem && foundkeys == allkeys) {
|
||||||
|
|
||||||
emlSetMem_xt(block, blockno, 1, sizeof(block));
|
uint8_t block[16] = {0};
|
||||||
}
|
for (int i = 0; i < sectorcnt; i++) {
|
||||||
int oldbg = DBGLEVEL;
|
|
||||||
DBGLEVEL = DBG_NONE;
|
uint8_t blockno;
|
||||||
MifareECardLoad(sectorcnt, 0);
|
if (i < 32) {
|
||||||
MifareECardLoad(sectorcnt, 1);
|
blockno = (i * 4) ^ 0x3;
|
||||||
DBGLEVEL = oldbg;
|
} else {
|
||||||
}
|
blockno = (32 * 4 + (i - 32) * 16) ^ 0xF;
|
||||||
|
}
|
||||||
|
// get ST
|
||||||
|
emlGetMem(block, blockno, 1);
|
||||||
|
|
||||||
|
memcpy(block, k_sector[i].keyA, 6);
|
||||||
|
memcpy(block + 10, k_sector[i].keyB, 6);
|
||||||
|
|
||||||
|
emlSetMem_xt(block, blockno, 1, sizeof(block));
|
||||||
|
}
|
||||||
|
int oldbg = DBGLEVEL;
|
||||||
|
DBGLEVEL = DBG_NONE;
|
||||||
|
MifareECardLoad(sectorcnt, 0);
|
||||||
|
MifareECardLoad(sectorcnt, 1);
|
||||||
|
DBGLEVEL = oldbg;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// partial/none keys found
|
// partial/none keys found
|
||||||
reply_mix(CMD_ACK, foundkeys, 0, 0, 0, 0);
|
reply_mix(CMD_ACK, foundkeys, 0, 0, 0, 0);
|
||||||
|
@ -1695,9 +1695,9 @@ void MifareEMemGet(uint8_t blockno, uint8_t blockcnt) {
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
int MifareECardLoadExt(uint8_t numSectors, uint8_t keyType) {
|
int MifareECardLoadExt(uint8_t numSectors, uint8_t keyType) {
|
||||||
int retval = MifareECardLoad(numSectors, keyType);
|
int retval = MifareECardLoad(numSectors, keyType);
|
||||||
reply_ng(CMD_HF_MIFARE_EML_LOAD, retval, NULL, 0);
|
reply_ng(CMD_HF_MIFARE_EML_LOAD, retval, NULL, 0);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MifareECardLoad(uint8_t numSectors, uint8_t keyType) {
|
int MifareECardLoad(uint8_t numSectors, uint8_t keyType) {
|
||||||
|
@ -1723,7 +1723,7 @@ int MifareECardLoad(uint8_t numSectors, uint8_t keyType) {
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
retval = PM3_ESOFT;
|
retval = PM3_ESOFT;
|
||||||
if (DBGLEVEL > DBG_ERROR) Dbprintf("Can't select card");
|
if (DBGLEVEL > DBG_ERROR) Dbprintf("Can't select card");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t sectorNo = 0; sectorNo < numSectors; sectorNo++) {
|
for (uint8_t sectorNo = 0; sectorNo < numSectors; sectorNo++) {
|
||||||
|
@ -1747,22 +1747,22 @@ int MifareECardLoad(uint8_t numSectors, uint8_t keyType) {
|
||||||
if (DBGLEVEL > DBG_ERROR) Dbprintf("Error reading sector %2d block %2d", sectorNo, blockNo);
|
if (DBGLEVEL > DBG_ERROR) Dbprintf("Error reading sector %2d block %2d", sectorNo, blockNo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (blockNo < NumBlocksPerSector(sectorNo) - 1) {
|
if (blockNo < NumBlocksPerSector(sectorNo) - 1) {
|
||||||
emlSetMem(dataoutbuf, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
emlSetMem(dataoutbuf, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
||||||
} else { // sector trailer, keep the keys, set only the AC
|
} else { // sector trailer, keep the keys, set only the AC
|
||||||
emlGetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
emlGetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
||||||
memcpy(&dataoutbuf2[6], &dataoutbuf[6], 4);
|
memcpy(&dataoutbuf2[6], &dataoutbuf[6], 4);
|
||||||
emlSetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
emlSetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mifare_classic_halt(pcs, cuid)) {
|
if (mifare_classic_halt(pcs, cuid)) {
|
||||||
if (DBGLEVEL > DBG_ERROR)
|
if (DBGLEVEL > DBG_ERROR)
|
||||||
Dbprintf("Halt error");
|
Dbprintf("Halt error");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_INFO) DbpString("Emulator fill sectors finished");
|
if (DBGLEVEL >= DBG_INFO) DbpString("Emulator fill sectors finished");
|
||||||
|
|
||||||
out:
|
out:
|
||||||
crypto1_destroy(pcs);
|
crypto1_destroy(pcs);
|
||||||
|
|
|
@ -696,7 +696,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
||||||
return usage_hf_iclass_eload();
|
return usage_hf_iclass_eload();
|
||||||
case 'f':
|
case 'f':
|
||||||
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
||||||
PrintAndLogEx(FAILED, "Filename too long");
|
PrintAndLogEx(FAILED, "Filename too long");
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -704,12 +704,12 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
dftype = JSON;
|
dftype = JSON;
|
||||||
cmdp++;
|
cmdp++;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
dftype = EML;
|
dftype = EML;
|
||||||
cmdp++;
|
cmdp++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||||
errors = true;
|
errors = true;
|
||||||
|
@ -733,9 +733,9 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
||||||
size_t bytes_read = 2048;
|
size_t bytes_read = 2048;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
switch ( dftype ) {
|
switch (dftype) {
|
||||||
case BIN: {
|
case BIN: {
|
||||||
res = loadFile(filename, ".bin", (void*)&dump, 2048, &bytes_read);
|
res = loadFile(filename, ".bin", (void *)&dump, 2048, &bytes_read);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EML: {
|
case EML: {
|
||||||
|
@ -747,11 +747,11 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
PrintAndLogEx(ERR, "No dictionary loaded");
|
PrintAndLogEx(ERR, "No dictionary loaded");
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( res != PM3_SUCCESS ) {
|
if (res != PM3_SUCCESS) {
|
||||||
free(dump);
|
free(dump);
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
}
|
}
|
||||||
|
@ -793,15 +793,15 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
||||||
#define ICLASS_DECRYPTION_BIN "iclass_decryptionkey.bin"
|
#define ICLASS_DECRYPTION_BIN "iclass_decryptionkey.bin"
|
||||||
|
|
||||||
static int CmdHFiClassDecrypt(const char *Cmd) {
|
static int CmdHFiClassDecrypt(const char *Cmd) {
|
||||||
|
|
||||||
bool errors = false;
|
bool errors = false;
|
||||||
bool have_key = false;
|
bool have_key = false;
|
||||||
uint8_t cmdp = 0;
|
uint8_t cmdp = 0;
|
||||||
|
|
||||||
size_t keylen = 0;
|
size_t keylen = 0;
|
||||||
uint8_t key[32] = {0};
|
uint8_t key[32] = {0};
|
||||||
uint8_t *keyptr = NULL;
|
uint8_t *keyptr = NULL;
|
||||||
|
|
||||||
size_t decryptedlen = 0;
|
size_t decryptedlen = 0;
|
||||||
uint8_t *decrypted = NULL;
|
uint8_t *decrypted = NULL;
|
||||||
char filename[FILE_PATH_SIZE];
|
char filename[FILE_PATH_SIZE];
|
||||||
|
@ -811,13 +811,13 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
||||||
case 'h':
|
case 'h':
|
||||||
return usage_hf_iclass_decrypt();
|
return usage_hf_iclass_decrypt();
|
||||||
case 'f':
|
case 'f':
|
||||||
if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename) ) == 0) {
|
if (param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)) == 0) {
|
||||||
PrintAndLogEx(WARNING, "no filename found after f");
|
PrintAndLogEx(WARNING, "no filename found after f");
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( loadFile_safe(filename, "", (void**)&decrypted, &decryptedlen) != PM3_SUCCESS ) {
|
if (loadFile_safe(filename, "", (void **)&decrypted, &decryptedlen) != PM3_SUCCESS) {
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -840,11 +840,11 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
||||||
|
|
||||||
if (errors || cmdp < 1) return usage_hf_iclass_decrypt();
|
if (errors || cmdp < 1) return usage_hf_iclass_decrypt();
|
||||||
|
|
||||||
if ( have_key == false ) {
|
if (have_key == false) {
|
||||||
int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void**)&keyptr, &keylen);
|
int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen);
|
||||||
if (res != PM3_SUCCESS)
|
if (res != PM3_SUCCESS)
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
|
|
||||||
memcpy(key, keyptr, sizeof(key));
|
memcpy(key, keyptr, sizeof(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,7 +857,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
||||||
uint8_t app_areas = 2;
|
uint8_t app_areas = 2;
|
||||||
uint8_t max_blk = 31;
|
uint8_t max_blk = 31;
|
||||||
getMemConfig(mem, chip, &max_blk, &app_areas, &kb);
|
getMemConfig(mem, chip, &max_blk, &app_areas, &kb);
|
||||||
|
|
||||||
// tripledes
|
// tripledes
|
||||||
mbedtls_des3_context ctx;
|
mbedtls_des3_context ctx;
|
||||||
mbedtls_des3_set2key_dec(&ctx, key);
|
mbedtls_des3_set2key_dec(&ctx, key);
|
||||||
|
@ -876,10 +876,10 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Use the first block (CSN) for filename
|
//Use the first block (CSN) for filename
|
||||||
char *fptr = calloc(42, sizeof(uint8_t));
|
char *fptr = calloc(42, sizeof(uint8_t));
|
||||||
strcat(fptr, "hf-iclass-");
|
strcat(fptr, "hf-iclass-");
|
||||||
FillFileNameByUID(fptr, hdr->csn, "-data-decrypted", sizeof(hdr->csn) );
|
FillFileNameByUID(fptr, hdr->csn, "-data-decrypted", sizeof(hdr->csn));
|
||||||
|
|
||||||
saveFile(fptr, ".bin", decrypted, decryptedlen);
|
saveFile(fptr, ".bin", decrypted, decryptedlen);
|
||||||
saveFileEML(fptr, decrypted, decryptedlen, 8);
|
saveFileEML(fptr, decrypted, decryptedlen, 8);
|
||||||
saveFileJSON(fptr, jsfIclass, decrypted, decryptedlen);
|
saveFileJSON(fptr, jsfIclass, decrypted, decryptedlen);
|
||||||
|
@ -935,12 +935,12 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) {
|
||||||
|
|
||||||
if (errors || cmdp < 1) return usage_hf_iclass_encrypt();
|
if (errors || cmdp < 1) return usage_hf_iclass_encrypt();
|
||||||
|
|
||||||
if ( have_key == false ) {
|
if (have_key == false) {
|
||||||
size_t keylen = 0;
|
size_t keylen = 0;
|
||||||
int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void**)&keyptr, &keylen);
|
int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen);
|
||||||
if (res != PM3_SUCCESS)
|
if (res != PM3_SUCCESS)
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
|
|
||||||
memcpy(key, keyptr, sizeof(key));
|
memcpy(key, keyptr, sizeof(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1265,7 +1265,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
|
||||||
|
|
||||||
//Use the first block (CSN) for filename
|
//Use the first block (CSN) for filename
|
||||||
strcat(filename, "hf-iclass-");
|
strcat(filename, "hf-iclass-");
|
||||||
FillFileNameByUID(filename, tag_data, "-data", 8 );
|
FillFileNameByUID(filename, tag_data, "-data", 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the dump to .bin file
|
// save the dump to .bin file
|
||||||
|
@ -1565,7 +1565,7 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite,
|
||||||
}
|
}
|
||||||
//data read is stored in: resp.data.asBytes[0-15]
|
//data read is stored in: resp.data.asBytes[0-15]
|
||||||
PrintAndLogEx(NORMAL, "block %02X: %s\n", blockno, sprint_hex(resp.data.asBytes, 8));
|
PrintAndLogEx(NORMAL, "block %02X: %s\n", blockno, sprint_hex(resp.data.asBytes, 8));
|
||||||
// should decrypt it if file is accessable.
|
// should decrypt it if file is accessable.
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1936,9 +1936,9 @@ static int saveKeys(char *filename) {
|
||||||
static int printKeys(void) {
|
static int printKeys(void) {
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++) {
|
for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++) {
|
||||||
if ( memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0)
|
if (memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0)
|
||||||
PrintAndLogEx(NORMAL, "%u: %s", i, sprint_hex(iClass_Key_Table[i], 8));
|
PrintAndLogEx(NORMAL, "%u: %s", i, sprint_hex(iClass_Key_Table[i], 8));
|
||||||
else
|
else
|
||||||
PrintAndLogEx(NORMAL, "%u: "_YELLOW_("%s"), i, sprint_hex(iClass_Key_Table[i], 8));
|
PrintAndLogEx(NORMAL, "%u: "_YELLOW_("%s"), i, sprint_hex(iClass_Key_Table[i], 8));
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
@ -2096,7 +2096,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
|
||||||
uint16_t keycount = 0;
|
uint16_t keycount = 0;
|
||||||
|
|
||||||
// load keys
|
// load keys
|
||||||
int res = loadFileDICTIONARY_safe(filename, (void**)&keyBlock, 8, &keycount);
|
int res = loadFileDICTIONARY_safe(filename, (void **)&keyBlock, 8, &keycount);
|
||||||
if (res != PM3_SUCCESS || keycount == 0) {
|
if (res != PM3_SUCCESS || keycount == 0) {
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
return res;
|
return res;
|
||||||
|
@ -2106,11 +2106,11 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
|
||||||
PrintAndLogEx(SUCCESS, "Reading tag CSN");
|
PrintAndLogEx(SUCCESS, "Reading tag CSN");
|
||||||
for (uint8_t i = 0; i < 10 && !got_csn; i++) {
|
for (uint8_t i = 0; i < 10 && !got_csn; i++) {
|
||||||
got_csn = select_only(CSN, CCNR, false, false);
|
got_csn = select_only(CSN, CCNR, false, false);
|
||||||
if ( got_csn == false )
|
if (got_csn == false)
|
||||||
PrintAndLogEx(WARNING, "one more try\n");
|
PrintAndLogEx(WARNING, "one more try\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( got_csn == false ) {
|
if (got_csn == false) {
|
||||||
PrintAndLogEx(WARNING, "Tried 10 times. Can't select card, aborting...");
|
PrintAndLogEx(WARNING, "Tried 10 times. Can't select card, aborting...");
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
@ -2232,13 +2232,13 @@ out:
|
||||||
PrintAndLogEx(SUCCESS, "\nTime in iclass checkkeys: %.0f seconds\n", (float)t1 / 1000.0);
|
PrintAndLogEx(SUCCESS, "\nTime in iclass checkkeys: %.0f seconds\n", (float)t1 / 1000.0);
|
||||||
DropField();
|
DropField();
|
||||||
|
|
||||||
// add to managekeys
|
// add to managekeys
|
||||||
if ( found_debit ) {
|
if (found_debit) {
|
||||||
for (uint8_t i=0; i< ICLASS_KEYS_MAX; i++) {
|
for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++) {
|
||||||
// simple check for preexistences
|
// simple check for preexistences
|
||||||
if ( memcmp(iClass_Key_Table[i], keyBlock + (key_offset + found_offset) * 8, 8) == 0 ) break;
|
if (memcmp(iClass_Key_Table[i], keyBlock + (key_offset + found_offset) * 8, 8) == 0) break;
|
||||||
|
|
||||||
if ( memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0 ) {
|
if (memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0) {
|
||||||
memcpy(iClass_Key_Table[i], keyBlock + (key_offset + found_offset) * 8, 8);
|
memcpy(iClass_Key_Table[i], keyBlock + (key_offset + found_offset) * 8, 8);
|
||||||
PrintAndLogEx(SUCCESS, "Added key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")" to view", i);
|
PrintAndLogEx(SUCCESS, "Added key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")" to view", i);
|
||||||
break;
|
break;
|
||||||
|
@ -2295,7 +2295,7 @@ static int CmdHFiClassLookUp(const char *Cmd) {
|
||||||
case 'h':
|
case 'h':
|
||||||
return usage_hf_iclass_lookup();
|
return usage_hf_iclass_lookup();
|
||||||
case 'f':
|
case 'f':
|
||||||
if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)) < 1 ) {
|
if (param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)) < 1) {
|
||||||
PrintAndLogEx(WARNING, "No filename found after f");
|
PrintAndLogEx(WARNING, "No filename found after f");
|
||||||
errors = true;
|
errors = true;
|
||||||
}
|
}
|
||||||
|
@ -2358,12 +2358,12 @@ static int CmdHFiClassLookUp(const char *Cmd) {
|
||||||
uint16_t keycount = 0;
|
uint16_t keycount = 0;
|
||||||
|
|
||||||
// load keys
|
// load keys
|
||||||
int res = loadFileDICTIONARY_safe(filename, (void**)&keyBlock, 8, &keycount);
|
int res = loadFileDICTIONARY_safe(filename, (void **)&keyBlock, 8, &keycount);
|
||||||
if (res != PM3_SUCCESS || keycount == 0) {
|
if (res != PM3_SUCCESS || keycount == 0) {
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
//iclass_prekey_t
|
//iclass_prekey_t
|
||||||
prekey = calloc(keycount, sizeof(iclass_prekey_t));
|
prekey = calloc(keycount, sizeof(iclass_prekey_t));
|
||||||
if (!prekey) {
|
if (!prekey) {
|
||||||
|
@ -2395,18 +2395,18 @@ static int CmdHFiClassLookUp(const char *Cmd) {
|
||||||
// foudn
|
// foudn
|
||||||
if (item != NULL) {
|
if (item != NULL) {
|
||||||
PrintAndLogEx(SUCCESS, "[debit] found key " _YELLOW_("%s"), sprint_hex(item->key, 8));
|
PrintAndLogEx(SUCCESS, "[debit] found key " _YELLOW_("%s"), sprint_hex(item->key, 8));
|
||||||
for (uint8_t i=0; i< ICLASS_KEYS_MAX; i++) {
|
for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++) {
|
||||||
// simple check for preexistences
|
// simple check for preexistences
|
||||||
if ( memcmp(item->key, iClass_Key_Table[i], 8) == 0 ) break;
|
if (memcmp(item->key, iClass_Key_Table[i], 8) == 0) break;
|
||||||
|
|
||||||
if ( memcmp(iClass_Key_Table[i] , "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0 ) {
|
if (memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0) {
|
||||||
memcpy(iClass_Key_Table[i], item->key, 8);
|
memcpy(iClass_Key_Table[i], item->key, 8);
|
||||||
PrintAndLogEx(SUCCESS, "Added key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")"to view", i);
|
PrintAndLogEx(SUCCESS, "Added key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")"to view", i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(prekey);
|
free(prekey);
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
|
148
client/cmdhfmf.c
148
client/cmdhfmf.c
|
@ -774,31 +774,31 @@ static char GetFormatFromSector(uint8_t sectorNo) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int FastDumpWithEcFill(uint8_t numsectors){
|
static int FastDumpWithEcFill(uint8_t numsectors) {
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
|
|
||||||
mfc_eload_t payload;
|
|
||||||
payload.sectorcnt = numsectors;
|
|
||||||
payload.keytype = 0;
|
|
||||||
|
|
||||||
// ecfill key A
|
mfc_eload_t payload;
|
||||||
clearCommandBuffer();
|
payload.sectorcnt = numsectors;
|
||||||
SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload));
|
payload.keytype = 0;
|
||||||
|
|
||||||
int res = WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 2000);
|
|
||||||
if ( res != PM3_SUCCESS) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// ecfill key B
|
|
||||||
payload.keytype = 1;
|
|
||||||
|
|
||||||
clearCommandBuffer();
|
|
||||||
SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload));
|
|
||||||
res = WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 2000);
|
|
||||||
if ( res != PM3_SUCCESS) {
|
|
||||||
|
|
||||||
}
|
// ecfill key A
|
||||||
return PM3_SUCCESS;
|
clearCommandBuffer();
|
||||||
|
SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload));
|
||||||
|
|
||||||
|
int res = WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 2000);
|
||||||
|
if (res != PM3_SUCCESS) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// ecfill key B
|
||||||
|
payload.keytype = 1;
|
||||||
|
|
||||||
|
clearCommandBuffer();
|
||||||
|
SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload));
|
||||||
|
res = WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 2000);
|
||||||
|
if (res != PM3_SUCCESS) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdHF14AMfDump(const char *Cmd) {
|
static int CmdHF14AMfDump(const char *Cmd) {
|
||||||
|
@ -1287,11 +1287,11 @@ static int CmdHF14AMfNested(const char *Cmd) {
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "Testing known keys. Sector count=%d", SectorsCnt);
|
PrintAndLogEx(SUCCESS, "Testing known keys. Sector count=%d", SectorsCnt);
|
||||||
int res = mfCheckKeys_fast(SectorsCnt, true, true, 1, ARRAYLEN(g_mifare_default_keys) + 1, keyBlock, e_sector, false);
|
int res = mfCheckKeys_fast(SectorsCnt, true, true, 1, ARRAYLEN(g_mifare_default_keys) + 1, keyBlock, e_sector, false);
|
||||||
if ( res == PM3_SUCCESS ) {
|
if (res == PM3_SUCCESS) {
|
||||||
// all keys found
|
// all keys found
|
||||||
PrintAndLogEx(SUCCESS, "Fast check found all keys");
|
PrintAndLogEx(SUCCESS, "Fast check found all keys");
|
||||||
goto jumptoend;
|
goto jumptoend;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t t2 = msclock() - t1;
|
uint64_t t2 = msclock() - t1;
|
||||||
PrintAndLogEx(SUCCESS, "Time to check %d known keys: %.0f seconds\n", ARRAYLEN(g_mifare_default_keys), (float)t2 / 1000.0);
|
PrintAndLogEx(SUCCESS, "Time to check %d known keys: %.0f seconds\n", ARRAYLEN(g_mifare_default_keys), (float)t2 / 1000.0);
|
||||||
|
@ -1663,29 +1663,29 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||||
bool prng_type = false;
|
bool prng_type = false;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
bool has_filename = false;
|
bool has_filename = false;
|
||||||
bool errors = false;
|
bool errors = false;
|
||||||
|
|
||||||
// Parse the options given by the user
|
// Parse the options given by the user
|
||||||
while ( (ctmp = param_getchar(Cmd, cmdp)) && !errors ) {
|
while ((ctmp = param_getchar(Cmd, cmdp)) && !errors) {
|
||||||
switch (tolower(ctmp)) {
|
switch (tolower(ctmp)) {
|
||||||
case 'h':
|
case 'h':
|
||||||
return usage_hf14_autopwn();
|
return usage_hf14_autopwn();
|
||||||
case 'f':
|
case 'f':
|
||||||
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
||||||
PrintAndLogEx(FAILED, "Filename too long");
|
PrintAndLogEx(FAILED, "Filename too long");
|
||||||
errors = true;
|
errors = true;
|
||||||
} else {
|
} else {
|
||||||
has_filename = true;
|
has_filename = true;
|
||||||
}
|
}
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
legacy_mfchk = true;
|
legacy_mfchk = true;
|
||||||
cmdp++;
|
cmdp++;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = true;
|
verbose = true;
|
||||||
cmdp++;
|
cmdp++;
|
||||||
break;
|
break;
|
||||||
case '*':
|
case '*':
|
||||||
// Get the number of sectors
|
// Get the number of sectors
|
||||||
|
@ -1696,35 +1696,35 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||||
case 'k':
|
case 'k':
|
||||||
// Get the known block number
|
// Get the known block number
|
||||||
if (param_getchar(Cmd, cmdp + 1) == 0x00) {
|
if (param_getchar(Cmd, cmdp + 1) == 0x00) {
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockNo = param_get8(Cmd, cmdp + 1);
|
blockNo = param_get8(Cmd, cmdp + 1);
|
||||||
|
|
||||||
// Get the knonwn block type
|
// Get the knonwn block type
|
||||||
ctmp = tolower(param_getchar(Cmd, cmdp + 2));
|
ctmp = tolower(param_getchar(Cmd, cmdp + 2));
|
||||||
if (ctmp != 'a' && ctmp != 'b') {
|
if (ctmp != 'a' && ctmp != 'b') {
|
||||||
PrintAndLogEx(WARNING, "Key type must be A or B");
|
PrintAndLogEx(WARNING, "Key type must be A or B");
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctmp != 'a') {
|
if (ctmp != 'a') {
|
||||||
keyType = 1;
|
keyType = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the known block key
|
// Get the known block key
|
||||||
if (param_gethex(Cmd, cmdp + 3, key, 12)) {
|
if (param_gethex(Cmd, cmdp + 3, key, 12)) {
|
||||||
PrintAndLogEx(WARNING, "Key must include 12 HEX symbols");
|
PrintAndLogEx(WARNING, "Key must include 12 HEX symbols");
|
||||||
errors = true;
|
errors = true;
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
know_target_key = true;
|
know_target_key = true;
|
||||||
cmdp += 3;
|
cmdp += 3;
|
||||||
case 's':
|
case 's':
|
||||||
slow = true;
|
slow = true;
|
||||||
cmdp++;
|
cmdp++;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
SetSIMDInstr(SIMD_AUTO);
|
SetSIMDInstr(SIMD_AUTO);
|
||||||
|
@ -1759,9 +1759,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||||
return usage_hf14_autopwn();
|
return usage_hf14_autopwn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( errors ) {
|
if (errors) {
|
||||||
return usage_hf14_autopwn();
|
return usage_hf14_autopwn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the key storage stucture
|
// Create the key storage stucture
|
||||||
|
@ -1821,7 +1821,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||||
);
|
);
|
||||||
PrintAndLogEx(WARNING, "falling back to dictionary");
|
PrintAndLogEx(WARNING, "falling back to dictionary");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the user supplied key is used by other sectors
|
// Check if the user supplied key is used by other sectors
|
||||||
for (int i = 0; i < sectors_cnt; i++) {
|
for (int i = 0; i < sectors_cnt; i++) {
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
|
@ -1858,18 +1858,18 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||||
bool load_success = true;
|
bool load_success = true;
|
||||||
// Load the dictionary
|
// Load the dictionary
|
||||||
if (has_filename) {
|
if (has_filename) {
|
||||||
int res = loadFileDICTIONARY_safe(filename, (void**) &keyBlock, 6, &key_cnt);
|
int res = loadFileDICTIONARY_safe(filename, (void **) &keyBlock, 6, &key_cnt);
|
||||||
if (res != PM3_SUCCESS || key_cnt == 0 || keyBlock == NULL) {
|
if (res != PM3_SUCCESS || key_cnt == 0 || keyBlock == NULL) {
|
||||||
PrintAndLogEx(FAILED, "An error occurred while loading the dictionary! (we will use the default keys now)");
|
PrintAndLogEx(FAILED, "An error occurred while loading the dictionary! (we will use the default keys now)");
|
||||||
if (keyBlock != NULL)
|
if (keyBlock != NULL)
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
|
|
||||||
load_success = false;
|
load_success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( has_filename == false || load_success == false ) {
|
if (has_filename == false || load_success == false) {
|
||||||
keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6);
|
keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6);
|
||||||
if (keyBlock == NULL) {
|
if (keyBlock == NULL) {
|
||||||
free(e_sector);
|
free(e_sector);
|
||||||
|
@ -1880,7 +1880,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||||
num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6);
|
num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6);
|
||||||
}
|
}
|
||||||
key_cnt = ARRAYLEN(g_mifare_default_keys);
|
key_cnt = ARRAYLEN(g_mifare_default_keys);
|
||||||
PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from hardcoded default array", key_cnt);
|
PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from hardcoded default array", key_cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the dictionary to find sector keys on the card
|
// Use the dictionary to find sector keys on the card
|
||||||
|
@ -1950,7 +1950,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||||
if (e_sector[i].foundKey[j] == 1) {
|
if (e_sector[i].foundKey[j] == 1) {
|
||||||
e_sector[i].foundKey[j] = 'D';
|
e_sector[i].foundKey[j] = 'D';
|
||||||
num_to_bytes(e_sector[i].Key[j], 6, tmp_key);
|
num_to_bytes(e_sector[i].Key[j], 6, tmp_key);
|
||||||
|
|
||||||
// Store valid credentials for the nested / hardnested attack if none exist
|
// Store valid credentials for the nested / hardnested attack if none exist
|
||||||
if (know_target_key == false) {
|
if (know_target_key == false) {
|
||||||
num_to_bytes(e_sector[i].Key[j], 6, key);
|
num_to_bytes(e_sector[i].Key[j], 6, key);
|
||||||
|
@ -2018,7 +2018,7 @@ noValidKeyFound:
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
// Clear the needed variables
|
// Clear the needed variables
|
||||||
num_to_bytes(0, 6, tmp_key);
|
num_to_bytes(0, 6, tmp_key);
|
||||||
|
@ -2062,7 +2062,7 @@ noValidKeyFound:
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
PrintAndLogEx(INFO, _YELLOW_("======================= START READ B KEY ATTACK ======================="));
|
PrintAndLogEx(INFO, _YELLOW_("======================= START READ B KEY ATTACK ======================="));
|
||||||
PrintAndLogEx(INFO, "reading B key: sector: %3d key type: %c",
|
PrintAndLogEx(INFO, "reading B key: sector: %3d key type: %c",
|
||||||
current_sector_i,
|
current_sector_i,
|
||||||
current_key_type_i ? 'B' : 'A');
|
current_key_type_i ? 'B' : 'A');
|
||||||
}
|
}
|
||||||
uint8_t sectrail = (FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1);
|
uint8_t sectrail = (FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1);
|
||||||
|
@ -2094,9 +2094,9 @@ noValidKeyFound:
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (verbose) PrintAndLogEx(WARNING, "unknown B key: sector: %3d key type: %c (reading the B key was not possible, maybe due to insufficient access rights) ",
|
if (verbose) PrintAndLogEx(WARNING, "unknown B key: sector: %3d key type: %c (reading the B key was not possible, maybe due to insufficient access rights) ",
|
||||||
current_sector_i,
|
current_sector_i,
|
||||||
current_key_type_i ? 'B' : 'A'
|
current_key_type_i ? 'B' : 'A'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP READ B KEY ATTACK ======================="));
|
if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP READ B KEY ATTACK ======================="));
|
||||||
}
|
}
|
||||||
|
@ -2226,13 +2226,13 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|");
|
PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|");
|
||||||
PrintAndLogEx(NORMAL, "( "
|
PrintAndLogEx(NORMAL, "( "
|
||||||
_YELLOW_("D") ":Dictionary / "
|
_YELLOW_("D") ":Dictionary / "
|
||||||
_YELLOW_("S") ":darkSide / "
|
_YELLOW_("S") ":darkSide / "
|
||||||
_YELLOW_("U") ":User / "
|
_YELLOW_("U") ":User / "
|
||||||
_YELLOW_("R") ":Reused / "
|
_YELLOW_("R") ":Reused / "
|
||||||
_YELLOW_("N") ":Nested / "
|
_YELLOW_("N") ":Nested / "
|
||||||
_YELLOW_("H") ":Hardnested / "
|
_YELLOW_("H") ":Hardnested / "
|
||||||
_YELLOW_("A") ":keyA "
|
_YELLOW_("A") ":keyA "
|
||||||
")"
|
")"
|
||||||
);
|
);
|
||||||
|
@ -2254,8 +2254,8 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack
|
||||||
mfEmlSetMem(block, FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1, 1);
|
mfEmlSetMem(block, FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// use ecfill trick
|
// use ecfill trick
|
||||||
FastDumpWithEcFill(sectors_cnt);
|
FastDumpWithEcFill(sectors_cnt);
|
||||||
|
|
||||||
bytes = block_cnt * MFBLOCK_SIZE;
|
bytes = block_cnt * MFBLOCK_SIZE;
|
||||||
dump = calloc(bytes, sizeof(uint8_t));
|
dump = calloc(bytes, sizeof(uint8_t));
|
||||||
|
@ -2526,12 +2526,12 @@ out:
|
||||||
|
|
||||||
printKeyTable(sectorsCnt, e_sector);
|
printKeyTable(sectorsCnt, e_sector);
|
||||||
|
|
||||||
if ( use_flashmemory && found_keys == (sectorsCnt << 1) ) {
|
if (use_flashmemory && found_keys == (sectorsCnt << 1)) {
|
||||||
PrintAndLogEx(SUCCESS, "Card dumped aswell. run " _YELLOW_("`%s %c`"),
|
PrintAndLogEx(SUCCESS, "Card dumped aswell. run " _YELLOW_("`%s %c`"),
|
||||||
"hf mf esave",
|
"hf mf esave",
|
||||||
GetFormatFromSector(sectorsCnt)
|
GetFormatFromSector(sectorsCnt)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transferToEml) {
|
if (transferToEml) {
|
||||||
// fast push mode
|
// fast push mode
|
||||||
|
@ -2551,10 +2551,10 @@ out:
|
||||||
mfEmlSetMem(block, blockno, 1);
|
mfEmlSetMem(block, blockno, 1);
|
||||||
}
|
}
|
||||||
PrintAndLogEx(SUCCESS, "Found keys have been transferred to the emulator memory");
|
PrintAndLogEx(SUCCESS, "Found keys have been transferred to the emulator memory");
|
||||||
|
|
||||||
if ( found_keys == (sectorsCnt << 1) ) {
|
if (found_keys == (sectorsCnt << 1)) {
|
||||||
FastDumpWithEcFill(sectorsCnt);
|
FastDumpWithEcFill(sectorsCnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createDumpFile) {
|
if (createDumpFile) {
|
||||||
|
@ -3534,10 +3534,10 @@ static int CmdHF14AMfECFill(const char *Cmd) {
|
||||||
PrintAndLogEx(NORMAL, "--params: numSectors: %d, keyType: %c\n", numSectors, (keyType == 0) ? 'A' : 'B');
|
PrintAndLogEx(NORMAL, "--params: numSectors: %d, keyType: %c\n", numSectors, (keyType == 0) ? 'A' : 'B');
|
||||||
|
|
||||||
mfc_eload_t payload;
|
mfc_eload_t payload;
|
||||||
payload.sectorcnt = numSectors;
|
payload.sectorcnt = numSectors;
|
||||||
payload.keytype = keyType;
|
payload.keytype = keyType;
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload));
|
SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload));
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2128,10 +2128,10 @@ static int CmdT55xxChkPwds(const char *Cmd) {
|
||||||
if (use_pwd_file) {
|
if (use_pwd_file) {
|
||||||
uint16_t keycount = 0;
|
uint16_t keycount = 0;
|
||||||
|
|
||||||
int res = loadFileDICTIONARY_safe(filename, (void**) &keyBlock, 4, &keycount);
|
int res = loadFileDICTIONARY_safe(filename, (void **) &keyBlock, 4, &keycount);
|
||||||
if (res != PM3_SUCCESS || keycount == 0 || keyBlock == NULL) {
|
if (res != PM3_SUCCESS || keycount == 0 || keyBlock == NULL) {
|
||||||
PrintAndLogEx(WARNING, "No keys found in file");
|
PrintAndLogEx(WARNING, "No keys found in file");
|
||||||
if (keyBlock != NULL)
|
if (keyBlock != NULL)
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
|
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
|
|
|
@ -435,7 +435,7 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes_read = fread(*pdata, 1, fsize, f);
|
size_t bytes_read = fread(*pdata, 1, fsize, f);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (bytes_read != fsize) {
|
if (bytes_read != fsize) {
|
||||||
|
@ -699,7 +699,7 @@ out:
|
||||||
int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t keylen, uint16_t *keycnt) {
|
int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t keylen, uint16_t *keycnt) {
|
||||||
|
|
||||||
int retval = PM3_SUCCESS;
|
int retval = PM3_SUCCESS;
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic", false) != PM3_SUCCESS)
|
if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic", false) != PM3_SUCCESS)
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
|
@ -713,7 +713,7 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t mem_size;
|
size_t mem_size;
|
||||||
size_t block_size = 10 * keylen;
|
size_t block_size = 10 * keylen;
|
||||||
|
|
||||||
// double up since its chars
|
// double up since its chars
|
||||||
keylen <<= 1;
|
keylen <<= 1;
|
||||||
|
@ -721,24 +721,25 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key
|
||||||
char line[255];
|
char line[255];
|
||||||
|
|
||||||
// allocate some space for the dictionary
|
// allocate some space for the dictionary
|
||||||
*pdata = calloc( block_size , sizeof(uint8_t));
|
*pdata = calloc(block_size, sizeof(uint8_t));
|
||||||
if (*pdata == NULL)
|
if (*pdata == NULL)
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
|
|
||||||
mem_size = block_size;
|
mem_size = block_size;
|
||||||
|
|
||||||
FILE *f = fopen(path, "r");
|
FILE *f = fopen(path, "r");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", path);
|
PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", path);
|
||||||
retval = PM3_EFILE;
|
retval = PM3_EFILE;
|
||||||
goto out; }
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
// read file
|
// read file
|
||||||
while (fgets(line, sizeof(line), f)) {
|
while (fgets(line, sizeof(line), f)) {
|
||||||
|
|
||||||
// check if we have enough space (if not allocate more)
|
// check if we have enough space (if not allocate more)
|
||||||
if ( (*keycnt * (keylen >> 1) ) >= mem_size ) {
|
if ((*keycnt * (keylen >> 1)) >= mem_size) {
|
||||||
|
|
||||||
mem_size += block_size;
|
mem_size += block_size;
|
||||||
*pdata = realloc(*pdata, mem_size);
|
*pdata = realloc(*pdata, mem_size);
|
||||||
|
|
||||||
|
@ -767,10 +768,10 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key
|
||||||
|
|
||||||
uint64_t key = strtoull(line, NULL, 16);
|
uint64_t key = strtoull(line, NULL, 16);
|
||||||
|
|
||||||
num_to_bytes(key, keylen >> 1, *pdata + (*keycnt * (keylen >> 1)) );
|
num_to_bytes(key, keylen >> 1, *pdata + (*keycnt * (keylen >> 1)));
|
||||||
|
|
||||||
(*keycnt)++;
|
(*keycnt)++;
|
||||||
|
|
||||||
memset(line, 0, sizeof(line));
|
memset(line, 0, sizeof(line));
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
|
@ -543,7 +543,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) {
|
||||||
|
|
||||||
size_t dumplen = 0;
|
size_t dumplen = 0;
|
||||||
uint8_t *dump = NULL;
|
uint8_t *dump = NULL;
|
||||||
if ( loadFile_safe(filename, "", (void**)&dump, &dumplen) != PM3_SUCCESS ) {
|
if (loadFile_safe(filename, "", (void **)&dump, &dumplen) != PM3_SUCCESS) {
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -655,19 +655,19 @@ static int doTestsWithKnownInputs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool readKeyFile(uint8_t* key, size_t keylen) {
|
static bool readKeyFile(uint8_t *key, size_t keylen) {
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
uint8_t *keyptr = NULL;
|
uint8_t *keyptr = NULL;
|
||||||
if ( loadFile_safe("iclass_key.bin", "", (void**)&keyptr, &len) != PM3_SUCCESS ) {
|
if (loadFile_safe("iclass_key.bin", "", (void **)&keyptr, &len) != PM3_SUCCESS) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( keylen != len ) {
|
if (keylen != len) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(key, keyptr, keylen );
|
memcpy(key, keyptr, keylen);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ int mfCheckKeys_fast(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk,
|
||||||
icesector_t *tmp = calloc(sectorsCnt, sizeof(icesector_t));
|
icesector_t *tmp = calloc(sectorsCnt, sizeof(icesector_t));
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return PM3_EMALLOC;
|
return PM3_EMALLOC;
|
||||||
|
|
||||||
memcpy(tmp, resp.data.asBytes, sectorsCnt * sizeof(icesector_t));
|
memcpy(tmp, resp.data.asBytes, sectorsCnt * sizeof(icesector_t));
|
||||||
|
|
||||||
for (int i = 0; i < sectorsCnt; i++) {
|
for (int i = 0; i < sectorsCnt; i++) {
|
||||||
|
|
|
@ -64,10 +64,10 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home)
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
struct _stat st;
|
struct _stat st;
|
||||||
// Mingw _stat fails if path ends with /, so let's use a stripped path
|
// Mingw _stat fails if path ends with /, so let's use a stripped path
|
||||||
if (path[strlen(path)-1]=='/') {
|
if (path[strlen(path) - 1] == '/') {
|
||||||
path[strlen(path)-1]='\0';
|
path[strlen(path) - 1] = '\0';
|
||||||
result = _stat(path, &st);
|
result = _stat(path, &st);
|
||||||
path[strlen(path)]='/';
|
path[strlen(path)] = '/';
|
||||||
} else {
|
} else {
|
||||||
result = _stat(path, &st);
|
result = _stat(path, &st);
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,9 +230,9 @@ typedef struct {
|
||||||
} PACKED mf_readblock_t;
|
} PACKED mf_readblock_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t sectorcnt;
|
uint8_t sectorcnt;
|
||||||
uint8_t keytype;
|
uint8_t keytype;
|
||||||
} PACKED mfc_eload_t;
|
} PACKED mfc_eload_t;
|
||||||
|
|
||||||
// For the bootloader
|
// For the bootloader
|
||||||
#define CMD_DEVICE_INFO 0x0000
|
#define CMD_DEVICE_INFO 0x0000
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue