This commit is contained in:
osboxes.org 2019-03-14 12:30:32 +01:00
commit 9c2736d1eb
14 changed files with 273 additions and 273 deletions

View file

@ -953,7 +953,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers // TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK; AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger, // TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
// external trigger rising edge, load RA on rising edge of TIOA. // external trigger rising edge, load RA on rising edge of TIOA.
@ -1159,7 +1159,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers // TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK; AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger, // TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
// external trigger rising edge, load RA on falling edge of TIOA. // external trigger rising edge, load RA on falling edge of TIOA.
@ -1414,7 +1414,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers // TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK; AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
// TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger, // TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
// external trigger rising edge, load RA on falling edge of TIOA. // external trigger rising edge, load RA on falling edge of TIOA.

View file

@ -255,7 +255,7 @@ static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len) {
// Send the content of the frame // Send the content of the frame
for (size_t i = 0; i < frame_len; i++) { for (size_t i = 0; i < frame_len; i++) {
// if (frame[0] == 0xf8) { // if (frame[0] == 0xf8) {
//Dbprintf("BIT: %d",(frame[i / 8] >> (7 - (i % 8))) & 1); //Dbprintf("BIT: %d",(frame[i / 8] >> (7 - (i % 8))) & 1);
// } // }
hitag_reader_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1); hitag_reader_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1);
} }
@ -376,11 +376,11 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
temp2++; temp2++;
*txlen = 32; *txlen = 32;
state = _hitag2_init(REV64(tag.key), state = _hitag2_init(REV64(tag.key),
REV32(tag.pages[0][0]), REV32(tag.pages[0][0]),
REV32(((rx[3] << 24) + (rx[2] << 16) + (rx[1] << 8) + rx[0])) REV32(((rx[3] << 24) + (rx[2] << 16) + (rx[1] << 8) + rx[0]))
); );
Dbprintf(",{0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}", Dbprintf(",{0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}",
rx[0], rx[1], rx[2], rx[3], rx[4], rx[5], rx[6], rx[7]); rx[0], rx[1], rx[2], rx[3], rx[4], rx[5], rx[6], rx[7]);
switch (tag.mode) { switch (tag.mode) {
case HT_STANDARD: case HT_STANDARD:
@ -681,40 +681,40 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
break; break;
} }
uid1 = (uid[0] << 7) uid1 = (uid[0] << 7)
| (uid[1] << 6) | (uid[1] << 6)
| (uid[2] << 5) | (uid[2] << 5)
| (uid[3] << 4) | (uid[3] << 4)
| (uid[4] << 3) | (uid[4] << 3)
| (uid[5] << 2) | (uid[5] << 2)
| (uid[6] << 1) | (uid[6] << 1)
| uid[7]; | uid[7];
uid2 = (uid[8] << 7) uid2 = (uid[8] << 7)
| (uid[9] << 6) | (uid[9] << 6)
| (uid[10] << 5) | (uid[10] << 5)
| (uid[11] << 4) | (uid[11] << 4)
| (uid[12] << 3) | (uid[12] << 3)
| (uid[13] << 2) | (uid[13] << 2)
| (uid[14] << 1) | (uid[14] << 1)
| uid[15]; | uid[15];
uid3 = (uid[16] << 7) uid3 = (uid[16] << 7)
| (uid[17] << 6) | (uid[17] << 6)
| (uid[18] << 5) | (uid[18] << 5)
| (uid[19] << 4) | (uid[19] << 4)
| (uid[20] << 3) | (uid[20] << 3)
| (uid[21] << 2) | (uid[21] << 2)
| (uid[22] << 1) | (uid[22] << 1)
| uid[23]; | uid[23];
uid4 = (uid[24] << 7) uid4 = (uid[24] << 7)
| (uid[25] << 6) | (uid[25] << 6)
| (uid[26] << 5) | (uid[26] << 5)
| (uid[27] << 4) | (uid[27] << 4)
| (uid[28] << 3) | (uid[28] << 3)
| (uid[29] << 2) | (uid[29] << 2)
| (uid[30] << 1) | (uid[30] << 1)
| uid[31]; | uid[31];
if (DEBUG) if (DEBUG)
Dbprintf("UID: %02X %02X %02X %02X", uid1, uid2, uid3, uid4); Dbprintf("UID: %02X %02X %02X %02X", uid1, uid2, uid3, uid4);
@ -752,13 +752,13 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
k = 0; k = 0;
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
tx[i] = (response_bit[k] << 7) tx[i] = (response_bit[k] << 7)
| (response_bit[k + 1] << 6) | (response_bit[k + 1] << 6)
| (response_bit[k + 2] << 5) | (response_bit[k + 2] << 5)
| (response_bit[k + 3] << 4) | (response_bit[k + 3] << 4)
| (response_bit[k + 4] << 3) | (response_bit[k + 4] << 3)
| (response_bit[k + 5] << 2) | (response_bit[k + 5] << 2)
| (response_bit[k + 6] << 1) | (response_bit[k + 6] << 1)
| response_bit[k + 7]; | response_bit[k + 7];
k += 8; k += 8;
} }
@ -1008,7 +1008,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers // TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK; AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger, // TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
// external trigger rising edge, load RA on rising edge of TIOA. // external trigger rising edge, load RA on rising edge of TIOA.
@ -1208,7 +1208,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers // TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK; AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
// TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger, // TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
// external trigger rising edge, load RA on falling edge of TIOA. // external trigger rising edge, load RA on falling edge of TIOA.
@ -1264,8 +1264,8 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
tx[1] = 0x00 + ((sendNum % 16) * 16) + (crc / 16); tx[1] = 0x00 + ((sendNum % 16) * 16) + (crc / 16);
tx[2] = 0x00 + (crc % 16) * 16; tx[2] = 0x00 + (crc % 16) * 16;
} else if (tag.pstate == HT_SELECTED } else if (tag.pstate == HT_SELECTED
&& tag.tstate == HT_READING_PAGE && tag.tstate == HT_READING_PAGE
&& rxlen > 0) { && rxlen > 0) {
//save received data //save received data
z = 0; z = 0;
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
@ -1315,13 +1315,13 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
(uint8_t) key & 0xff, (uint8_t) key & 0xff,
pwdl1, pwdl1,
pwdl0 pwdl0
); );
Dbprintf("Page[ 3]: %02X %02X %02X %02X", Dbprintf("Page[ 3]: %02X %02X %02X %02X",
(uint8_t)(key >> 40) & 0xff, (uint8_t)(key >> 40) & 0xff,
(uint8_t)(key >> 32) & 0xff, (uint8_t)(key >> 32) & 0xff,
(uint8_t)(key >> 24) & 0xff, (uint8_t)(key >> 24) & 0xff,
(uint8_t)(key >> 16) & 0xff (uint8_t)(key >> 16) & 0xff
); );
} else { } else {
//if the authentication is done with a challenge the key and password are unknown //if the authentication is done with a challenge the key and password are unknown
Dbprintf("Page[ 2]: __ __ __ __"); Dbprintf("Page[ 2]: __ __ __ __");
@ -1807,7 +1807,7 @@ void check_challenges(bool file_given, uint8_t *data) {
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers // TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK; AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
// TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger, // TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
// external trigger rising edge, load RA on falling edge of TIOA. // external trigger rising edge, load RA on falling edge of TIOA.

View file

@ -106,7 +106,7 @@ int usage_hitag_writer(void) {
} }
int usage_hitag_checkchallenges(void) { int usage_hitag_checkchallenges(void) {
PrintAndLogEx(NORMAL, "Check challenges, load a file with save hitag crypto challenges and test them all."); PrintAndLogEx(NORMAL, "Check challenges, load a file with save hitag crypto challenges and test them all.");
PrintAndLogEx(NORMAL, "The file should be 8 * 60 bytes long, the file extension defaults to " _YELLOW_("`.cc`") ); PrintAndLogEx(NORMAL, "The file should be 8 * 60 bytes long, the file extension defaults to " _YELLOW_("`.cc`"));
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf hitag cc [h] f <filename w/o extension>"); PrintAndLogEx(NORMAL, "Usage: lf hitag cc [h] f <filename w/o extension>");
PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, "Options:");
@ -289,9 +289,9 @@ int CmdLFHitagSim(const char *Cmd) {
cmdp++; cmdp++;
break; break;
case 'e': case 'e':
param_getstr(Cmd, cmdp+1, filename, sizeof(filename)); param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
res = loadFileEML(filename, "eml", data, &datalen); res = loadFileEML(filename, "eml", data, &datalen);
if ( res > 0 || datalen != maxdatalen) { if (res > 0 || datalen != maxdatalen) {
PrintAndLogDevice(FAILED, "error, bytes read mismatch file size"); PrintAndLogDevice(FAILED, "error, bytes read mismatch file size");
errors = true; errors = true;
break; break;
@ -300,9 +300,9 @@ int CmdLFHitagSim(const char *Cmd) {
cmdp += 2; cmdp += 2;
break; break;
case 'j': case 'j':
param_getstr(Cmd, cmdp+1, filename, sizeof(filename)); param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
res = loadFileJSON(filename, "json", data, maxdatalen, &datalen); res = loadFileJSON(filename, "json", data, maxdatalen, &datalen);
if ( res > 0) { if (res > 0) {
errors = true; errors = true;
break; break;
} }
@ -310,9 +310,9 @@ int CmdLFHitagSim(const char *Cmd) {
cmdp += 2; cmdp += 2;
break; break;
case 'b': case 'b':
param_getstr(Cmd, cmdp+1, filename, sizeof(filename)); param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
res = loadFile(filename, "bin", data, maxdatalen, &datalen); res = loadFile(filename, "bin", data, maxdatalen, &datalen);
if ( res > 0 ) { if (res > 0) {
errors = true; errors = true;
break; break;
} }
@ -333,7 +333,7 @@ int CmdLFHitagSim(const char *Cmd) {
} }
c.arg[0] = (uint32_t)tag_mem_supplied; c.arg[0] = (uint32_t)tag_mem_supplied;
if ( tag_mem_supplied ) { if (tag_mem_supplied) {
memcpy(c.d.asBytes, data, datalen); memcpy(c.d.asBytes, data, datalen);
} }
clearCommandBuffer(); clearCommandBuffer();
@ -447,9 +447,9 @@ int CmdLFHitagCheckChallenges(const char *Cmd) {
free(data); free(data);
return usage_hitag_checkchallenges(); return usage_hitag_checkchallenges();
case 'f': case 'f':
param_getstr(Cmd, cmdp+1, filename, sizeof(filename)); param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
res = loadFile(filename, "cc", data, 8 * 60, &datalen); res = loadFile(filename, "cc", data, 8 * 60, &datalen);
if ( res > 0 ) { if (res > 0) {
errors = true; errors = true;
break; break;
} }

View file

@ -191,12 +191,12 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
for (int j = 0; j < data_len && j / 18 < 18; j++) { for (int j = 0; j < data_len && j / 18 < 18; j++) {
uint8_t parityBits = parityBytes[j >> 3]; uint8_t parityBits = parityBytes[j >> 3];
if ( protocol != LEGIC if (protocol != LEGIC
&& protocol != ISO_14443B && protocol != ISO_14443B
&& protocol != ISO_7816_4 && protocol != ISO_7816_4
&& protocol != PROTO_HITAG && protocol != PROTO_HITAG
&& (isResponse || protocol == ISO_14443A) && (isResponse || protocol == ISO_14443A)
&& (oddparity8(frame[j]) != ((parityBits >> (7 - (j & 0x0007))) & 0x01))) { && (oddparity8(frame[j]) != ((parityBits >> (7 - (j & 0x0007))) & 0x01))) {
snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x! ", frame[j]); snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x! ", frame[j]);
} else { } else {

View file

@ -314,7 +314,7 @@ int loadFile(const char *preferredName, const char *suffix, void *data, size_t m
goto out; goto out;
} }
if ( bytes_read != maxdatalen ) { if (bytes_read != maxdatalen) {
PrintAndLogDevice(WARNING, "Warning, bytes read exeed calling array limit. Max bytes is %d bytes", maxdatalen); PrintAndLogDevice(WARNING, "Warning, bytes read exeed calling array limit. Max bytes is %d bytes", maxdatalen);
bytes_read = maxdatalen; bytes_read = maxdatalen;
} }
@ -470,7 +470,7 @@ int loadFileJSON(const char *preferredName, const char *suffix, void *data, size
if (!strcmp(ctype, "hitag")) { if (!strcmp(ctype, "hitag")) {
size_t sptr = 0; size_t sptr = 0;
for (int i = 0; i < (maxdatalen/4); i++) { for (int i = 0; i < (maxdatalen / 4); i++) {
if (sptr + 4 > maxdatalen) { if (sptr + 4 > maxdatalen) {
retval = 5; retval = 5;
goto out; goto out;

View file

@ -21,36 +21,36 @@
#endif #endif
typedef enum { typedef enum {
RHTSF_CHALLENGE = 01, RHTSF_CHALLENGE = 01,
RHTSF_KEY = 02, RHTSF_KEY = 02,
WHTSF_CHALLENGE = 03, WHTSF_CHALLENGE = 03,
WHTSF_KEY = 04, WHTSF_KEY = 04,
RHT2F_PASSWORD = 21, RHT2F_PASSWORD = 21,
RHT2F_AUTHENTICATE = 22, RHT2F_AUTHENTICATE = 22,
RHT2F_CRYPTO = 23, RHT2F_CRYPTO = 23,
WHT2F_CRYPTO = 24, WHT2F_CRYPTO = 24,
RHT2F_TEST_AUTH_ATTEMPTS = 25, RHT2F_TEST_AUTH_ATTEMPTS = 25,
RHT2F_UID_ONLY = 26, RHT2F_UID_ONLY = 26,
} hitag_function; } hitag_function;
typedef struct { typedef struct {
uint8_t password[4]; uint8_t password[4];
} PACKED rht2d_password; } PACKED rht2d_password;
typedef struct { typedef struct {
uint8_t NrAr[8]; uint8_t NrAr[8];
uint8_t data[4]; uint8_t data[4];
} PACKED rht2d_authenticate; } PACKED rht2d_authenticate;
typedef struct { typedef struct {
uint8_t key[6]; uint8_t key[6];
uint8_t data[4]; uint8_t data[4];
} PACKED rht2d_crypto; } PACKED rht2d_crypto;
typedef union { typedef union {
rht2d_password pwd; rht2d_password pwd;
rht2d_authenticate auth; rht2d_authenticate auth;
rht2d_crypto crypto; rht2d_crypto crypto;
} hitag_data; } hitag_data;
@ -86,32 +86,32 @@ typedef enum SOF_TYPE {
} stype; } stype;
struct hitagS_tag { struct hitagS_tag {
PSTATE pstate; //protocol-state PSTATE pstate; //protocol-state
TSATE tstate; //tag-state TSATE tstate; //tag-state
uint32_t uid; uint32_t uid;
uint8_t pages[64][4]; uint8_t pages[64][4];
uint64_t key; uint64_t key;
uint8_t pwdl0, pwdl1, pwdh0; uint8_t pwdl0, pwdl1, pwdh0;
//con0 //con0
int max_page; int max_page;
stype mode; stype mode;
//con1 //con1
bool auth; //0=Plain 1=Auth bool auth; //0=Plain 1=Auth
bool TTFC; //Transponder Talks first coding. 0=Manchester 1=Biphase bool TTFC; //Transponder Talks first coding. 0=Manchester 1=Biphase
int TTFDR; //data rate in TTF Mode int TTFDR; //data rate in TTF Mode
int TTFM; //the number of pages that are sent to the RWD int TTFM; //the number of pages that are sent to the RWD
bool LCON; //0=con1/2 read write 1=con1 read only and con2 OTP bool LCON; //0=con1/2 read write 1=con1 read only and con2 OTP
bool LKP; //0=page2/3 read write 1=page2/3 read only in Plain mode and no access in authenticate mode bool LKP; //0=page2/3 read write 1=page2/3 read only in Plain mode and no access in authenticate mode
//con2 //con2
//0=read write 1=read only //0=read write 1=read only
bool LCK7; //page4/5 bool LCK7; //page4/5
bool LCK6; //page6/7 bool LCK6; //page6/7
bool LCK5; //page8-11 bool LCK5; //page8-11
bool LCK4; //page12-15 bool LCK4; //page12-15
bool LCK3; //page16-23 bool LCK3; //page16-23
bool LCK2; //page24-31 bool LCK2; //page24-31
bool LCK1; //page32-47 bool LCK1; //page32-47
bool LCK0; //page48-63 bool LCK0; //page48-63
}; };
#endif #endif

View file

@ -2,7 +2,7 @@
function wait4proxmark_Linux { function wait4proxmark_Linux {
echo >&2 "Waiting for Proxmark to appear..." echo >&2 "Waiting for Proxmark to appear..."
while [ ! -c /dev/ttyACM? -a ! -L /dev/pm3-? ]; do while [ ! -c /dev/ttyACM? -a ! -c /dev/pm3-? ]; do
sleep .1 sleep .1
done done
local PM3=`ls -1 /dev/pm3-? /dev/ttyACM? 2>/dev/null | head -1` local PM3=`ls -1 /dev/pm3-? /dev/ttyACM? 2>/dev/null | head -1`