wiegand decode now accepts --new parameter to decode new padding format <len 1byte><pacs bytes> where len denotes number of zeros bits added in the end of the pacs bytes. You will need to shift accordingly.

This commit is contained in:
iceman1001 2025-02-23 23:10:13 +01:00
commit 98f6b263ff
6 changed files with 74 additions and 15 deletions

View file

@ -3,6 +3,7 @@ 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... 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] ## [unreleased][unreleased]
- Changed `wiegand decode` - now accepts new padding format (@iceman1001)
- Changed `mem spiffs tree` - ID is now shown in decimal (@iceman1001) - Changed `mem spiffs tree` - ID is now shown in decimal (@iceman1001)
- Added sample wiegand format 56bit (@iceman1001) - Added sample wiegand format 56bit (@iceman1001)
- Changed Wiegand formats to include number of bits (@iceman1001) - Changed Wiegand formats to include number of bits (@iceman1001)

View file

@ -66,6 +66,7 @@ static uint8_t empty[PICOPASS_BLOCK_SIZE] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
static uint8_t zeros[PICOPASS_BLOCK_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static uint8_t zeros[PICOPASS_BLOCK_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
static uint8_t iClass_Key_Table[ICLASS_KEYS_MAX][PICOPASS_BLOCK_SIZE] = { static uint8_t iClass_Key_Table[ICLASS_KEYS_MAX][PICOPASS_BLOCK_SIZE] = {
{ 0xAE, 0xA6, 0x84, 0xA6, 0xDA, 0xB2, 0x32, 0x78 }, { 0xAE, 0xA6, 0x84, 0xA6, 0xDA, 0xB2, 0x32, 0x78 },
{ 0xFD, 0xCB, 0x5A, 0x52, 0xEA, 0x8F, 0x30, 0x90 }, { 0xFD, 0xCB, 0x5A, 0x52, 0xEA, 0x8F, 0x30, 0x90 },
@ -1395,7 +1396,7 @@ static int CmdHFiClassESetBlk(const char *Cmd) {
static bool iclass_detect_new_pacs(uint8_t *d) { static bool iclass_detect_new_pacs(uint8_t *d) {
uint8_t n = 0; uint8_t n = 0;
while (n++ < (PICOPASS_BLOCK_SIZE / 2)) { while (n++ < (PICOPASS_BLOCK_SIZE >> 1)) {
if (d[n] && d[n + 1] == 0xA6) { if (d[n] && d[n + 1] == 0xA6) {
return true; return true;
} }
@ -1467,8 +1468,7 @@ static void iclass_decode_credentials(uint8_t *data) {
if (has_values && encryption == None) { if (has_values && encryption == None) {
// todo: remove preamble/sentinel // todo: remove preamble/sentinel
PrintAndLogEx(INFO, "Block 7 decoder"); PrintAndLogEx(INFO, "------------------------ " _CYAN_("Block 7 decoder") " --------------------------");
if (has_new_pacs) { if (has_new_pacs) {
iclass_decode_credentials_new_pacs(b7); iclass_decode_credentials_new_pacs(b7);
} else { } else {
@ -1483,9 +1483,7 @@ static void iclass_decode_credentials(uint8_t *data) {
char *pbin = binstr; char *pbin = binstr;
while (strlen(pbin) && *(++pbin) == '0'); while (strlen(pbin) && *(++pbin) == '0');
PrintAndLogEx(SUCCESS, "Binary..................... " _GREEN_("%s"), pbin); PrintAndLogEx(SUCCESS, "Binary... %zu - " _GREEN_("%s"), strlen(pbin), pbin);
PrintAndLogEx(INFO, "Wiegand decode");
decode_wiegand(top, mid, bot, 0); decode_wiegand(top, mid, bot, 0);
} }
@ -1736,7 +1734,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
} }
} }
PrintAndLogEx(INFO, "-----------------------------------------------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------------");
free(decrypted); free(decrypted);
} }

View file

@ -1756,7 +1756,7 @@ static command_t CommandTable[] = {
{"list", CmdHfSeosList, AlwaysAvailable, "List SEOS history"}, {"list", CmdHfSeosList, AlwaysAvailable, "List SEOS history"},
{"sam", CmdHfSeosSAM, IfPm3Smartcard, "SAM tests"}, {"sam", CmdHfSeosSAM, IfPm3Smartcard, "SAM tests"},
{"-----------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operations") " -----------------------"}, {"-----------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operations") " -----------------------"},
{"info", CmdHfSeosInfo, IfPm3NfcBarcode, "Tag information"}, {"info", CmdHfSeosInfo, IfPm3Iso14443a, "Tag information"},
{"pacs", CmdHfSeosPACS, AlwaysAvailable, "Extract PACS Information from card"}, {"pacs", CmdHfSeosPACS, AlwaysAvailable, "Extract PACS Information from card"},
{"adf", CmdHfSeosADF, AlwaysAvailable, "Read an ADF from the card"}, {"adf", CmdHfSeosADF, AlwaysAvailable, "Read an ADF from the card"},
{"gdf", CmdHfSeosGDF, AlwaysAvailable, "Read an GDF from card"}, {"gdf", CmdHfSeosGDF, AlwaysAvailable, "Read an GDF from card"},

View file

@ -33,6 +33,47 @@
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
#define PACS_EXTRA_LONG_FORMAT 18 // 144 bits
#define PACS_LONG_FORMAT 12 // 96 bits
#define PACS_FORMAT 6 // 44 bits
static int wiegand_new_pacs(uint8_t *padded_pacs, uint8_t plen) {
uint8_t d[PACS_EXTRA_LONG_FORMAT] = {0};
memcpy(d, padded_pacs, plen);
uint8_t pad = d[0];
char *binstr = (char *)calloc((PACS_EXTRA_LONG_FORMAT * 8) + 1, sizeof(uint8_t));
if (binstr == NULL) {
PrintAndLogEx(INFO, "failed to allocate memory");
return PM3_EMALLOC;
}
uint8_t n = plen - 1;
bytes_2_binstr(binstr, d + 1, n);
binstr[strlen(binstr) - pad] = '\0';
size_t tlen = 0;
uint8_t tmp[16] = {0};
binstr_2_bytes(tmp, &tlen, binstr);
PrintAndLogEx(SUCCESS, "Wiegand raw.... " _YELLOW_("%s"), sprint_hex_inrow(tmp, tlen));
uint32_t top = 0, mid = 0, bot = 0;
if (binstring_to_u96(&top, &mid, &bot, binstr) != strlen(binstr)) {
PrintAndLogEx(ERR, "Binary string contains none <0|1> chars");
free(binstr);
return PM3_EINVARG;
}
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "------------------------- " _CYAN_("SIO - Wiegand") " ---------------------------");
wiegand_message_t packed = initialize_message_object(top, mid, bot, strlen(binstr));
HIDTryUnpack(&packed);
free(binstr);
return PM3_SUCCESS;
}
int CmdWiegandList(const char *Cmd) { int CmdWiegandList(const char *Cmd) {
CLIParserContext *ctx; CLIParserContext *ctx;
@ -116,16 +157,18 @@ int CmdWiegandDecode(const char *Cmd) {
CLIParserContext *ctx; CLIParserContext *ctx;
CLIParserInit(&ctx, "wiegand decode", CLIParserInit(&ctx, "wiegand decode",
"Decode raw hex or binary to wiegand format", "Decode raw hex or binary to wiegand format",
"wiegand decode --raw 2006f623ae" "wiegand decode --raw 2006F623AE\n"
"wiegand decode --new 06BD88EB80 -> 4..8 bytes, new padded format "
); );
void *argtable[] = { void *argtable[] = {
arg_param_begin, arg_param_begin,
arg_str0("r", "raw", "<hex>", "raw hex to be decoded"), arg_str0("r", "raw", "<hex>", "raw hex to be decoded"),
arg_str0("b", "bin", "<bin>", "binary string to be decoded"), arg_str0("b", "bin", "<bin>", "binary string to be decoded"),
arg_str0("n", "new", "<hex>", "new padded pacs as raw hex to be decoded"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(ctx, Cmd, argtable, true); CLIExecWithReturn(ctx, Cmd, argtable, false);
int hlen = 0; int hlen = 0;
char hex[40] = {0}; char hex[40] = {0};
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)hex, sizeof(hex), &hlen); CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)hex, sizeof(hex), &hlen);
@ -133,6 +176,11 @@ int CmdWiegandDecode(const char *Cmd) {
int blen = 0; int blen = 0;
uint8_t binarr[100] = {0x00}; uint8_t binarr[100] = {0x00};
int res = CLIParamBinToBuf(arg_get_str(ctx, 2), binarr, sizeof(binarr), &blen); int res = CLIParamBinToBuf(arg_get_str(ctx, 2), binarr, sizeof(binarr), &blen);
int plen = 0;
uint8_t phex[8] = {0};
res = CLIParamHexToBuf(arg_get_str(ctx, 3), phex, sizeof(phex), &plen);
CLIParserFree(ctx); CLIParserFree(ctx);
if (res) { if (res) {
@ -155,12 +203,20 @@ int CmdWiegandDecode(const char *Cmd) {
return PM3_EINVARG; return PM3_EINVARG;
} }
PrintAndLogEx(INFO, "Input bin len... %d", blen); PrintAndLogEx(INFO, "Input bin len... %d", blen);
} else if (plen) {
return wiegand_new_pacs(phex, plen);
} else { } else {
PrintAndLogEx(ERR, "Empty input"); PrintAndLogEx(ERR, "Empty input");
return PM3_EINVARG; return PM3_EINVARG;
} }
decode_wiegand(top, mid, bot, blen); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "Wiegand decode");
wiegand_message_t packed = initialize_message_object(top, mid, bot, blen);
HIDTryUnpack(&packed);
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -13167,15 +13167,17 @@
"command": "wiegand decode", "command": "wiegand decode",
"description": "Decode raw hex or binary to wiegand format", "description": "Decode raw hex or binary to wiegand format",
"notes": [ "notes": [
"wiegand decode --raw 2006f623ae" "wiegand decode --raw 2006f623ae",
"wiegand decode --new 04801EEF8DC0 -> 4..8 bytes, new padded format"
], ],
"offline": true, "offline": true,
"options": [ "options": [
"-h, --help This help", "-h, --help This help",
"-r, --raw <hex> raw hex to be decoded", "-r, --raw <hex> raw hex to be decoded",
"-b, --bin <bin> binary string to be decoded" "-b, --bin <bin> binary string to be decoded",
"-n, --new <hex> new padded pacs as raw hex to be decoded"
], ],
"usage": "wiegand decode [-h] [-r <hex>] [-b <bin>]" "usage": "wiegand decode [-h] [-r <hex>] [-b <bin>] [-n <hex>]"
}, },
"wiegand encode": { "wiegand encode": {
"command": "wiegand encode", "command": "wiegand encode",
@ -13212,6 +13214,6 @@
"metadata": { "metadata": {
"commands_extracted": 759, "commands_extracted": 759,
"extracted_by": "PM3Help2JSON v1.00", "extracted_by": "PM3Help2JSON v1.00",
"extracted_on": "2025-02-22T17:26:54" "extracted_on": "2025-02-23T21:55:16"
} }
} }

View file

@ -445,6 +445,8 @@ while true; do
if ! CheckExecute "nfc decode test - vcard" "$CLIENTBIN -c 'nfc decode -d d20ca3746578742f782d7643617264424547494e3a56434152440a56455253494f4e3a332e300a4e3a43687269733b4963656d616e3b3b3b0a464e3a476f7468656e627572670a5245563a323032312d30362d32345432303a31353a30385a0a6974656d322e582d4142444154453b747970653d707265663a323032302d30362d32340a4954454d322e582d41424c4142454c3a5f24213c416e6e69766572736172793e21245f0a454e443a56434152440a'" "END:VCARD"; then break; fi if ! CheckExecute "nfc decode test - vcard" "$CLIENTBIN -c 'nfc decode -d d20ca3746578742f782d7643617264424547494e3a56434152440a56455253494f4e3a332e300a4e3a43687269733b4963656d616e3b3b3b0a464e3a476f7468656e627572670a5245563a323032312d30362d32345432303a31353a30385a0a6974656d322e582d4142444154453b747970653d707265663a323032302d30362d32340a4954454d322e582d41424c4142454c3a5f24213c416e6e69766572736172793e21245f0a454e443a56434152440a'" "END:VCARD"; then break; fi
if ! CheckExecute "nfc decode test - apple wallet" "$CLIENTBIN -c 'nfc decode -d 031AD10116550077616C6C65743A2F2F61637469766174652F6E6663FE'" "activate/nfc"; then break; fi if ! CheckExecute "nfc decode test - apple wallet" "$CLIENTBIN -c 'nfc decode -d 031AD10116550077616C6C65743A2F2F61637469766174652F6E6663FE'" "activate/nfc"; then break; fi
if ! CheckExecute "nfc decode test - signature" "$CLIENTBIN -c 'nfc decode -d 03FF010194113870696C65742E65653A656B616172743A3266195F26063132303832325904202020205F28033233335F2701316E1B5A13333038363439303039303030323636343030355304EBF2CE704103000000AC536967010200803A2448FCA7D354A654A81BD021150D1A152D1DF4D7A55D2B771F12F094EAB6E5E10F2617A2F8DAD4FD38AFF8EA39B71C19BD42618CDA86EE7E144636C8E0E7CFC4096E19C3680E09C78A0CDBC05DA2D698E551D5D709717655E56FE3676880B897D2C70DF5F06ECE07C71435255144F8EE41AF110E7B180DA0E6C22FB8FDEF61800025687474703A2F2F70696C65742E65652F6372742F33303836343930302D303030312E637274FE'" "30864900-0001.crt"; then break; fi if ! CheckExecute "nfc decode test - signature" "$CLIENTBIN -c 'nfc decode -d 03FF010194113870696C65742E65653A656B616172743A3266195F26063132303832325904202020205F28033233335F2701316E1B5A13333038363439303039303030323636343030355304EBF2CE704103000000AC536967010200803A2448FCA7D354A654A81BD021150D1A152D1DF4D7A55D2B771F12F094EAB6E5E10F2617A2F8DAD4FD38AFF8EA39B71C19BD42618CDA86EE7E144636C8E0E7CFC4096E19C3680E09C78A0CDBC05DA2D698E551D5D709717655E56FE3676880B897D2C70DF5F06ECE07C71435255144F8EE41AF110E7B180DA0E6C22FB8FDEF61800025687474703A2F2F70696C65742E65652F6372742F33303836343930302D303030312E637274FE'" "30864900-0001.crt"; then break; fi
if ! CheckExecute "wiegand decode test - raw" "$CLIENTBIN -c 'wiegand decode --raw 2006F623AE'" "FC: 123 CN: 4567 parity \( ok \)"; then break; fi
if ! CheckExecute "wiegand decode test - new" "$CLIENTBIN -c 'wiegand decode --new 06BD88EB80'" "FC: 123 CN: 4567 parity \( ok \)"; then break; fi
echo -e "\n${C_BLUE}Testing LF:${C_NC}" 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 hitag2 test" "$CLIENTBIN -c 'lf hitag test'" "Tests \( ok"; then break; fi