Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds hf iclass esetblk, equivalent to hf mf esetblk #2086

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/pyscripts/pm3_help2list.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def main():

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};

Expand Down
55 changes: 51 additions & 4 deletions client/src/cmdhficlass.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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, "");
Expand Down Expand Up @@ -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`"));
Expand Down Expand Up @@ -1222,6 +1222,52 @@ static int CmdHFiClassEView(const char *Cmd) {
return PM3_SUCCESS;
}

static int CmdHFiClassESetBlk(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf iclass esetblk",
"Display emulator memory.\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you need to update this texts to match the new command

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops missed that one!

"Number of bytes to download defaults to 256. Other value is 2048.",
"hf iclass eview\n"
"hf iclass eview -s 2048\n"
"hf iclass eview -s 2048 -v");

void *argtable[] = {
arg_param_begin,
arg_int1("b", "blk", "<dec>", "block number"),
arg_str0("d", "data", "<hex>", "bytes to write, 16 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);
Expand Down Expand Up @@ -4226,6 +4272,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"},
Expand Down
8 changes: 4 additions & 4 deletions client/src/cmdhftexkom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
1 change: 1 addition & 0 deletions client/src/pm3line_vocabulary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
28 changes: 22 additions & 6 deletions doc/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -3150,6 +3149,22 @@
],
"usage": "hf iclass esave [-h] [-f <fn>] [-s <256|2048>]"
},
"hf iclass esetblk": {
"command": "hf iclass esetblk",
"description": "Display emulator memory. Number of bytes to download defaults to 256. Other value is 2048.",
"notes": [
"hf iclass eview",
"hf iclass eview -s 2048",
"hf iclass eview -s 2048 -v"
],
"offline": false,
"options": [
"-h, --help This help",
"-b, --blk <dec> block number",
"-d, --data <hex> bytes to write, 16 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.",
Expand Down Expand Up @@ -6986,6 +7001,7 @@
"description": "Simulate a texkom tag",
"notes": [
"hf texkom sim",
"",
"hf texkom sim --raw FFFF638C7DC45553 -> simulate TK13 tag with id 8C7DC455",
"hf texkom sim --tk17 --raw FFFFCA17F31EC512 -> simulate TK17 tag with id 17F31EC5",
"hf texkom sim --id 8C7DC455 -> simulate TK13 tag with id 8C7DC455",
Expand Down Expand Up @@ -8770,7 +8786,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>"
},
Expand Down Expand Up @@ -11819,8 +11835,8 @@
}
},
"metadata": {
"commands_extracted": 685,
"commands_extracted": 686,
"extracted_by": "PM3Help2JSON v1.00",
"extracted_on": "2023-08-02T20:39:48"
"extracted_on": "2023-08-21T21:25:03"
}
}
1 change: 1 addition & 0 deletions doc/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Loading