From 042db564ba14cfc87dbcd356568bfb25b1383a2d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 10 Jan 2017 22:21:16 +0100 Subject: [PATCH] CHG: 'hf iclass replay' added help text. CHG: 'hf iclass snoop' added help text. CHG: 'hf iclass reader' added help text. ADD: 'hf iclass reader' added the possibility to read only one tag instead of looping. CHG: 'sprint_hex_ascii' function now replaces unprintable chars with '.', added this call to printIclassDumpInfo --- client/cmdhficlass.c | 53 +++++++++++++++++++++++++++++++++++--------- client/util.c | 19 ++++++++++------ 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 020ee51a..acf3de87 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -172,6 +172,33 @@ int usage_hf_iclass_managekeys(void) { PrintAndLog(" print keys : hf iclass managekeys p\n"); return 0; } +int usage_hf_iclass_reader(void) { + PrintAndLog("HELP : Act as a Iclass reader:\n"); + PrintAndLog("Usage: hf iclass reader [h] [1]\n"); + PrintAndLog("Options:"); + PrintAndLog(" h This help text"); + PrintAndLog(" 1 read only 1 tag"); + PrintAndLog("Samples:"); + PrintAndLog(" hf iclass reader 1"); + return 0; +} +int usage_hf_iclass_replay(void){ + PrintAndLog("HELP: Replay a collected mac message"); + PrintAndLog("Usage: hf iclass replay [h] "); + PrintAndLog("Options:"); + PrintAndLog(" h This help text"); + PrintAndLog(" Mac bytes to replay (8 hexsymbols)"); + PrintAndLog("Samples:"); + PrintAndLog(" hf iclass replay 00112233"); + return 0; +} +int usage_hf_iclass_snoop(void){ + PrintAndLog("HELP: Snoops the communication between reader and tag"); + PrintAndLog("Usage: hf iclass snoop [h]"); + PrintAndLog("Samples:"); + PrintAndLog(" hf iclass snoop"); + return 0; +} int xorbits_8(uint8_t val) { uint8_t res = val ^ (val >> 1); //1st pass @@ -188,6 +215,9 @@ int CmdHFiClassList(const char *Cmd) { } int CmdHFiClassSnoop(const char *Cmd) { + char cmdp = param_getchar(Cmd, 0); + if (cmdp == 'h' || cmdp == 'H') return usage_hf_iclass_snoop(); + UsbCommand c = {CMD_SNOOP_ICLASS}; SendCommand(&c); return 0; @@ -318,19 +348,18 @@ int HFiClassReader(const char *Cmd, bool loop, bool verbose) { return 0; } -int CmdHFiClassReader(const char *Cmd) { - return HFiClassReader(Cmd, true, true); +int CmdHFiClassReader(const char *Cmd) { + char cmdp = param_getchar(Cmd, 0); + if (cmdp == 'h' || cmdp == 'H') return usage_hf_iclass_reader(); + bool findone = (cmdp == '1') ? FALSE : TRUE; + return HFiClassReader(Cmd, findone, true); } int CmdHFiClassReader_Replay(const char *Cmd) { uint8_t readerType = 0; uint8_t MAC[4]={0x00, 0x00, 0x00, 0x00}; - if (strlen(Cmd)<1) { - PrintAndLog("Usage: hf iclass replay "); - PrintAndLog(" sample: hf iclass replay 00112233"); - return 0; - } + if (strlen(Cmd)<1) return usage_hf_iclass_replay(); if (param_gethex(Cmd, 0, MAC, 8)) { PrintAndLog("MAC must include 8 HEX symbols"); @@ -437,12 +466,14 @@ static int readKeyfile(const char *filename, size_t len, uint8_t* buffer) { } int CmdHFiClassDecrypt(const char *Cmd) { + + char opt = param_getchar(Cmd, 0); + if (strlen(Cmd)<1 || opt == 'h' || opt == 'H') return usage_hf_iclass_decrypt(); + uint8_t key[16] = { 0 }; if(readKeyfile("iclass_decryptionkey.bin", 16, key)) return usage_hf_iclass_decrypt(); - PrintAndLog("Decryption file found... "); - char opt = param_getchar(Cmd, 0); - if (strlen(Cmd)<1 || opt == 'h' || opt == 'H') return usage_hf_iclass_decrypt(); + PrintAndLog("Decryption file found..."); //Open the tagdump-file FILE *f; @@ -1304,7 +1335,7 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e printf("------+--+-------------------------+\n"); while (i <= endblock){ uint8_t *blk = iclass_dump + (i * 8); - printf("Block |%02X| %s|\n", i, sprint_hex(blk, 8) ); + printf("Block |%02X| %s\n", i, sprint_hex_ascii(blk, 8) ); i++; } printf("------+--+-------------------------+\n"); diff --git a/client/util.c b/client/util.c index f70b5aed..c07981fe 100644 --- a/client/util.c +++ b/client/util.c @@ -181,7 +181,18 @@ char *sprint_hex_ascii(const uint8_t *data, const size_t len) { char *tmp = buf; memset(buf, 0x00, 1024); size_t max_len = (len > 1010) ? 1010 : len; - sprintf(tmp, "%s| %s", sprint_hex(data, max_len) , data); + + sprintf(tmp, "%s| ", sprint_hex(data, max_len) ); + + size_t i = 0; + size_t pos = (max_len * 3)+2; + while(i < max_len){ + char c = data[i]; + if ( (c < 32) || (c == 127)) + c = '.'; + sprintf(tmp+pos+i, "%c", c); + ++i; + } return buf; } @@ -284,9 +295,7 @@ int param_getptr(const char *line, int *bg, int *en, int paramnum) char param_getchar(const char *line, int paramnum) { int bg, en; - if (param_getptr(line, &bg, &en, paramnum)) return 0x00; - return line[bg]; } @@ -327,7 +336,6 @@ uint8_t param_isdec(const char *line, int paramnum) uint8_t param_get8ex(const char *line, int paramnum, int deflt, int base) { int bg, en; - if (!param_getptr(line, &bg, &en, paramnum)) return strtoul(&line[bg], NULL, base) & 0xff; else @@ -337,7 +345,6 @@ uint8_t param_get8ex(const char *line, int paramnum, int deflt, int base) uint32_t param_get32ex(const char *line, int paramnum, int deflt, int base) { int bg, en; - if (!param_getptr(line, &bg, &en, paramnum)) return strtoul(&line[bg], NULL, base); else @@ -347,7 +354,6 @@ uint32_t param_get32ex(const char *line, int paramnum, int deflt, int base) uint64_t param_get64ex(const char *line, int paramnum, int deflt, int base) { int bg, en; - if (!param_getptr(line, &bg, &en, paramnum)) return strtoull(&line[bg], NULL, base); else @@ -398,7 +404,6 @@ int param_gethex_ex(const char *line, int paramnum, uint8_t * data, int *hexcnt) int param_getstr(const char *line, int paramnum, char * str) { int bg, en; - if (param_getptr(line, &bg, &en, paramnum)) return 0; memcpy(str, line + bg, en - bg + 1); -- 2.39.2