mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
Merge branch 'master' into smartcard-relay
This commit is contained in:
commit
4e346e8ca2
159 changed files with 10035 additions and 2880 deletions
|
@ -22,6 +22,7 @@
|
|||
#include "cmdsmartcard.h"
|
||||
#include "ui.h"
|
||||
#include "util.h"
|
||||
#include "commonutil.h"
|
||||
|
||||
#define CARD_INS_DECRYPT 0x01
|
||||
#define CARD_INS_ENCRYPT 0x02
|
||||
|
@ -60,39 +61,48 @@ bool IsCardHelperPresent(bool verbose) {
|
|||
bool IsHIDSamPresent(bool verbose) {
|
||||
|
||||
if (IfPm3Smartcard() == false) {
|
||||
PrintAndLogEx(WARNING, "Proxmark3 does not have SMARTCARD support enabled, exiting");
|
||||
return false;
|
||||
}
|
||||
|
||||
// detect SAM
|
||||
smart_card_atr_t card;
|
||||
smart_select(verbose, &card);
|
||||
if (!card.atr_len) {
|
||||
if (card.atr_len == 0) {
|
||||
PrintAndLogEx(ERR, "Can't get ATR from a smart card");
|
||||
return false;
|
||||
}
|
||||
|
||||
// SAM identification
|
||||
uint8_t sam_atr[] = {0x3B, 0x95, 0x96, 0x80, 0xB1, 0xFE, 0x55, 0x1F, 0xC7, 0x47, 0x72, 0x61, 0x63, 0x65, 0x13};
|
||||
if (memcmp(card.atr, sam_atr, card.atr_len) < 0) {
|
||||
|
||||
uint8_t sam_atr2[] = {0x3b, 0x90, 0x96, 0x91, 0x81, 0xb1, 0xfe, 0x55, 0x1f, 0xc7, 0xd4};
|
||||
if (memcmp(card.atr, sam_atr2, card.atr_len) < 0) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(SUCCESS, "Not detecting a SAM");
|
||||
}
|
||||
return false;
|
||||
smart_card_atr_t supported[] = {
|
||||
{15, {0x3B, 0x95, 0x96, 0x80, 0xB1, 0xFE, 0x55, 0x1F, 0xC7, 0x47, 0x72, 0x61, 0x63, 0x65, 0x13}},
|
||||
{11, {0x3b, 0x90, 0x96, 0x91, 0x81, 0xb1, 0xfe, 0x55, 0x1f, 0xc7, 0xd4}},
|
||||
};
|
||||
bool found = false;
|
||||
for (int i = 0; i < ARRAYLEN(supported); i++) {
|
||||
if ((card.atr_len == supported[i].atr_len) &&
|
||||
(memcmp(card.atr, supported[i].atr, supported[i].atr_len) == 0)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Suspect some SAMs has version name in their ATR
|
||||
uint8_t T0 = card.atr[1];
|
||||
uint8_t K = T0 & 0x0F;
|
||||
if (K > 4 && verbose) {
|
||||
if (byte_strstr(card.atr, card.atr_len, (const uint8_t *)"Grace", 5) > -1) {
|
||||
PrintAndLogEx(SUCCESS, "SAM (Grace) detected");
|
||||
} else if (byte_strstr(card.atr, card.atr_len, (const uint8_t *)"Hopper", 6) > -1) {
|
||||
PrintAndLogEx(SUCCESS, "SAM (Hopper) detected");
|
||||
if (found == false) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(SUCCESS, "Not detecting a SAM");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Suspect some SAMs has version name in the historical bytes
|
||||
uint8_t T0 = card.atr[1];
|
||||
uint8_t K = T0 & 0x0F; // Number of historical bytes
|
||||
if (K > 0 && (K < (card.atr_len - 3)) && verbose) {
|
||||
// Last byte of ATR is CRC and before that we have K bytes of
|
||||
// "historical bytes".
|
||||
// By construction K can't go above 15
|
||||
char sam_name[16] = {0};
|
||||
memcpy(sam_name, &card.atr[card.atr_len - 1 - K], K);
|
||||
PrintAndLogEx(SUCCESS, "SAM (%s) detected", sam_name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -485,3 +485,45 @@ void reverse_array_copy(const uint8_t *src, int src_len, uint8_t *dest) {
|
|||
dest[i] = src[(src_len - 1) - i];
|
||||
}
|
||||
}
|
||||
|
||||
static int hexchar_to_dec(char ch) {
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
return ch - '0';
|
||||
}
|
||||
if (ch >= 'a' && ch <= 'f') {
|
||||
return ch - 'a' + 10;
|
||||
}
|
||||
if (ch >= 'A' && ch <= 'F') {
|
||||
return ch - 'A' + 10;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// no spaces allowed for input hex string
|
||||
bool hexstr_to_byte_array(const char *hexstr, uint8_t *d, size_t *n) {
|
||||
|
||||
size_t hexstr_len = strlen(hexstr);
|
||||
if (hexstr_len & 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*n = (hexstr_len >> 1);
|
||||
|
||||
for (int i = 0; i < *n; i++) {
|
||||
|
||||
char c1 = *hexstr++;
|
||||
char c2 = *hexstr++;
|
||||
|
||||
if (c1 == '\0' || c2 == '\0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
int b = (hexchar_to_dec(c1) << 4) | hexchar_to_dec(c2);
|
||||
if (b < 0) {
|
||||
// Error: invalid hex character
|
||||
return false;
|
||||
}
|
||||
d[i] = (uint8_t) b;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -109,4 +109,5 @@ uint16_t get_sw(const uint8_t *d, uint16_t n);
|
|||
void reverse_array(uint8_t *d, size_t n);
|
||||
void reverse_array_copy(const uint8_t *src, int src_len, uint8_t *dest);
|
||||
|
||||
bool hexstr_to_byte_array(const char *hexstr, uint8_t *d, size_t *n);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue