mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-04 07:11:10 +08:00
commit
f08649ac0e
1 changed files with 26 additions and 15 deletions
|
@ -27,8 +27,11 @@
|
|||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
|
||||
// Successful crypto auth
|
||||
static bool bCrypto;
|
||||
// Is in auth stage
|
||||
static bool bAuthenticating;
|
||||
// Successful password auth
|
||||
static bool bPwd;
|
||||
static bool bSuccessful;
|
||||
|
||||
|
@ -272,8 +275,8 @@ static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_
|
|||
break;
|
||||
}
|
||||
|
||||
// LogTrace(rx, nbytes(rxlen), 0, 0, NULL, false);
|
||||
// LogTrace(tx, nbytes(txlen), 0, 0, NULL, true);
|
||||
// LogTrace(rx, nbytes(rxlen), 0, 0, NULL, false);
|
||||
// LogTrace(tx, nbytes(txlen), 0, 0, NULL, true);
|
||||
|
||||
if (tag.crypto_active) {
|
||||
hitag2_cipher_transcrypt(&(tag.cs), tx, *txlen / 8, *txlen % 8);
|
||||
|
@ -398,6 +401,7 @@ static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t
|
|||
|
||||
// Received UID, tag password
|
||||
case 32: {
|
||||
// stage 1, got UID
|
||||
if (!bPwd) {
|
||||
bPwd = true;
|
||||
bAuthenticating = true;
|
||||
|
@ -405,6 +409,7 @@ static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t
|
|||
*txlen = 32;
|
||||
}
|
||||
else {
|
||||
// stage 2, got config byte+password TAG, discard as will read later
|
||||
if (bAuthenticating) {
|
||||
bAuthenticating = false;
|
||||
if (write) {
|
||||
|
@ -414,6 +419,7 @@ static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t
|
|||
break;
|
||||
}
|
||||
}
|
||||
// stage 2+, got data block
|
||||
else {
|
||||
memcpy(tag.sectors[blocknr], rx, 4);
|
||||
blocknr++;
|
||||
|
@ -493,19 +499,22 @@ static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *
|
|||
}
|
||||
// Received UID, crypto tag answer
|
||||
case 32: {
|
||||
// stage 1, got UID
|
||||
if (!bCrypto) {
|
||||
uint64_t ui64key = key[0] | ((uint64_t)key[1]) << 8 | ((uint64_t)key[2]) << 16 | ((uint64_t)key[3]) << 24 | ((uint64_t)key[4]) << 32 | ((uint64_t)key[5]) << 40;
|
||||
uint32_t ui32uid = rx[0] | ((uint32_t)rx[1]) << 8 | ((uint32_t)rx[2]) << 16 | ((uint32_t)rx[3]) << 24;
|
||||
Dbprintf("hitag2_crypto: key=0x%x%x uid=0x%x", (uint32_t)((REV64(ui64key)) >> 32), (uint32_t)((REV64(ui64key)) & 0xffffffff), REV32(ui32uid));
|
||||
cipher_state = _hitag2_init(REV64(ui64key), REV32(ui32uid), 0);
|
||||
// PRN
|
||||
memset(tx, 0x00, 4);
|
||||
// Secret data
|
||||
memset(tx + 4, 0xff, 4);
|
||||
hitag2_cipher_transcrypt(&cipher_state, tx + 4, 4, 0);
|
||||
*txlen = 64;
|
||||
bCrypto = true;
|
||||
bAuthenticating = true;
|
||||
} else {
|
||||
// Check if we received answer tag (at)
|
||||
// stage 2, got config byte+password TAG, discard as will read later
|
||||
if (bAuthenticating) {
|
||||
bAuthenticating = false;
|
||||
if (write) {
|
||||
|
@ -514,7 +523,9 @@ static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *
|
|||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
// stage 2+, got data block
|
||||
else {
|
||||
// Store the received block
|
||||
memcpy(tag.sectors[blocknr], rx, 4);
|
||||
blocknr++;
|
||||
|
@ -697,7 +708,7 @@ void SniffHitag(void) {
|
|||
|
||||
StopTicks();
|
||||
|
||||
// int frame_count;
|
||||
// int frame_count;
|
||||
int response;
|
||||
int overflow;
|
||||
bool rising_edge;
|
||||
|
@ -755,7 +766,7 @@ void SniffHitag(void) {
|
|||
|
||||
// Reset the received frame, frame count and timing info
|
||||
memset(rx, 0x00, sizeof(rx));
|
||||
// frame_count = 0;
|
||||
// frame_count = 0;
|
||||
response = 0;
|
||||
overflow = 0;
|
||||
reader_frame = false;
|
||||
|
@ -862,7 +873,7 @@ void SniffHitag(void) {
|
|||
|
||||
// Check if frame was captured
|
||||
if (rxlen > 0) {
|
||||
// frame_count++;
|
||||
// frame_count++;
|
||||
LogTrace(rx, nbytes(rxlen), response, 0, NULL, reader_frame);
|
||||
|
||||
// Check if we recognize a valid authentication attempt
|
||||
|
@ -912,7 +923,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
|||
|
||||
StopTicks();
|
||||
|
||||
// int frame_count = 0;
|
||||
// int frame_count = 0;
|
||||
int response = 0, overflow = 0;
|
||||
uint8_t rx[HITAG_FRAME_LEN];
|
||||
size_t rxlen = 0;
|
||||
|
@ -1030,7 +1041,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
|||
|
||||
// Check if frame was captured
|
||||
if (rxlen > 4) {
|
||||
// frame_count++;
|
||||
// frame_count++;
|
||||
LogTrace(rx, nbytes(rxlen), response, response, NULL, true);
|
||||
|
||||
// Disable timer 1 with external trigger to avoid triggers during our own modulation
|
||||
|
@ -1086,7 +1097,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
|
|||
|
||||
StopTicks();
|
||||
|
||||
// int frame_count = 0;
|
||||
// int frame_count = 0;
|
||||
int response = 0;
|
||||
uint8_t rx[HITAG_FRAME_LEN];
|
||||
size_t rxlen = 0;
|
||||
|
@ -1222,7 +1233,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
|
|||
|
||||
// Check if frame was captured and store it
|
||||
if (rxlen > 0) {
|
||||
// frame_count++;
|
||||
// frame_count++;
|
||||
LogTrace(rx, nbytes(rxlen), response, response, NULL, false);
|
||||
}
|
||||
|
||||
|
@ -1278,7 +1289,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
|
|||
|
||||
// Add transmitted frame to total count
|
||||
if (txlen > 0) {
|
||||
// frame_count++;
|
||||
// frame_count++;
|
||||
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true);
|
||||
}
|
||||
|
||||
|
@ -1372,7 +1383,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
|||
|
||||
StopTicks();
|
||||
|
||||
// int frame_count = 0;
|
||||
// int frame_count = 0;
|
||||
int response = 0;
|
||||
uint8_t rx[HITAG_FRAME_LEN];
|
||||
size_t rxlen = 0;
|
||||
|
@ -1493,7 +1504,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
|||
|
||||
// Check if frame was captured and store it
|
||||
if (rxlen > 0) {
|
||||
// frame_count++;
|
||||
// frame_count++;
|
||||
LogTrace(rx, nbytes(rxlen), response, response, NULL, false);
|
||||
}
|
||||
|
||||
|
@ -1534,7 +1545,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
|||
|
||||
// Add transmitted frame to total count
|
||||
if (txlen > 0) {
|
||||
// frame_count++;
|
||||
// frame_count++;
|
||||
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue