lf hitag: refuse bad pages and data, fix eview, Paxton and LCK1 output
The page check covers the Hitag 2, S and µ `wrbl`, the data check S and µ. `htu rdbl -c` stops at the 55 blocks the reply holds, `hts -m` above 3 is refused, `ta -h` shows its help and argument errors free the parser. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bf3d37e00a
commit
96ad2981bd
5 files changed
+50
-10
No files matched your search
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
|
||||
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
|
||||
|
||||
## [unreleased][unreleased]
|
||||
- Fixed `lf hitag wrbl`, `hts wrbl` and `htu wrbl` - a page out of range or data shorter than 4 bytes is refused (@matrix)
|
||||
- Fixed `lf hitag eview -1/-s/-m` and `htu rdbl -c` - no read past the label table or the reply (@matrix)
|
||||
- Fixed `lf hitag` and `lf search` Paxton id - no garbage before the form factor (@matrix)
|
||||
- Fixed `lf hitag hts rdbl`, `hts -m` and `ta -h` - page 32 under LCK1, mode above 3 refused, help shown (@matrix)
|
||||
- Added `lf destron sim` - simulates the FDX-A frame that `lf destron clone` writes (@matrix)
|
||||
- Fixed `lf destron clone` - a uid that is not 5 bytes of 00-7F is refused instead of written as another id or with bad parity (@matrix)
|
||||
- Fixed `lf fdxb` decoding - ISO 11784:2024 and ISO 24631-6 fields and names, and many more fixes. See commit message (@matrix)
|
||||
|
||||
+13
-3
@@ -250,7 +250,7 @@ static void print_hitag2_paxton(bool show_header, const uint8_t *data) {
|
||||
// [=] 4/0x04 | 39 04 21 1C | 9.!. | RW | User
|
||||
// [=] 5/0x05 | AC 3F 00 06 | .?.. | RW | User
|
||||
|
||||
char formfactor[16];
|
||||
char formfactor[16] = {0};
|
||||
switch (data[23]) {
|
||||
case 0x06: {
|
||||
strcat(formfactor, "isocard");
|
||||
@@ -332,7 +332,7 @@ static void print_hitag2_configuration(uint32_t uid, uint8_t config) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
}
|
||||
|
||||
const char *annotation[] = {
|
||||
static const char *annotation[] = {
|
||||
"UID", "Pwd", "Key/Pwd", "Config",
|
||||
"User", "User", "User", "User",
|
||||
"User", "User", "User", "User"
|
||||
@@ -410,7 +410,7 @@ static void print_hitag2_blocks(uint8_t *d, uint16_t n) {
|
||||
, sprint_hex(d + (i * HITAG_BLOCK_SIZE), HITAG_BLOCK_SIZE)
|
||||
, sprint_ascii(d + (i * HITAG_BLOCK_SIZE), HITAG_BLOCK_SIZE)
|
||||
, lckstr
|
||||
, annotation[i]
|
||||
, (i < ARRAYLEN(annotation)) ? annotation[i] : "User"
|
||||
);
|
||||
}
|
||||
PrintAndLogEx(INFO, "--------+-------------+-------+-----+---------");
|
||||
@@ -1225,6 +1225,11 @@ static int CmdLFHitag2CheckChallenges(const char *Cmd) {
|
||||
"Test recorded authentications (replay?)",
|
||||
"lf hitag ta"
|
||||
);
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
lf_hitag_data_t packet;
|
||||
@@ -1333,6 +1338,11 @@ static int CmdLFHitagWriter(const char *Cmd) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if ((page < 0) || (page >= HITAG2_MAX_BLOCKS)) {
|
||||
PrintAndLogEx(WARNING, "Page address out-of-range. Max is %d, got %d", HITAG2_MAX_BLOCKS - 1, page);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (nalen != 0 && nalen != 8) {
|
||||
PrintAndLogEx(WARNING, "Wrong NR/AR len expected 0 or 8, got %d", nalen);
|
||||
return PM3_EINVARG;
|
||||
|
||||
@@ -229,9 +229,9 @@ static int process_hitags_common_args(CLIParserContext *ctx, lf_hitag_data_t *co
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
uint8_t mode = arg_get_int_def(ctx, 5, 3);
|
||||
int mode = arg_get_int_def(ctx, 5, 3);
|
||||
|
||||
if (mode > 3) {
|
||||
if ((mode < 0) || (mode > 3)) {
|
||||
PrintAndLogEx(WARNING, "Wrong response protocol mode, expected 0, 1, 2 or 3, got %d", mode);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
@@ -416,6 +416,7 @@ static int CmdLFHitagSRead(const char *Cmd) {
|
||||
|
||||
if (page > 255) {
|
||||
PrintAndLogEx(WARNING, "Page address Invalid.");
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
@@ -423,6 +424,7 @@ static int CmdLFHitagSRead(const char *Cmd) {
|
||||
|
||||
if (count > HITAGS_MAX_PAGES) {
|
||||
PrintAndLogEx(WARNING, "No more than 64 pages can be read at once.");
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
@@ -480,7 +482,6 @@ static int CmdLFHitagSRead(const char *Cmd) {
|
||||
// access right
|
||||
if (page_addr == HITAGS_UID_PADR) {
|
||||
PrintAndLogEx(NORMAL, _RED_("RO ")NOLF);
|
||||
\
|
||||
} else if (packet.cmd == HTSF_82xx && page_addr > 40) { // using an 82xx (pages>40 are RO)
|
||||
PrintAndLogEx(NORMAL, _RED_("RO ")NOLF);
|
||||
} else if (page_addr == HITAGS_CONFIG_PADR) {
|
||||
@@ -524,7 +525,7 @@ static int CmdLFHitagSRead(const char *Cmd) {
|
||||
PrintAndLogEx(NORMAL, _RED_("RO ")NOLF);
|
||||
else
|
||||
PrintAndLogEx(NORMAL, _GREEN_("RW ")NOLF);
|
||||
} else if (24 <= page_addr && page_addr <= 32) {
|
||||
} else if (24 <= page_addr && page_addr <= 31) {
|
||||
if (card->config_page.s.LCK2)
|
||||
PrintAndLogEx(NORMAL, _RED_("RO ")NOLF);
|
||||
else
|
||||
@@ -701,6 +702,7 @@ static int CmdLFHitagSRestore(const char *Cmd) {
|
||||
int fnlen = 0;
|
||||
char filename[FILE_PATH_SIZE] = {0};
|
||||
CLIParamStrToBuf(arg_get_str(ctx, 6), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (fnlen == 0) {
|
||||
PrintAndLogEx(ERR, "Must specify a file");
|
||||
@@ -930,6 +932,16 @@ static int CmdLFHitagSWrite(const char *Cmd) {
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if ((page < 0) || (page > 255)) {
|
||||
PrintAndLogEx(WARNING, "Page address Invalid.");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (data_len != sizeof(data)) {
|
||||
PrintAndLogEx(WARNING, "Wrong DATA len expected 4, got %d", data_len);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
packet.page = page;
|
||||
memcpy(packet.data, data, sizeof(packet.data));
|
||||
|
||||
|
||||
@@ -349,13 +349,16 @@ static int CmdLFHitagURead(const char *Cmd) {
|
||||
|
||||
if (page >= HITAGU_MAX_BLOCKS) {
|
||||
PrintAndLogEx(WARNING, "Block address out-of-range. Max is 255, got %u", page);
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
uint32_t count = arg_get_int_def(ctx, 4, 1);
|
||||
|
||||
if (count > HITAGU_MAX_BLOCKS) {
|
||||
PrintAndLogEx(WARNING, "No more than %d blocks can be read at once", HITAGU_MAX_BLOCKS);
|
||||
// the read response holds HITAGU_MAX_PAGE_ADVANCED_PLUS blocks
|
||||
if (count > HITAGU_MAX_PAGE_ADVANCED_PLUS) {
|
||||
PrintAndLogEx(WARNING, "No more than %d blocks can be read at once", HITAGU_MAX_PAGE_ADVANCED_PLUS);
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
@@ -422,7 +425,7 @@ static int CmdLFHitagURead(const char *Cmd) {
|
||||
count = (user_blocks > page) ? (user_blocks - page) : HITAGU_MAX_BLOCKS;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
for (int i = 0; (i < count) && (i < HITAGU_MAX_PAGE_ADVANCED_PLUS); ++i) {
|
||||
|
||||
int page_addr = page + i;
|
||||
if (page_addr >= HITAGU_MAX_BLOCKS) {
|
||||
@@ -645,6 +648,16 @@ static int CmdLFHitagUWrite(const char *Cmd) {
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if ((page < 0) || (page >= HITAGU_MAX_BLOCKS)) {
|
||||
PrintAndLogEx(WARNING, "Block address out-of-range. Max is 255, got %d", page);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (data_len != sizeof(data)) {
|
||||
PrintAndLogEx(WARNING, "Wrong DATA len expected 4, got %d", data_len);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
packet.page = page;
|
||||
memcpy(packet.data, data, sizeof(packet.data));
|
||||
|
||||
|
||||
@@ -561,6 +561,7 @@ while true; do
|
||||
|
||||
echo -e "\n${C_BLUE}Testing LF:${C_NC}"
|
||||
if ! CheckExecute "lf hitag2 test" "$CLIENTBIN -c 'lf hitag test'" "Tests \( ok"; then break; fi
|
||||
if ! CheckExecute "lf hitag ta help" "$CLIENTBIN -c 'lf hitag ta -h'" "Test recorded authentications"; then break; fi
|
||||
if ! CheckExecute "lf cotag demod test 1/4" "$CLIENTBIN -c 'data load -f traces/lf_cotag_220_8331.pm3; lf cotag demod -c 272 -v'" \
|
||||
"data hex: 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 5 8 2 4 E 0 0 0 0 8 0 2 3 D F 7 7"; then break; fi
|
||||
if ! CheckExecute "lf cotag demod test 2/4" "$CLIENTBIN -c 'data load -f traces/cotag/lf_cotag_passive_02402447_700000.pm3; lf cotag demod -v'" \
|
||||
|
||||
Reference in new issue
Block a user