From 2517e8b345f8591e38eb4a6221876c0dc401578c Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Tue, 12 Dec 2023 01:11:10 +0200 Subject: [PATCH] make style --- armsrc/Standalone/hf_unisniff.c | 2 +- armsrc/appmain.c | 2 +- armsrc/mifarecmd.c | 2 +- client/src/cmddata.c | 2 +- client/src/cmdhfmfp.c | 16 ++++----- client/src/pm3line_vocabulary.h | 3 ++ client/src/util.c | 6 ++-- common/generator.c | 2 +- doc/commands.json | 62 ++++++++++++++++++++++++--------- doc/commands.md | 1 + 10 files changed, 65 insertions(+), 33 deletions(-) diff --git a/armsrc/Standalone/hf_unisniff.c b/armsrc/Standalone/hf_unisniff.c index a39cd7277..6d2a6ee54 100644 --- a/armsrc/Standalone/hf_unisniff.c +++ b/armsrc/Standalone/hf_unisniff.c @@ -180,7 +180,7 @@ void RunMod(void) { char *config_buffer = &config_buffer_array[0]; uint32_t config_size = size_in_spiffs(HF_UNISNIFF_CONFIG); if (config_size > HF_UNISNIFF_CONFIG_SIZE) config_size = HF_UNISNIFF_CONFIG_SIZE; - rdv40_spiffs_read_as_filetype(HF_UNISNIFF_CONFIG, (uint8_t *)config_buffer, + rdv40_spiffs_read_as_filetype(HF_UNISNIFF_CONFIG, (uint8_t *)config_buffer, config_size, RDV40_SPIFFS_SAFETY_SAFE); // This parser is terrible but I think fairly memory efficient? Maybe better to use JSON? char *x = config_buffer; diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 849bfcb2b..66fdcf3a3 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1873,7 +1873,7 @@ static void PacketReceived(PacketCommandNG *packet) { uint8_t key[6]; } PACKED; struct p *payload = (struct p *) packet->data.asBytes; - + MifareHasStaticEncryptedNonce(payload->block_no, payload->key_type, payload->key); break; } diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 1f0683599..0d0eb97e0 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -2724,7 +2724,7 @@ void MifareHasStaticEncryptedNonce(uint8_t block_no, uint8_t key_type, uint8_t * goto OUT; }; - if (g_dbglevel >= DBG_INFO) + if (g_dbglevel >= DBG_INFO) Dbprintf("nt: %x, nt encoded: %x", nt, ntenc); if (oldntenc == 0) diff --git a/client/src/cmddata.c b/client/src/cmddata.c index 30d68d6ba..238bff88d 100644 --- a/client/src/cmddata.c +++ b/client/src/cmddata.c @@ -3392,7 +3392,7 @@ static int CmdNumCon(const char *Cmd) { PrintAndLogEx(SUCCESS, _CYAN_("Inverted")); for (uint8_t i = 0; i < ARRAYLEN(radix); i++) { MBEDTLS_MPI_CHK(mbedtls_mpi_write_string(&N, radix[i].radix, s, sizeof(s), &slen)); - if (slen == 0) { + if (slen == 0) { continue; } diff --git a/client/src/cmdhfmfp.c b/client/src/cmdhfmfp.c index 5d6c94929..c8feeb044 100644 --- a/client/src/cmdhfmfp.c +++ b/client/src/cmdhfmfp.c @@ -798,7 +798,7 @@ static int CmdHFMFPRdbl(const char *Cmd) { PrintAndLogEx(ERR, "Error return length: %d", datalen); return PM3_ESOFT; } - + if (!plain) data_crypt(&mf4session, &data[1], &data[1], true); uint8_t sector = mfSectorNum(blockn); mf_print_sector_hdr(sector); @@ -1061,9 +1061,9 @@ static int CmdHFMFPChKey(const char *Cmd) { bool verbose = arg_get_lit(ctx, 1); bool nomacres = arg_get_lit(ctx, 2); - + uint8_t keyn[250] = {0}; - + uint8_t ki[250] = {0}; int kilen = 0; CLIGetHexWithReturn(ctx, 3, ki, &kilen); @@ -1076,7 +1076,7 @@ static int CmdHFMFPChKey(const char *Cmd) { uint8_t datain[250] = {0}; int datainlen = 0; CLIGetHexWithReturn(ctx, 6, datain, &datainlen); - + CLIParserFree(ctx); mfpSetVerboseMode(verbose); @@ -1177,7 +1177,7 @@ static int CmdHFMFPChConf(const char *Cmd) { bool verbose = arg_get_lit(ctx, 1); bool nomacres = arg_get_lit(ctx, 2); - + uint8_t keyn[250] = {0}; uint32_t blockNum = arg_get_int(ctx, 3); @@ -1185,11 +1185,11 @@ static int CmdHFMFPChConf(const char *Cmd) { int keylen = 0; CLIGetHexWithReturn(ctx, 4, key, &keylen); bool usecck = arg_get_lit(ctx, 5); - + uint8_t datain[250] = {0}; int datainlen = 0; CLIGetHexWithReturn(ctx, 6, datain, &datainlen); - + CLIParserFree(ctx); mfpSetVerboseMode(verbose); @@ -1208,7 +1208,7 @@ static int CmdHFMFPChConf(const char *Cmd) { PrintAndLogEx(ERR, " must be 16 bytes. Got %d", datainlen); return PM3_EINVARG; } - + if (blockNum > 3) { PrintAndLogEx(ERR, " must be in range [0..3]. Got %d", blockNum); return PM3_EINVARG; diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index 48a2ecb91..df1c8ec75 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -322,6 +322,7 @@ const static vocabulary_t vocabulary[] = { { 0, "hf lto wrbl" }, { 1, "hf mf help" }, { 1, "hf mf list" }, + { 0, "hf mf info" }, { 0, "hf mf darkside" }, { 0, "hf mf nested" }, { 1, "hf mf hardnested" }, @@ -390,6 +391,8 @@ const static vocabulary_t vocabulary[] = { { 0, "hf mfp rdbl" }, { 0, "hf mfp rdsc" }, { 0, "hf mfp wrbl" }, + { 0, "hf mfp chkey" }, + { 0, "hf mfp chconf" }, { 0, "hf mfp commitp" }, { 0, "hf mfp initp" }, { 0, "hf mfp wrp" }, diff --git a/client/src/util.c b/client/src/util.c index 76a7b24ea..ad6b4f447 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -104,7 +104,7 @@ static char inv_b2s(char v, bool uppercase) { '7', '6', '5', '4', '3', '2', '1', '0' }; - + uint8_t tmp = (tolower(v) - 'a' + 10); if (isdigit(v)) { tmp = (v - 0x30); @@ -112,7 +112,7 @@ static char inv_b2s(char v, bool uppercase) { if (uppercase) return toupper(lut[tmp]); - else + else return lut[tmp]; } @@ -1254,7 +1254,7 @@ void str_inverse_bin(char *buf, size_t len) { buf[i] = '0'; else if ( c == '0') buf[i] = '1'; - else + else buf[i] = '.'; } } diff --git a/common/generator.c b/common/generator.c index 27099224a..28c8a5fa2 100644 --- a/common/generator.c +++ b/common/generator.c @@ -354,7 +354,7 @@ int mfc_algo_saflok_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t uint64_t id = (bytes_to_num(uid, 4) << 8); *key = (h + (id + m + ((uint64_t)h << 40ULL))) & 0xFFFFFFFFFFFFULL; - + } else { *key = 0xFFFFFFFFFFFF; } diff --git a/doc/commands.json b/doc/commands.json index 89f0ac7fd..277e54e91 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -608,9 +608,10 @@ "--dec decimal value", "--hex hexadecimal value", "--bin binary value", - "-i print inverted value" + "-i print inverted value", + "-r print reversed value" ], - "usage": "data num [-hi] [--dec ] [--hex ] [--bin ]" + "usage": "data num [-hir] [--dec ] [--hex ] [--bin ]" }, "data plot": { "command": "data plot", @@ -4706,6 +4707,25 @@ ], "usage": "hf mf hardnested [-habrstw] [-k ] [--blk ] [--tblk ] [--ta] [--tb] [--tk ] [-u ] [-f ] [--in] [--im] [--is] [--ia] [--i2] [--i5]" }, + "hf mf info": { + "command": "hf mf info", + "description": "Information and check vulnerabilities in a MIFARE Classic card Some cards in order to extract information you need to specify key and/or specific keys in the copmmand line", + "notes": [ + "hf mf info", + "hf mf info -k ffffffff -n -v" + ], + "offline": false, + "options": [ + "-h, --help This help", + "--blk block number", + "-a input key type is key A (def)", + "-b input key type is key B", + "-k, --key key, 6 hex bytes", + "-n, --nack do nack test", + "-v, --verbose verbose output" + ], + "usage": "hf mf info [-habnv] [--blk ] [-k ]" + }, "hf mf list": { "command": "hf mf list", "description": "Alias of `trace list -t mf -c` with selected protocol data to annotate trace buffer You can load a trace from file (see `trace load -h`) or it be downloaded from device by default It accepts all other arguments of `trace list`. Note that some might not be relevant for this specific protocol", @@ -6257,7 +6277,7 @@ "* Block B001 (01; CCK): Installation identifier for Virtual Card. Please consult NXP for data.", "* Block B002 (02; CCK): ATS data.", "* Block B003 (03; CCK): Use Random ID in SL3, decide whether proximity check is mandatory.", - " * DO NOT WRITE THIS BLOCK UNDER ANY CIRCUMSTANCES! Risk of bricking.", + "* DO NOT WRITE THIS BLOCK UNDER ANY CIRCUMSTANCES! Risk of bricking.", "More configuration tips to follow. Check JMY600 Series IC Card Module.", "hf mfp chconf -c 00 -d 10ffffffffffffffffffffffffffffff --key A0A1A2A3A4A5A6A7A0A1A2A3A4A5A6A7 -> Allow 16 commands without MAC in a single transaction." ], @@ -6312,11 +6332,11 @@ "options": [ "-h, --help This help", "-v, --verbose Verbose mode", - "--nmr Do not expect MAC in response", - "--ki Key Index, 2 hex bytes", - "-k, --key Current sector key, 16 hex bytes", - "-b, --typeb Sector key is key B", - "-d, --data New key, 16 hex bytes" + "--nmr Do not expect MAC in response", + "--ki Key Index, 2 hex bytes", + "-k, --key Current sector key, 16 hex bytes", + "-b, --typeb Sector key is key B", + "-d, --data New key, 16 hex bytes" ], "usage": "hf mfp chkey [-hvb] [--nmr] --ki [-k ] -d " }, @@ -6482,7 +6502,7 @@ "-v, --verbose Verbose mode", "-n, --count Blocks count (def: 1)", "-b, --keyb Use key B (def: keyA)", - "-p, --plain Do not use encrypted transmission between reader and card", + "-p, --plain Do not use encrypted communication mode between reader and card", "--nmc Do not append MAC to command", "--nmr Do not expect MAC in reply", "--blk <0..255> Block number", @@ -6502,7 +6522,7 @@ "-h, --help This help", "-v, --verbose Verbose mode", "-b, --keyb Use key B (def: keyA)", - "-p, --plain Do not use encrypted transmission between reader and card", + "-p, --plain Do not use encrypted communication mode between reader and card", "--nmc Do not append MAC to command", "--nmr Do not expect MAC in reply", "-s, --sn <0..255> Sector number", @@ -6534,10 +6554,18 @@ "command": "hf mfp wrp", "description": "Executes Write Perso command. Can be used in SL0 mode only.", "notes": [ + "Use this command to program AES keys, as well as personalize other data on the tag.", + "You can program:", + "* Address 00 [00-FF]: Memory blocks (as well as ACLs and Crypto1 keys)", + "* Address 40 [00-40]: AES sector keys", + "* Address 90 [00-04]: AES administrative keys", + "* Address A0 [00, 01, 80, 81]: Virtual Card keys", + "* Address B0 [00-03]: Configuration data (DO NOT TOUCH B003)", + "Examples:", "hf mfp wrp --adr 4000 --data 000102030405060708090a0b0c0d0e0f -> write key (00..0f) to key number 4000", "hf mfp wrp --adr 4000 -> write default key(0xff..0xff) to key number 4000", - "hf mfp wrp -a b000 -d 20FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -> allow 32 commands without MAC in configuration block (B000)", - "hf mfp wrp -a 0003 -d 1234561234567F078869B0B1B2B3B4B5 -> write crypto1 keys A: 123456123456 and B: B0B1B2B3B4B5 to block 3" + "hf mfp wrp --adr b000 -d FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -> allow 255 commands without MAC in configuration block (B000)", + "hf mfp wrp --adr 0003 -d 1234561234567F078869B0B1B2B3B4B5 -> write crypto1 keys A: 123456123456 and B: B0B1B2B3B4B5 to block 3" ], "offline": false, "options": [ @@ -7446,7 +7474,7 @@ }, "hf tune": { "command": "hf tune", - "description": "Continuously measure HF antenna tuning. Press button or to interrupt.", + "description": "Continuously measure HF antenna tuning. Press pm3 button or to interrupt.", "notes": [ "hf tune", "hf tune --mix" @@ -9027,7 +9055,7 @@ "-1, --ht1 Card type Hitag 1", "-2, --ht2 Card type Hitag 2", "-s, --hts Card type Hitag S", - "-m, --htm Card type Hitag \u03bc" + "-m, --htm Card type Hitag \u041e\u0458" ], "usage": "lf hitag eload [-h12sm] -f " }, @@ -12118,8 +12146,8 @@ } }, "metadata": { - "commands_extracted": 699, + "commands_extracted": 702, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2023-12-01T14:06:40" + "extracted_on": "2023-12-11T23:10:13" } -} +} \ No newline at end of file diff --git a/doc/commands.md b/doc/commands.md index 8e6060400..447478cfa 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -485,6 +485,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`hf mf help `|Y |`This help` |`hf mf list `|Y |`List MIFARE history` +|`hf mf info `|N |`mfc card Info` |`hf mf darkside `|N |`Darkside attack` |`hf mf nested `|N |`Nested attack` |`hf mf hardnested `|Y |`Nested attack for hardened MIFARE Classic cards`