mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 13:00:42 -07:00
chg: 'hf mf fchk' - depth first search
This commit is contained in:
parent
da57e74140
commit
dd024b5300
5 changed files with 84 additions and 54 deletions
|
@ -1131,7 +1131,7 @@ void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, ui
|
||||||
found[(s*2)] = 1;
|
found[(s*2)] = 1;
|
||||||
++*foundkeys;
|
++*foundkeys;
|
||||||
|
|
||||||
if (MF_DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Scan A (%d)", c->block);
|
if (MF_DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Scan A found (%d)", c->block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1151,7 +1151,7 @@ void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, ui
|
||||||
found[(s*2)+1] = 1;
|
found[(s*2)+1] = 1;
|
||||||
++*foundkeys;
|
++*foundkeys;
|
||||||
|
|
||||||
if (MF_DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Scan B (%d)", c->block);
|
if (MF_DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Scan B found (%d)", c->block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1171,7 +1171,7 @@ void chkKey_loopBonly(struct chk_t *c, struct sector_t *k_sector, uint8_t *found
|
||||||
found[(s*2)+1] = 1;
|
found[(s*2)+1] = 1;
|
||||||
++*foundkeys;
|
++*foundkeys;
|
||||||
|
|
||||||
if (MF_DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Loop B only (%d)", c->block);
|
if (MF_DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Reading B found (%d)", c->block);
|
||||||
|
|
||||||
// try quick find all B?
|
// try quick find all B?
|
||||||
// assume: keys comes in groups. Find one B, test against all B.
|
// assume: keys comes in groups. Find one B, test against all B.
|
||||||
|
@ -1256,8 +1256,19 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
|
||||||
chk_data.pcs = pcs;
|
chk_data.pcs = pcs;
|
||||||
chk_data.block = 0;
|
chk_data.block = 0;
|
||||||
|
|
||||||
// keychunk loop - depth first for sector0.
|
|
||||||
|
// keychunk loop - depth first one sector.
|
||||||
if ( strategy == 1 ) {
|
if ( strategy == 1 ) {
|
||||||
|
// Sector main loop
|
||||||
|
// keep track of how many sectors on card.
|
||||||
|
for (uint8_t s = 0; s < sectorcnt; ++s) {
|
||||||
|
|
||||||
|
if ( found[(s*2)] && found[(s*2)+1] )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// assume: block0,1,2 has more read rights in accessbits than the sectortrailer. authenticating against block0 in each sector
|
||||||
|
chk_data.block = FirstBlockOfSector( s );
|
||||||
|
|
||||||
for (uint8_t i = 0; i < keyCount; ++i) {
|
for (uint8_t i = 0; i < keyCount; ++i) {
|
||||||
// Allow button press / usb cmd to interrupt device
|
// Allow button press / usb cmd to interrupt device
|
||||||
if (BUTTON_PRESS() && !usb_poll_validate_length()) {
|
if (BUTTON_PRESS() && !usb_poll_validate_length()) {
|
||||||
|
@ -1268,17 +1279,16 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
|
||||||
|
|
||||||
// new key
|
// new key
|
||||||
chk_data.key = bytes_to_num(datain + i * 6, 6);
|
chk_data.key = bytes_to_num(datain + i * 6, 6);
|
||||||
// those scans messes with block.
|
|
||||||
chk_data.block = 0;
|
|
||||||
// assume: block0,1,2 has more read rights in accessbits than the sectortrailer. authenticating against block0 in each sector
|
// assume: block0,1,2 has more read rights in accessbits than the sectortrailer. authenticating against block0 in each sector
|
||||||
|
|
||||||
// skip already found A keys
|
// skip already found A keys
|
||||||
if( !found[0] ) {
|
if( !found[(s*2)] ) {
|
||||||
chk_data.keyType = 0;
|
chk_data.keyType = 0;
|
||||||
status = chkKey( &chk_data);
|
status = chkKey( &chk_data);
|
||||||
if ( status == 0 ) {
|
if ( status == 0 ) {
|
||||||
memcpy(k_sector[0].keyA, datain + i * 6, 6);
|
memcpy(k_sector[s].keyA, datain + i * 6, 6);
|
||||||
found[0] = 1;
|
found[(s*2)] = 1;
|
||||||
++foundkeys;
|
++foundkeys;
|
||||||
|
|
||||||
chkKey_scanA(&chk_data, k_sector, found, §orcnt, &foundkeys);
|
chkKey_scanA(&chk_data, k_sector, found, §orcnt, &foundkeys);
|
||||||
|
@ -1286,24 +1296,25 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
|
||||||
// read Block B, if A is found.
|
// read Block B, if A is found.
|
||||||
chkKey_loopBonly( &chk_data, k_sector, found, §orcnt, &foundkeys);
|
chkKey_loopBonly( &chk_data, k_sector, found, §orcnt, &foundkeys);
|
||||||
|
|
||||||
chk_data.block = 0;
|
chk_data.block = FirstBlockOfSector( s );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip already found B keys
|
// skip already found B keys
|
||||||
if( !found[1] ) {
|
if( !found[(s*2)+1] ) {
|
||||||
chk_data.keyType = 1;
|
chk_data.keyType = 1;
|
||||||
status = chkKey( &chk_data);
|
status = chkKey( &chk_data);
|
||||||
if ( status == 0 ) {
|
if ( status == 0 ) {
|
||||||
memcpy(k_sector[0].keyB, datain + i * 6, 6);
|
memcpy(k_sector[s].keyB, datain + i * 6, 6);
|
||||||
found[1] = 1;
|
found[(s*2)+1] = 1;
|
||||||
++foundkeys;
|
++foundkeys;
|
||||||
|
|
||||||
chkKey_scanB(&chk_data, k_sector, found, §orcnt, &foundkeys);
|
chkKey_scanB(&chk_data, k_sector, found, §orcnt, &foundkeys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // end look - depth first
|
} // end loop - depth first
|
||||||
} // strategy 1
|
} // end loop - sector
|
||||||
|
} // end strategy 1
|
||||||
|
|
||||||
if ( strategy == 2 ) {
|
if ( strategy == 2 ) {
|
||||||
// Keychunk loop
|
// Keychunk loop
|
||||||
|
|
|
@ -418,6 +418,24 @@ int CmdAnalyseTEASelfTest(const char *Cmd){
|
||||||
|
|
||||||
int CmdAnalyseA(const char *Cmd){
|
int CmdAnalyseA(const char *Cmd){
|
||||||
|
|
||||||
|
bool term = !isatty(STDIN_FILENO);
|
||||||
|
if (!term) {
|
||||||
|
char star[4];
|
||||||
|
star[0] = '-';
|
||||||
|
star[1] = '\\';
|
||||||
|
star[2] = '|';
|
||||||
|
star[4] = '/';
|
||||||
|
|
||||||
|
for (uint8_t k=0; k<5; k = (k+1) % 4 ) {
|
||||||
|
printf("\e[s%c\e[u", star[k]);
|
||||||
|
fflush(stdout);
|
||||||
|
if (ukbhit()) {
|
||||||
|
int gc = getchar(); (void)gc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//piwi
|
//piwi
|
||||||
// uid(2e086b1a) nt(230736f6) ks(0b0008000804000e) nr(000000000)
|
// uid(2e086b1a) nt(230736f6) ks(0b0008000804000e) nr(000000000)
|
||||||
// uid(2e086b1a) nt(230736f6) ks(0e0b0e0b090c0d02) nr(000000001)
|
// uid(2e086b1a) nt(230736f6) ks(0e0b0e0b090c0d02) nr(000000001)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include <stdlib.h> //size_t
|
#include <stdlib.h> //size_t
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "cmdmain.h"
|
#include "cmdmain.h"
|
||||||
#include "proxmark3.h"
|
#include "proxmark3.h"
|
||||||
#include "ui.h" // PrintAndLog
|
#include "ui.h" // PrintAndLog
|
||||||
|
|
|
@ -1272,7 +1272,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 defKeys");
|
PrintAndLog("Cannot allocate memory for default keys");
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -1372,11 +1372,11 @@ int CmdHF14AMfChk_fast(const char *Cmd) {
|
||||||
// all keys?
|
// all keys?
|
||||||
if ( curr_keys == SectorsCnt*2 || lastChunk ) {
|
if ( curr_keys == SectorsCnt*2 || lastChunk ) {
|
||||||
memcpy(e_sector, resp.d.asBytes, SectorsCnt * sizeof(icesector_t) );
|
memcpy(e_sector, resp.d.asBytes, SectorsCnt * sizeof(icesector_t) );
|
||||||
break;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
out:
|
||||||
t1 = msclock() - t1;
|
t1 = msclock() - t1;
|
||||||
PrintAndLog("[+] Time in checkkeys (fast): %.1fs\n", (float)(t1/1000.0));
|
PrintAndLog("[+] Time in checkkeys (fast): %.1fs\n", (float)(t1/1000.0));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue