added login function

This commit is contained in:
tharexde 2020-09-27 23:22:51 +02:00
commit 2e5cf12d7d
7 changed files with 88 additions and 25 deletions

View file

@ -1041,6 +1041,10 @@ static void PacketReceived(PacketCommandNG *packet) {
em4x50_brute((em4x50_data_t *)packet->data.asBytes); em4x50_brute((em4x50_data_t *)packet->data.asBytes);
break; break;
} }
case CMD_LF_EM4X50_LOGIN: {
em4x50_login((em4x50_data_t *)packet->data.asBytes);
break;
}
#endif #endif
#ifdef WITH_ISO15693 #ifdef WITH_ISO15693

View file

@ -1184,3 +1184,30 @@ void em4x50_brute(em4x50_data_t *etd) {
lf_finalize(); lf_finalize();
reply_ng(CMD_ACK, bsuccess, (uint8_t *)(&pwd), 32); reply_ng(CMD_ACK, bsuccess, (uint8_t *)(&pwd), 32);
} }
void em4x50_login(em4x50_data_t *etd) {
// login into EM4x50
uint8_t status = 0;
uint8_t bytes[4] = {0x0, 0x0, 0x0, 0x0};
uint32_t rpwd = 0x0;
em4x50_setup_read();
// set gHigh and gLow
if (get_signalproperties() && find_em4x50_tag()) {
// lsb -> msb
rpwd = reflect32(etd->login_password);
// convert to "old" data format
for (int i = 0; i < 4; i++)
bytes[i] = (rpwd >> ((3 - i) * 8)) & 0xFF;
status = login(bytes);
}
lf_finalize();
reply_ng(CMD_ACK, status, 0, 0);
}

View file

@ -27,5 +27,6 @@ void em4x50_write_password(em4x50_data_t *etd);
void em4x50_read(em4x50_data_t *etd); void em4x50_read(em4x50_data_t *etd);
void em4x50_wipe(em4x50_data_t *etd); void em4x50_wipe(em4x50_data_t *etd);
void em4x50_brute(em4x50_data_t *etd); void em4x50_brute(em4x50_data_t *etd);
void em4x50_login(em4x50_data_t *etd);
#endif /* EM4X50_H */ #endif /* EM4X50_H */

View file

@ -1399,6 +1399,7 @@ static command_t CommandTable[] = {
{"4x50_read", CmdEM4x50Read, IfPm3EM4x50, "read word data from EM4x50"}, {"4x50_read", CmdEM4x50Read, IfPm3EM4x50, "read word data from EM4x50"},
{"4x50_wipe", CmdEM4x50Wipe, IfPm3EM4x50, "wipe data from EM4x50"}, {"4x50_wipe", CmdEM4x50Wipe, IfPm3EM4x50, "wipe data from EM4x50"},
{"4x50_brute", CmdEM4x50Brute, IfPm3EM4x50, "guess password of EM4x50"}, {"4x50_brute", CmdEM4x50Brute, IfPm3EM4x50, "guess password of EM4x50"},
{"4x50_login", CmdEM4x50Login, IfPm3EM4x50, "login into EM4x50"},
{NULL, NULL, NULL, NULL} {NULL, NULL, NULL, NULL}
}; };

View file

@ -97,31 +97,6 @@ static int usage_lf_em4x50_wipe(void) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int usage_lf_em4x50_sim(void) {
PrintAndLogEx(NORMAL, "Simulate EM4x50 tag. ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_sim [h] w <word>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h - this help");
PrintAndLogEx(NORMAL, " w <word> - word (hex)");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_sim w 12345678"));
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
static int usage_lf_em4x50_test(void) {
PrintAndLogEx(NORMAL, "Test functionality for EM4x50 tag. ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_test [h] ...");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h - this help");
PrintAndLogEx(NORMAL, " c <0|1> - carrier on|off (optional)");
PrintAndLogEx(NORMAL, " b <byte> - byte (hex) (optional)");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_test ..."));
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
static int usage_lf_em4x50_brute(void) { static int usage_lf_em4x50_brute(void) {
PrintAndLogEx(NORMAL, "Guess password of EM4x50 tag. Tag must be on antenna. "); PrintAndLogEx(NORMAL, "Guess password of EM4x50 tag. Tag must be on antenna. ");
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
@ -135,6 +110,18 @@ static int usage_lf_em4x50_brute(void) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int usage_lf_em4x50_login(void) {
PrintAndLogEx(NORMAL, "Login into EM4x50 tag. Tag must be on antenna. ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_login [h] p <pwd>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h - this help");
PrintAndLogEx(NORMAL, " p <pwd> - password (hex, lsb notation)");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_login p 11200000"));
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t *words) { static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t *words) {
@ -841,3 +828,44 @@ int CmdEM4x50Brute(const char *Cmd) {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
int CmdEM4x50Login(const char *Cmd) {
bool errors = false, pwd_given = false;
uint8_t cmdp = 0;
em4x50_data_t etd;
PacketResponseNG resp;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) {
case 'h':
return usage_lf_em4x50_login();
case 'p':
etd.login_password = param_get32ex(Cmd, cmdp + 1, 0, 16);
pwd_given = true;
cmdp += 2;
break;
default:
PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
errors = true;
break;
}
}
if (errors || !pwd_given)
return usage_lf_em4x50_login();
// start
clearCommandBuffer();
SendCommandNG(CMD_LF_EM4X50_LOGIN, (uint8_t *)&etd, sizeof(etd));
WaitForResponse(CMD_ACK, &resp);
// print response
if ((bool)resp.status)
PrintAndLogEx(NORMAL, "\nlogin " _GREEN_("ok") "\n");
else
PrintAndLogEx(NORMAL, "\nlogin " _RED_("failed") "\n");
return PM3_SUCCESS;
}

View file

@ -25,5 +25,6 @@ int CmdEM4x50Read(const char *Cmd);
int CmdEM4x50Dump(const char *Cmd); int CmdEM4x50Dump(const char *Cmd);
int CmdEM4x50Wipe(const char *Cmd); int CmdEM4x50Wipe(const char *Cmd);
int CmdEM4x50Brute(const char *Cmd); int CmdEM4x50Brute(const char *Cmd);
int CmdEM4x50Login(const char *Cmd);
#endif #endif

View file

@ -494,6 +494,7 @@ typedef struct {
#define CMD_LF_EM4X50_READ 0x0243 #define CMD_LF_EM4X50_READ 0x0243
#define CMD_LF_EM4X50_WIPE 0x0244 #define CMD_LF_EM4X50_WIPE 0x0244
#define CMD_LF_EM4X50_BRUTE 0x0245 #define CMD_LF_EM4X50_BRUTE 0x0245
#define CMD_LF_EM4X50_LOGIN 0x0246
// Sampling configuration for LF reader/sniffer // Sampling configuration for LF reader/sniffer
#define CMD_LF_SAMPLING_SET_CONFIG 0x021D #define CMD_LF_SAMPLING_SET_CONFIG 0x021D
#define CMD_LF_FSK_SIMULATE 0x021E #define CMD_LF_FSK_SIMULATE 0x021E