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