mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 13:00:42 -07:00
Merge pull request #1000 from tcprst/iclass_cliparser
hf iclass view, permute - now use cliparser
This commit is contained in:
commit
ddd92fcf69
4 changed files with 52 additions and 81 deletions
|
@ -125,7 +125,7 @@ static void download_instructions(uint8_t t) {
|
||||||
case ICE_STATE_FULLSIM: {
|
case ICE_STATE_FULLSIM: {
|
||||||
DbpString("The emulator memory was saved to SPIFFS");
|
DbpString("The emulator memory was saved to SPIFFS");
|
||||||
DbpString("1. " _YELLOW_("mem spiffs dump o " HF_ICLASS_FULLSIM_MOD_BIN " f " HF_ICLASS_FULLSIM_MOD" e"));
|
DbpString("1. " _YELLOW_("mem spiffs dump o " HF_ICLASS_FULLSIM_MOD_BIN " f " HF_ICLASS_FULLSIM_MOD" e"));
|
||||||
DbpString("2. " _YELLOW_("hf iclass view f " HF_ICLASS_FULLSIM_MOD_BIN));
|
DbpString("2. " _YELLOW_("hf iclass view -f " HF_ICLASS_FULLSIM_MOD_BIN));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ICE_STATE_ATTACK: {
|
case ICE_STATE_ATTACK: {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "cmdparser.h" // command_t
|
#include "cmdparser.h" // command_t
|
||||||
#include "commonutil.h" // ARRAYLEN
|
#include "commonutil.h" // ARRAYLEN
|
||||||
#include "cmdtrace.h"
|
#include "cmdtrace.h"
|
||||||
|
#include "cliparser.h"
|
||||||
#include "util_posix.h"
|
#include "util_posix.h"
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
#include "des.h"
|
#include "des.h"
|
||||||
|
@ -224,21 +225,6 @@ static int usage_hf_iclass_readblock(void) {
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
static int usage_hf_iclass_view(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Print a iCLASS tag dump file\n");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: hf iClass view [f <filename>] [s <startblock>] [e <endblock>] [v]\n");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h Show this help");
|
|
||||||
PrintAndLogEx(NORMAL, " f <filename> filename of dump");
|
|
||||||
PrintAndLogEx(NORMAL, " s <startblock> print from this block (default block6)");
|
|
||||||
PrintAndLogEx(NORMAL, " e <endblock> end printing at this block (default 0, ALL)");
|
|
||||||
PrintAndLogEx(NORMAL, " v verbose output");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_("\thf iclass view f hf-iclass-AA162D30F8FF12F1-dump.bin"));
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_("\thf iclass view s 1 f hf-iclass-AA162D30F8FF12F1-dump.bin"));
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
static int usage_hf_iclass_calc_newkey(void) {
|
static int usage_hf_iclass_calc_newkey(void) {
|
||||||
PrintAndLogEx(NORMAL, "Calculate new key for updating\n");
|
PrintAndLogEx(NORMAL, "Calculate new key for updating\n");
|
||||||
PrintAndLogEx(NORMAL, "Usage: hf iclass calc_newkey o <old key> n <new key> s [csn] e\n");
|
PrintAndLogEx(NORMAL, "Usage: hf iclass calc_newkey o <old key> n <new key> s [csn] e\n");
|
||||||
|
@ -359,20 +345,7 @@ static int usage_hf_iclass_lookup(void) {
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
static int usage_hf_iclass_permutekey(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Permute function from 'heart of darkness' paper.\n");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: hf iclass permute [h] <r|f> <bytes>\n");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h Show this help");
|
|
||||||
PrintAndLogEx(NORMAL, " r reverse permuted key");
|
|
||||||
PrintAndLogEx(NORMAL, " f permute key");
|
|
||||||
PrintAndLogEx(NORMAL, " <bytes> input bytes");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_("\thf iclass permute r 0123456789abcdef"));
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cmp_uint32(const void *a, const void *b) {
|
static int cmp_uint32(const void *a, const void *b) {
|
||||||
|
|
||||||
|
@ -2680,43 +2653,31 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdHFiClassView(const char *Cmd) {
|
static int CmdHFiClassView(const char *Cmd) {
|
||||||
int startblock = 0;
|
CLIParserContext *ctx;
|
||||||
int endblock = 0;
|
CLIParserInit(&ctx, "hf iclass view",
|
||||||
char filename[FILE_PATH_SIZE];
|
"Print a iCLASS tag dump file",
|
||||||
bool errors = false, verbose = false;
|
"hf iclass view -f hf-iclass-AA162D30F8FF12F1-dump.bin\n"
|
||||||
uint8_t cmdp = 0;
|
"hf iclass view --startblock 1 --file hf-iclass-AA162D30F8FF12F1-dump.bin\n");
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
|
||||||
case 'h':
|
|
||||||
return usage_hf_iclass_view();
|
|
||||||
case 'f':
|
|
||||||
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
|
||||||
PrintAndLogEx(FAILED, "Filename too long");
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
startblock = param_get8ex(Cmd, cmdp + 1, 0, 10);
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
case 'e':
|
|
||||||
endblock = param_get8ex(Cmd, cmdp + 1, 0, 10);
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
verbose = true;
|
|
||||||
cmdp++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errors || (strlen(Cmd) == 0)) return usage_hf_iclass_view();
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_str1("f", "file", "<filename>", "filename of dump"),
|
||||||
|
arg_int0("s", "startblock", "<dec>", "print from this block (default block6)"),
|
||||||
|
arg_int0("e", "endblock", "<dec>", "end printing at this block (default 0, ALL)"),
|
||||||
|
arg_lit0("v", "verbose", "verbose output"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||||
|
|
||||||
|
int fnlen = 0;
|
||||||
|
char filename[FILE_PATH_SIZE];
|
||||||
|
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t*)filename, FILE_PATH_SIZE, &fnlen);
|
||||||
|
|
||||||
|
int startblock = arg_get_int_def(ctx, 2, 0);
|
||||||
|
int endblock = arg_get_int_def(ctx, 3, 0);
|
||||||
|
bool verbose = arg_get_lit(ctx, 4);
|
||||||
|
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
uint8_t *dump = NULL;
|
uint8_t *dump = NULL;
|
||||||
size_t bytes_read = 0;
|
size_t bytes_read = 0;
|
||||||
|
@ -3522,17 +3483,26 @@ static int CmdHFiClassPermuteKey(const char *Cmd) {
|
||||||
uint8_t data[16] = {0};
|
uint8_t data[16] = {0};
|
||||||
bool isReverse = false;
|
bool isReverse = false;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
char cmdp = tolower(param_getchar(Cmd, 0));
|
|
||||||
if (strlen(Cmd) == 0 || cmdp == 'h')
|
|
||||||
return usage_hf_iclass_permutekey();
|
|
||||||
|
|
||||||
isReverse = (cmdp == 'r');
|
CLIParserContext *ctx;
|
||||||
|
CLIParserInit(&ctx, "hf iclass permute",
|
||||||
|
"Permute function from 'heart of darkness' paper.",
|
||||||
|
"hf iclass permute --reverse --key 0123456789abcdef\n"
|
||||||
|
"hf iclass permute --key ff55330f0055330f\n");
|
||||||
|
|
||||||
param_gethex_ex(Cmd, 1, data, &len);
|
void *argtable[] = {
|
||||||
if (len % 2)
|
arg_param_begin,
|
||||||
return usage_hf_iclass_permutekey();
|
arg_lit0("r", "reverse", "reverse permuted key"),
|
||||||
|
arg_str1(NULL, "key", "<bytes>", "input key"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||||
|
|
||||||
len >>= 1;
|
isReverse = arg_get_lit(ctx, 1);
|
||||||
|
|
||||||
|
CLIGetHexWithReturn(ctx, 2, data, &len);
|
||||||
|
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
memcpy(key, data, 8);
|
memcpy(key, data, 8);
|
||||||
|
|
||||||
|
@ -3580,7 +3550,7 @@ static command_t CommandTable[] = {
|
||||||
{"encrypt", CmdHFiClassEncryptBlk, AlwaysAvailable, "[options..] Encrypt given block data"},
|
{"encrypt", CmdHFiClassEncryptBlk, AlwaysAvailable, "[options..] Encrypt given block data"},
|
||||||
{"decrypt", CmdHFiClassDecrypt, AlwaysAvailable, "[options..] Decrypt given block data or tag dump file" },
|
{"decrypt", CmdHFiClassDecrypt, AlwaysAvailable, "[options..] Decrypt given block data or tag dump file" },
|
||||||
{"managekeys", CmdHFiClassManageKeys, AlwaysAvailable, "[options..] Manage keys to use with iclass commands"},
|
{"managekeys", CmdHFiClassManageKeys, AlwaysAvailable, "[options..] Manage keys to use with iclass commands"},
|
||||||
{"permutekey", CmdHFiClassPermuteKey, IfPm3Iclass, " Permute function from 'heart of darkness' paper"},
|
{"permute", CmdHFiClassPermuteKey, IfPm3Iclass, " Permute function from 'heart of darkness' paper"},
|
||||||
{"view", CmdHFiClassView, AlwaysAvailable, "[options..] Display content from tag dump file"},
|
{"view", CmdHFiClassView, AlwaysAvailable, "[options..] Display content from tag dump file"},
|
||||||
|
|
||||||
{NULL, NULL, NULL, NULL}
|
{NULL, NULL, NULL, NULL}
|
||||||
|
|
|
@ -46,9 +46,10 @@ Reverse permute iCLASS master key
|
||||||
```
|
```
|
||||||
Options
|
Options
|
||||||
---
|
---
|
||||||
r reverse permuted key
|
-r --reverse : reverse permuted key
|
||||||
|
--key <bytes> : input key
|
||||||
|
|
||||||
pm3 --> hf iclass permute r 3F90EBF0910F7B6F
|
pm3 --> hf iclass permute --reverse --key 3F90EBF0910F7B6F
|
||||||
```
|
```
|
||||||
|
|
||||||
iCLASS Reader
|
iCLASS Reader
|
||||||
|
|
|
@ -265,7 +265,7 @@ Check column "offline" for their availability.
|
||||||
|`hf iclass encrypt `|Y |`[options..] Encrypt given block data`
|
|`hf iclass encrypt `|Y |`[options..] Encrypt given block data`
|
||||||
|`hf iclass decrypt `|Y |`[options..] Decrypt given block data or tag dump file`
|
|`hf iclass decrypt `|Y |`[options..] Decrypt given block data or tag dump file`
|
||||||
|`hf iclass managekeys `|Y |`[options..] Manage keys to use with iclass commands`
|
|`hf iclass managekeys `|Y |`[options..] Manage keys to use with iclass commands`
|
||||||
|`hf iclass permutekey `|N |` Permute function from 'heart of darkness' paper`
|
|`hf iclass permute `|N |` Permute function from 'heart of darkness' paper`
|
||||||
|`hf iclass view `|Y |`[options..] Display content from tag dump file`
|
|`hf iclass view `|Y |`[options..] Display content from tag dump file`
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue