move hitag2 crypto parts to the common folder in order to be able to use it on the client side. Some textual and minor adaptations across the bord
This commit is contained in:
1 parent
cdc46d5d2b
commit
700d558432
17 files changed
+185
-117
No files matched your search
@@ -771,6 +771,7 @@ SRCS += bucketsort.c \
|
||||
crc32.c \
|
||||
crc64.c \
|
||||
commonutil.c \
|
||||
hitag2/hitag2_crypto.c \
|
||||
iso15693tools.c \
|
||||
legic_prng.c \
|
||||
lfdemod.c \
|
||||
|
||||
+48
-2
@@ -3649,6 +3649,51 @@ static int CmdBinaryMap(const char *Cmd) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int CmdXor(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "data xor",
|
||||
"takes input string and xor string. Perform xor on it.\n"
|
||||
"If no xor string, try the most reoccuring value to xor against",
|
||||
"data xor -d 99aabbcc8888888888\n"
|
||||
"data xor -d 99aabbcc --xor 88888888\n"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1("d", "data", "<hex>", "input hex string"),
|
||||
arg_str0("x", "xor", "<str>", "input xor string"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
int hlen = 128;
|
||||
uint8_t hex[128 + 1];
|
||||
CLIGetHexWithReturn(ctx, 1, hex, &hlen);
|
||||
|
||||
int xlen = 128;
|
||||
uint8_t xor[128 + 1];
|
||||
CLIGetHexWithReturn(ctx, 2, xor, &xlen);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// find xor value
|
||||
if (xlen == 0) {
|
||||
uint8_t x = get_highest_frequency(hex, hlen);
|
||||
xlen = hlen;
|
||||
memset(xor, x, xlen);
|
||||
}
|
||||
|
||||
if (hlen != xlen) {
|
||||
PrintAndLogEx(FAILED, "Length mismatch, got %i != %i", hlen, xlen);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "input... %s", sprint_hex_inrow(hex, hlen));
|
||||
PrintAndLogEx(SUCCESS, "xor..... %s", sprint_hex_inrow(xor, xlen));
|
||||
hex_xor(hex, xor, hlen);
|
||||
PrintAndLogEx(SUCCESS, "plain... " _YELLOW_("%s"), sprint_hex_inrow(hex, hlen));
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("General") "-------------------------"},
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
@@ -3700,9 +3745,10 @@ static command_t CommandTable[] = {
|
||||
{"load", CmdLoad, AlwaysAvailable, "Load contents of file into graph window"},
|
||||
{"num", CmdNumCon, AlwaysAvailable, "Converts dec/hex/bin"},
|
||||
{"print", CmdPrintDemodBuff, AlwaysAvailable, "Print the data in the DemodBuffer"},
|
||||
{"samples", CmdSamples, IfPm3Present, "Get raw samples for graph window (GraphBuffer)"},
|
||||
{"save", CmdSave, AlwaysAvailable, "Save signal trace data (from graph window)"},
|
||||
{"samples", CmdSamples, IfPm3Present, "Get raw samples for graph window ( GraphBuffer )"},
|
||||
{"save", CmdSave, AlwaysAvailable, "Save signal trace data ( GraphBuffer )"},
|
||||
{"setdebugmode", CmdSetDebugMode, AlwaysAvailable, "Set Debugging Level on client side"},
|
||||
{"xor", CmdXor, AlwaysAvailable, "Xor a input string"},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ int applyIso14443a(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool i
|
||||
break;
|
||||
case MIFARE_ULEV1_AUTH:
|
||||
if (cmdsize == 7)
|
||||
snprintf(exp, size, "PWD-AUTH KEY: " _GREEN_("0x%02X%02X%02X%02X"), cmd[1], cmd[2], cmd[3], cmd[4]);
|
||||
snprintf(exp, size, "PWD-AUTH: " _GREEN_("0x%02X%02X%02X%02X"), cmd[1], cmd[2], cmd[3], cmd[4]);
|
||||
else
|
||||
snprintf(exp, size, "PWD-AUTH");
|
||||
break;
|
||||
@@ -2103,9 +2103,9 @@ void annotateMifare(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize,
|
||||
break;
|
||||
}
|
||||
|
||||
if ((MifareAuthState == masNone) || (MifareAuthState == masError))
|
||||
if ((MifareAuthState == masNone) || (MifareAuthState == masError)) {
|
||||
annotateIso14443a(exp, size, cmd, cmdsize, isResponse);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void mf_get_paritybinstr(char *s, uint32_t val, uint8_t par) {
|
||||
|
||||
@@ -366,18 +366,16 @@ static void print_hitag2_blocks(uint8_t *d, uint16_t n) {
|
||||
, annotation[i]
|
||||
);
|
||||
}
|
||||
PrintAndLogEx(INFO, "---------+-------------+-------+-----+---------");
|
||||
PrintAndLogEx(INFO, " L = Locked, "_GREEN_("RW") " = Read Write, R = Read Only");
|
||||
PrintAndLogEx(INFO, "--------+-------------+-------+-----+---------");
|
||||
PrintAndLogEx(INFO, " "_RED_("L") " = Locked, "_GREEN_("RW") " = Read Write, R = Read Only");
|
||||
PrintAndLogEx(INFO, " FI = Fixed / Irreversible");
|
||||
PrintAndLogEx(INFO, "-----------------------------------------------");
|
||||
PrintAndLogEx(INFO, "----------------------------------------------");
|
||||
}
|
||||
|
||||
// Annotate HITAG protocol
|
||||
void annotateHitag1(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, bool is_response) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
static struct {
|
||||
enum {
|
||||
STATE_HALT,
|
||||
@@ -387,16 +385,12 @@ static struct {
|
||||
} state;
|
||||
} _ht2state;
|
||||
|
||||
|
||||
void annotateHitag2_init(void) {
|
||||
_ht2state.state = STATE_HALT;
|
||||
}
|
||||
|
||||
void annotateHitag2(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, uint8_t bits, bool is_response) {
|
||||
|
||||
// I think its better to handle this log bytes as a long array of bits instead.
|
||||
// 1100 0
|
||||
// 1100 0001 1100 0000 00
|
||||
if (cmdsize == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@
|
||||
#define HITAG_PASSWORD_SIZE 4
|
||||
#define HITAG_UID_SIZE 4
|
||||
#define HITAG_BLOCK_SIZE 4
|
||||
#define HITAG2_MAX_BYTE_SIZE (12 * HITAG_BLOCK_SIZE)
|
||||
#define HITAG2_MAX_BLOCKS 8
|
||||
#define HITAG2_MAX_BYTE_SIZE (HITAG2_MAX_BLOCKS * HITAG_BLOCK_SIZE)
|
||||
|
||||
// need to see which limits these cards has
|
||||
#define HITAG1_MAX_BYTE_SIZE 64
|
||||
#define HITAGS_MAX_BYTE_SIZE 64
|
||||
|
||||
@@ -650,26 +650,26 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
||||
if (data_len == 1) {
|
||||
|
||||
if (nbits == 5) {
|
||||
snprintf(line[0], 120, "%2u: %02x ", nbits, frame[0] >> (8 - nbits));
|
||||
snprintf(line[0], 120, "%2u: %02X ", nbits, frame[0] >> (8 - nbits));
|
||||
} else {
|
||||
snprintf(line[0], 120, "%2u: %02x ", nbits, frame[0] >> (8 - nbits));
|
||||
snprintf(line[0], 120, "%2u: %02X ", nbits, frame[0] >> (8 - nbits));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (nbits == 0) {
|
||||
snprintf(line[0], 120, "%2u: %02x ", (data_len * 8), frame[0]);
|
||||
snprintf(line[0], 120, "%2u: %02X ", (data_len * 8), frame[0]);
|
||||
} else {
|
||||
snprintf(line[0], 120, "%2u: %02x ", ((data_len - 1) * 8) + nbits, frame[0]);
|
||||
snprintf(line[0], 120, "%2u: %02X ", ((data_len - 1) * 8) + nbits, frame[0]);
|
||||
}
|
||||
}
|
||||
offset = 4;
|
||||
|
||||
} else {
|
||||
snprintf(line[j / 18] + ((j % 18) * 4) + offset, 120, "%02x ", frame[j]);
|
||||
snprintf(line[j / 18] + ((j % 18) * 4) + offset, 120, "%02X ", frame[j]);
|
||||
}
|
||||
|
||||
} else {
|
||||
snprintf(line[j / 18] + ((j % 18) * 4), 120, "%02x ", frame[j]);
|
||||
snprintf(line[j / 18] + ((j % 18) * 4), 120, "%02X ", frame[j]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-4
@@ -314,19 +314,26 @@ static void PacketResponseReceived(PacketResponseNG *packet) {
|
||||
//PrintAndLogEx(NORMAL, "[" _MAGENTA_("pm3") "] ["_BLUE_("#")"] " "%s", s);
|
||||
PrintAndLogEx(NORMAL, "[" _BLUE_("#") "] %s", s);
|
||||
} else {
|
||||
if (flag & FLAG_INPLACE)
|
||||
if (flag & FLAG_INPLACE) {
|
||||
PrintAndLogEx(NORMAL, "\r" NOLF);
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "%s" NOLF, s);
|
||||
|
||||
if (flag & FLAG_NEWLINE)
|
||||
if (flag & FLAG_NEWLINE) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CMD_DEBUG_PRINT_INTEGERS: {
|
||||
if (packet->ng == false)
|
||||
PrintAndLogEx(NORMAL, "[" _MAGENTA_("pm3") "] ["_BLUE_("#")"] " "%" PRIx64 ", %" PRIx64 ", %" PRIx64 "", packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
|
||||
if (packet->ng == false) {
|
||||
PrintAndLogEx(NORMAL, "[" _MAGENTA_("pm3") "] ["_BLUE_("#")"] " "%" PRIx64 ", %" PRIx64 ", %" PRIx64 ""
|
||||
, packet->oldarg[0]
|
||||
, packet->oldarg[1]
|
||||
, packet->oldarg[2]
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// iceman: hw status - down the path on device, runs printusbspeed which starts sending a lot of
|
||||
|
||||
Reference in new issue
Block a user