mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-12 18:25:07 +08: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;
|
||||
}
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ static int g_wait = 300;
|
|||
static int timeout = 2900;
|
||||
static uint32_t time_rdr = 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 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.
|
||||
/*
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = 0x00;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = 0x00;
|
||||
}
|
||||
*/
|
||||
// Wait for byte be become available in rx holding register
|
||||
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;
|
||||
|
||||
c++;
|
||||
|
@ -1896,7 +1896,7 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples,
|
|||
if (ManchesterDecoding_iclass(b & 0x0f)) {
|
||||
if (samples)
|
||||
*samples = c << 3;
|
||||
|
||||
|
||||
time_response = GetCountSspClk() - foo;
|
||||
return true;
|
||||
}
|
||||
|
@ -1959,7 +1959,7 @@ bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *re
|
|||
// since its called with fixed sized arrays
|
||||
|
||||
// update/write commadn takes 4ms to 15ms before responding
|
||||
if ( command[0] == ICLASS_CMD_UPDATE )
|
||||
if (command[0] == ICLASS_CMD_UPDATE)
|
||||
g_wait = 15000;
|
||||
|
||||
uint8_t got_n = ReaderReceiveIClass(resp);
|
||||
|
|
|
@ -1523,33 +1523,33 @@ OUT:
|
|||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
BigBuf_free();
|
||||
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);
|
||||
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;
|
||||
}
|
||||
// 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);
|
||||
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 {
|
||||
// partial/none keys found
|
||||
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 retval = MifareECardLoad(numSectors, keyType);
|
||||
reply_ng(CMD_HF_MIFARE_EML_LOAD, retval, NULL, 0);
|
||||
return retval;
|
||||
int retval = MifareECardLoad(numSectors, keyType);
|
||||
reply_ng(CMD_HF_MIFARE_EML_LOAD, retval, NULL, 0);
|
||||
return retval;
|
||||
}
|
||||
|
||||
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)) {
|
||||
retval = PM3_ESOFT;
|
||||
if (DBGLEVEL > DBG_ERROR) Dbprintf("Can't select card");
|
||||
goto out;
|
||||
goto out;
|
||||
}
|
||||
|
||||
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);
|
||||
break;
|
||||
}
|
||||
if (blockNo < NumBlocksPerSector(sectorNo) - 1) {
|
||||
emlSetMem(dataoutbuf, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
||||
} else { // sector trailer, keep the keys, set only the AC
|
||||
emlGetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
||||
memcpy(&dataoutbuf2[6], &dataoutbuf[6], 4);
|
||||
emlSetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
||||
}
|
||||
if (blockNo < NumBlocksPerSector(sectorNo) - 1) {
|
||||
emlSetMem(dataoutbuf, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
||||
} else { // sector trailer, keep the keys, set only the AC
|
||||
emlGetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
||||
memcpy(&dataoutbuf2[6], &dataoutbuf[6], 4);
|
||||
emlSetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mifare_classic_halt(pcs, cuid)) {
|
||||
if (DBGLEVEL > DBG_ERROR)
|
||||
Dbprintf("Halt error");
|
||||
}
|
||||
}
|
||||
|
||||
if (DBGLEVEL >= DBG_INFO) DbpString("Emulator fill sectors finished");
|
||||
if (DBGLEVEL >= DBG_INFO) DbpString("Emulator fill sectors finished");
|
||||
|
||||
out:
|
||||
crypto1_destroy(pcs);
|
||||
|
|
|
@ -696,7 +696,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
|||
return usage_hf_iclass_eload();
|
||||
case 'f':
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
@ -704,12 +704,12 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
|||
break;
|
||||
case 'j':
|
||||
dftype = JSON;
|
||||
cmdp++;
|
||||
break;
|
||||
cmdp++;
|
||||
break;
|
||||
case 'e':
|
||||
dftype = EML;
|
||||
cmdp++;
|
||||
break;
|
||||
dftype = EML;
|
||||
cmdp++;
|
||||
break;
|
||||
default:
|
||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
|
@ -733,9 +733,9 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
|||
size_t bytes_read = 2048;
|
||||
int res = 0;
|
||||
|
||||
switch ( dftype ) {
|
||||
switch (dftype) {
|
||||
case BIN: {
|
||||
res = loadFile(filename, ".bin", (void*)&dump, 2048, &bytes_read);
|
||||
res = loadFile(filename, ".bin", (void *)&dump, 2048, &bytes_read);
|
||||
break;
|
||||
}
|
||||
case EML: {
|
||||
|
@ -747,11 +747,11 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
default:
|
||||
PrintAndLogEx(ERR, "No dictionary loaded");
|
||||
return PM3_ESOFT;
|
||||
PrintAndLogEx(ERR, "No dictionary loaded");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if ( res != PM3_SUCCESS ) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
free(dump);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
|
@ -793,15 +793,15 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
|||
#define ICLASS_DECRYPTION_BIN "iclass_decryptionkey.bin"
|
||||
|
||||
static int CmdHFiClassDecrypt(const char *Cmd) {
|
||||
|
||||
|
||||
bool errors = false;
|
||||
bool have_key = false;
|
||||
uint8_t cmdp = 0;
|
||||
|
||||
|
||||
size_t keylen = 0;
|
||||
uint8_t key[32] = {0};
|
||||
uint8_t *keyptr = NULL;
|
||||
|
||||
|
||||
size_t decryptedlen = 0;
|
||||
uint8_t *decrypted = NULL;
|
||||
char filename[FILE_PATH_SIZE];
|
||||
|
@ -811,13 +811,13 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
|||
case 'h':
|
||||
return usage_hf_iclass_decrypt();
|
||||
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");
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( loadFile_safe(filename, "", (void**)&decrypted, &decryptedlen) != PM3_SUCCESS ) {
|
||||
if (loadFile_safe(filename, "", (void **)&decrypted, &decryptedlen) != PM3_SUCCESS) {
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
|
@ -840,11 +840,11 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
|||
|
||||
if (errors || cmdp < 1) return usage_hf_iclass_decrypt();
|
||||
|
||||
if ( have_key == false ) {
|
||||
int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void**)&keyptr, &keylen);
|
||||
if (have_key == false) {
|
||||
int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen);
|
||||
if (res != PM3_SUCCESS)
|
||||
return PM3_EINVARG;
|
||||
|
||||
|
||||
memcpy(key, keyptr, sizeof(key));
|
||||
}
|
||||
|
||||
|
@ -857,7 +857,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
|||
uint8_t app_areas = 2;
|
||||
uint8_t max_blk = 31;
|
||||
getMemConfig(mem, chip, &max_blk, &app_areas, &kb);
|
||||
|
||||
|
||||
// tripledes
|
||||
mbedtls_des3_context ctx;
|
||||
mbedtls_des3_set2key_dec(&ctx, key);
|
||||
|
@ -876,10 +876,10 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
|||
}
|
||||
|
||||
//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-");
|
||||
FillFileNameByUID(fptr, hdr->csn, "-data-decrypted", sizeof(hdr->csn) );
|
||||
|
||||
FillFileNameByUID(fptr, hdr->csn, "-data-decrypted", sizeof(hdr->csn));
|
||||
|
||||
saveFile(fptr, ".bin", decrypted, decryptedlen);
|
||||
saveFileEML(fptr, decrypted, decryptedlen, 8);
|
||||
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 ( have_key == false ) {
|
||||
if (have_key == false) {
|
||||
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)
|
||||
return PM3_EINVARG;
|
||||
|
||||
|
||||
memcpy(key, keyptr, sizeof(key));
|
||||
}
|
||||
|
||||
|
@ -1265,7 +1265,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
|
|||
|
||||
//Use the first block (CSN) for filename
|
||||
strcat(filename, "hf-iclass-");
|
||||
FillFileNameByUID(filename, tag_data, "-data", 8 );
|
||||
FillFileNameByUID(filename, tag_data, "-data", 8);
|
||||
}
|
||||
|
||||
// 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]
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1936,9 +1936,9 @@ static int saveKeys(char *filename) {
|
|||
static int printKeys(void) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
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));
|
||||
else
|
||||
else
|
||||
PrintAndLogEx(NORMAL, "%u: "_YELLOW_("%s"), i, sprint_hex(iClass_Key_Table[i], 8));
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
@ -2096,7 +2096,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
|
|||
uint16_t keycount = 0;
|
||||
|
||||
// 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) {
|
||||
free(keyBlock);
|
||||
return res;
|
||||
|
@ -2106,11 +2106,11 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
|
|||
PrintAndLogEx(SUCCESS, "Reading tag CSN");
|
||||
for (uint8_t i = 0; i < 10 && !got_csn; i++) {
|
||||
got_csn = select_only(CSN, CCNR, false, false);
|
||||
if ( got_csn == false )
|
||||
if (got_csn == false)
|
||||
PrintAndLogEx(WARNING, "one more try\n");
|
||||
}
|
||||
}
|
||||
|
||||
if ( got_csn == false ) {
|
||||
if (got_csn == false) {
|
||||
PrintAndLogEx(WARNING, "Tried 10 times. Can't select card, aborting...");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
@ -2232,13 +2232,13 @@ out:
|
|||
PrintAndLogEx(SUCCESS, "\nTime in iclass checkkeys: %.0f seconds\n", (float)t1 / 1000.0);
|
||||
DropField();
|
||||
|
||||
// add to managekeys
|
||||
if ( found_debit ) {
|
||||
for (uint8_t i=0; i< ICLASS_KEYS_MAX; i++) {
|
||||
// add to managekeys
|
||||
if (found_debit) {
|
||||
for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++) {
|
||||
// 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);
|
||||
PrintAndLogEx(SUCCESS, "Added key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")" to view", i);
|
||||
break;
|
||||
|
@ -2295,7 +2295,7 @@ static int CmdHFiClassLookUp(const char *Cmd) {
|
|||
case 'h':
|
||||
return usage_hf_iclass_lookup();
|
||||
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");
|
||||
errors = true;
|
||||
}
|
||||
|
@ -2358,12 +2358,12 @@ static int CmdHFiClassLookUp(const char *Cmd) {
|
|||
uint16_t keycount = 0;
|
||||
|
||||
// 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) {
|
||||
free(keyBlock);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
//iclass_prekey_t
|
||||
prekey = calloc(keycount, sizeof(iclass_prekey_t));
|
||||
if (!prekey) {
|
||||
|
@ -2395,18 +2395,18 @@ static int CmdHFiClassLookUp(const char *Cmd) {
|
|||
// foudn
|
||||
if (item != NULL) {
|
||||
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
|
||||
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);
|
||||
PrintAndLogEx(SUCCESS, "Added key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")"to view", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free(prekey);
|
||||
free(keyBlock);
|
||||
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){
|
||||
PacketResponseNG resp;
|
||||
|
||||
mfc_eload_t payload;
|
||||
payload.sectorcnt = numsectors;
|
||||
payload.keytype = 0;
|
||||
static int FastDumpWithEcFill(uint8_t numsectors) {
|
||||
PacketResponseNG resp;
|
||||
|
||||
// ecfill key A
|
||||
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) {
|
||||
mfc_eload_t payload;
|
||||
payload.sectorcnt = numsectors;
|
||||
payload.keytype = 0;
|
||||
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
// ecfill key A
|
||||
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) {
|
||||
|
@ -1287,11 +1287,11 @@ static int CmdHF14AMfNested(const char *Cmd) {
|
|||
|
||||
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);
|
||||
if ( res == PM3_SUCCESS ) {
|
||||
// all keys found
|
||||
PrintAndLogEx(SUCCESS, "Fast check found all keys");
|
||||
goto jumptoend;
|
||||
}
|
||||
if (res == PM3_SUCCESS) {
|
||||
// all keys found
|
||||
PrintAndLogEx(SUCCESS, "Fast check found all keys");
|
||||
goto jumptoend;
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -1663,29 +1663,29 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
|||
bool prng_type = false;
|
||||
bool verbose = false;
|
||||
bool has_filename = false;
|
||||
bool errors = false;
|
||||
bool errors = false;
|
||||
|
||||
// Parse the options given by the user
|
||||
while ( (ctmp = param_getchar(Cmd, cmdp)) && !errors ) {
|
||||
while ((ctmp = param_getchar(Cmd, cmdp)) && !errors) {
|
||||
switch (tolower(ctmp)) {
|
||||
case 'h':
|
||||
return usage_hf14_autopwn();
|
||||
case 'f':
|
||||
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
||||
PrintAndLogEx(FAILED, "Filename too long");
|
||||
errors = true;
|
||||
errors = true;
|
||||
} else {
|
||||
has_filename = true;
|
||||
has_filename = true;
|
||||
}
|
||||
cmdp += 2;
|
||||
break;
|
||||
case 'l':
|
||||
legacy_mfchk = true;
|
||||
cmdp++;
|
||||
cmdp++;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
cmdp++;
|
||||
cmdp++;
|
||||
break;
|
||||
case '*':
|
||||
// Get the number of sectors
|
||||
|
@ -1696,35 +1696,35 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
|||
case 'k':
|
||||
// Get the known block number
|
||||
if (param_getchar(Cmd, cmdp + 1) == 0x00) {
|
||||
errors = true;
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
blockNo = param_get8(Cmd, cmdp + 1);
|
||||
|
||||
|
||||
// Get the knonwn block type
|
||||
ctmp = tolower(param_getchar(Cmd, cmdp + 2));
|
||||
if (ctmp != 'a' && ctmp != 'b') {
|
||||
PrintAndLogEx(WARNING, "Key type must be A or B");
|
||||
errors = true;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (ctmp != 'a') {
|
||||
keyType = 1;
|
||||
}
|
||||
|
||||
|
||||
// Get the known block key
|
||||
if (param_gethex(Cmd, cmdp + 3, key, 12)) {
|
||||
PrintAndLogEx(WARNING, "Key must include 12 HEX symbols");
|
||||
errors = true;
|
||||
errors = true;
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
know_target_key = true;
|
||||
cmdp += 3;
|
||||
case 's':
|
||||
slow = true;
|
||||
cmdp++;
|
||||
cmdp++;
|
||||
break;
|
||||
case 'i':
|
||||
SetSIMDInstr(SIMD_AUTO);
|
||||
|
@ -1759,9 +1759,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
|||
return usage_hf14_autopwn();
|
||||
}
|
||||
}
|
||||
|
||||
if ( errors ) {
|
||||
return usage_hf14_autopwn();
|
||||
|
||||
if (errors) {
|
||||
return usage_hf14_autopwn();
|
||||
}
|
||||
|
||||
// Create the key storage stucture
|
||||
|
@ -1821,7 +1821,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
|||
);
|
||||
PrintAndLogEx(WARNING, "falling back to dictionary");
|
||||
}
|
||||
|
||||
|
||||
// Check if the user supplied key is used by other sectors
|
||||
for (int i = 0; i < sectors_cnt; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
|
@ -1858,18 +1858,18 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
|||
bool load_success = true;
|
||||
// Load the dictionary
|
||||
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) {
|
||||
PrintAndLogEx(FAILED, "An error occurred while loading the dictionary! (we will use the default keys now)");
|
||||
if (keyBlock != NULL)
|
||||
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);
|
||||
if (keyBlock == NULL) {
|
||||
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);
|
||||
}
|
||||
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
|
||||
|
@ -1950,7 +1950,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
|||
if (e_sector[i].foundKey[j] == 1) {
|
||||
e_sector[i].foundKey[j] = 'D';
|
||||
num_to_bytes(e_sector[i].Key[j], 6, tmp_key);
|
||||
|
||||
|
||||
// Store valid credentials for the nested / hardnested attack if none exist
|
||||
if (know_target_key == false) {
|
||||
num_to_bytes(e_sector[i].Key[j], 6, key);
|
||||
|
@ -2018,7 +2018,7 @@ noValidKeyFound:
|
|||
return PM3_ESOFT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free(keyBlock);
|
||||
// Clear the needed variables
|
||||
num_to_bytes(0, 6, tmp_key);
|
||||
|
@ -2062,7 +2062,7 @@ noValidKeyFound:
|
|||
if (verbose) {
|
||||
PrintAndLogEx(INFO, _YELLOW_("======================= START READ B KEY ATTACK ======================="));
|
||||
PrintAndLogEx(INFO, "reading B key: sector: %3d key type: %c",
|
||||
current_sector_i,
|
||||
current_sector_i,
|
||||
current_key_type_i ? 'B' : 'A');
|
||||
}
|
||||
uint8_t sectrail = (FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1);
|
||||
|
@ -2094,9 +2094,9 @@ noValidKeyFound:
|
|||
);
|
||||
} 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) ",
|
||||
current_sector_i,
|
||||
current_key_type_i ? 'B' : 'A'
|
||||
);
|
||||
current_sector_i,
|
||||
current_key_type_i ? 'B' : 'A'
|
||||
);
|
||||
}
|
||||
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, "( "
|
||||
_YELLOW_("D") ":Dictionary / "
|
||||
_YELLOW_("S") ":darkSide / "
|
||||
_YELLOW_("U") ":User / "
|
||||
_YELLOW_("R") ":Reused / "
|
||||
_YELLOW_("N") ":Nested / "
|
||||
_YELLOW_("H") ":Hardnested / "
|
||||
_YELLOW_("H") ":Hardnested / "
|
||||
_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);
|
||||
}
|
||||
|
||||
// use ecfill trick
|
||||
FastDumpWithEcFill(sectors_cnt);
|
||||
// use ecfill trick
|
||||
FastDumpWithEcFill(sectors_cnt);
|
||||
|
||||
bytes = block_cnt * MFBLOCK_SIZE;
|
||||
dump = calloc(bytes, sizeof(uint8_t));
|
||||
|
@ -2526,12 +2526,12 @@ out:
|
|||
|
||||
printKeyTable(sectorsCnt, e_sector);
|
||||
|
||||
if ( use_flashmemory && found_keys == (sectorsCnt << 1) ) {
|
||||
PrintAndLogEx(SUCCESS, "Card dumped aswell. run " _YELLOW_("`%s %c`"),
|
||||
"hf mf esave",
|
||||
GetFormatFromSector(sectorsCnt)
|
||||
);
|
||||
}
|
||||
if (use_flashmemory && found_keys == (sectorsCnt << 1)) {
|
||||
PrintAndLogEx(SUCCESS, "Card dumped aswell. run " _YELLOW_("`%s %c`"),
|
||||
"hf mf esave",
|
||||
GetFormatFromSector(sectorsCnt)
|
||||
);
|
||||
}
|
||||
|
||||
if (transferToEml) {
|
||||
// fast push mode
|
||||
|
@ -2551,10 +2551,10 @@ out:
|
|||
mfEmlSetMem(block, blockno, 1);
|
||||
}
|
||||
PrintAndLogEx(SUCCESS, "Found keys have been transferred to the emulator memory");
|
||||
|
||||
if ( found_keys == (sectorsCnt << 1) ) {
|
||||
FastDumpWithEcFill(sectorsCnt);
|
||||
}
|
||||
|
||||
if (found_keys == (sectorsCnt << 1)) {
|
||||
FastDumpWithEcFill(sectorsCnt);
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
mfc_eload_t payload;
|
||||
payload.sectorcnt = numSectors;
|
||||
payload.keytype = keyType;
|
||||
payload.sectorcnt = numSectors;
|
||||
payload.keytype = keyType;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -2128,10 +2128,10 @@ static int CmdT55xxChkPwds(const char *Cmd) {
|
|||
if (use_pwd_file) {
|
||||
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) {
|
||||
PrintAndLogEx(WARNING, "No keys found in file");
|
||||
if (keyBlock != NULL)
|
||||
if (keyBlock != NULL)
|
||||
free(keyBlock);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
fclose(f);
|
||||
|
||||
if (bytes_read != fsize) {
|
||||
|
@ -699,7 +699,7 @@ out:
|
|||
int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t keylen, uint16_t *keycnt) {
|
||||
|
||||
int retval = PM3_SUCCESS;
|
||||
|
||||
|
||||
char *path;
|
||||
if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic", false) != PM3_SUCCESS)
|
||||
return PM3_EFILE;
|
||||
|
@ -713,7 +713,7 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key
|
|||
}
|
||||
|
||||
size_t mem_size;
|
||||
size_t block_size = 10 * keylen;
|
||||
size_t block_size = 10 * keylen;
|
||||
|
||||
// double up since its chars
|
||||
keylen <<= 1;
|
||||
|
@ -721,24 +721,25 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key
|
|||
char line[255];
|
||||
|
||||
// allocate some space for the dictionary
|
||||
*pdata = calloc( block_size , sizeof(uint8_t));
|
||||
*pdata = calloc(block_size, sizeof(uint8_t));
|
||||
if (*pdata == NULL)
|
||||
return PM3_EFILE;
|
||||
return PM3_EFILE;
|
||||
|
||||
mem_size = block_size;
|
||||
mem_size = block_size;
|
||||
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) {
|
||||
PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", path);
|
||||
retval = PM3_EFILE;
|
||||
goto out; }
|
||||
goto out;
|
||||
}
|
||||
|
||||
// read file
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
|
||||
// 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;
|
||||
*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);
|
||||
|
||||
num_to_bytes(key, keylen >> 1, *pdata + (*keycnt * (keylen >> 1)) );
|
||||
|
||||
num_to_bytes(key, keylen >> 1, *pdata + (*keycnt * (keylen >> 1)));
|
||||
|
||||
(*keycnt)++;
|
||||
|
||||
|
||||
memset(line, 0, sizeof(line));
|
||||
}
|
||||
fclose(f);
|
||||
|
|
|
@ -543,7 +543,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) {
|
|||
|
||||
size_t dumplen = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
uint8_t *keyptr = NULL;
|
||||
if ( loadFile_safe("iclass_key.bin", "", (void**)&keyptr, &len) != PM3_SUCCESS ) {
|
||||
uint8_t *keyptr = NULL;
|
||||
if (loadFile_safe("iclass_key.bin", "", (void **)&keyptr, &len) != PM3_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( keylen != len ) {
|
||||
|
||||
if (keylen != len) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(key, keyptr, keylen );
|
||||
|
||||
memcpy(key, keyptr, keylen);
|
||||
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));
|
||||
if (tmp == NULL)
|
||||
return PM3_EMALLOC;
|
||||
|
||||
|
||||
memcpy(tmp, resp.data.asBytes, sectorsCnt * sizeof(icesector_t));
|
||||
|
||||
for (int i = 0; i < sectorsCnt; i++) {
|
||||
|
|
|
@ -64,10 +64,10 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home)
|
|||
#ifdef _WIN32
|
||||
struct _stat st;
|
||||
// Mingw _stat fails if path ends with /, so let's use a stripped path
|
||||
if (path[strlen(path)-1]=='/') {
|
||||
path[strlen(path)-1]='\0';
|
||||
if (path[strlen(path) - 1] == '/') {
|
||||
path[strlen(path) - 1] = '\0';
|
||||
result = _stat(path, &st);
|
||||
path[strlen(path)]='/';
|
||||
path[strlen(path)] = '/';
|
||||
} else {
|
||||
result = _stat(path, &st);
|
||||
}
|
||||
|
|
|
@ -230,9 +230,9 @@ typedef struct {
|
|||
} PACKED mf_readblock_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t sectorcnt;
|
||||
uint8_t keytype;
|
||||
} PACKED mfc_eload_t;
|
||||
uint8_t sectorcnt;
|
||||
uint8_t keytype;
|
||||
} PACKED mfc_eload_t;
|
||||
|
||||
// For the bootloader
|
||||
#define CMD_DEVICE_INFO 0x0000
|
||||
|
|
Loading…
Reference in a new issue