Merge pull request #2086 from nvx/feature/cmd_iclass_esetblk

Adds `hf iclass esetblk`, equivalent to `hf mf esetblk`
This commit is contained in:
Iceman 2023-08-22 19:22:35 +02:00 committed by GitHub
commit 4547a1beba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 76 additions and 16 deletions

View file

@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased]
- Added `hf iclass esetblk` - set iClass emulator memory block data (@nvx)
- Added cryptorf regressiontests (@iceman1001)
- Fixed `cryptorf/sma_multi` - local state used in multithread (@iceman1001)
- Changed `fpga_compress` - better deallocation of memory and closing of file handles (@iceman1001)

View file

@ -327,7 +327,7 @@ style:
# Make sure python3 is installed
@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 - doc/commands.json
[ -x client/proxmark3 ] && client/proxmark3 --fulltext | sed 's#com[0-9]#/dev/ttyACM0#'|python3 client/pyscripts/pm3_help2json.py - doc/commands.json
# Update the readline autocomplete autogenerated code
[ -x client/proxmark3 ] && client/proxmark3 --fulltext | python3 client/pyscripts/pm3_help2list.py - client/src/pm3line_vocabulary.h

View file

@ -88,7 +88,7 @@ const static vocabulary_t vocabulary[] = {\n""")
cmd = values['command']
args.output_file.write(' {{ {}, "{}" }}, \n'.format(offline, cmd))
args.output_file.write(' {{ {}, "{}" }},\n'.format(offline, cmd))
args.output_file.write(""" {0, NULL}\n};

View file

@ -129,7 +129,7 @@ static inline uint32_t leadingzeros(uint64_t a) {
#endif
}
static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t *bytes_sent) {
static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t offset, uint16_t *bytes_sent) {
struct p {
uint16_t offset;
@ -155,7 +155,7 @@ static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t *bytes_sent) {
}
struct p *payload = calloc(4 + bytes_in_packet, sizeof(uint8_t));
payload->offset = *bytes_sent;
payload->offset = offset + *bytes_sent;
payload->len = bytes_in_packet;
memcpy(payload->data, d + *bytes_sent, bytes_in_packet);
@ -424,7 +424,7 @@ static int generate_config_card(const iclass_config_card_item_t *o, uint8_t *ke
//Send to device
PrintAndLogEx(INFO, "Uploading to device... ");
uint16_t bytes_sent = 0;
iclass_upload_emul(data, tot_bytes, &bytes_sent);
iclass_upload_emul(data, tot_bytes, 0, &bytes_sent);
free(data);
PrintAndLogEx(NORMAL, "");
@ -1092,7 +1092,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
//Send to device
uint16_t bytes_sent = 0;
iclass_upload_emul(dump, bytes_read, &bytes_sent);
iclass_upload_emul(dump, bytes_read, 0, &bytes_sent);
free(dump);
PrintAndLogEx(SUCCESS, "uploaded " _YELLOW_("%d") " bytes to emulator memory", bytes_sent);
PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`hf iclass sim -h`"));
@ -1222,6 +1222,49 @@ static int CmdHFiClassEView(const char *Cmd) {
return PM3_SUCCESS;
}
static int CmdHFiClassESetBlk(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf iclass esetblk",
"Sets an individual block in emulator memory.",
"hf iclass esetblk -b 7 -d 0000000000000000");
void *argtable[] = {
arg_param_begin,
arg_int1("b", "blk", "<dec>", "block number"),
arg_str0("d", "data", "<hex>", "bytes to write, 8 hex bytes"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
int blk = arg_get_int_def(ctx, 1, 0);
if (blk > 255) {
PrintAndLogEx(WARNING, "block number must be between 0 and 255. Got %i", blk);
return PM3_EINVARG;
}
uint8_t data[PICOPASS_BLOCK_SIZE] = {0x00};
int datalen = 0;
int res = CLIParamHexToBuf(arg_get_str(ctx, 2), data, sizeof(data), &datalen);
CLIParserFree(ctx);
if (res) {
PrintAndLogEx(FAILED, "Error parsing bytes");
return PM3_EINVARG;
}
if (datalen != sizeof(data)) {
PrintAndLogEx(WARNING, "block data must include 8 HEX bytes. Got %i", datalen);
return PM3_EINVARG;
}
CLIParserFree(ctx);
uint16_t bytes_sent = 0;
iclass_upload_emul(data, sizeof(data), blk * PICOPASS_BLOCK_SIZE, &bytes_sent);
return PM3_SUCCESS;
}
static void iclass_decode_credentials(uint8_t *data) {
BLOCK79ENCRYPTION encryption = (data[(6 * 8) + 7] & 0x03);
bool has_values = (memcmp(data + (8 * 7), empty, 8) != 0) && (memcmp(data + (8 * 7), zeros, 8) != 0);
@ -4226,6 +4269,7 @@ static command_t CommandTable[] = {
{"sim", CmdHFiClassSim, IfPm3Iclass, "Simulate iCLASS tag"},
{"eload", CmdHFiClassELoad, IfPm3Iclass, "Load Picopass / iCLASS dump file into emulator memory"},
{"esave", CmdHFiClassESave, IfPm3Iclass, "Save emulator memory to file"},
{"esetblk", CmdHFiClassESetBlk, IfPm3Iclass, "Set emulator memory block data"},
{"eview", CmdHFiClassEView, IfPm3Iclass, "View emulator memory"},
{"-----------", CmdHelp, AlwaysAvailable, "---------------------- " _CYAN_("utils") " ----------------------"},
{"configcard", CmdHFiClassConfigCard, AlwaysAvailable, "Reader configuration card"},

View file

@ -850,10 +850,10 @@ static int CmdHFTexkomSim(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf texkom sim",
"Simulate a texkom tag",
"hf texkom sim \r\n"
"hf texkom sim --raw FFFF638C7DC45553 -> simulate TK13 tag with id 8C7DC455\r\n"
"hf texkom sim --tk17 --raw FFFFCA17F31EC512 -> simulate TK17 tag with id 17F31EC5\r\n"
"hf texkom sim --id 8C7DC455 -> simulate TK13 tag with id 8C7DC455\r\n"
"hf texkom sim \n"
"hf texkom sim --raw FFFF638C7DC45553 -> simulate TK13 tag with id 8C7DC455\n"
"hf texkom sim --tk17 --raw FFFFCA17F31EC512 -> simulate TK17 tag with id 17F31EC5\n"
"hf texkom sim --id 8C7DC455 -> simulate TK13 tag with id 8C7DC455\n"
"hf texkom sim --id 8C7DC455 --tk17 -> simulate TK17 tag with id 17F31EC5");
void *argtable[] = {

View file

@ -282,6 +282,7 @@ const static vocabulary_t vocabulary[] = {
{ 0, "hf iclass sim" },
{ 0, "hf iclass eload" },
{ 0, "hf iclass esave" },
{ 0, "hf iclass esetblk" },
{ 0, "hf iclass eview" },
{ 1, "hf iclass configcard" },
{ 1, "hf iclass calcnewkey" },

View file

@ -215,10 +215,9 @@
"offline": true,
"options": [
"-h, --help This help",
"-d <hex> ASN1 encoded byte array",
"-t, --test perform selftest"
"-d <hex> ASN1 encoded byte array"
],
"usage": "data atr [-ht] [-d <hex>]"
"usage": "data atr [-h] [-d <hex>]"
},
"data autocorr": {
"command": "data autocorr",
@ -3150,6 +3149,20 @@
],
"usage": "hf iclass esave [-h] [-f <fn>] [-s <256|2048>]"
},
"hf iclass esetblk": {
"command": "hf iclass esetblk",
"description": "Sets an individual block in emulator memory.",
"notes": [
"hf iclass esetblk -b 7 -d 0000000000000000"
],
"offline": false,
"options": [
"-h, --help This help",
"-b, --blk <dec> block number",
"-d, --data <hex> bytes to write, 8 hex bytes"
],
"usage": "hf iclass esetblk [-h] -b <dec> [-d <hex>]"
},
"hf iclass eview": {
"command": "hf iclass eview",
"description": "Display emulator memory. Number of bytes to download defaults to 256. Other value is 2048.",
@ -8770,7 +8783,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 \u00ce\u00bc"
],
"usage": "lf hitag eload [-h12sm] -f <fn>"
},
@ -11819,8 +11832,8 @@
}
},
"metadata": {
"commands_extracted": 685,
"commands_extracted": 686,
"extracted_by": "PM3Help2JSON v1.00",
"extracted_on": "2023-08-02T20:39:48"
"extracted_on": "2023-08-22T17:13:49"
}
}

View file

@ -421,6 +421,7 @@ Check column "offline" for their availability.
|`hf iclass sim `|N |`Simulate iCLASS tag`
|`hf iclass eload `|N |`Load Picopass / iCLASS dump file into emulator memory`
|`hf iclass esave `|N |`Save emulator memory to file`
|`hf iclass esetblk `|N |`Set emulator memory block data`
|`hf iclass eview `|N |`View emulator memory`
|`hf iclass configcard `|Y |`Reader configuration card`
|`hf iclass calcnewkey `|Y |`Calc diversified keys (blocks 3 & 4) to write new keys`