Merge branch 'master' into fix-trace-list
Signed-off-by: Iceman <iceman@iuse.se>
This commit is contained in:
9 files changed
+154
-56
No files matched your search
+79
-19
@@ -17,6 +17,7 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "cmdlfdestron.h"
|
||||
#include <ctype.h> // tolower
|
||||
#include <stdlib.h> // calloc
|
||||
#include <string.h> // memcpy
|
||||
#include "commonutil.h" // ARRAYLEN
|
||||
#include "common.h"
|
||||
@@ -134,6 +135,37 @@ static int CmdDestronReader(const char *Cmd) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// a uid is five bytes of 7 bits, the top bit of each carries its parity
|
||||
static int checkDestronUid(const uint8_t *data, int datalen) {
|
||||
if (datalen != 5) {
|
||||
PrintAndLogEx(FAILED, "Uid must include 5 hex bytes (10 hex symbols), got " _YELLOW_("%d"), datalen);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
for (int i = 0; i < datalen; i++) {
|
||||
if (data[i] & 0x80) {
|
||||
PrintAndLogEx(FAILED, "Uid byte %d is " _YELLOW_("%02X") ", each byte holds 7 bits (00-7F)", i + 1, data[i]);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// the three data blocks of a frame, as cloned and simulated
|
||||
static void getDestronBlocks(const uint8_t *data, int datalen, uint32_t *blocks) {
|
||||
uint8_t data_ex[12 + 24] = {0}; // ManchesterEncode need extra room
|
||||
for (int i = 0; i < datalen; i++) {
|
||||
data_ex[i + 1] = ~(data [i] | (oddparity8(data[i]) << 7));
|
||||
}
|
||||
|
||||
// manchester encode it
|
||||
for (int i = 0; i < 3; i++) {
|
||||
blocks[i] = manchesterEncode2Bytes((data_ex[i * 2] << 8) + data_ex[i * 2 + 1]);
|
||||
}
|
||||
// inject preamble
|
||||
blocks[0] = (blocks[0] & 0xFFFF) | 0xAAE20000;
|
||||
}
|
||||
|
||||
static int CmdDestronClone(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "lf destron clone",
|
||||
@@ -145,7 +177,7 @@ static int CmdDestronClone(const char *Cmd) {
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1("u", "uid", "<hex>", "5 bytes max"),
|
||||
arg_str1("u", "uid", "<hex>", "5 hex bytes, 00-7F each"),
|
||||
arg_lit0(NULL, "q5", "optional - specify writing to Q5/T5555 tag"),
|
||||
arg_lit0(NULL, "em", "optional - specify writing to EM4305/4469 tag"),
|
||||
arg_param_end
|
||||
@@ -166,8 +198,7 @@ static int CmdDestronClone(const char *Cmd) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (datalen > 5) {
|
||||
PrintAndLogEx(FAILED, "Uid is max 5 bytes. (got %u)", datalen);
|
||||
if (checkDestronUid(data, datalen) != PM3_SUCCESS) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
@@ -187,17 +218,7 @@ static int CmdDestronClone(const char *Cmd) {
|
||||
snprintf(cardtype, sizeof(cardtype), "EM4305/4469");
|
||||
}
|
||||
|
||||
uint8_t data_ex[12 + 24] = {0}; // ManchesterEncode need extra room
|
||||
for (int i = 0; i < datalen; i++) {
|
||||
data_ex[i + 1] = ~(data [i] | (oddparity8(data[i]) << 7));
|
||||
}
|
||||
|
||||
// manchester encode it
|
||||
for (int i = 0; i < 3; i++) {
|
||||
blocks[i + 1] = manchesterEncode2Bytes((data_ex[i * 2] << 8) + data_ex[i * 2 + 1]);
|
||||
}
|
||||
// inject preamble
|
||||
blocks[1] = (blocks[1] & 0xFFFF) | 0xAAE20000;
|
||||
getDestronBlocks(data, datalen, blocks + 1);
|
||||
|
||||
PrintAndLogEx(INFO, "Preparing to clone Destron tag to " _YELLOW_("%s") " with ID: " _YELLOW_("%s")
|
||||
, cardtype
|
||||
@@ -220,18 +241,57 @@ static int CmdDestronClone(const char *Cmd) {
|
||||
static int CmdDestronSim(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "lf destron sim",
|
||||
"Try to find Destron preamble, if found decode / descramble data",
|
||||
"lf destron sim"
|
||||
"Enables simulation of Destron card with specified uid.\n"
|
||||
"Simulation runs until the button is pressed or another USB command is issued.",
|
||||
"lf destron sim --uid 1A2B3C4D5E"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1("u", "uid", "<hex>", "5 hex bytes, 00-7F each"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
uint8_t data[8];
|
||||
int datalen = 0;
|
||||
CLIGetHexWithReturn(ctx, 1, data, &datalen);
|
||||
CLIParserFree(ctx);
|
||||
PrintAndLogEx(INFO, " To be implemented, feel free to contribute!");
|
||||
return PM3_ENOTIMPL;
|
||||
|
||||
if (checkDestronUid(data, datalen) != PM3_SUCCESS) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
uint32_t blocks[3] = {0};
|
||||
getDestronBlocks(data, datalen, blocks);
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Simulating Destron - ID: " _YELLOW_("%s") ", Raw: " _YELLOW_("%08X%08X%08X")
|
||||
, sprint_hex_inrow(data, datalen)
|
||||
, blocks[0], blocks[1], blocks[2]
|
||||
);
|
||||
|
||||
uint8_t bs[96];
|
||||
for (size_t i = 0; i < ARRAYLEN(blocks); i++) {
|
||||
num_to_bytebits(blocks[i], 32, bs + (i * 32));
|
||||
}
|
||||
|
||||
// FSK2 as in clone: 1 is fc/8, 0 is fc/10
|
||||
lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs));
|
||||
if (payload == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
payload->fchigh = 8;
|
||||
payload->fclow = 10;
|
||||
payload->separator = 0;
|
||||
payload->clock = 50;
|
||||
memcpy(payload->data, bs, sizeof(bs));
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_FSK_SIMULATE, (uint8_t *)payload, sizeof(lf_fsksim_t) + sizeof(bs));
|
||||
free(payload);
|
||||
|
||||
return lfsim_wait_check(CMD_LF_FSK_SIMULATE);
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
|
||||
+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, "--------+-------------+-------+-----+---------");
|
||||
@@ -1226,6 +1226,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;
|
||||
@@ -1334,6 +1339,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));
|
||||
|
||||
|
||||
@@ -372,13 +372,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;
|
||||
}
|
||||
|
||||
@@ -445,7 +448,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) {
|
||||
@@ -668,6 +671,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));
|
||||
|
||||
|
||||
@@ -1162,13 +1162,15 @@ int getIndalaBits(uint8_t fc, uint16_t cn, uint8_t *bits) {
|
||||
chk += ((cn >> 5) & 1); //y11 == 67 - 30 = 37
|
||||
chk += ((cn >> 2) & 1); //y14 == 89 - 30 = 59
|
||||
chk += (cn & 1); //y16 == 71 - 30 = 41
|
||||
chk += evenparity8(fc & 0xEE); // x1 x2 x3 x5 x6 x7
|
||||
|
||||
if ((chk & 1) == 0) { // If the sum is even, checksum is '10' (binary) = 2.
|
||||
bits[62] = 1;
|
||||
bits[63] = 0;
|
||||
} else { // If the sum is odd, checksum is '01' (binary) = 1.
|
||||
// fitted to the genuine Indala and Keri W cards on record
|
||||
if ((chk & 1) == 0) { // If the sum is even, checksum is '01' (binary) = 1.
|
||||
bits[62] = 0;
|
||||
bits[63] = 1;
|
||||
} else { // If the sum is odd, checksum is '10' (binary) = 2.
|
||||
bits[62] = 1;
|
||||
bits[63] = 0;
|
||||
}
|
||||
|
||||
// add parity
|
||||
@@ -1178,20 +1180,9 @@ int getIndalaBits(uint8_t fc, uint16_t cn, uint8_t *bits) {
|
||||
// 92 = 62
|
||||
// 93 = 63
|
||||
|
||||
bits[34] = 0; // parity for odd bits
|
||||
bits[38] = 0; // parity for even bits
|
||||
uint8_t p1 = 1;
|
||||
uint8_t p2 = 1;
|
||||
|
||||
for (int i = 33; i < 64; i++) {
|
||||
if (i % 2)
|
||||
p1 ^= bits[i];
|
||||
else
|
||||
p2 ^= bits[i];
|
||||
}
|
||||
|
||||
bits[34] = p1; // parity for odd bits
|
||||
bits[38] = p2; // parity for even bits
|
||||
// 26-bit wiegand parity, as in getIndalaBits4041x
|
||||
bits[34] = evenparity16((fc << 4) | (cn >> 12));
|
||||
bits[38] = oddparity16(cn & 0x0fff);
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ int demodNoralsy(bool verbose) {
|
||||
(void) verbose; // unused so far
|
||||
//ASK / Manchester
|
||||
bool st = true;
|
||||
if (ASKDemod_ext(32, 0, 0, 0, false, false, false, 1, &st) != PM3_SUCCESS) {
|
||||
if (ASKDemod_ext(32, 0, 100, 0, false, false, false, 1, &st) != PM3_SUCCESS) {
|
||||
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - Noralsy: ASK/Manchester Demod failed");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
@@ -104,8 +104,8 @@ int demodNoralsy(bool verbose) {
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Noralsy - Card: " _GREEN_("%u")", Year: " _GREEN_("%u") ", Raw: %08X%08X%08X", cardid, year, raw1, raw2, raw3);
|
||||
if (raw1 != 0xBB0214FF) {
|
||||
PrintAndLogEx(WARNING, "Unknown bits set in first block! Expected 0xBB0214FF, Found: 0x%08X", raw1);
|
||||
if ((raw1 != 0xBB0214FF) && (raw1 != 0xBB0314FF)) {
|
||||
PrintAndLogEx(WARNING, "Unknown bits set in first block! Expected 0xBB0214FF or 0xBB0314FF, Found: 0x%08X", raw1);
|
||||
PrintAndLogEx(WARNING, "Please post this output in forum to further research on this format");
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
@@ -346,7 +346,7 @@ int detectNoralsy(uint8_t *dest, size_t *size) {
|
||||
}
|
||||
/*
|
||||
*
|
||||
* 2520116 | BB0214FF2529900116360000 | 10111011 00000011 00010100 11111111 00100101 00101001 10010000 00000001 00010110 00110110 00000000 00000000
|
||||
* 2520116 | BB0314FF2529900116360000 | 10111011 00000011 00010100 11111111 00100101 00101001 10010000 00000001 00010110 00110110 00000000 00000000
|
||||
* aaa*aaaaiiiYY*iiiicc---- **** iiiiiiii iiiiYYYY YYYY**** iiiiiiii iiiiiiii cccccccc
|
||||
*
|
||||
* a = fixed value BB0*14FF
|
||||
|
||||
Reference in new issue
Block a user