CHG: 'lf t55xx recoverpw" - added the possibility to cancel the command when pressing 'enter' key.

This commit is contained in:
iceman1001 2017-01-18 11:27:17 +01:00
parent 243f899b92
commit bf35008962

View file

@ -150,6 +150,7 @@ int usage_t55xx_wakup(){
int usage_t55xx_bruteforce(){ int usage_t55xx_bruteforce(){
PrintAndLog("This command uses A) bruteforce to scan a number range"); PrintAndLog("This command uses A) bruteforce to scan a number range");
PrintAndLog(" B) a dictionary attack"); PrintAndLog(" B) a dictionary attack");
PrintAndLog("press 'enter' to cancel the command");
PrintAndLog("Usage: lf t55xx bruteforce [h] <start password> <end password> [i <*.dic>]"); PrintAndLog("Usage: lf t55xx bruteforce [h] <start password> <end password> [i <*.dic>]");
PrintAndLog(" password must be 4 bytes (8 hex symbols)"); PrintAndLog(" password must be 4 bytes (8 hex symbols)");
PrintAndLog("Options:"); PrintAndLog("Options:");
@ -166,6 +167,7 @@ int usage_t55xx_bruteforce(){
} }
int usage_t55xx_recoverpw(){ int usage_t55xx_recoverpw(){
PrintAndLog("This command uses a few tricks to try to recover mangled password"); PrintAndLog("This command uses a few tricks to try to recover mangled password");
PrintAndLog("press 'enter' to cancel the command");
PrintAndLog("WARNING: this may brick non-password protected chips!"); PrintAndLog("WARNING: this may brick non-password protected chips!");
PrintAndLog("Usage: lf t55xx recoverpw [password]"); PrintAndLog("Usage: lf t55xx recoverpw [password]");
PrintAndLog(" password must be 4 bytes (8 hex symbols)"); PrintAndLog(" password must be 4 bytes (8 hex symbols)");
@ -1474,13 +1476,22 @@ int CmdT55xxWipe(const char *Cmd) {
return 0; return 0;
} }
bool IsCancelled(void) {
if (ukbhit()) {
int ch = getchar();
(void)ch;
printf("\naborted via keyboard!\n");
return TRUE;
}
return FALSE;
}
int CmdT55xxBruteForce(const char *Cmd) { int CmdT55xxBruteForce(const char *Cmd) {
// load a default pwd file. // load a default pwd file.
char buf[9]; char buf[9];
char filename[FILE_PATH_SIZE]={0}; char filename[FILE_PATH_SIZE]={0};
int keycnt = 0; int keycnt = 0;
int ch;
uint8_t stKeyBlock = 20; uint8_t stKeyBlock = 20;
uint8_t *keyBlock = NULL, *p = NULL; uint8_t *keyBlock = NULL, *p = NULL;
uint32_t start_password = 0x00000000; //start password uint32_t start_password = 0x00000000; //start password
@ -1561,10 +1572,7 @@ int CmdT55xxBruteForce(const char *Cmd) {
return 2; return 2;
} }
if (ukbhit()) { if (IsCancelled()) {
ch = getchar();
(void)ch;
printf("\naborted via keyboard!\n");
free(keyBlock); free(keyBlock);
return 0; return 0;
} }
@ -1610,10 +1618,8 @@ int CmdT55xxBruteForce(const char *Cmd) {
printf("."); printf(".");
fflush(stdout); fflush(stdout);
if (ukbhit()) {
ch = getchar(); if (IsCancelled()) {
(void)ch;
printf("\naborted via keyboard!\n");
free(keyBlock); free(keyBlock);
return 0; return 0;
} }
@ -1675,6 +1681,8 @@ int CmdT55xxRecoverPW(const char *Cmd) {
else if (found == -1) else if (found == -1)
return 0; return 0;
bit++; bit++;
if (IsCancelled()) return 0;
} }
// now try to use partial original password, since block 7 should have been completely // now try to use partial original password, since block 7 should have been completely
@ -1697,7 +1705,9 @@ int CmdT55xxRecoverPW(const char *Cmd) {
else if (found == -1) else if (found == -1)
return 0; return 0;
bit++; bit++;
prev_password=curr_password; prev_password = curr_password;
if (IsCancelled()) return 0;
} }
// from high bit to low // from high bit to low
@ -1717,7 +1727,9 @@ int CmdT55xxRecoverPW(const char *Cmd) {
else if (found == -1) else if (found == -1)
return 0; return 0;
bit++; bit++;
prev_password=curr_password; prev_password = curr_password;
if (IsCancelled()) return 0;
} }
done: done:
PrintAndLog(""); PrintAndLog("");