fix 'lf pcf7931 bruteforce' (bug reported in http://www.proxmark.org/forum/viewtopic.php?id=6490)

(and whitespace fixes)
This commit is contained in:
pwpiwi 2019-05-22 18:55:02 +02:00
commit 42c135a3b9
2 changed files with 83 additions and 89 deletions

View file

@ -13,11 +13,11 @@ size_t DemodPCF7931(uint8_t **outBlocks) {
uint8_t bits[256] = {0x00}; uint8_t bits[256] = {0x00};
uint8_t blocks[8][16]; uint8_t blocks[8][16];
uint8_t *dest = BigBuf_get_addr(); uint8_t *dest = BigBuf_get_addr();
int GraphTraceLen = BigBuf_max_traceLen(); int GraphTraceLen = BigBuf_max_traceLen();
if (GraphTraceLen > 18000) if (GraphTraceLen > 18000)
GraphTraceLen = 18000; GraphTraceLen = 18000;
int i, j, lastval, bitidx, half_switch; int i, j, lastval, bitidx, half_switch;
int clock = 64; int clock = 64;
int tolerance = clock / 8; int tolerance = clock / 8;
@ -107,7 +107,7 @@ size_t DemodPCF7931(uint8_t **outBlocks) {
for(j = 0; j < 16; ++j) { for(j = 0; j < 16; ++j) {
blocks[num_blocks][j] = blocks[num_blocks][j] =
128 * bits[j*8 + 7]+ 128 * bits[j*8 + 7]+
64 * bits[j*8 + 6] + 64 * bits[j*8 + 6] +
32 * bits[j*8 + 5] + 32 * bits[j*8 + 5] +
16 * bits[j*8 + 4] + 16 * bits[j*8 + 4] +
8 * bits[j*8 + 3] + 8 * bits[j*8 + 3] +
@ -161,44 +161,44 @@ bool IsBlock1PCF7931(uint8_t *block) {
void ReadPCF7931() { void ReadPCF7931() {
int found_blocks = 0; // successfully read blocks int found_blocks = 0; // successfully read blocks
int max_blocks = 8; // readable blocks int max_blocks = 8; // readable blocks
uint8_t memory_blocks[8][17]; // PCF content uint8_t memory_blocks[8][17]; // PCF content
uint8_t single_blocks[8][17]; // PFC blocks with unknown position uint8_t single_blocks[8][17]; // PFC blocks with unknown position
int single_blocks_cnt = 0; int single_blocks_cnt = 0;
size_t n = 0; // transmitted blocks size_t n = 0; // transmitted blocks
uint8_t tmp_blocks[4][16]; // temporary read buffer uint8_t tmp_blocks[4][16]; // temporary read buffer
uint8_t found_0_1 = 0; // flag: blocks 0 and 1 were found uint8_t found_0_1 = 0; // flag: blocks 0 and 1 were found
int errors = 0; // error counter int errors = 0; // error counter
int tries = 0; // tries counter int tries = 0; // tries counter
memset(memory_blocks, 0, 8*17*sizeof(uint8_t)); memset(memory_blocks, 0, 8*17*sizeof(uint8_t));
memset(single_blocks, 0, 8*17*sizeof(uint8_t)); memset(single_blocks, 0, 8*17*sizeof(uint8_t));
int i = 0, j = 0; int i = 0, j = 0;
do { do {
i = 0; i = 0;
memset(tmp_blocks, 0, 4*16*sizeof(uint8_t)); memset(tmp_blocks, 0, 4*16*sizeof(uint8_t));
n = DemodPCF7931((uint8_t**)tmp_blocks); n = DemodPCF7931((uint8_t**)tmp_blocks);
if(!n) if(!n)
++errors; ++errors;
// exit if no block is received // exit if no block is received
if (errors >= 10 && found_blocks == 0 && single_blocks_cnt == 0) { if (errors >= 10 && found_blocks == 0 && single_blocks_cnt == 0) {
Dbprintf("Error, no tag or bad tag"); Dbprintf("Error, no tag or bad tag");
return; return;
} }
// exit if too many errors during reading // exit if too many errors during reading
if (tries > 50 && (2*errors > tries)) { if (tries > 50 && (2*errors > tries)) {
Dbprintf("Error reading the tag"); Dbprintf("Error reading the tag");
Dbprintf("Here is the partial content"); Dbprintf("Here is the partial content");
goto end; goto end;
} }
// our logic breaks if we don't get at least two blocks // our logic breaks if we don't get at least two blocks
if (n < 2) { if (n < 2) {
if (n == 0 || !memcmp(tmp_blocks[0], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16)) if (n == 0 || !memcmp(tmp_blocks[0], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16))
@ -219,12 +219,12 @@ void ReadPCF7931() {
} }
++tries; ++tries;
continue; continue;
} }
Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors); Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors);
i = 0; i = 0;
if(!found_0_1) { if(!found_0_1) {
while (i < n - 1) { while (i < n - 1) {
if (IsBlock0PCF7931(tmp_blocks[i]) && IsBlock1PCF7931(tmp_blocks[i+1])) { if (IsBlock0PCF7931(tmp_blocks[i]) && IsBlock1PCF7931(tmp_blocks[i+1])) {
found_0_1 = 1; found_0_1 = 1;
@ -234,9 +234,9 @@ void ReadPCF7931() {
// block 1 tells how many blocks are going to be sent // block 1 tells how many blocks are going to be sent
max_blocks = MAX((memory_blocks[1][14] & 0x7f), memory_blocks[1][15]) + 1; max_blocks = MAX((memory_blocks[1][14] & 0x7f), memory_blocks[1][15]) + 1;
found_blocks = 2; found_blocks = 2;
Dbprintf("Found blocks 0 and 1. PCF is transmitting %d blocks.", max_blocks); Dbprintf("Found blocks 0 and 1. PCF is transmitting %d blocks.", max_blocks);
// handle the following blocks // handle the following blocks
for (j = i + 2; j < n; ++j) { for (j = i + 2; j < n; ++j) {
memcpy(memory_blocks[found_blocks], tmp_blocks[j], 16); memcpy(memory_blocks[found_blocks], tmp_blocks[j], 16);
@ -297,14 +297,14 @@ void ReadPCF7931() {
Dbprintf("<missing block %d>", i); Dbprintf("<missing block %d>", i);
} }
Dbprintf("-----------------------------------------"); Dbprintf("-----------------------------------------");
if (found_blocks < max_blocks) { if (found_blocks < max_blocks) {
Dbprintf("-----------------------------------------"); Dbprintf("-----------------------------------------");
Dbprintf("Blocks with unknown position:"); Dbprintf("Blocks with unknown position:");
Dbprintf("-----------------------------------------"); Dbprintf("-----------------------------------------");
for (i = 0; i < single_blocks_cnt; ++i) for (i = 0; i < single_blocks_cnt; ++i)
print_result("Block", single_blocks[i], 16); print_result("Block", single_blocks[i], 16);
Dbprintf("-----------------------------------------"); Dbprintf("-----------------------------------------");
} }
cmd_send(CMD_ACK,0,0,0,0,0); cmd_send(CMD_ACK,0,0,0,0,0);
@ -332,42 +332,42 @@ static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int3
AddBytePCF7931(pass[6], tab, l, p); AddBytePCF7931(pass[6], tab, l, p);
//programming mode (0 or 1) //programming mode (0 or 1)
AddBitPCF7931(0, tab, l, p); AddBitPCF7931(0, tab, l, p);
//block adress on 6 bits //block adress on 6 bits
for (u = 0; u < 6; ++u) { for (u = 0; u < 6; ++u) {
if (address & (1 << u)) { // bit 1 if (address & (1 << u)) { // bit 1
++parity; ++parity;
AddBitPCF7931(1, tab, l, p); AddBitPCF7931(1, tab, l, p);
} else { // bit 0 } else { // bit 0
AddBitPCF7931(0, tab, l, p); AddBitPCF7931(0, tab, l, p);
} }
} }
//byte address on 4 bits //byte address on 4 bits
for (u = 0; u < 4; ++u) for (u = 0; u < 4; ++u)
{ {
if (byte & (1 << u)) { // bit 1 if (byte & (1 << u)) { // bit 1
parity++; parity++;
AddBitPCF7931(1, tab, l, p); AddBitPCF7931(1, tab, l, p);
} }
else // bit 0 else // bit 0
AddBitPCF7931(0, tab, l, p); AddBitPCF7931(0, tab, l, p);
} }
//data on 8 bits //data on 8 bits
for (u=0; u<8; u++) for (u=0; u<8; u++)
{ {
if (data&(1<<u)) { // bit 1 if (data&(1<<u)) { // bit 1
parity++; parity++;
AddBitPCF7931(1, tab, l, p); AddBitPCF7931(1, tab, l, p);
} }
else //bit 0 else //bit 0
AddBitPCF7931(0, tab, l, p); AddBitPCF7931(0, tab, l, p);
} }
//parity bit //parity bit
if ((parity % 2) == 0) if ((parity % 2) == 0)
AddBitPCF7931(0, tab, l, p); //even parity AddBitPCF7931(0, tab, l, p); //even parity
else else
AddBitPCF7931(1, tab, l, p);//odd parity AddBitPCF7931(1, tab, l, p);//odd parity
@ -394,20 +394,14 @@ static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int3
void BruteForcePCF7931(uint64_t password, uint8_t tries, uint16_t init_delay, int32_t l, int32_t p) { void BruteForcePCF7931(uint64_t password, uint8_t tries, uint16_t init_delay, int32_t l, int32_t p) {
uint8_t i = 0; uint8_t i = 0;
uint8_t pass_array[7]; uint8_t pass_array[7];
while (password < 0x00FFFFFFFFFFFFFF) { while (password < 0x00FFFFFFFFFFFFFF) {
if (BUTTON_PRESS()) { if (BUTTON_PRESS()) {
Dbprintf("Button pressed, stopping bruteforce ..."); Dbprintf("Button pressed, stopping bruteforce ...");
return; return;
} }
pass_array[0] = password & 0xFF; num_to_bytes(password, 7, pass_array);
pass_array[1] = (password >> 8) & 0xFF;
pass_array[2] = (password >> 16) & 0xFF;
pass_array[3] = (password >> 24) & 0xFF;
pass_array[4] = (password >> 32) & 0xFF;
pass_array[5] = (password >> 40) & 0xFF;
pass_array[6] = (password >> 48) & 0xFF;
Dbprintf("Trying: %02x %02x %02x %02x %02x %02x %02x ...", Dbprintf("Trying: %02x %02x %02x %02x %02x %02x %02x ...",
pass_array[0], pass_array[0],
@ -417,7 +411,7 @@ void BruteForcePCF7931(uint64_t password, uint8_t tries, uint16_t init_delay, in
pass_array[4], pass_array[4],
pass_array[5], pass_array[5],
pass_array[6]); pass_array[6]);
for (i = 0; i < tries; ++i) for (i = 0; i < tries; ++i)
RealWritePCF7931 RealWritePCF7931
( (
@ -429,15 +423,15 @@ void BruteForcePCF7931(uint64_t password, uint8_t tries, uint16_t init_delay, in
7, 7,
0x01 0x01
); );
++password; ++password;
} }
} }
/* Write on a byte of a PCF7931 tag /* Write on a byte of a PCF7931 tag
* @param address : address of the block to write * @param address : address of the block to write
@param byte : address of the byte to write @param byte : address of the byte to write
@param data : data to write @param data : data to write
*/ */
void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) { void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) {
Dbprintf("Initialization delay : %d us", init_delay); Dbprintf("Initialization delay : %d us", init_delay);
@ -446,9 +440,9 @@ void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, ui
Dbprintf("Block address : %02x", address); Dbprintf("Block address : %02x", address);
Dbprintf("Byte address : %02x", byte); Dbprintf("Byte address : %02x", byte);
Dbprintf("Data : %02x", data); Dbprintf("Data : %02x", data);
uint8_t password[7] = {pass1, pass2, pass3, pass4, pass5, pass6, pass7}; uint8_t password[7] = {pass1, pass2, pass3, pass4, pass5, pass6, pass7};
RealWritePCF7931 (password, init_delay, l, p, address, byte, data); RealWritePCF7931 (password, init_delay, l, p, address, byte, data);
} }
@ -488,7 +482,7 @@ void SendCmdPCF7931(uint32_t * tab) {
HIGH(GPIO_SSC_DOUT); HIGH(GPIO_SSC_DOUT);
while(tempo != tab[u]) while(tempo != tab[u])
tempo = AT91C_BASE_TC0->TC_CV; tempo = AT91C_BASE_TC0->TC_CV;
// stop modulating antenna // stop modulating antenna
LOW(GPIO_SSC_DOUT); LOW(GPIO_SSC_DOUT);
while(tempo != tab[u+1]) while(tempo != tab[u+1])
@ -510,7 +504,7 @@ void SendCmdPCF7931(uint32_t * tab) {
} }
/* Add a byte for building the data frame of PCF7931 tags /* Add a byte for building the data frame of PCF7931 tags
* @param b : byte to add * @param b : byte to add
* @param tab : array of the data frame * @param tab : array of the data frame
* @param l : offset on low pulse width * @param l : offset on low pulse width
@ -519,7 +513,7 @@ void SendCmdPCF7931(uint32_t * tab) {
bool AddBytePCF7931(uint8_t byte, uint32_t * tab, int32_t l, int32_t p) { bool AddBytePCF7931(uint8_t byte, uint32_t * tab, int32_t l, int32_t p) {
uint32_t u; uint32_t u;
for (u = 0; u < 8; ++u) { for (u = 0; u < 8; ++u) {
if (byte & (1 << u)) { //bit is 1 if (byte & (1 << u)) { //bit is 1
if(AddBitPCF7931(1, tab, l, p)==1)return 1; if(AddBitPCF7931(1, tab, l, p)==1)return 1;
} else { //bit is 0 } else { //bit is 0
if(AddBitPCF7931(0, tab, l, p)==1)return 1; if(AddBitPCF7931(0, tab, l, p)==1)return 1;
@ -529,7 +523,7 @@ bool AddBytePCF7931(uint8_t byte, uint32_t * tab, int32_t l, int32_t p) {
return 0; return 0;
} }
/* Add a bits for building the data frame of PCF7931 tags /* Add a bits for building the data frame of PCF7931 tags
* @param b : bit to add * @param b : bit to add
* @param tab : array of the data frame * @param tab : array of the data frame
* @param l : offset on low pulse width * @param l : offset on low pulse width
@ -540,23 +534,23 @@ bool AddBitPCF7931(bool b, uint32_t * tab, int32_t l, int32_t p) {
for (u = 0; tab[u] != 0; u += 3){} //we put the cursor at the last value of the array for (u = 0; tab[u] != 0; u += 3){} //we put the cursor at the last value of the array
if (b == 1) { //add a bit 1 if (b == 1) { //add a bit 1
if (u == 0) tab[u] = 34 * T0_PCF + p; if (u == 0) tab[u] = 34 * T0_PCF + p;
else tab[u] = 34 * T0_PCF + tab[u-1] + p; else tab[u] = 34 * T0_PCF + tab[u-1] + p;
tab[u+1] = 6 * T0_PCF+tab[u] + l; tab[u+1] = 6 * T0_PCF+tab[u] + l;
tab[u+2] = 88 * T0_PCF+tab[u + 1] - l - p; tab[u+2] = 88 * T0_PCF+tab[u + 1] - l - p;
return 0; return 0;
} else { //add a bit 0 } else { //add a bit 0
if (u == 0) tab[u] = 98 * T0_PCF + p; if (u == 0) tab[u] = 98 * T0_PCF + p;
else tab[u] = 98 * T0_PCF + tab[u-1] + p; else tab[u] = 98 * T0_PCF + tab[u-1] + p;
tab[u + 1] = 6 * T0_PCF + tab[u] + l; tab[u + 1] = 6 * T0_PCF + tab[u] + l;
tab[u + 2] = 24 * T0_PCF + tab[u + 1] - l - p; tab[u + 2] = 24 * T0_PCF + tab[u + 1] - l - p;
return 0; return 0;
} }
return 1; return 1;
} }
@ -570,8 +564,8 @@ bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t * tab) {
uint32_t u = 0; uint32_t u = 0;
for(u = 0; tab[u] != 0; u += 3){} //we put the cursor at the last value of the array for(u = 0; tab[u] != 0; u += 3){} //we put the cursor at the last value of the array
if (u == 0) tab[u] = a; if (u == 0) tab[u] = a;
else tab[u] = a + tab[u - 1]; else tab[u] = a + tab[u - 1];
tab[u + 1] = b + tab[u]; tab[u + 1] = b + tab[u];
tab[u + 2] = c + tab[u + 1]; tab[u + 2] = c + tab[u + 1];

View file

@ -1,7 +1,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012 Chalk <chalk.secu at gmail.com> // Copyright (C) 2012 Chalk <chalk.secu at gmail.com>
// 2015 Dake <thomas.cayrou at gmail.com> // 2015 Dake <thomas.cayrou at gmail.com>
// 2018 sguerrini97 <sguerrini97 at gmail.com> // 2018 sguerrini97 <sguerrini97 at gmail.com>
// This code is licensed to you under the terms of the GNU GPL, version 2 or, // This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of // at your option, any later version. See the LICENSE.txt file for the text of
@ -33,7 +33,7 @@ static int CmdHelp(const char *Cmd);
struct pcf7931_config configPcf = { struct pcf7931_config configPcf = {
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
PCF7931_DEFAULT_INITDELAY, PCF7931_DEFAULT_INITDELAY,
PCF7931_DEFAULT_OFFSET_WIDTH, PCF7931_DEFAULT_OFFSET_WIDTH,
PCF7931_DEFAULT_OFFSET_POSITION PCF7931_DEFAULT_OFFSET_POSITION
}; };
@ -41,8 +41,8 @@ struct pcf7931_config configPcf = {
int pcf7931_resetConfig(){ int pcf7931_resetConfig(){
memset(configPcf.Pwd, 0xFF, sizeof(configPcf.Pwd) ); memset(configPcf.Pwd, 0xFF, sizeof(configPcf.Pwd) );
configPcf.InitDelay = PCF7931_DEFAULT_INITDELAY; configPcf.InitDelay = PCF7931_DEFAULT_INITDELAY;
configPcf.OffsetWidth = PCF7931_DEFAULT_OFFSET_WIDTH; configPcf.OffsetWidth = PCF7931_DEFAULT_OFFSET_WIDTH;
configPcf.OffsetPosition = PCF7931_DEFAULT_OFFSET_POSITION; configPcf.OffsetPosition = PCF7931_DEFAULT_OFFSET_POSITION;
return 0; return 0;
} }
@ -103,7 +103,7 @@ int usage_pcf7931_config(){
PrintAndLog(" pwd Password, hex, 7bytes, LSB-order"); PrintAndLog(" pwd Password, hex, 7bytes, LSB-order");
PrintAndLog(" delay Tag initialization delay (in us) decimal"); PrintAndLog(" delay Tag initialization delay (in us) decimal");
PrintAndLog(" offset Low pulses width (in us) decimal"); PrintAndLog(" offset Low pulses width (in us) decimal");
PrintAndLog(" offset Low pulses position (in us) decimal"); PrintAndLog(" offset Low pulses position (in us) decimal");
PrintAndLog("Examples:"); PrintAndLog("Examples:");
PrintAndLog(" lf pcf7931 config"); PrintAndLog(" lf pcf7931 config");
PrintAndLog(" lf pcf7931 config r"); PrintAndLog(" lf pcf7931 config r");
@ -112,7 +112,7 @@ int usage_pcf7931_config(){
return 0; return 0;
} }
int CmdLFPCF7931Read(const char *Cmd){ int CmdLFPCF7931Read(const char *Cmd){
uint8_t ctmp = param_getchar(Cmd, 0); uint8_t ctmp = param_getchar(Cmd, 0);
if ( ctmp == 'H' || ctmp == 'h' ) return usage_pcf7931_read(); if ( ctmp == 'H' || ctmp == 'h' ) return usage_pcf7931_read();
@ -128,12 +128,12 @@ int CmdLFPCF7931Read(const char *Cmd){
return 0; return 0;
} }
int CmdLFPCF7931Config(const char *Cmd){ int CmdLFPCF7931Config(const char *Cmd){
uint8_t ctmp = param_getchar(Cmd, 0); uint8_t ctmp = param_getchar(Cmd, 0);
if ( ctmp == 0) return pcf7931_printConfig(); if ( ctmp == 0) return pcf7931_printConfig();
if ( ctmp == 'H' || ctmp == 'h' ) return usage_pcf7931_config(); if ( ctmp == 'H' || ctmp == 'h' ) return usage_pcf7931_config();
if ( ctmp == 'R' || ctmp == 'r' ) return pcf7931_resetConfig(); if ( ctmp == 'R' || ctmp == 'r' ) return pcf7931_resetConfig();
if ( param_gethex(Cmd, 0, configPcf.Pwd, 14) ) return usage_pcf7931_config(); if ( param_gethex(Cmd, 0, configPcf.Pwd, 14) ) return usage_pcf7931_config();
@ -148,17 +148,17 @@ int CmdLFPCF7931Config(const char *Cmd){
int CmdLFPCF7931Write(const char *Cmd){ int CmdLFPCF7931Write(const char *Cmd){
uint8_t ctmp = param_getchar(Cmd, 0); uint8_t ctmp = param_getchar(Cmd, 0);
if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_pcf7931_write(); if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_pcf7931_write();
uint8_t block = 0, bytepos = 0, data = 0; uint8_t block = 0, bytepos = 0, data = 0;
if ( param_getdec(Cmd, 0, &block) ) return usage_pcf7931_write(); if ( param_getdec(Cmd, 0, &block) ) return usage_pcf7931_write();
if ( param_getdec(Cmd, 1, &bytepos) ) return usage_pcf7931_write(); if ( param_getdec(Cmd, 1, &bytepos) ) return usage_pcf7931_write();
if ( (block > 7) || (bytepos > 15) ) return usage_pcf7931_write(); if ( (block > 7) || (bytepos > 15) ) return usage_pcf7931_write();
data = param_get8ex(Cmd, 2, 0, 16); data = param_get8ex(Cmd, 2, 0, 16);
PrintAndLog("Writing block: %d", block); PrintAndLog("Writing block: %d", block);
PrintAndLog(" pos: %d", bytepos); PrintAndLog(" pos: %d", bytepos);
PrintAndLog(" data: 0x%02X", data); PrintAndLog(" data: 0x%02X", data);
@ -178,27 +178,27 @@ int CmdLFPCF7931Write(const char *Cmd){
int CmdLFPCF7931BruteForce(const char *Cmd){ int CmdLFPCF7931BruteForce(const char *Cmd){
uint8_t ctmp = param_getchar(Cmd, 0); uint8_t ctmp = param_getchar(Cmd, 0);
if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_pcf7931_bruteforce(); if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_pcf7931_bruteforce();
uint64_t start_password = 0; uint8_t start_password[7] = {0};
uint8_t tries = 3; uint8_t tries = 3;
if (param_gethex(Cmd, 0, (uint8_t*)(&start_password), 14)) return usage_pcf7931_bruteforce(); if (param_gethex(Cmd, 0, start_password, 14)) return usage_pcf7931_bruteforce();
if (param_getdec(Cmd, 1, &tries)) return usage_pcf7931_bruteforce(); if (param_getdec(Cmd, 1, &tries)) return usage_pcf7931_bruteforce();
PrintAndLog("Bruteforcing from password: %02x %02x %02x %02x %02x %02x %02x", PrintAndLog("Bruteforcing from password: %02x %02x %02x %02x %02x %02x %02x",
start_password & 0xFF, start_password[0],
(start_password >> 8) & 0xFF, start_password[1],
(start_password >> 16) & 0xFF, start_password[2],
(start_password >> 24) & 0xFF, start_password[3],
(start_password >> 32) & 0xFF, start_password[4],
(start_password >> 48) & 0xFF, start_password[5],
(start_password >> 56) & 0xFF); start_password[6]);
PrintAndLog("Trying each password %d times", tries); PrintAndLog("Trying each password %d times", tries);
UsbCommand c = {CMD_PCF7931_BRUTEFORCE, {start_password, tries} }; UsbCommand c = {CMD_PCF7931_BRUTEFORCE, {bytes_to_num(start_password, 7), tries} };
c.d.asDwords[7] = (configPcf.OffsetWidth + 128); c.d.asDwords[7] = (configPcf.OffsetWidth + 128);
c.d.asDwords[8] = (configPcf.OffsetPosition + 128); c.d.asDwords[8] = (configPcf.OffsetPosition + 128);
c.d.asDwords[9] = configPcf.InitDelay; c.d.asDwords[9] = configPcf.InitDelay;
@ -209,7 +209,7 @@ int CmdLFPCF7931BruteForce(const char *Cmd){
return 0; return 0;
} }
static command_t CommandTable[] = static command_t CommandTable[] =
{ {
{"help", CmdHelp, 1, "This help"}, {"help", CmdHelp, 1, "This help"},
{"read", CmdLFPCF7931Read, 0, "Read content of a PCF7931 transponder"}, {"read", CmdLFPCF7931Read, 0, "Read content of a PCF7931 transponder"},