diff --git a/CHANGELOG.md b/CHANGELOG.md index 22900aa96..7cc89bb45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac ## [unreleased][unreleased] - Fixed `lf indala clone`, `sim` and `brute` with `--fc`/`--cn` - parity and checksum bits as on genuine cards (@matrix) +- 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) +- Fixed `lf noralsy demod` - one demod error outside the frame, like a cut first bit, no longer loses the read (@matrix) +- Fixed `lf noralsy demod` - a card with the 0xBB0314FF first block no longer gets the unknown bits warning (@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) +- Fixed `lf fdxb clone` and `sim` - a country above 1023 or a national code above 274877906943 is refused instead of cut, `sim` sends the data block flag for `--extended 000000` (@matrix) +- Added `lf fdxb clone` and `sim` `--biothermo` and `--no-datablock` - a Bio-Thermo temperature, or any `--extended` trailer, sent with the data block flag clear as Bio-Thermo chips do (@matrix) +- Changed `lf fdxb reader` - each read tries 134 kHz, then 125 kHz for emulators tuned there (@matrix) +- Fixed payload for `CMD_HF_MIFARE_EML_MEMSET` in `hf_mfu_amiibo_sim.lua` (@tpglitch) - Fixed `hf thinfilm sim` - a second simulation in the same client no longer ends at once with `Done!` (@matrix) - Added `hf mf supercard -u` - UID change on super card generation 2 (@mishamyte) - Changed `hf mf supercard` - a refused `-r`/`-u` now exits non-zero instead of reporting success (@mishamyte) @@ -20,7 +33,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Fixed `recovery.bin` on the AT91 platforms - the bootrom is padded to 0x102000 again, so the OS image is at its load address (@matrix) - Added `hf mfu info` weak-PRNG backstop - detects counterfeit ULC via RndB collision (@Ryan4n6) - Updated `/Getting_Started_With_PM5.md` (@innocentbystanderproxmark) -- Fixed `hf seos pacs`/`write` - 2K3DES GET/UPDATE DATA no longer fails silently with exit 236; print APDU exchange errors, check DES-CMAC, decode SELECT `85` at its real length, and use short-form `85` when the cryptogram is under 128 bytes +- Fixed `hf seos pacs`/`write` - 2K3DES GET/UPDATE DATA no longer fails silently with exit 236; print APDU exchange errors, check DES-CMAC, decode SELECT `85` at its real lengthm () - Fixed client build with `-march=x86-64-v3` (CentOS/RHEL 10 default) - false `-Wstringop-overflow` in the EMV AID list table (@r3wretrhy) - Changed `hf seos info` - now prints UID, ATQA, SAK, ATS, MIFARE Classic emulation, which SEOS AIDs answer and the known AIDs found (@antoniovazquezblanco) - Fixed `hf seos managekeys -p` - key table columns stay aligned for slots 10 and up (@antoniovazquezblanco) diff --git a/client/luascripts/hf_mfu_amiibo_sim.lua b/client/luascripts/hf_mfu_amiibo_sim.lua index bedd0b8a6..0ea66422c 100644 --- a/client/luascripts/hf_mfu_amiibo_sim.lua +++ b/client/luascripts/hf_mfu_amiibo_sim.lua @@ -6,8 +6,8 @@ local ansicolors = require('ansicolors') local amiibo_tools = require('amiibo_tools') copyright = '' -author = 'George Talusan, modified by Lee Hambley' -version = 'v0.0.3' +author = 'George Talusan, modified by Lee Hambley and tpglitch' +version = 'v0.0.4' desc = [[ This script will try to load a binary datadump of an Amiibo. It will recalculate PWD and PACK if necessary. @@ -82,10 +82,10 @@ local function LoadEmulator(uid, blocks) io.write('.') io.flush() core.clearCommandBuffer() - -- Pack blockno (uint16_t LE) + blockcnt (uint8_t) + blockwidth (uint8_t) + data + -- Pack blockno (uint16_t LE) + blockcnt (uint8_t) + blockwidth (uint8_t) + flags (uint8_t) + data local block_lo = bit32.band(i, 0xff) local block_hi = bit32.rshift(i, 8) - local payload = ('%02x%02x%02x%02x'):format(block_lo, block_hi, 1, 4)..blockdata + local payload = ('%02x%02x%02x%02x%02x'):format(block_lo, block_hi, 1, 4, 0)..blockdata cmd = Command:newNG{cmd = cmds.CMD_HF_MIFARE_EML_MEMSET, data = payload} local err, msg = cmd:sendNG(true) if err == nil then return err, msg end diff --git a/client/src/cmdlfdestron.c b/client/src/cmdlfdestron.c index a9c6b1bd2..f9f1b06e3 100644 --- a/client/src/cmdlfdestron.c +++ b/client/src/cmdlfdestron.c @@ -17,6 +17,7 @@ //----------------------------------------------------------------------------- #include "cmdlfdestron.h" #include // tolower +#include // calloc #include // 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", "", "5 bytes max"), + arg_str1("u", "uid", "", "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", "", "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[] = { diff --git a/client/src/cmdlffdxb.c b/client/src/cmdlffdxb.c index b541724c8..adfbeef6b 100644 --- a/client/src/cmdlffdxb.c +++ b/client/src/cmdlffdxb.c @@ -114,20 +114,9 @@ static int getFDXBBits(uint64_t national_code, uint16_t country_code, uint8_t is return PM3_SUCCESS; } -// clearing the topbit needed for the preambl detection. -static void verify_values(uint64_t *animalid, uint32_t *countryid, uint32_t *extended) { - if ((*animalid & 0x3FFFFFFFFF) != *animalid) { - *animalid &= 0x3FFFFFFFFF; - PrintAndLogEx(INFO, "Animal ID truncated to 38bits: " _YELLOW_("%"PRIx64), *animalid); - } - if ((*countryid & 0x3FF) != *countryid) { - *countryid &= 0x3FF; - PrintAndLogEx(INFO, "Country ID truncated to 10bits:" _YELLOW_("%03d"), *countryid); - } - if ((*extended & 0xFFFFFF) != *extended) { - *extended &= 0xFFFFFF; - PrintAndLogEx(INFO, "Extended truncated to 24bits: " _YELLOW_("0x%03X"), *extended); - } +// trailer of a Bio-Thermo chip: 00000000 0000000P TTTTTTTT, P the odd parity of T +static uint32_t getFDXBBioThermo(uint8_t temperature) { + return ((bitcount32(temperature) & 0x1) ? 0 : 0x100) | temperature; } // FDX-B ISO11784/85 demod (aka animal tag) BIPHASE, inverted, rf/32, with preamble of 00000000001 (128bits) @@ -222,11 +211,11 @@ static int CmdFDXBdemodBI(const char *Cmd) { } */ -// For the country part: -// wget -q -O - "https://en.wikipedia.org/w/index.php?title=List_of_ISO_3166_country_codes&action=raw" | awk '/id=/{match($0, /\[\[([^\]|]*)/, a); name=a[1];getline;getline;getline;getline;getline;match($0, /numeric#([0-9]*)/, a);num=a[1]; if (num != "") {printf " { %3u, \"%s\" },\n", num, name}}' +// For the country part: ISO 3166-1 numeric codes, names based on the ISO short names, long ones abbreviated to fit one Flipper Zero screen line // Beware the bottom of the list contains also Manufacturers list static const fdxbCountryMapping_t fdxbCountryMapping[] = { { 4, "Afghanistan" }, + { 248, "Aland Isl." }, { 8, "Albania" }, { 12, "Algeria" }, { 16, "American Samoa" }, @@ -234,13 +223,14 @@ static const fdxbCountryMapping_t fdxbCountryMapping[] = { { 24, "Angola" }, { 660, "Anguilla" }, { 10, "Antarctica" }, - { 28, "Antigua and Barbuda" }, + { 28, "Antigua & Barbuda" }, { 32, "Argentina" }, { 51, "Armenia" }, { 533, "Aruba" }, + { 36, "Australia" }, { 40, "Austria" }, { 31, "Azerbaijan" }, - { 44, "The Bahamas" }, + { 44, "Bahamas" }, { 48, "Bahrain" }, { 50, "Bangladesh" }, { 52, "Barbados" }, @@ -249,91 +239,102 @@ static const fdxbCountryMapping_t fdxbCountryMapping[] = { { 84, "Belize" }, { 204, "Benin" }, { 60, "Bermuda" }, + { 535, "BES Isl." }, { 64, "Bhutan" }, { 68, "Bolivia" }, - { 535, "Bonaire" }, - { 70, "Bosnia and Herzegovina" }, + { 70, "Bosnia & Herzegovina" }, { 72, "Botswana" }, - { 74, "Bouvet Island" }, + { 74, "Bouvet Isl." }, { 76, "Brazil" }, - { 86, "British Indian Ocean Territory" }, + { 86, "British Indian Oc. Terr." }, + { 92, "British Virgin Isl." }, + { 96, "Brunei Darussalam" }, { 100, "Bulgaria" }, { 854, "Burkina Faso" }, - { 132, "Cape Verde" }, + { 108, "Burundi" }, + { 132, "Cabo Verde" }, { 116, "Cambodia" }, { 120, "Cameroon" }, { 124, "Canada" }, - { 140, "Central African Republic" }, + { 136, "Cayman Isl." }, + { 140, "Central African Rep." }, { 148, "Chad" }, { 152, "Chile" }, { 156, "China" }, + { 162, "Christmas Isl." }, + { 166, "Cocos (Keeling) Isl." }, { 170, "Colombia" }, { 174, "Comoros" }, - { 180, "Democratic Republic of the Congo" }, - { 178, "Republic of the Congo" }, - { 184, "Cook Islands" }, - { 384, "Ivory Coast" }, + { 178, "Congo" }, + { 184, "Cook Isl." }, + { 188, "Costa Rica" }, + { 384, "Cote d'Ivoire" }, { 191, "Croatia" }, { 192, "Cuba" }, - { 531, "Curaçao" }, + { 531, "Curacao" }, { 196, "Cyprus" }, - { 203, "Czech Republic" }, + { 203, "Czechia" }, + { 180, "Dem. Rep. of the Congo" }, + { 208, "Denmark" }, { 262, "Djibouti" }, { 212, "Dominica" }, - { 214, "Dominican Republic" }, + { 214, "Dominican Rep." }, + { 218, "Ecuador" }, { 818, "Egypt" }, { 222, "El Salvador" }, + { 226, "Equatorial Guinea" }, { 232, "Eritrea" }, { 233, "Estonia" }, { 748, "Eswatini" }, { 231, "Ethiopia" }, - { 238, "Falkland Islands" }, - { 234, "Faroe Islands" }, + { 238, "Falkland Isl. (Malvinas)" }, + { 234, "Faroe Isl." }, { 242, "Fiji" }, { 246, "Finland" }, { 250, "France" }, { 254, "French Guiana" }, { 258, "French Polynesia" }, - { 260, "French Southern Territories" }, + { 260, "French Southern Terr." }, { 266, "Gabon" }, - { 270, "The Gambia" }, - { 268, "Georgia (country)" }, + { 270, "Gambia" }, + { 268, "Georgia" }, { 276, "Germany" }, { 288, "Ghana" }, { 292, "Gibraltar" }, + { 300, "Greece" }, { 304, "Greenland" }, { 308, "Grenada" }, { 312, "Guadeloupe" }, { 316, "Guam" }, { 320, "Guatemala" }, - { 831, "Bailiwick of Guernsey" }, + { 831, "Guernsey" }, { 324, "Guinea" }, { 624, "Guinea-Bissau" }, { 328, "Guyana" }, { 332, "Haiti" }, - { 336, "Holy See" }, + { 334, "Heard & McDonald Isl." }, { 340, "Honduras" }, { 344, "Hong Kong" }, { 348, "Hungary" }, { 352, "Iceland" }, { 356, "India" }, { 360, "Indonesia" }, - { 364, "Iran (Islamic Republic of)" }, + { 364, "Iran" }, { 368, "Iraq" }, - { 372, "Republic of Ireland" }, + { 372, "Ireland" }, { 833, "Isle of Man" }, { 376, "Israel" }, { 380, "Italy" }, + { 388, "Jamaica" }, + { 392, "Japan" }, { 832, "Jersey" }, { 400, "Jordan" }, { 398, "Kazakhstan" }, { 404, "Kenya" }, { 296, "Kiribati" }, - { 408, "North Korea" }, - { 410, "South Korea" }, { 414, "Kuwait" }, { 417, "Kyrgyzstan" }, - { 418, "Laos" }, + { 418, "Lao People's Dem. Rep." }, { 428, "Latvia" }, { 422, "Lebanon" }, { 426, "Lesotho" }, @@ -342,21 +343,21 @@ static const fdxbCountryMapping_t fdxbCountryMapping[] = { { 438, "Liechtenstein" }, { 440, "Lithuania" }, { 442, "Luxembourg" }, - { 446, "Macau" }, - { 807, "North Macedonia" }, + { 446, "Macao" }, { 450, "Madagascar" }, { 454, "Malawi" }, { 458, "Malaysia" }, { 462, "Maldives" }, { 466, "Mali" }, { 470, "Malta" }, - { 584, "Marshall Islands" }, + { 584, "Marshall Isl." }, { 474, "Martinique" }, { 478, "Mauritania" }, { 480, "Mauritius" }, { 175, "Mayotte" }, { 484, "Mexico" }, - { 583, "Federated States of Micronesia" }, + { 583, "Micronesia" }, + { 581, "Minor Outlying Isl. (US)" }, { 498, "Moldova" }, { 492, "Monaco" }, { 496, "Mongolia" }, @@ -366,87 +367,98 @@ static const fdxbCountryMapping_t fdxbCountryMapping[] = { { 508, "Mozambique" }, { 104, "Myanmar" }, { 516, "Namibia" }, - { 520, "Nauru" }, + { 520, "Naoero" }, { 524, "Nepal" }, - { 528, "Kingdom of the Netherlands" }, + { 528, "Netherlands" }, { 540, "New Caledonia" }, { 554, "New Zealand" }, { 558, "Nicaragua" }, { 562, "Niger" }, { 566, "Nigeria" }, { 570, "Niue" }, - { 574, "Norfolk Island" }, + { 574, "Norfolk Isl." }, + { 408, "North Korea" }, + { 807, "North Macedonia" }, + { 580, "Northern Mariana Isl." }, { 578, "Norway" }, { 512, "Oman" }, { 586, "Pakistan" }, { 585, "Palau" }, - { 275, "State of Palestine" }, + { 275, "Palestine" }, { 591, "Panama" }, { 598, "Papua New Guinea" }, { 600, "Paraguay" }, + { 604, "Peru" }, { 608, "Philippines" }, - { 612, "Pitcairn Islands" }, + { 612, "Pitcairn" }, { 616, "Poland" }, { 620, "Portugal" }, { 630, "Puerto Rico" }, { 634, "Qatar" }, - { 638, "Réunion" }, + { 638, "Reunion" }, { 642, "Romania" }, - { 643, "Russia" }, + { 643, "Russian Federation" }, { 646, "Rwanda" }, - { 654, "Saint Helena" }, - { 659, "Saint Kitts and Nevis" }, - { 662, "Saint Lucia" }, - { 663, "Collectivity of Saint Martin" }, - { 666, "Saint Pierre and Miquelon" }, - { 670, "Saint Vincent and the Grenadines" }, + { 239, "S. Georgia & Sandw. Isl." }, { 882, "Samoa" }, { 674, "San Marino" }, - { 678, "São Tomé and Príncipe" }, + { 678, "Sao Tome & Principe" }, { 682, "Saudi Arabia" }, + { 686, "Senegal" }, { 688, "Serbia" }, { 690, "Seychelles" }, { 694, "Sierra Leone" }, { 702, "Singapore" }, + { 534, "Sint Maarten (Dutch)" }, { 703, "Slovakia" }, { 705, "Slovenia" }, - { 90, "Solomon Islands" }, + { 90, "Solomon Isl." }, { 706, "Somalia" }, { 710, "South Africa" }, - { 239, "South Georgia and the South Sandwich Islands" }, + { 410, "South Korea" }, + { 728, "South Sudan" }, { 724, "Spain" }, { 144, "Sri Lanka" }, + { 652, "St. Barthelemy" }, + { 654, "St. Helena" }, + { 659, "St. Kitts & Nevis" }, + { 662, "St. Lucia" }, + { 663, "St. Martin (French)" }, + { 666, "St. Pierre & Miquelon" }, + { 670, "St. Vincent & Grenadin." }, { 729, "Sudan" }, { 740, "Suriname" }, - { 744, "Svalbard" }, + { 744, "Svalbard & Jan Mayen" }, { 752, "Sweden" }, { 756, "Switzerland" }, - { 760, "Syria" }, + { 760, "Syrian Arab Rep." }, { 158, "Taiwan" }, { 762, "Tajikistan" }, { 834, "Tanzania" }, { 764, "Thailand" }, - { 626, "East Timor" }, + { 626, "Timor-Leste" }, { 768, "Togo" }, { 772, "Tokelau" }, { 776, "Tonga" }, - { 780, "Trinidad and Tobago" }, + { 780, "Trinidad & Tobago" }, { 788, "Tunisia" }, - { 792, "Turkey" }, + { 792, "Turkiye" }, { 795, "Turkmenistan" }, - { 796, "Turks and Caicos Islands" }, + { 796, "Turks & Caicos Isl." }, { 798, "Tuvalu" }, { 800, "Uganda" }, { 804, "Ukraine" }, { 784, "United Arab Emirates" }, { 826, "United Kingdom" }, - { 581, "United States Minor Outlying Islands" }, - { 840, "United States" }, + { 858, "Uruguay" }, + { 840, "USA" }, { 860, "Uzbekistan" }, { 548, "Vanuatu" }, + { 336, "Vatican City State" }, + { 862, "Venezuela" }, { 704, "Vietnam" }, - { 92, "British Virgin Islands" }, - { 850, "United States Virgin Islands" }, + { 850, "Virgin Isl. (US)" }, + { 876, "Wallis & Futuna" }, { 732, "Western Sahara" }, { 887, "Yemen" }, { 894, "Zambia" }, @@ -542,10 +554,14 @@ int demodFDXB(bool verbose) { uint8_t rudiBit = g_DemodBuffer[offset]; offset++; - // ISO: bits 10..14 - uint32_t reservedCode = bytebits_to_byteLSBF(g_DemodBuffer + offset, 5); + // ISO: bits 12..14, starting digit of the visual number (ISO 11784:2024) + uint32_t visualStart = bytebits_to_byteLSBF(g_DemodBuffer + offset, 3); - offset += 5; + offset += 3; + // ISO: bits 10..11 + uint32_t reservedCode = bytebits_to_byteLSBF(g_DemodBuffer + offset, 2); + + offset += 2; // ISO: bits 5..9 uint32_t userInfo = bytebits_to_byteLSBF(g_DemodBuffer + offset, 5); @@ -569,28 +585,31 @@ int demodFDXB(bool verbose) { if (verbose == false) { PROMPT_CLEARLINE; - PrintAndLogEx(SUCCESS, "Animal ID........... " _GREEN_("%03u-%012"PRIu64), countryCode, NationalCode); + PrintAndLogEx(SUCCESS, "Animal code......... " _GREEN_("%03u %012"PRIu64), countryCode, NationalCode); return PM3_SUCCESS; } PrintAndLogEx(NORMAL, ""); PrintAndLogEx(SUCCESS, _CYAN_("FDX-B / ISO 11784/5 Animal")); - PrintAndLogEx(SUCCESS, "Animal ID......... " _GREEN_("%03u-%012"PRIu64), countryCode, NationalCode); - PrintAndLogEx(SUCCESS, "National Code..... " _GREEN_("%012" PRIu64) " ( 0x%" PRIX64 " )", NationalCode, NationalCode); - PrintAndLogEx(SUCCESS, "Country Code...... " _GREEN_("%03u") " - %s", countryCode, mapFDBX(countryCode)); - PrintAndLogEx(SUCCESS, "Reserved/RFU...... %u (0x%04X)", reservedCode, reservedCode); - PrintAndLogEx(SUCCESS, "Animal bit set?... %s", animalBit ? _YELLOW_("True") : "False"); - PrintAndLogEx(SUCCESS, "Data block?....... %s ( 0x%X )", dataBlockBit ? _YELLOW_("True") : "False", extended); - PrintAndLogEx(SUCCESS, "RUDI bit?......... %s", rudiBit ? _YELLOW_("True") " ( advanced transponder )" : "False"); - PrintAndLogEx(SUCCESS, "User Info?........ %u %s", userInfo, (userInfo == 0) ? "( RFU )" : ""); - PrintAndLogEx(SUCCESS, "Replacement No?... %u %s", replacementNr, replacementNr == 0 ? "( RFU )" : ""); + PrintAndLogEx(SUCCESS, "Animal code......... " _GREEN_("%03u %012"PRIu64), countryCode, NationalCode); + PrintAndLogEx(SUCCESS, "National ID code.... " _GREEN_("%012" PRIu64) " ( 0x%010" PRIX64 " )", NationalCode, NationalCode); + PrintAndLogEx(SUCCESS, "Country code........ " _GREEN_("%03u") " - %s", countryCode, mapFDBX(countryCode)); + PrintAndLogEx(SUCCESS, "Starting digit...... %u ( 0x%02X )", visualStart, visualStart); + PrintAndLogEx(SUCCESS, "Reserved field...... %u ( 0x%02X )", reservedCode, reservedCode); + PrintAndLogEx(SUCCESS, "Animal bit.......... %s", animalBit ? _YELLOW_("True") : "False"); + PrintAndLogEx(SUCCESS, "Data block flag..... %s", dataBlockBit ? _YELLOW_("True") : "False"); + PrintAndLogEx(SUCCESS, "Trailer............. 0x%06X", extended); + PrintAndLogEx(SUCCESS, "RUDI-bit............ %s", rudiBit ? _YELLOW_("True") " ( advanced transponder )" : "False"); + // ISO 24631-6: user information on two digits, retagging counter on one + PrintAndLogEx(SUCCESS, "User information.... %02u ( 0x%02X )", userInfo, userInfo); + PrintAndLogEx(SUCCESS, "Retagging counter... %u ( 0x%02X )", replacementNr, replacementNr); // crc only calculated over NORMAL data (8 bytes) uint8_t c[] = {0, 0}; compute_crc(CRC_11784, raw, 8, &c[0], &c[1]); - PrintAndLogEx(SUCCESS, "CRC-16............ 0x%04X ( %s )", crc, (crc == (c[1] << 8 | c[0])) ? _GREEN_("ok") : _RED_("fail")); + PrintAndLogEx(SUCCESS, "CRC-16.............. 0x%04X ( %s )", crc, (crc == (c[1] << 8 | c[0])) ? _GREEN_("ok") : _RED_("fail")); // iceman: crc doesn't protect the extended data? - PrintAndLogEx(SUCCESS, "Raw............... " _GREEN_("%s"), sprint_hex(raw, sizeof(raw))); + PrintAndLogEx(SUCCESS, "Raw................. " _GREEN_("%s"), sprint_hex(raw, sizeof(raw))); if (g_debugMode) { PrintAndLogEx(DEBUG, "Start marker %d; Size %zu", preambleIndex, size); @@ -598,17 +617,16 @@ int demodFDXB(bool verbose) { PrintAndLogEx(DEBUG, "DEBUG bin stream:\n%s", bin); } - uint8_t bt_par = (extended & 0x100) >> 8; uint8_t bt_temperature = extended & 0xff; - uint8_t bt_calc_parity = (bitcount32(bt_temperature) & 0x1) ? 0 : 1; - uint8_t is_bt_temperature = (bt_calc_parity == bt_par) && !(extended & 0xe00) ; + // only the exact layout of the chips, every other bit clear + bool is_bt_temperature = (extended == getFDXBBioThermo(bt_temperature)); if (is_bt_temperature) { float bt_F = 74 + bt_temperature * 0.2; float bt_C = (bt_F - 32) / 1.8; PrintAndLogEx(NORMAL, ""); PrintAndLogEx(SUCCESS, "Bio-Thermo detected"); - PrintAndLogEx(INFO, " temperature... " _GREEN_("%.1f")" F / " _GREEN_("%.1f") " C", bt_F, bt_C); + PrintAndLogEx(INFO, " temperature... " _GREEN_("%.2f")" F / " _GREEN_("%.2f") " C", bt_F, bt_C); } // set block 0 for later @@ -662,40 +680,37 @@ static int CmdFdxBReader(const char *Cmd) { config.verbose = false; - int16_t curr_div = config.divisor; - int16_t old_div = curr_div; + int16_t old_div = config.divisor; if (cm) { PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); } + // 134 kHz for animal tags, then 125 kHz for emulators tuned there + const int16_t divisors[] = {LF_DIVISOR_134, LF_DIVISOR_125}; + int ret = PM3_SUCCESS; do { - if (curr_div == LF_DIVISOR_125) { - config.divisor = LF_DIVISOR_134; + for (size_t i = 0; i < ARRAYLEN(divisors); i++) { + config.divisor = divisors[i]; res = lf_setconfig(&config); if (res != PM3_SUCCESS) { - PrintAndLogEx(ERR, "failed to change to 134 KHz LF configuration"); + PrintAndLogEx(ERR, "failed to change to %s KHz LF configuration", (divisors[i] == LF_DIVISOR_134) ? "134" : "125"); return res; } - } else { - config.divisor = LF_DIVISOR_125; - res = lf_setconfig(&config); - if (res != PM3_SUCCESS) { - PrintAndLogEx(ERR, "failed to change to 125 KHz LF configuration"); - return res; + + lf_read(false, 10000); + ret = demodFDXB(!cm); // be verbose only if not in continuous mode + if (ret == PM3_SUCCESS) { + break; } } - curr_div = config.divisor; - - lf_read(false, 10000); - ret = demodFDXB(!cm); // be verbose only if not in continuous mode } while (cm && (kbd_enter_pressed() == false)); - if (old_div != curr_div) { + if (old_div != config.divisor) { config.divisor = old_div; res = lf_setconfig(&config); if (res != PM3_SUCCESS) { @@ -713,6 +728,7 @@ static int CmdFdxBClone(const char *Cmd) { "clone a FDX-B tag to a T55x7, Q5/T5555 or EM4305/4469 tag.", "lf fdxb clone --country 999 --national 1337 --animal -> encode for T55x7 tag, with animal bit\n" "lf fdxb clone --country 999 --national 1337 --extended 016A -> encode for T55x7 tag, with extended data\n" + "lf fdxb clone --country 999 --national 1337 --biothermo 106 -> encode for T55x7 tag, Bio-Thermo 95.20 F\n" "lf fdxb clone --country 999 --national 1337 --q5 -> encode for Q5/T5555 tag\n" "lf fdxb clone --country 999 --national 1337 --em -> encode for EM4305/4469" ); @@ -725,11 +741,13 @@ static int CmdFdxBClone(const char *Cmd) { arg_lit0("a", "animal", "optional - set animal bit"), arg_lit0(NULL, "q5", "optional - specify writing to Q5/T5555 tag"), arg_lit0(NULL, "em", "optional - specify writing to EM4305/4469 tag"), + arg_u64_0(NULL, "biothermo", "", "Bio-Thermo temperature value 0-255, 74 + 0.2 x value F"), + arg_lit0(NULL, "no-datablock", "optional - leave the data block flag clear, as Bio-Thermo chips do"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); - uint32_t country_code = arg_get_u32_def(ctx, 1, 0); + uint64_t country_code = arg_get_u64_def(ctx, 1, 0); uint64_t national_code = arg_get_u64_def(ctx, 2, 0); int extended_len = 0; @@ -739,6 +757,9 @@ static int CmdFdxBClone(const char *Cmd) { bool is_animal = arg_get_lit(ctx, 4); bool q5 = arg_get_lit(ctx, 5); bool em = arg_get_lit(ctx, 6); + bool has_biothermo = (arg_get_u64_count(ctx, 7) > 0); + uint64_t biothermo = arg_get_u64_def(ctx, 7, 0); + bool no_datablock = arg_get_lit(ctx, 8); CLIParserFree(ctx); if (q5 && em) { @@ -753,14 +774,39 @@ static int CmdFdxBClone(const char *Cmd) { has_extended = true; } - verify_values(&national_code, &country_code, &extended); + // the frame carries 10 bits of country code and 38 of national code + if (country_code > 0x3FF || national_code > 0x3FFFFFFFFF) { + PrintAndLogEx(FAILED, "Country code has a max value of 1023 and national code has a max value of 274877906943"); + return PM3_EINVARG; + } - PrintAndLogEx(INFO, "Country code........ %"PRIu32, country_code); - PrintAndLogEx(INFO, "National code....... %"PRIu64, national_code); - PrintAndLogEx(INFO, "Set animal bit...... %c", (is_animal) ? 'Y' : 'N'); - PrintAndLogEx(INFO, "Set data block bit.. %c", (has_extended) ? 'Y' : 'N'); - PrintAndLogEx(INFO, "Extended data....... 0x%"PRIX32, extended); - PrintAndLogEx(INFO, "RFU................. 0"); + if (has_extended && has_biothermo) { + PrintAndLogEx(FAILED, "Can't specify both extended data and Bio-Thermo at the same time"); + return PM3_EINVARG; + } + + if (biothermo > 0xFF) { + PrintAndLogEx(FAILED, "Bio-Thermo has a max value of 255"); + return PM3_EINVARG; + } + + if (has_biothermo) { + extended = getFDXBBioThermo(biothermo); + } + // Bio-Thermo chips send their temperature with the data block flag clear + bool data_block = has_extended && (no_datablock == false); + + PrintAndLogEx(INFO, "Country code........ %"PRIu64, country_code); + PrintAndLogEx(INFO, "National ID code.... %"PRIu64, national_code); + PrintAndLogEx(INFO, "Animal bit.......... %s", is_animal ? _YELLOW_("True") : "False"); + PrintAndLogEx(INFO, "Data block flag..... %s", data_block ? _YELLOW_("True") : "False"); + PrintAndLogEx(INFO, "Trailer............. 0x%06"PRIX32, extended); + if (has_biothermo) { + float bt_F = 74 + biothermo * 0.2; + PrintAndLogEx(INFO, "Bio-Thermo.......... %"PRIu64" ( %.2f F / %.2f C )", biothermo, bt_F, (bt_F - 32) / 1.8); + } + PrintAndLogEx(INFO, "Starting digit...... 0 ( 0x00 )"); + PrintAndLogEx(INFO, "Reserved field...... 0 ( 0x00 )"); uint8_t *bs = calloc(128, sizeof(uint8_t)); if (bs == NULL) { @@ -768,7 +814,7 @@ static int CmdFdxBClone(const char *Cmd) { return PM3_EMALLOC; } - if (getFDXBBits(national_code, country_code, is_animal, has_extended, extended, bs) != PM3_SUCCESS) { + if (getFDXBBits(national_code, country_code, is_animal, data_block, extended, bs) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Error with tag bitstream generation."); free(bs); return PM3_ESOFT; @@ -797,7 +843,7 @@ static int CmdFdxBClone(const char *Cmd) { free(bs); - PrintAndLogEx(INFO, "Preparing to clone FDX-B to " _YELLOW_("%s") " with animal ID: " _GREEN_("%04u-%"PRIu64) + PrintAndLogEx(INFO, "Preparing to clone FDX-B to " _YELLOW_("%s") " with animal code: " _GREEN_("%03"PRIu64" %012"PRIu64) , cardtype , country_code , national_code @@ -823,6 +869,7 @@ static int CmdFdxBSim(const char *Cmd) { "Simulation runs until the button is pressed or another USB command is issued.", "lf fdxb sim --country 999 --national 1337 --animal\n" "lf fdxb sim --country 999 --national 1337 --extended 016A\n" + "lf fdxb sim --country 999 --national 1337 --biothermo 106\n" ); void *argtable[] = { @@ -831,17 +878,22 @@ static int CmdFdxBSim(const char *Cmd) { arg_u64_1("n", "national", "", "national code"), arg_str0(NULL, "extended", "", "extended data"), arg_lit0("a", "animal", "optional - set animal bit"), + arg_u64_0(NULL, "biothermo", "", "Bio-Thermo temperature value 0-255, 74 + 0.2 x value F"), + arg_lit0(NULL, "no-datablock", "optional - leave the data block flag clear, as Bio-Thermo chips do"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); - uint32_t country_code = arg_get_u32_def(ctx, 1, 0); + uint64_t country_code = arg_get_u64_def(ctx, 1, 0); uint64_t national_code = arg_get_u64_def(ctx, 2, 0); int extended_len = 0; uint8_t edata[3] = {0}; CLIGetHexWithReturn(ctx, 3, edata, &extended_len); bool is_animal = arg_get_lit(ctx, 4); + bool has_biothermo = (arg_get_u64_count(ctx, 5) > 0); + uint64_t biothermo = arg_get_u64_def(ctx, 5, 0); + bool no_datablock = arg_get_lit(ctx, 6); CLIParserFree(ctx); uint32_t extended = 0; @@ -851,23 +903,48 @@ static int CmdFdxBSim(const char *Cmd) { has_extended = true; } - verify_values(&national_code, &country_code, &extended); + // the frame carries 10 bits of country code and 38 of national code + if (country_code > 0x3FF || national_code > 0x3FFFFFFFFF) { + PrintAndLogEx(FAILED, "Country code has a max value of 1023 and national code has a max value of 274877906943"); + return PM3_EINVARG; + } - PrintAndLogEx(INFO, "Country code........ %"PRIu32, country_code); - PrintAndLogEx(INFO, "National code....... %"PRIu64, national_code); - PrintAndLogEx(INFO, "Set animal bit...... %c", (is_animal) ? 'Y' : 'N'); - PrintAndLogEx(INFO, "Set data block bit.. %c", (has_extended) ? 'Y' : 'N'); - PrintAndLogEx(INFO, "Extended data....... 0x%"PRIX16, extended); - PrintAndLogEx(INFO, "RFU................. 0"); + if (has_extended && has_biothermo) { + PrintAndLogEx(FAILED, "Can't specify both extended data and Bio-Thermo at the same time"); + return PM3_EINVARG; + } - PrintAndLogEx(SUCCESS, "Simulating FDX-B animal ID: " _YELLOW_("%04u-%"PRIu64), country_code, national_code); + if (biothermo > 0xFF) { + PrintAndLogEx(FAILED, "Bio-Thermo has a max value of 255"); + return PM3_EINVARG; + } + + if (has_biothermo) { + extended = getFDXBBioThermo(biothermo); + } + // Bio-Thermo chips send their temperature with the data block flag clear + bool data_block = has_extended && (no_datablock == false); + + PrintAndLogEx(INFO, "Country code........ %"PRIu64, country_code); + PrintAndLogEx(INFO, "National ID code.... %"PRIu64, national_code); + PrintAndLogEx(INFO, "Animal bit.......... %s", is_animal ? _YELLOW_("True") : "False"); + PrintAndLogEx(INFO, "Data block flag..... %s", data_block ? _YELLOW_("True") : "False"); + PrintAndLogEx(INFO, "Trailer............. 0x%06"PRIX32, extended); + if (has_biothermo) { + float bt_F = 74 + biothermo * 0.2; + PrintAndLogEx(INFO, "Bio-Thermo.......... %"PRIu64" ( %.2f F / %.2f C )", biothermo, bt_F, (bt_F - 32) / 1.8); + } + PrintAndLogEx(INFO, "Starting digit...... 0 ( 0x00 )"); + PrintAndLogEx(INFO, "Reserved field...... 0 ( 0x00 )"); + + PrintAndLogEx(SUCCESS, "Simulating FDX-B animal code: " _YELLOW_("%03"PRIu64" %012"PRIu64), country_code, national_code); uint8_t *bs = calloc(128, sizeof(uint8_t)); if (bs == NULL) { PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } - if (getFDXBBits(national_code, country_code, is_animal, (extended > 0), extended, bs) != PM3_SUCCESS) { + if (getFDXBBits(national_code, country_code, is_animal, data_block, extended, bs) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Error with tag bitstream generation."); free(bs); return PM3_ESOFT; @@ -892,20 +969,13 @@ static int CmdFdxBSim(const char *Cmd) { free(bs); free(payload); - PacketResponseNG resp; - WaitForResponse(CMD_LF_ASK_SIMULATE, &resp); - - PrintAndLogEx(INFO, "Done!"); - if (resp.status != PM3_EOPABORTED) { - return resp.status; - } - return PM3_SUCCESS; + return lfsim_wait_check(CMD_LF_ASK_SIMULATE); } static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "this help"}, {"demod", CmdFdxBDemod, AlwaysAvailable, "demodulate a FDX-B ISO11784/85 tag from the GraphBuffer"}, - {"reader", CmdFdxBReader, IfPm3Lf, "attempt to read at 134kHz and extract tag data"}, + {"reader", CmdFdxBReader, IfPm3Lf, "attempt to read at 134 kHz, then 125 kHz, and extract tag data"}, {"clone", CmdFdxBClone, IfPm3Lf, "clone animal ID tag to T55x7, Q5/T5555 or EM4305/4469"}, {"sim", CmdFdxBSim, IfPm3Lf, "simulate Animal ID tag"}, {NULL, NULL, NULL, NULL} diff --git a/client/src/cmdlfhitag.c b/client/src/cmdlfhitag.c index c7aa90f08..321e9353a 100644 --- a/client/src/cmdlfhitag.c +++ b/client/src/cmdlfhitag.c @@ -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; diff --git a/client/src/cmdlfhitaghts.c b/client/src/cmdlfhitaghts.c index 2f52823f8..a9e1afa05 100644 --- a/client/src/cmdlfhitaghts.c +++ b/client/src/cmdlfhitaghts.c @@ -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)); diff --git a/client/src/cmdlfhitagu.c b/client/src/cmdlfhitagu.c index 5d0ec275f..1430823df 100644 --- a/client/src/cmdlfhitagu.c +++ b/client/src/cmdlfhitagu.c @@ -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)); diff --git a/client/src/cmdlfnoralsy.c b/client/src/cmdlfnoralsy.c index b10ee7f97..e3278ddfb 100644 --- a/client/src/cmdlfnoralsy.c +++ b/client/src/cmdlfnoralsy.c @@ -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 diff --git a/doc/commands.json b/doc/commands.json index 9c22c6718..7bc8d6832 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -11796,7 +11796,7 @@ "offline": false, "options": [ "-h, --help This help", - "-u, --uid 5 bytes max", + "-u, --uid 5 hex bytes, 00-7F each", "--q5 optional - specify writing to Q5/T5555 tag", "--em optional - specify writing to EM4305/4469 tag" ], @@ -11829,15 +11829,16 @@ }, "lf destron sim": { "command": "lf destron sim", - "description": "Try to find Destron preamble, if found decode / descramble data", + "description": "Enables simulation of Destron card with specified uid. Simulation runs until the button is pressed or another USB command is issued.", "notes": [ - "lf destron sim" + "lf destron sim --uid 1A2B3C4D5E" ], "offline": false, "options": [ - "-h, --help This help" + "-h, --help This help", + "-u, --uid 5 hex bytes, 00-7F each" ], - "usage": "lf destron sim [-h]" + "usage": "lf destron sim [-h] -u " }, "lf em 410x brute": { "command": "lf em 410x brute", @@ -12564,6 +12565,7 @@ "notes": [ "lf fdxb clone --country 999 --national 1337 --animal -> encode for T55x7 tag, with animal bit", "lf fdxb clone --country 999 --national 1337 --extended 016A -> encode for T55x7 tag, with extended data", + "lf fdxb clone --country 999 --national 1337 --biothermo 106 -> encode for T55x7 tag, Bio-Thermo 95.20 F", "lf fdxb clone --country 999 --national 1337 --q5 -> encode for Q5/T5555 tag", "lf fdxb clone --country 999 --national 1337 --em -> encode for EM4305/4469" ], @@ -12575,9 +12577,11 @@ "--extended extended data", "-a, --animal optional - set animal bit", "--q5 optional - specify writing to Q5/T5555 tag", - "--em optional - specify writing to EM4305/4469 tag" + "--em optional - specify writing to EM4305/4469 tag", + "--biothermo Bio-Thermo temperature value 0-255, 74 + 0.2 x value F", + "--no-datablock optional - leave the data block flag clear, as Bio-Thermo chips do" ], - "usage": "lf fdxb clone [-ha] -c -n [--extended ] [--q5] [--em]" + "usage": "lf fdxb clone [-ha] -c -n [--extended ] [--q5] [--em] [--biothermo ] [--no-datablock]" }, "lf fdxb help": { "command": "lf fdxb help", @@ -12609,7 +12613,8 @@ "description": "Enables simulation of FDX-B animal tag. Simulation runs until the button is pressed or another USB command is issued.", "notes": [ "lf fdxb sim --country 999 --national 1337 --animal", - "lf fdxb sim --country 999 --national 1337 --extended 016A" + "lf fdxb sim --country 999 --national 1337 --extended 016A", + "lf fdxb sim --country 999 --national 1337 --biothermo 106" ], "offline": false, "options": [ @@ -12617,9 +12622,11 @@ "-c, --country country code", "-n, --national national code", "--extended extended data", - "-a, --animal optional - set animal bit" + "-a, --animal optional - set animal bit", + "--biothermo Bio-Thermo temperature value 0-255, 74 + 0.2 x value F", + "--no-datablock optional - leave the data block flag clear, as Bio-Thermo chips do" ], - "usage": "lf fdxb sim [-ha] -c -n [--extended ]" + "usage": "lf fdxb sim [-ha] -c -n [--extended ] [--biothermo ] [--no-datablock]" }, "lf gallagher clone": { "command": "lf gallagher clone", @@ -16812,6 +16819,6 @@ "metadata": { "commands_extracted": 936, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2026-11-06T22:34:07+00:00" + "extracted_on": "2026-11-07T21:01:26+00:00" } } diff --git a/doc/commands.md b/doc/commands.md index ff131cbea..a41446d46 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -1234,7 +1234,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`lf fdxb help `|Y |`this help` |`lf fdxb demod `|Y |`demodulate a FDX-B ISO11784/85 tag from the GraphBuffer` -|`lf fdxb reader `|N |`attempt to read at 134kHz and extract tag data` +|`lf fdxb reader `|N |`attempt to read at 134 kHz, then 125 kHz, and extract tag data` |`lf fdxb clone `|N |`clone animal ID tag to T55x7, Q5/T5555 or EM4305/4469` |`lf fdxb sim `|N |`simulate Animal ID tag` diff --git a/tools/pm3_tests.sh b/tools/pm3_tests.sh index 74a45e0b4..10f1f7815 100755 --- a/tools/pm3_tests.sh +++ b/tools/pm3_tests.sh @@ -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'" \ @@ -577,8 +578,9 @@ while true; do if ! CheckExecute "lf EM4x70 recover test 2/3" "$CLIENTBIN -c 'lf em 4x70 recover --key 022A028C02BE --rnd 7D5167003571F8 --frn 982DBCC0 --grn 36C0E0'" "022a028c02be366866191b60"; then break; fi if ! CheckExecute "lf EM4x70 recover test 3/3" "$CLIENTBIN -c 'lf em 4x70 recover --key 022A028C02BE --rnd 7D5167003571F8 --frn 982DBCC0 --grn 36C0E0'" "022a028c02bef1e352c2718d"; then break; fi if ! CheckExecute "lf FDX-A FECAVA test" "$CLIENTBIN -c 'data load -f traces/lf_EM4305_fdxa_destron.pm3;lf search -1'" "FDX-A FECAVA Destron ID found"; then break; fi + if ! CheckExecute "lf destron sim help" "$CLIENTBIN -c 'lf destron sim -h'" "lf destron sim --uid 1A2B3C4D5E"; then break; fi if ! CheckExecute "lf FDX-B test" "$CLIENTBIN -c 'data load -f traces/lf_HomeAgain1600.pm3;lf search -1'" "FDX-B ID found"; then break; fi - if ! CheckExecute "lf FDX/BioThermo test" "$CLIENTBIN -c 'data load -f traces/lf_FDXB_Bio-Thermo.pm3; lf fdxb demod'" "95.2 F / 35.1 C"; then break; fi + if ! CheckExecute "lf FDX/BioThermo test" "$CLIENTBIN -c 'data load -f traces/lf_FDXB_Bio-Thermo.pm3; lf fdxb demod'" "95.20 F / 35.11 C"; then break; fi if ! CheckExecute "lf GPROXII test" "$CLIENTBIN -c 'data load -f traces/lf_GProx_36_30_14489.pm3; lf search -1'" "Guardall G-Prox II ID found"; then break; fi if ! CheckExecute "lf HID Prox test" "$CLIENTBIN -c 'data load -f traces/lf_HID-proxCardII-05512-11432784-1.pm3;lf search -1'" "HID Prox ID found"; then break; fi if ! CheckExecute "lf IDTECK test" "$CLIENTBIN -c 'data load -f traces/lf_IDTECK_4944544BAC40E069.pm3; lf search -1'" "Idteck ID found"; then break; fi @@ -612,10 +614,10 @@ while true; do "EM 410x ID 0F0368568B"; then break; fi if ! CheckExecute "lf T55 fdxb_animal test" "$CLIENTBIN -c 'data load -f traces/lf_ATA5577_fdxb_animal.pm3; lf search -1'" "FDX-B ID found"; then break; fi if ! CheckExecute "lf T55 fdxb_animal test 2" "$CLIENTBIN -c 'data load -f traces/lf_ATA5577_fdxb_animal.pm3; lf fdxb demod'" \ - "Animal ID......... 999-000000112233"; then break; fi + "Animal code......... 999 000000112233"; then break; fi if ! CheckExecute "lf T55 fdxb_extended test" "$CLIENTBIN -c 'data load -f traces/lf_ATA5577_fdxb_extended.pm3; lf search -1'" "FDX-B ID found"; then break; fi if ! CheckExecute "lf T55 fdxb_extended test 2" "$CLIENTBIN -c 'data load -f traces/lf_ATA5577_fdxb_extended.pm3; lf fdxb demod'" \ - "temperature... 95.2 F / 35.1 C"; then break; fi + "temperature... 95.20 F / 35.11 C"; then break; fi if ! CheckExecute "lf T55 gallagher test" "$CLIENTBIN -c 'data load -f traces/lf_ATA5577_gallagher.pm3; lf search -1'" "GALLAGHER ID found"; then break; fi if ! CheckExecute "lf T55 gallagher test 2" "$CLIENTBIN -c 'data load -f traces/lf_ATA5577_gallagher.pm3; lf gallagher demod'" \ "GALLAGHER - Region: 1 Facility: 16640 Card No.: 201 Issue Level: 1"; then break; fi