diff --git a/.github/ISSUE_TEMPLATE/checklist-for-release.md b/.github/ISSUE_TEMPLATE/checklist-for-release.md index 534124ca9..aada17dd8 100644 --- a/.github/ISSUE_TEMPLATE/checklist-for-release.md +++ b/.github/ISSUE_TEMPLATE/checklist-for-release.md @@ -11,7 +11,7 @@ assignees: doegox, iceman1001 - [ ] `make style` - [ ] `make miscchecks` -- [ ] `make clean; make host CC=clang CXX=clang++ LD=clang++` on recent Debian or Ubuntu +- [ ] `make clean; make -j host CC=clang CXX=clang++ LD=clang++` on recent Debian or Ubuntu - [ ] `mymanualchecks.sh` - [ ] `mycppcheck.sh` no alarming warning? - [ ] `tools/build_all_firmwares.sh` check that the script contains all standalone modes then compile all standalone modes (linux only) @@ -44,7 +44,7 @@ Run `tools/release_tests.sh` on: - [ ] Ubuntu 25.10 - [ ] OSX (MacPorts) - [ ] OSX (Homebrew) -- [ ] Termux +- [ ] Termux cf `docker/termux-README.md` - [ ] Android cmake cross-compilation ? # creating release diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2cfca5970..6cb9823c2 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -23,7 +23,6 @@ jobs: run: shell: pwsh env: - PATH: C:/ProxSpace/msys2/ucrt64/bin;C:/ProxSpace/msys2/usr/local/bin;C:/ProxSpace/msys2/usr/bin;C:/ProxSpace/msys2/bin MSYSTEM: UCRT64 PYTHONHOME: /ucrt64 @@ -107,6 +106,19 @@ jobs: - uses: actions/checkout@v6 + # Prepend MSYS2 tools to PATH only for steps after checkout, so actions/checkout + # keeps using the runner's native git (MSYS2's git.exe mangles refs like + # 'tag^{commit}' due to its own bash-style argv reparsing). + - name: Add ProxSpace/MSYS2 to PATH + run: | + Add-Content -Path $env:GITHUB_PATH -Value "C:\ProxSpace\msys2\ucrt64\bin" + Add-Content -Path $env:GITHUB_PATH -Value "C:\ProxSpace\msys2\usr\local\bin" + Add-Content -Path $env:GITHUB_PATH -Value "C:\ProxSpace\msys2\usr\bin" + Add-Content -Path $env:GITHUB_PATH -Value "C:\ProxSpace\msys2\bin" + # Not set by an MSYS2 login shell here, so pkg-config wouldn't otherwise + # find the ucrt64 .pc files (zlib, jansson, gdlib, python3, etc). + Add-Content -Path $env:GITHUB_ENV -Value "PKG_CONFIG_PATH=/ucrt64/lib/pkgconfig:/ucrt64/share/pkgconfig" + # TODO workaround: "error: linker script file 'xxxx' appears multiple times" # This should be reverted once MSYS2 ships a non-broken version of the linker. - name: Downgrade ARM linker (Windows, temporary) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad7b664cb..e4214034d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `hf mfu restore` to support Ultralight AES (@iceman1001) +- Fixed `hf mfu info` to print UL-AES config pages again (@iceman1001) + +## [Frosty Lemon.4.23346][2026-09-18] - Fixed `hf mfdes sim` - the ATS now advertises 106 kbit/s only, PPS to a higher rate is refused, a selected card ignores REQA/WUPA, and ISO-DEP block recovery now follows the card sequence (@mistial-dev) - Added `hf mfdes sim` - answers ISO 7816 SELECT by DF name or file id with real status words, so a reader that opens with a SELECT reaches the card (@mistial-dev) - Fixed `hf mfdes sim` - a session opened with the 0x0A legacy authentication now uses the legacy secure messaging: 4 byte DES MAC, CRC16, no MAC on plain answers (@mistial-dev) @@ -77,6 +81,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Fixed `hf 14a sim` - a dynamic response now gets a modulation buffer sized to fit it, instead of one 68 bytes too small (or 1788 too large for ST25TA) (@iceman1001) - Fixed `BigBuf_malloc` - takes a uint32_t, so a request of 64KB or more fails instead of wrapping to zero (@iceman1001) - Fixed `BigBuf_max_traceLen` - returns a uint32_t, so LF sampling on a device with more than 64KB of BigBuf is not handed a truncated buffer (@iceman1001) +- Fixed PM5 BigBuf allocation - Changed `hf mf view` - now show which VIGIK fields are RSA signed (@iceman1001) - Changed `hw status` - now reports EMULATOR memory (@iceman1001) - Changed `hf mf view` - Urmet Captiv cards now decode their number field and data regions (@iceman1001) diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index 28470f8d2..000000000 --- a/CLAUDE.md +++ /dev/null @@ -1,3 +0,0 @@ -# Instructions - -See [AGENTS.md](./AGENTS.md) for coding, build, and PR guidelines. This project keeps a single source of truth in AGENTS.md rather than duplicating instructions per tool. diff --git a/Makefile b/Makefile index 556ee5341..b5536fad4 100644 --- a/Makefile +++ b/Makefile @@ -354,13 +354,20 @@ style: commands --style=google --unpad-paren --pad-header \ --align-pointer=name {} \; +COMMANDS_UTF8_FILTER := cat +COMMANDS_PYTHON := $(PYTHON3) +ifdef IS_MINGW + COMMANDS_UTF8_FILTER := iconv -f CP850 -t UTF-8 + COMMANDS_PYTHON := PYTHONIOENCODING=utf-8 $(PYTHON3) +endif + commands: client # Update commands.md - [ -x client/proxmark3 ] && client/proxmark3 -m | tr -d '\r' > doc/commands.md + [ -x client/proxmark3 ] && client/proxmark3 -m | $(COMMANDS_UTF8_FILTER) | tr -d '\r' > doc/commands.md # Make sure python3 is installed - @command -v python3 >/dev/null || ( echo "Please install 'python3' package first" ; exit 1 ) + @command -v $(PYTHON3) >/dev/null || ( echo "Please install '$(PYTHON3)' package first" ; exit 1 ) # Update commands.json, patch port in case it was run under Windows - [ -x client/proxmark3 ] && client/proxmark3 --fulltext | sed 's#com[0-9]#/dev/ttyACM0#'|python3 client/pyscripts/pm3_help2json.py - - | tr -d '\r' > doc/commands.json + [ -x client/proxmark3 ] && client/proxmark3 --fulltext | $(COMMANDS_UTF8_FILTER) | sed 's#com[0-9]#/dev/ttyACM0#'|$(COMMANDS_PYTHON) client/pyscripts/pm3_help2json.py - - | tr -d '\r' > doc/commands.json # Detecting weird codepages and tabs. diff --git a/Makefile.defs b/Makefile.defs index 8cfcce10e..7304bb5f6 100644 --- a/Makefile.defs +++ b/Makefile.defs @@ -53,6 +53,7 @@ USERMOD = usermod -aG ADDUSER = adduser GETENT_BL = getent group bluetooth +PYTHON3 ?= python3 PYTHON3_PKGCONFIG ?= python3 PATHSEP=/ diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index 6ec041ec8..a3172ffb5 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -23,7 +23,7 @@ #include "util.h" // nbytes #define BIGBUF_ALIGN_BYTES (4) -#define BIGBUF_ALIGN_MASK (0xFFFF + 1 - BIGBUF_ALIGN_BYTES) +#define BIGBUF_ALIGN_MASK (~(uint32_t)(BIGBUF_ALIGN_BYTES - 1)) extern uint32_t _stack_start[], __bss_end__[]; diff --git a/armsrc/BigBuf.h b/armsrc/BigBuf.h index d588e9a22..43dfe66d8 100644 --- a/armsrc/BigBuf.h +++ b/armsrc/BigBuf.h @@ -20,6 +20,7 @@ #define __BIGBUF_H #include "common.h" +#include "pm3_cmd.h" #define MAX_FRAME_SIZE 256 // maximum allowed ISO14443 frame // The 14a demodulator stores 8 parity bits per 8 received bytes and then flushes @@ -50,6 +51,11 @@ // 8 data bits and 1 parity bit per payload byte, 1 correction bit, 1 SOC bit, 2 EOC bits #define TOSEND_BUFFER_SIZE (9 * MAX_FRAME_SIZE + 1 + 1 + 2) +// For double buffering, must be at least 2x PM3_CMD_DATA_SIZE +#if (PM3_CMD_DATA_SIZE * 2) > TOSEND_BUFFER_SIZE +#undef TOSEND_BUFFER_SIZE +#define TOSEND_BUFFER_SIZE (PM3_CMD_DATA_SIZE * 2) +#endif uint8_t *BigBuf_get_addr(void); uint32_t BigBuf_get_size(void); diff --git a/armsrc/Standalone/Makefile.hal b/armsrc/Standalone/Makefile.hal index 0c8673151..906f68cc9 100644 --- a/armsrc/Standalone/Makefile.hal +++ b/armsrc/Standalone/Makefile.hal @@ -77,10 +77,10 @@ define KNOWN_STANDALONE_DEFINITIONS | HF_14BSNIFF | 14b sniff to flashmem (rdv4) or ram | | | | +-----------------------------------------------------------+ -| HF_15SNIFF | 15693 sniff to flashmem (rdv4) or ram | +| HF_15SIM | 15693 tag simulator | | | | +-----------------------------------------------------------+ -| HF_15SIM | 15693 tag simulator | +| HF_15SNIFF | 15693 sniff to flashmem (rdv4) or ram | | | | +-----------------------------------------------------------+ | HF_AVEFUL | Mifare ultralight read/simulation | @@ -104,6 +104,9 @@ define KNOWN_STANDALONE_DEFINITIONS | HF_DOEGOX_COMMIT | DESFire suspended commit | | | - Philippe Teuwen | +-----------------------------------------------------------+ +| HF_EMVPNG | Read and emulate EMV Visa cards | +| | - Davi Mikael (Penegui) | ++-----------------------------------------------------------+ | HF_ICECLASS | Simulate HID iCLASS legacy ags | | (RDV4 only) | storing in flashmem | +-----------------------------------------------------------+ @@ -146,15 +149,12 @@ define KNOWN_STANDALONE_DEFINITIONS | DANKARMULTI | Load multiple standalone modes. | | | - Daniel Karling | +-----------------------------------------------------------+ -| HF_EMVPNG | Read and emulate EMV Visa cards | -| | - Davi Mikael (Penegui) | -+-----------------------------------------------------------+ endef STANDALONE_MODES := LF_SKELETON STANDALONE_MODES += LF_EM4100EMUL LF_EM4100RSWB LF_EM4100RSWW LF_EM4100RWC LF_HIDBRUTE LF_HIDFCBRUTE LF_ICEHID LF_MULTIHID LF_NEDAP_SIM LF_NEXID LF_PROXBRUTE LF_PROX2BRUTE LF_SAMYRUN LF_THAREXDE -STANDALONE_MODES += HF_14ASNIFF HF_14BSNIFF HF_15SNIFF HF_15SIM HF_AVEFUL HF_BOG HF_CARDHOPPER HF_COLIN HF_CRAFTBYTE HF_DOEGOX_AUTH0 HF_DOEGOX_COMMIT HF_ICECLASS HF_LEGIC HF_LEGIC_RDV4 HF_LEGICSIM HF_MATTYRUN HF_MFCSIM HF_MSDSAL HF_REBLAY HF_ST25_TEAROFF HF_TCPRST HF_TMUDFORD HF_UNISNIFF HF_YOUNG HF_EMVPNG +STANDALONE_MODES += HF_14ASNIFF HF_14BSNIFF HF_15SIM HF_15SNIFF HF_AVEFUL HF_BOG HF_CARDHOPPER HF_COLIN HF_CRAFTBYTE HF_DOEGOX_AUTH0 HF_DOEGOX_COMMIT HF_EMVPNG HF_ICECLASS HF_LEGIC HF_LEGIC_RDV4 HF_LEGICSIM HF_MATTYRUN HF_MFCSIM HF_MSDSAL HF_REBLAY HF_ST25_TEAROFF HF_TCPRST HF_TMUDFORD HF_UNISNIFF HF_YOUNG STANDALONE_MODES += DANKARMULTI STANDALONE_MODES_REQ_BT := HF_CARDHOPPER HF_REBLAY STANDALONE_MODES_REQ_SMARTCARD := diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 652ddd566..e0af71124 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -2739,6 +2739,7 @@ static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing // If further research is needed, an oscilloscope needs to be used to observe the specific DOUT modulation status. // --- // Clear TXRDY: + while (!FPGA_SSC_TX_Ready()) {} FPGA_SSC_TX_Value(SEC_Y); uint16_t c = 0; @@ -2972,6 +2973,7 @@ int EmSendCmd14443aRaw(const uint8_t *resp, uint16_t respLen) { while ((ThisTransferTime = GetCountSspClk()) & 0x00000007); // Clear TXRDY: + while (!FPGA_SSC_TX_Ready()) {} FPGA_SSC_TX_Value(SEC_F); // send cycle diff --git a/armsrc/thinfilm.c b/armsrc/thinfilm.c index 9d0e7141c..34131fd6d 100644 --- a/armsrc/thinfilm.c +++ b/armsrc/thinfilm.c @@ -281,6 +281,7 @@ static int EmSendCmdThinfilmRaw(const uint8_t *resp, uint16_t respLen) { while ((ThisTransferTime = GetCountSspClk()) & 0x00000007); // Clear TXRDY: + while (!FPGA_SSC_TX_Ready()) {} FPGA_SSC_TX_Value(SEC_F); uint16_t FpgaSendQueueDelay = 0; diff --git a/client/Makefile b/client/Makefile index 9002ea8c9..e2c518f22 100644 --- a/client/Makefile +++ b/client/Makefile @@ -1070,11 +1070,13 @@ endif install: all $(info [@] Installing client to $(DESTDIR)$(PREFIX)...) ifneq (,$(INSTALLBIN)) - $(Q)$(INSTALLSUDO) $(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH) - $(Q)$(INSTALLSUDO) $(CP) $(INSTALLBIN) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH) -ifeq ($(platform),Linux) - $(Q)$(INSTALLSUDO) setcap 'cap_net_raw,cap_net_admin+eip' $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH)$(PATHSEP)$(INSTALLBIN) || echo "[!] setcap failed - BLE connect-by-name (-p ble:) will need sudo; connect-by-MAC is unaffected" -endif + $(Q)$(INSTALLSUDO) $(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH) + $(Q)$(INSTALLSUDO) $(CP) $(INSTALLBIN) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH) + ifeq ($(platform),Linux) + ifneq ($(SKIP_SETCAP), 1) + $(Q)$(INSTALLSUDO) setcap 'cap_net_raw,cap_net_admin+eip' $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH)$(PATHSEP)$(INSTALLBIN) || echo "[!] setcap failed - BLE connect-by-name (-p ble:) will need sudo; connect-by-MAC is unaffected" + endif + endif endif ifneq (,$(INSTALLSHARE)) $(Q)$(INSTALLSUDO) $(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH) diff --git a/client/src/cmdhfepa.c b/client/src/cmdhfepa.c index 2cd8092c2..7c0106c39 100644 --- a/client/src/cmdhfepa.c +++ b/client/src/cmdhfepa.c @@ -81,7 +81,7 @@ static int CmdHFEPACollectPACENonces(const char *Cmd) { return PM3_ESOFT; } - const epa_result_t *r = (const epa_result_t *)resp.data.asBytes; + const epa_result_t *r = (const epa_result_t *)(const void *)resp.data.asBytes; if (r->step != 0) { PrintAndLogEx(FAILED, "Error in step %u, Return code: %d", r->step, r->func_return); @@ -211,7 +211,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) { return PM3_ESOFT; } - const epa_result_t *rr = (const epa_result_t *)resp.data.asBytes; + const epa_result_t *rr = (const epa_result_t *)(const void *)resp.data.asBytes; if (rr->step != 0) { PrintAndLogEx(SUCCESS, "\nPACE replay failed in step %u!", rr->step); @@ -273,7 +273,7 @@ static int CmdHFEPAPACESimulate(const char *Cmd) { return PM3_ESOFT; } - const epa_result_t *sr = (const epa_result_t *)resp.data.asBytes; + const epa_result_t *sr = (const epa_result_t *)(const void *)resp.data.asBytes; const uint32_t *data = sr->timings; if (sr->step != 0) { diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 96531ce6b..58d3d8764 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -65,6 +65,14 @@ #define MAX_ST25TN512 0x3F #define MAX_ST25TN01K 0x3F +// UL-AES fixed memory map, MF0AES(H)20 +#define MFU_AES_USER_FIRST 0x04 +#define MFU_AES_USER_LAST 0x27 +#define MFU_AES_LOCK_PAGE 0x28 +#define MFU_AES_CFG0_PAGE 0x29 +#define MFU_AES_CFG1_PAGE 0x2A +#define MFU_AES_KEY0_PAGE 0x30 + #define MIFAREU3P_KEY_SIZE 16 #define MIFAREULC_KEY_INDEX 3 #define MFU_DEFAULT_KEY_DIC "mfulc_default_keys.dic" @@ -4043,6 +4051,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { "hf mfu restore -f myfile -s -> special write\n" "hf mfu restore -f myfile -k AABBCCDD -s -> special write, use key\n" "hf mfu restore -f myfile -k AABBCCDD -ser -> special write, use key, write dump pwd, ...\n" + "hf mfu restore -f myfile -k 00112233445566778899AABBCCDDEEFF -> UL-C / UL-AES, use key\n" "\n" "Note: Restoring a NTAG/UL dump to a UMC will likely result in incorrect PWD and PACK\n" ); @@ -4050,7 +4059,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { void *argtable[] = { arg_param_begin, arg_str1("f", "file", "", "Specify a filename for dump file"), - arg_str0("k", "key", "", "key for authentication (UL-C 16 bytes, EV1/NTAG 4 bytes)"), + arg_str0("k", "key", "", "key for authentication (UL-C/UL-AES 16 bytes, EV1/NTAG 4 bytes)"), arg_lit0("l", NULL, "swap entered key's endianness"), arg_lit0("s", NULL, "enable special write UID -MAGIC TAG ONLY-"), arg_lit0("e", NULL, "enable special write version/signature -MAGIC NTAG 21* ONLY-"), @@ -4142,6 +4151,8 @@ static int CmdHF14AMfURestore(const char *Cmd) { return PM3_ESOFT; } + bool is_ulaes = ((tagtype & MFU_TT_UL_AES) == MFU_TT_UL_AES); + if ((tagtype & MFU_TT_UL_C) == MFU_TT_UL_C) { if ((has_key == true) && (ak_len != 16)) { PrintAndLogEx(ERR, "UL-C key must be 16 bytes"); @@ -4172,12 +4183,6 @@ static int CmdHF14AMfURestore(const char *Cmd) { } } - if ((tagtype & MFU_TT_UL_AES) == MFU_TT_UL_AES) { - PrintAndLogEx(ERR, "Sorry, UL-AES not yet supported. Feel free to implement!"); - free(dump); - return PM3_ENOTIMPL; - } - PrintAndLogEx(INFO, "Restoring " _YELLOW_("%s")" to card", filename); mfu_print_dump(mem, pages, 0, dense_output); @@ -4279,7 +4284,19 @@ static int CmdHF14AMfURestore(const char *Cmd) { // write all other data // Skip block 0,1,2,3 (only magic tags can write to them) // Skip last 5 blocks usually is configuration - for (uint8_t b = 4; b < pages - 5; b++) { + uint8_t first_page = 4; + uint8_t last_page = pages - 5; + + if (is_ulaes) { + // UL-AES user memory stops before the lock, config and key pages + first_page = MFU_AES_USER_FIRST; + last_page = MFU_AES_USER_LAST + 1; + if (pages < last_page) { + last_page = pages; + } + } + + for (uint8_t b = first_page; b < last_page; b++) { //Send write Block memcpy(packetw.data, mem->data + (b * 4), 4); @@ -4306,8 +4323,19 @@ static int CmdHF14AMfURestore(const char *Cmd) { // otp, uid, lock, dynlockbits, cfg0, cfg1 uint8_t blocks[] = {3, 0, 1, 2, pages - 5, pages - 4, pages - 3}; #endif - for (uint8_t i = 0; i < ARRAYLEN(blocks); i++) { - uint8_t b = blocks[i]; + // otp, uid, lock, cfg0, cfg1. + // RFU pages (0x2B, 0x2C) and the key lock bits (0x2D) are left alone, they are one way + uint8_t ulaes_blocks[] = {3, 0, 1, 2, MFU_AES_LOCK_PAGE, MFU_AES_CFG0_PAGE, MFU_AES_CFG1_PAGE}; + + uint8_t *pblocks = blocks; + uint8_t blockcnt = ARRAYLEN(blocks); + if (is_ulaes) { + pblocks = ulaes_blocks; + blockcnt = ARRAYLEN(ulaes_blocks); + } + + for (uint8_t i = 0; i < blockcnt; i++) { + uint8_t b = pblocks[i]; memcpy(packetw.data, mem->data + (b * 4), 4); packetw.block_no = b; clearCommandBuffer(); @@ -4319,6 +4347,12 @@ static int CmdHF14AMfURestore(const char *Cmd) { DropField(); free(dump); + + if (is_ulaes) { + PrintAndLogEx(INFO, "Key pages 0x%02X..0x%02X not restored", MFU_AES_KEY0_PAGE, MAX_UL_AES); + PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf mfu setkey -k <16 hex bytes>") "` to restore the AES keys"); + } + PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf mfu dump --ns") "` to verify"); PrintAndLogEx(INFO, "Done!"); return PM3_SUCCESS; diff --git a/client/src/cmdhfntag424.c b/client/src/cmdhfntag424.c index 97108a741..8aa8ce716 100644 --- a/client/src/cmdhfntag424.c +++ b/client/src/cmdhfntag424.c @@ -48,6 +48,8 @@ #define NTAG424_CMD_MORE_DATA 0xAF #define NTAG424_CMD_GET_VERSION 0x60 #define NTAG424_CMD_GET_SIGNATURE 0x3C +#define NTAG424_CMD_GET_TT_STATUS 0xF7 +#define NTAG424_CMD_SET_CONFIGURATION 0x5C // // Original from https://github.com/rfidhacking/node-sdm/ @@ -148,6 +150,11 @@ typedef struct { ntag424_production_information_t production; } ntag424_full_version_information_t; +typedef struct { + uint8_t perm; + uint8_t curr; +} ntag424_tag_tamper_status_t; + static void ntag424_print_version_information(ntag424_version_information_t *version, bool is_hw) { PrintAndLogEx(INFO, " vendor id: " _GREEN_("%02X"), version->vendor_id); @@ -856,6 +863,35 @@ static int ntag424_read_data(uint8_t fileno, uint16_t offset, uint16_t num_bytes return PM3_SUCCESS; } +static const char *tt_status_str(uint8_t status) { + switch (status) { + case 'C': return "Close"; + case 'O': return "Open"; + case 'I': return "Invalid"; + default: return "Unknown"; + } +} + +static int ntag424_get_tt_status(ntag424_tag_tamper_status_t *status, ntag424_communication_mode_t comm_mode, ntag424_session_keys_t *session_keys) { + APDU_t apdu = { + .cla = 0x90, + .ins = NTAG424_CMD_GET_TT_STATUS, + .lc = 0 + }; + + // align_up(sizeof(ntag424_tag_tamper_status_t) + 1, 16) + sizeof(mac) + sizeof(status_word) + int response_length = 16 + 8 + 2; + uint8_t response[response_length]; + + int res = ntag424_exchange_apdu(apdu, 0, response, &response_length, comm_mode, session_keys, 0x91, 0x00); + if (res != PM3_SUCCESS) { + return res; + } + + memcpy(status, response, sizeof(*status)); + return PM3_SUCCESS; +} + static int ntag424_get_version(ntag424_full_version_information_t *version) { APDU_t apdu = { .cla = 0x90, @@ -913,6 +949,25 @@ static int ntag424_get_signature(uint8_t *signature_out) { return PM3_SUCCESS; } +static int ntag424_set_configuration(uint8_t option, const uint8_t *data, int data_len, ntag424_session_keys_t *session_keys) { + uint8_t cmd_buffer[64]; + cmd_buffer[0] = option; + memcpy(&cmd_buffer[1], data, data_len); + + APDU_t apdu = { + .cla = 0x90, + .ins = NTAG424_CMD_SET_CONFIGURATION, + .lc = 1 + data_len, + .data = cmd_buffer + }; + + // No response data, only MAC and status word + int response_length = 8 + 2; + uint8_t response[response_length]; + + return ntag424_exchange_apdu(apdu, 1, response, &response_length, COMM_FULL, session_keys, 0x91, 0x00); +} + static int ntag424_change_key(uint8_t keyno, const uint8_t *new_key, const uint8_t *old_key, uint8_t version, ntag424_session_keys_t *session_keys) { // -------- Calculate xor and crc uint8_t key[16] = {0}; @@ -1513,7 +1568,13 @@ static int CmdHF_ntag424_changekey(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, false); - uint8_t version = arg_get_int(ctx, 6); + int kv = arg_get_int(ctx, 5); + if (kv < 0 || kv > 0xFF) { + PrintAndLogEx(ERR, "Key version must be 0..255, got ( %d )", kv); + CLIParserFree(ctx); + return PM3_EINVARG; + } + uint8_t version = (uint8_t)kv; int keyno = arg_get_int(ctx, 1); uint8_t oldkey[16] = {0}; @@ -1573,6 +1634,136 @@ static int CmdHF_ntag424_changekey(const char *Cmd) { return res; } +static int CmdHF_ntag424_getttstatus(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf ntag424 gettt", + "Read and print Tag Tamper status. Will authenticate if key information is provided.", + "hf ntag424 gettt --keyno 0 -k 00000000000000000000000000000000"); + + void *argtable[] = { + arg_param_begin, + arg_int0(NULL, "keyno", "", "Key number"), + arg_str0("k", "key", "", "Key for authentication (HEX 16 bytes)"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + + int keyno = 0; + uint8_t key[16] = {0}; + bool auth = arg_get_str(ctx, 2)->count > 0; + if (auth && ntag424_cli_get_auth_information(ctx, 1, 2, &keyno, key) != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Could not get key settings"); + CLIParserFree(ctx); + return PM3_EINVARG; + } + + CLIParserFree(ctx); + + if (SelectCard14443A_4(false, true, NULL) != PM3_SUCCESS) { + DropField(); + PrintAndLogEx(ERR, "Failed to select card"); + return PM3_ERFTRANS; + } + + if (ntag424_select_application() != PM3_SUCCESS) { + DropField(); + return PM3_ESOFT; + } + + int res = PM3_SUCCESS; + ntag424_session_keys_t session_keys = {0}; + if (auth) { + res = ntag424_authenticate_ev2_first(keyno, key, &session_keys); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Auth key %d ( " _RED_("fail") " )", keyno); + DropField(); + return res; + } else { + PrintAndLogEx(SUCCESS, "Auth key %d ( " _GREEN_("ok") " )", keyno); + } + } + + ntag424_tag_tamper_status_t tt_status = {0}; + res = ntag424_get_tt_status(&tt_status, auth ? COMM_FULL : COMM_PLAIN, &session_keys); + DropField(); + if (res == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "--- " _CYAN_("Tag Tamper status:")); + PrintAndLogEx(SUCCESS, " TTPermStatus: " _GREEN_("%02X (%s)"), tt_status.perm, tt_status_str(tt_status.perm)); + PrintAndLogEx(SUCCESS, " TTCurrStatus: " _GREEN_("%02X (%s)"), tt_status.curr, tt_status_str(tt_status.curr)); + } + return res; +} + +static int CmdHF_ntag424_setconfig(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf ntag424 setconfig", + "Change a PICC configuration option.\n" + "Several options are one-way, see the datasheet before using this.", + "hf ntag424 setconfig -k 00000000000000000000000000000000 --option 07 -d 0100"); + + void *argtable[] = { + arg_param_begin, + arg_str1("k", "key0", "", "Authentication key (must be key 0, HEX 16 bytes)"), + arg_str1(NULL, "option", "", "Configuration option (HEX 1 byte)"), + arg_strx1("d", "data", "", "Option data (HEX, 1..47 bytes)"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + uint8_t key[16] = {0}; + if (ntag424_cli_get_auth_information(ctx, 0, 1, NULL, key) != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Could not get key settings"); + CLIParserFree(ctx); + return PM3_EINVARG; + } + + uint8_t option[1] = {0}; + int optionlen = sizeof(option); + if (CLIParamHexToBuf(arg_get_str(ctx, 2), option, sizeof(option), &optionlen) || (optionlen != sizeof(option))) { + PrintAndLogEx(ERR, "Option must be 1 byte"); + CLIParserFree(ctx); + return PM3_EINVARG; + } + + uint8_t data[47] = {0}; + int datalen = sizeof(data); + if (CLIParamHexToBuf(arg_get_str(ctx, 3), data, sizeof(data), &datalen) || (datalen < 1)) { + PrintAndLogEx(ERR, "Data must be 1..%zu bytes", sizeof(data)); + CLIParserFree(ctx); + return PM3_EINVARG; + } + CLIParserFree(ctx); + + if (SelectCard14443A_4(false, true, NULL) != PM3_SUCCESS) { + DropField(); + PrintAndLogEx(ERR, "Failed to select card"); + return PM3_ERFTRANS; + } + + if (ntag424_select_application() != PM3_SUCCESS) { + DropField(); + return PM3_ESOFT; + } + + ntag424_session_keys_t session = {0}; + int res = ntag424_authenticate_ev2_first(0, key, &session); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Auth key 0 ( " _RED_("fail") " )"); + DropField(); + return res; + } + PrintAndLogEx(SUCCESS, "Auth key 0 ( " _GREEN_("ok") " )"); + + res = ntag424_set_configuration(option[0], data, datalen, &session); + DropField(); + if (res == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "Set configuration option %02X ( " _GREEN_("ok") " )", option[0]); + } else { + PrintAndLogEx(ERR, "Set configuration option %02X ( " _RED_("fail") " )", option[0]); + } + return res; +} + static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"-----------", CmdHelp, IfPm3Iso14443a, "----------------------- " _CYAN_("operations") " -----------------------"}, @@ -1584,6 +1775,8 @@ static command_t CommandTable[] = { {"getfs", CmdHF_ntag424_getfilesettings, IfPm3Iso14443a, "Get file settings"}, {"changefs", CmdHF_ntag424_changefilesettings, IfPm3Iso14443a, "Change file settings"}, {"changekey", CmdHF_ntag424_changekey, IfPm3Iso14443a, "Change key"}, + {"gettt", CmdHF_ntag424_getttstatus, IfPm3Iso14443a, "Get Tag Tamper status"}, + {"setconfig", CmdHF_ntag424_setconfig, IfPm3Iso14443a, "Set PICC configuration option"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/cmdlfhitag.c b/client/src/cmdlfhitag.c index 8772c8742..c7aa90f08 100644 --- a/client/src/cmdlfhitag.c +++ b/client/src/cmdlfhitag.c @@ -1940,7 +1940,7 @@ static int CmdLFHitagEload(const char *Cmd) { arg_lit0("1", "ht1", "Card type Hitag 1"), arg_lit0("2", "ht2", "Card type Hitag 2"), arg_lit0("s", "hts", "Card type Hitag S"), - arg_lit0("m", "htm", "Card type Hitag \xce\xbc"), // μ + arg_lit0("m", "htm", "Card type Hitag µ"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); @@ -1990,7 +1990,7 @@ static int CmdLFHitagEload(const char *Cmd) { } else if (use_htm) { // a u dump is sized by the tag's ICR, so accept anything that fits expected = 0; - tname = "Hitag \xce\xbc"; + tname = "Hitag µ"; } if (use_htm) { @@ -2053,7 +2053,7 @@ static int CmdLFHitagEview(const char *Cmd) { arg_lit0("1", "ht1", "Card type Hitag 1"), arg_lit0("2", "ht2", "Card type Hitag 2 (default)"), arg_lit0("s", "hts", "Card type Hitag S"), - arg_lit0("m", "htm", "Card type Hitag \xce\xbc"), + arg_lit0("m", "htm", "Card type Hitag µ"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); @@ -2933,4 +2933,3 @@ int CmdLFHitag(const char *Cmd) { return CmdsParse(CommandTable, Cmd); } - diff --git a/common_arm/fpga/fpga_hw_at32.c b/common_arm/fpga/fpga_hw_at32.c index 7ab507a38..d3fcb6a29 100644 --- a/common_arm/fpga/fpga_hw_at32.c +++ b/common_arm/fpga/fpga_hw_at32.c @@ -5,7 +5,6 @@ #include "gpio_apis.h" #include "dbprint.h" #include "pm3_cmd.h" -#include "string.h" uint16_t g_ssc_dma_rx_count; uint8_t g_ssc_data_byte_width; @@ -263,12 +262,20 @@ static void spi_cmd_setup(void) { void FpgaSendCommand(uint16_t cmd, uint16_t v) { // Init spi spi_cmd_setup(); + + // Before switching modes, disable SPI_SSC to prevent signal changes from triggering a CSPAS event, + // which would cause the SPI to hang. + SPI_SSC->ctrl1_bit.spien = FALSE; + // Send data gpio_bits_reset(AT32_GPIO_SPI_CS, AT32_GPIO_SPI_CS_PIN); // CS LOW while (spi_i2s_flag_get(SPI_CMD, SPI_I2S_TDBE_FLAG) == RESET) {} spi_i2s_data_transmit(SPI_CMD, cmd | v); while (spi_i2s_flag_get(SPI_CMD, SPI_I2S_BF_FLAG) != RESET) {} // Waiting for SPI transmit finish. gpio_bits_set(AT32_GPIO_SPI_CS, AT32_GPIO_SPI_CS_PIN); // CS HIGH + + // Re-enable SPI_SSC after sending the command + SPI_SSC->ctrl1_bit.spien = TRUE; } void Fpga_print_status(void) { diff --git a/common_arm/fpga/fpga_hw_at32.h b/common_arm/fpga/fpga_hw_at32.h index b36c46c0d..7c633f81a 100644 --- a/common_arm/fpga/fpga_hw_at32.h +++ b/common_arm/fpga/fpga_hw_at32.h @@ -17,9 +17,9 @@ extern uint8_t g_ssc_data_byte_width; // Is tx lsb first? If diff with rx frame settings, the data will reverse before send. extern bool g_tx_lsb_first; -// TODO DXL 纠正SPI和DMA通道选择,为了方便修改,此处可先暂时定义SPI和DMA外设和DMA通道的对应宏 -// spi-ti_mode 用到了 SPI4, DMA1 -// spi-cmd 用到了 SPI3,无DMA +// TODO DXL Move to the config header? +// spi-ti_mode Using SPI4, DMA1 +// spi-cmd Using SPI3, No DMA #define SPI_SSC SPI4 #define SPI_CRM_CLOCK_SSC CRM_SPI4_PERIPH_CLOCK #define DMA_SSC DMA1 @@ -31,7 +31,39 @@ extern bool g_tx_lsb_first; #define SPI_CMD SPI3 #define SPI_CRM_CLOCK_CMD CRM_SPI3_PERIPH_CLOCK +/** + * A workaround for the SPI_CSPAS_FLAG issue in AT32F435/437. + * + * --- + * + * In slave mode, once the TI mode is enabled, the SPI interface is capable of detecting CS pulse errors + * during data transmission, and setting the CSPAS bit (It is cleared by reading the SPI_STS) as soon as + * a CS pulse error is detected. At this point, the detected pulse error will be discarded by the SPI. However, + * since there is something wrong with the CS signal, the software should disable the SPI slave and + * reconfigure the SPI master before re-enabling the SPI slave for communication. + * + * (Copy from AT32F435/437 reference manual, section 13.2.7) + * See: https://www.arterychip.com/download/RM/RM_AT32F435_437_EN_V2.06.pdf + * + * --- + * + * DXL NOTE: Theoretically, to completely resolve this issue, strict timing control should be implemented between the SPI master and slave; + * the SPI slave should not be enabled until the SPI master is ready. But it is extremely difficult to implement; + * in many places, `FpgaSetupSsc` is called before switching the FPGA mode—an approach taken to improve transmission and reception processing speeds. + * So we can only use this workaround to handle the issue after it occurs, which is not ideal. but it is the only feasible solution for now. + * + * @param status The status register value of the SPI peripheral. + */ +#define CSPAS_WORKAROUND(status) \ + if (status & SPI_CSPAS_FLAG) { \ + SPI_SSC->ctrl1_bit.spien = FALSE; \ + SPI_SSC->ctrl1_bit.spien = TRUE; \ + } + STATIC_FORCE_INLINE bool FPGA_SSC_RX_Ready(void) { + uint32_t sts = SPI_SSC->sts; + CSPAS_WORKAROUND(sts); + /* * Note that according to the manual description, if SPI receives data but does not read it after startup, * the SPI peripheral will generate an overflow interrupt and no longer receive new data. At this time, @@ -47,18 +79,22 @@ STATIC_FORCE_INLINE bool FPGA_SSC_RX_Ready(void) { // Reading SPI_DT register and SPI_STS register sequentially can clear ROERR(Must to read DT reg) // Only when the ROERR flag is set, it is necessary to read DT, so the '&&' condition is very important. // If the former does not hold, the DT register will not be read. - return ((SPI_SSC->sts & (SPI_I2S_RDBF_FLAG | SPI_I2S_ROERR_FLAG)) == SPI_I2S_RDBF_FLAG) - || (((SPI_SSC->sts & SPI_I2S_ROERR_FLAG) == SPI_I2S_ROERR_FLAG) && (SPI_SSC->dt & 0)); // Readout data for clear the ROERR flag. IMPORTANT! + return ((sts & (SPI_I2S_RDBF_FLAG | SPI_I2S_ROERR_FLAG)) == SPI_I2S_RDBF_FLAG) + || (((sts & SPI_I2S_ROERR_FLAG) == SPI_I2S_ROERR_FLAG) && (SPI_SSC->dt & 0)); // Readout data for clear the ROERR flag. IMPORTANT! } STATIC_FORCE_INLINE bool FPGA_SSC_TX_Ready(void) { // spi_i2s_flag_get(SPI_SSC, SPI_I2S_TDBE_FLAG) == SET - return (SPI_SSC->sts & SPI_I2S_TDBE_FLAG) == SPI_I2S_TDBE_FLAG; + uint32_t sts = SPI_SSC->sts; + CSPAS_WORKAROUND(sts); + return (sts & SPI_I2S_TDBE_FLAG) == SPI_I2S_TDBE_FLAG; } STATIC_FORCE_INLINE bool FPGA_SSC_TX_Done(void) { // spi_i2s_flag_get(SPI_SSC, SPI_I2S_BF_FLAG) == RESET - return (SPI_SSC->sts & SPI_I2S_BF_FLAG) != SPI_I2S_BF_FLAG; // SPI currently has no transmission transactions. + uint32_t sts = SPI_SSC->sts; + CSPAS_WORKAROUND(sts); + return (sts & SPI_I2S_BF_FLAG) != SPI_I2S_BF_FLAG; // SPI currently has no transmission transactions. } STATIC_FORCE_INLINE uint32_t FPGA_SSC_RX_Value(void) { diff --git a/doc/commands.json b/doc/commands.json index 7e9fdb119..364afb575 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -9636,6 +9636,7 @@ "hf mfu restore -f myfile -s -> special write", "hf mfu restore -f myfile -k AABBCCDD -s -> special write, use key", "hf mfu restore -f myfile -k AABBCCDD -ser -> special write, use key, write dump pwd, ...", + "hf mfu restore -f myfile -k 00112233445566778899AABBCCDDEEFF -> UL-C / UL-AES, use key", "", "Note: Restoring a NTAG/UL dump to a UMC will likely result in incorrect PWD and PACK" ], @@ -9643,7 +9644,7 @@ "options": [ "-h, --help This help", "-f, --file Specify a filename for dump file", - "-k, --key key for authentication (UL-C 16 bytes, EV1/NTAG 4 bytes)", + "-k, --key key for authentication (UL-C/UL-AES 16 bytes, EV1/NTAG 4 bytes)", "-l swap entered key's endianness", "-s enable special write UID -MAGIC TAG ONLY-", "-e enable special write version/signature -MAGIC NTAG 21* ONLY-", diff --git a/doc/magic_cards_notes.md b/doc/magic_cards_notes.md index 2d5a7d1de..d3f49444a 100644 --- a/doc/magic_cards_notes.md +++ b/doc/magic_cards_notes.md @@ -2685,9 +2685,97 @@ More commands to follow. Be careful with some. ^[Top](#top) +Three kinds of UID changeable ISO15693 tags are known, called V1 (Gen1), V2 (Gen2) and V3 (Gen3) here. +`hf 15 info` only matches the UID prefix against its vendor list, so it can't tell them apart from genuine tags. + ### Identify -**TODO** +^[Top](#top) + +| Kind | Blocks on tags tested | Set UID with | +|------|-----------------------|--------------| +| V1 (Gen1) | 28/40/56 | `hf 15 csetuid` | +| V2 (Gen2) | 64 | `hf 15 csetuid --v2` | +| V3 (Gen3) | 80 | `hf 15 csetuid --v3`, then `hf 15 cfinalize` | + +The block counts come from the few tags tested, they are only a hint. + +The same kind of magic can behave a bit differently between manufacturers, for example the block layout, +or how the V1 backdoor blocks answer to read and write commands. What is described here comes from the tags tested. + +V1: no reliable way to identify it, the only sure check is to set a UID and see if it changes. +On the V1 tags tested, reading blocks `0x38`, `0x39`, `0x3E` and `0x3F` fails while writing `0x38` and `0x39` works. That may be a hint but it is not confirmed. + +``` +hf 15 raw -ac -d 022038 # command failed on the V1 tags tested +``` + +V2: no passive identification known. It uses the custom command `0xE0`, which genuine tags do not implement. + +V3: blocks `0x14` and `0x15` hold a signature while the tag is not finalized. + +``` +hf 15 raw -ac -d 022014 # A5 2B 44 2C +hf 15 raw -ac -d 022015 # 21 AE 93 00 (69 E2 5D 00 after finalize) +``` + + + +### V1 (Gen1) + +^[Top](#top) + +The UID is written to blocks `0x38` and `0x39` with plain `WRITEBLOCK`, each holding four UID bytes in reverse order. +Blocks `0x3E` and `0x3F` are written first as an unlock, this is what `hf 15 csetuid` sends for `E011223344556677`: + +``` +hf 15 raw -acw -d 02213E00000000 +hf 15 raw -acw -d 02213F69960000 +hf 15 raw -acw -d 02213877665544 +hf 15 raw -acw -d 022139332211E0 +``` + +On the tags tested, writing only `0x38` and `0x39` is enough, the new UID is active immediately. +`0x3E` and `0x3F` accept the unlock values once, later writes fail with `command failed`. + +### V2 (Gen2) + +^[Top](#top) + +Uses the custom command `0xE0`, this is what `hf 15 csetuid --v2` sends for `E011223344556677`: + +``` +hf 15 raw -acw -d 02E009473F038B00 +hf 15 raw -acw -d 02E0095200000000 +hf 15 raw -acw -d 02E0094077665544 +hf 15 raw -acw -d 02E00941332211E0 +``` + +On the V2 tag tested, block `0x38` reads as normal memory, a `WRITEBLOCK` to it is refused with error code 3 (option not supported) unless the request flags carry the option flag (`42` instead of `02`). + +### V3 (Gen3) + +^[Top](#top) + +The UID sits in blocks `0x10` (last four bytes, reversed) and `0x11` (first four bytes, reversed). +It can be rewritten as often as needed until the tag is finalized: + +``` +hf 15 raw -acw -d 02211077665544 +hf 15 raw -acw -d 022111332211E0 +``` + +Finalize locks the UID for good and can't be undone, block `0x15` changes to `69 E2 5D 00`: + +``` +hf 15 raw -acw -d 022114A52B442C +hf 15 raw -acw -d 02211569E25D00 +``` + +> [!WARNING] +> Writing anything other than these two finalize values to blocks `0x14` and `0x15` bricks the tag. +> +> `hf 15 wipe` may brick v3 tag. ### Proxmark3 commands @@ -2696,9 +2784,20 @@ More commands to follow. Be careful with some. Always set a UID starting with `E0`. ``` -hf 15 csetuid E011223344556677 +hf 15 csetuid -u E011223344556677 # V1 +hf 15 csetuid -u E011223344556677 --v2 # V2 +hf 15 csetuid -u E011223344556677 --v3 # V3 +hf 15 cfinalize -y # V3, irreversible ``` +Before writing, `csetuid` checks that the tag looks like the selected kind: + +* V1 reads blocks `0x38`, `0x39`, `0x3E`, `0x3F` and stops if one holds data other than `00000000` (or `69960000` in `0x3F`), + or if a read fails other than with no answer / block not available. + If the write or the UID check fails and the tag still shows its original UID, it writes those four blocks back to `00000000`. +* V3 stops unless blocks `0x14` and `0x15` still hold the un-finalized signature, `cfinalize` does the same. +* V2 has no check, the `0xE0` command is ignored by genuine tags. + or (ignore errors): ``` diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index fbd66da2f..87953ebef 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -126,3 +126,7 @@ Host binaries are compiled with hardening flags (only with Makefile, not with cm * udev rule on Linux Same logic for `make all`, `make clean`, `make uninstall` and `make check`. + +The client is installed with the additional capabilities required for direct BLE connections. See `client/Makefile` for details. +Depending on your distribution, you may need to ensure that binaries with such capabilities can be run by regular users, else an *operation not permitted* will occur. +If you prefer to not set these capabilities, run `make install SKIP_SETCAP=1`. diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 000000000..cbf521148 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,7 @@ +# Docker tests + +Usage: +- enter one of the subfolders +- `../build.sh` to build the docker image +- `../run.sh` to run a container and get a shell +- `../run.sh tests` to run a container and execute its `run_tests.sh` diff --git a/docker/build-all.sh b/docker/build-all.sh index 999d6ef26..db61e734f 100755 --- a/docker/build-all.sh +++ b/docker/build-all.sh @@ -1,6 +1,6 @@ #!/bin/bash -for os in archlinux debian-13-trixie debian-13-trixie-arm64 debian-13-trixie-armhf debian-14-forky fedora-41 fedora-42 fedora-43 homebrew kali opensuse-leap opensuse-tumbleweed parrot-core-latest ubuntu-24.04 ubuntu-24.10 ubuntu-25.04; do +for os in archlinux debian-13-trixie debian-13-trixie-arm64 debian-13-trixie-armhf debian-14-forky fedora-41 fedora-42 fedora-43 homebrew kali opensuse-leap opensuse-tumbleweed parrot-core-latest ubuntu-22.04 ubuntu-24.04 ubuntu-24.10 ubuntu-25.04 ubuntu-25.10; do echo -e "\n\n================= Building for $os ======================\n" ( cd $os && ../build.sh ) done diff --git a/docker/debian-13-trixie-arm64/README.md b/docker/debian-13-trixie-arm64/README.md index 68cc52712..485f84893 100644 --- a/docker/debian-13-trixie-arm64/README.md +++ b/docker/debian-13-trixie-arm64/README.md @@ -1,4 +1,4 @@ -# Notes to install corss-platform support +# Notes to install cross-platform support ``` sudo apt install qemu-user qemu-user-binfmt binfmt-support ``` diff --git a/docker/debian-13-trixie-arm64/run_tests.sh b/docker/debian-13-trixie-arm64/run_tests.sh index 8d31f8332..c8febcc29 100755 --- a/docker/debian-13-trixie-arm64/run_tests.sh +++ b/docker/debian-13-trixie-arm64/run_tests.sh @@ -2,14 +2,25 @@ # This script is to be run from proxmark root folder inside the docker env # docker/debian-13-trixie-arm64/run_tests.sh; +# sudo not supported in this docker image, update packages before running as rrg user +if [ "$EUID" -eq 0 ]; then + apt update && sudo apt upgrade -y +fi + +# Re-execute the script as rrg user if not already running as rrg +if [[ $(id -un) != rrg ]]; then + script_path=$(readlink -f -- "${BASH_SOURCE[0]}") + working_directory=$(pwd -P) + exec su - rrg -c 'cd "$1" && exec bash "$2" "${@:3}"' bash \ + "$working_directory" "$script_path" "$@" +fi + # Check that we are not running as root if [ "$EUID" -eq 0 ]; then echo "Error: This script should not be run as root" >&2 exit 1 fi -# sudo not supported in this docker image, update packages before running as rrg user -# sudo apt update && sudo apt upgrade -y git config --global --add safe.directory /home/rrg/proxmark3 tools/release_tests.sh # beeps diff --git a/docker/debian-13-trixie-armhf/README.md b/docker/debian-13-trixie-armhf/README.md index aceaf5c44..351349fb5 100644 --- a/docker/debian-13-trixie-armhf/README.md +++ b/docker/debian-13-trixie-armhf/README.md @@ -1,4 +1,4 @@ -# Notes to install corss-platform support +# Notes to install cross-platform support ``` sudo apt install qemu-user qemu-user-binfmt binfmt-support ``` diff --git a/docker/debian-13-trixie-armhf/run_tests.sh b/docker/debian-13-trixie-armhf/run_tests.sh index bb0e350e0..eb9ff714b 100755 --- a/docker/debian-13-trixie-armhf/run_tests.sh +++ b/docker/debian-13-trixie-armhf/run_tests.sh @@ -2,15 +2,25 @@ # This script is to be run from proxmark root folder inside the docker env # docker/debian-13-trixie-armhf/run_tests.sh; +# sudo not supported in this docker image, update packages before running as rrg user +if [ "$EUID" -eq 0 ]; then + apt update && sudo apt upgrade -y +fi + +# Re-execute the script as rrg user if not already running as rrg +if [[ $(id -un) != rrg ]]; then + script_path=$(readlink -f -- "${BASH_SOURCE[0]}") + working_directory=$(pwd -P) + exec su - rrg -c 'cd "$1" && exec bash "$2" "${@:3}"' bash \ + "$working_directory" "$script_path" "$@" +fi + # Check that we are not running as root if [ "$EUID" -eq 0 ]; then echo "Error: This script should not be run as root" >&2 exit 1 fi -# sudo not supported in this docker image, update packages before running as rrg user -# sudo apt update && sudo apt upgrade -y - git config --global --add safe.directory /home/rrg/proxmark3 tools/release_tests.sh # beeps diff --git a/docker/run.sh b/docker/run.sh index df178fb6c..0af9b49c8 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -11,4 +11,9 @@ if [ -n "$UART_PORT" ]; then else DEV="" fi -docker run $DEV $DOCKER_PLATFORM --volume="$(pwd)/../..:/home/rrg/proxmark3" -w /home/rrg/proxmark3 --net=host --rm -it "$DOCKER_IMAGE" +TEST_PATH=$(basename $(pwd -L)) +DOCKER_COMMAND=() +if [ "$1" = "tests" ]; then + DOCKER_COMMAND=("docker/$TEST_PATH/run_tests.sh") +fi +docker run $DEV $DOCKER_PLATFORM --volume="$(pwd)/../..:/home/rrg/proxmark3" -w /home/rrg/proxmark3 --net=host --rm -it "$DOCKER_IMAGE" "${DOCKER_COMMAND[@]}" diff --git a/tools/build_all_firmwares.sh b/tools/build_all_firmwares.sh index 33f42c6b7..cdc7b533c 100755 --- a/tools/build_all_firmwares.sh +++ b/tools/build_all_firmwares.sh @@ -32,7 +32,7 @@ mv bootrom/obj/bootrom.elf "$DEST/PM3BOOTROM.elf" # cf armsrc/Standalone/Makefile.hal STANDALONE_MODES=(LF_SKELETON) STANDALONE_MODES+=(LF_EM4100EMUL LF_EM4100RSWB LF_EM4100RSWW LF_EM4100RWC LF_HIDBRUTE LF_HIDFCBRUTE LF_ICEHID LF_MULTIHID LF_NEDAP_SIM LF_NEXID LF_PROXBRUTE LF_PROX2BRUTE LF_SAMYRUN LF_THAREXDE) -STANDALONE_MODES+=(HF_14ASNIFF HF_14BSNIFF HF_15SNIFF HF_15SIM HF_AVEFUL HF_BOG HF_CARDHOPPER HF_COLIN HF_DOEGOX_AUTH0 HF_DOEGOX_COMMIT HF_CRAFTBYTE HF_ICECLASS HF_LEGIC HF_LEGIC_RDV4 HF_LEGICSIM HF_MATTYRUN HF_MFCSIM HF_MSDSAL HF_REBLAY HF_ST25_TEAROFF HF_TCPRST HF_TMUDFORD HF_UNISNIFF HF_YOUNG HF_EMVPNG) +STANDALONE_MODES+=(HF_14ASNIFF HF_14BSNIFF HF_15SIM HF_15SNIFF HF_AVEFUL HF_BOG HF_CARDHOPPER HF_COLIN HF_CRAFTBYTE HF_DOEGOX_AUTH0 HF_DOEGOX_COMMIT HF_EMVPNG HF_ICECLASS HF_LEGIC HF_LEGIC_RDV4 HF_LEGICSIM HF_MATTYRUN HF_MFCSIM HF_MSDSAL HF_REBLAY HF_ST25_TEAROFF HF_TCPRST HF_TMUDFORD HF_UNISNIFF HF_YOUNG) STANDALONE_MODES+=(DANKARMULTI) STANDALONE_MODES_REQ_BT=(HF_CARDHOPPER HF_REBLAY) STANDALONE_MODES_REQ_SMARTCARD=() diff --git a/tools/pm3_tests.sh b/tools/pm3_tests.sh index 80df512c1..135dc2a76 100755 --- a/tools/pm3_tests.sh +++ b/tools/pm3_tests.sh @@ -338,7 +338,7 @@ while true; do if ! CheckFileExist "staticnested_2x1nt_rf08s exists" "$STATICNESTED2X1NTBIN"; then break; fi if ! CheckFileExist "staticnested_2x1nt_rf08s_1key exists" "$STATICNESTED2X11KNTBIN"; then break; fi # very slow one... - if ! CheckExecute slow "staticnested_0nt test" "$STATICNESTED0NTBIN a13e4902 2e9e49fc 1111 . 7bfc7a5b 1110 a17e4902 50f2abc2 1101; rm keys.dic" "Key ffffffffffff found in 3 arrays"; then break; fi +# if ! CheckExecute slow "staticnested_0nt test" "$STATICNESTED0NTBIN a13e4902 2e9e49fc 1111 . 7bfc7a5b 1110 a17e4902 50f2abc2 1101; rm keys.dic" "Key ffffffffffff found in 3 arrays"; then break; fi if ! CheckExecute "staticnested_1nt 1/2 test" "$STATICNESTED1NTBIN 5c467f63 0 456ace4e da53428d 1001" "found 19823 keys"; then break; fi if ! CheckExecute "staticnested_1nt 2/2 test" "$STATICNESTED1NTBIN 5c467f63 0 e56f9fa2 7a9616b6 1110" "found 34531 keys"; then break; fi if ! CheckExecute "staticnested_2nt test" "$STATICNESTED2NTBIN 461dce03 7eef3586 7fa28c7e 322bc14d 7f62b3d6" "\[ 2 \].*ffffffffff40.*"; then break; fi diff --git a/tools/release_tests.sh b/tools/release_tests.sh index 9dd168cc7..649958a3b 100755 --- a/tools/release_tests.sh +++ b/tools/release_tests.sh @@ -11,7 +11,7 @@ set -x make clean && make -j PLATFORM=PM3GENERIC PLATFORM_EXTRAS= STANDALONE=LF_SAMYRUN && tools/pm3_tests.sh --long || exit 1 make clean && make -j PLATFORM=PM3RDV4 PLATFORM_EXTRAS= STANDALONE=HF_ST25_TEAROFF || exit 1 make clean && make -j PLATFORM=PM3RDV4 PLATFORM_EXTRAS=BTADDON STANDALONE=HF_REBLAY || exit 1 -make -j PLATFORM=PM3RDV4 PLATFORM_EXTRAS=BTADDON STANDALONE=HF_REBLAY && if sudo true; then INSTALLSUDO=sudo make install PLATFORM=PM3RDV4 PLATFORM_EXTRAS=BTADDON STANDALONE=HF_REBLAY && ( cd /tmp; proxmark3 -c 'data load -f lf_EM4x05.pm3;lf search -1'|grep 'Valid FDX-B ID found' ) && INSTALLSUDO=sudo make uninstall || exit 1; fi +make -j PLATFORM=PM3RDV4 PLATFORM_EXTRAS=BTADDON STANDALONE=HF_REBLAY && if sudo true; then INSTALLSUDO=sudo make install SKIP_SETCAP=1 PLATFORM=PM3RDV4 PLATFORM_EXTRAS=BTADDON STANDALONE=HF_REBLAY && ( cd /tmp; proxmark3 -c 'data load -f lf_EM4x05.pm3;lf search -1'|grep 'Valid FDX-B ID found' ) && INSTALLSUDO=sudo make uninstall || exit 1; fi ( cd client; rm -rf build; mkdir build;cd build;cmake .. && make -j PLATFORM=PM3GENERIC PLATFORM_EXTRAS= STANDALONE=LF_SAMYRUN && cp -a ../*scripts ../*libs . && ../../tools/pm3_tests.sh --clientbin $(pwd)/proxmark3 client ) || exit 1 ( cd client; rm -rf build; mkdir build;cd build;cmake .. && make -j PLATFORM=PM3RDV4 PLATFORM_EXTRAS= STANDALONE=HF_ST25_TEAROFF ) || exit 1 ( cd client; rm -rf build; mkdir build;cd build;cmake .. && make -j PLATFORM=PM3RDV4 PLATFORM_EXTRAS=BTADDON STANDALONE=HF_REBLAY ) || exit 1