From 3125812f93c3f5ca0a596b22c241fd7111907957 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Sat, 21 Mar 2020 20:08:11 +1100 Subject: [PATCH 1/5] Update cmdlfkeri.c Added clone for FC and CardID --- client/cmdlfkeri.c | 83 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 11 deletions(-) diff --git a/client/cmdlfkeri.c b/client/cmdlfkeri.c index 982eb8193..2fa8181b3 100644 --- a/client/cmdlfkeri.c +++ b/client/cmdlfkeri.c @@ -30,13 +30,21 @@ static int CmdHelp(const char *Cmd); static int usage_lf_keri_clone(void) { PrintAndLogEx(NORMAL, "clone a KERI tag to a T55x7 tag."); PrintAndLogEx(NORMAL, "Usage: lf keri clone [h] "); + PrintAndLogEx(NORMAL, "Usage extended: lf keri clone [h] t [f ] i [Q5]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h : This help"); PrintAndLogEx(NORMAL, " : Keri Internal ID"); PrintAndLogEx(NORMAL, " : specify write to Q5 (t5555 instead of t55x7)"); + // New format + PrintAndLogEx(NORMAL, " [m|i] : Type. m - MS, i - Internal ID"); + PrintAndLogEx(NORMAL, " : Facility Code"); + PrintAndLogEx(NORMAL, " : Card ID"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf keri clone 112233"); + PrintAndLogEx(NORMAL, " lf keri clone type ms fc 6 id 12345"); + PrintAndLogEx(NORMAL, " lf keri clone t m f 6 i 12345"); + return PM3_SUCCESS; } @@ -98,7 +106,7 @@ static int CmdKeriMSScramble (KeriMSScramble_t Action, uint32_t *FC, uint32_t *I } // Card FC if (CardToFC[CardIdx] < 32) { - if ((*ID & (1 << CardToFC[CardIdx])) > 0) + if ((*FC & (1 << CardToFC[CardIdx])) > 0) *CardID |= (1 << CardIdx); } } @@ -122,7 +130,7 @@ static int CmdKeriMSScramble (KeriMSScramble_t Action, uint32_t *FC, uint32_t *I // Bit 31 was fixed but not in check/parity bits *CardID |= (1 << 31); - PrintAndLogEx(SUCCESS, "Scrambled FC : %d - Card ID : %d to RAW : E0000000%08X",*FC,*ID,*CardID); + PrintAndLogEx(SUCCESS, "Scrambled MS : FC %d - Card ID %d to RAW : E0000000%08X",*FC,*ID,*CardID); } return PM3_SUCCESS; } @@ -192,10 +200,10 @@ static int CmdKeriDemod(const char *Cmd) { /* Scamble: For dev testing only, will/should move to the create keri-ms code when added. - - uint32_t testCard = 0; - CmdKeriMSScramble (Scramble,&fc,&cardid,&testCard); -*/ + */ + // uint32_t testCard = 0; + // CmdKeriMSScramble (Scramble,&fc,&cardid,&testCard); + // End Descramble test @@ -216,6 +224,11 @@ static int CmdKeriRead(const char *Cmd) { static int CmdKeriClone(const char *Cmd) { + uint8_t cmdptr = 0; + char format = 'r'; // default to raw + uint32_t fc = 0; + uint32_t cid = 0; + uint32_t cardid = 0; uint32_t internalid = 0; uint32_t blocks[3] = { T55x7_TESTMODE_DISABLED | @@ -233,8 +246,45 @@ static int CmdKeriClone(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_keri_clone(); - internalid = param_get32ex(Cmd, 0, 0, 10); + // Assume old format for backwards compatibility and only parameter is the internal id + cid = param_get32ex(Cmd, 0, 0, 10); + // find other options + while (param_getchar(Cmd, cmdptr) != 0x00) { // && !errors) { + PrintAndLogEx (SUCCESS,"[%c]",param_getchar(Cmd, cmdptr)); + switch (tolower(param_getchar(Cmd, cmdptr))) { + case 'h': // help + return usage_lf_keri_clone(); + case 't': // format type + format = tolower(param_getchar(Cmd,cmdptr+1)); + cmdptr += 2; + break; + case 'f': // fc + fc = param_get32ex(Cmd,cmdptr+1,0,10); + cmdptr += 2; + break; + case 'c': // cardid + cid = param_get32ex(Cmd,cmdptr+1,0,10); + cmdptr += 2; + break; + case 'q': // q5 + blocks[0] = + T5555_MODULATION_PSK1 | + T5555_SET_BITRATE(128) | + T5555_PSK_RF_2 | + 2 << T5555_MAXBLOCK_SHIFT; + cmdptr++; + break; + default: + // Skip unknown + cmdptr++; + } + } + + // this is managed in above code + // internalid = param_get32ex(Cmd, 0, 0, 10); +/* + // Q5 is caught in the while loop //Q5 if (tolower(param_getchar(Cmd, 1)) == 'q') { blocks[0] = @@ -243,10 +293,21 @@ static int CmdKeriClone(const char *Cmd) { T5555_PSK_RF_2 | 2 << T5555_MAXBLOCK_SHIFT; } - - // MSB is ONE - internalid |= 0x80000000; - +*/ + // Setup card data + switch (format) { + case 'i' : // Internal ID + // MSB is ONE + internalid = cid | 0x80000000; + break; + case 'm' : // MS + cardid = 0; + CmdKeriMSScramble (Scramble,&fc,&cid,&cardid); + internalid = 0xE000000000000000 + cardid; + break; + } + + // Prepare and write to card // 3 LSB is ONE uint64_t data = ((uint64_t)internalid << 3) + 7; PrintAndLogEx(INFO, "Preparing to clone KERI to T55x7 with Internal Id: %" PRIx32, internalid); From 6440f4c5b0d6797607b14b322e5ac3f4f56dc817 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Sat, 21 Mar 2020 21:36:37 +1100 Subject: [PATCH 2/5] Update cmdlfkeri.c --- client/cmdlfkeri.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/cmdlfkeri.c b/client/cmdlfkeri.c index 2fa8181b3..9f292c091 100644 --- a/client/cmdlfkeri.c +++ b/client/cmdlfkeri.c @@ -30,7 +30,7 @@ static int CmdHelp(const char *Cmd); static int usage_lf_keri_clone(void) { PrintAndLogEx(NORMAL, "clone a KERI tag to a T55x7 tag."); PrintAndLogEx(NORMAL, "Usage: lf keri clone [h] "); - PrintAndLogEx(NORMAL, "Usage extended: lf keri clone [h] t [f ] i [Q5]"); + PrintAndLogEx(NORMAL, "Usage extended: lf keri clone [h] t [f ] c [Q5]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h : This help"); PrintAndLogEx(NORMAL, " : Keri Internal ID"); @@ -225,7 +225,7 @@ static int CmdKeriRead(const char *Cmd) { static int CmdKeriClone(const char *Cmd) { uint8_t cmdptr = 0; - char format = 'r'; // default to raw + char format = 'i'; // default to raw uint32_t fc = 0; uint32_t cid = 0; uint32_t cardid = 0; @@ -294,7 +294,7 @@ static int CmdKeriClone(const char *Cmd) { 2 << T5555_MAXBLOCK_SHIFT; } */ - // Setup card data + // Setup card data/build internal id switch (format) { case 'i' : // Internal ID // MSB is ONE From 4175297f57af0d44b6a067276c52ac3990814486 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Sat, 21 Mar 2020 21:42:00 +1100 Subject: [PATCH 3/5] Update cmdlfkeri.c help update --- client/cmdlfkeri.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/cmdlfkeri.c b/client/cmdlfkeri.c index 9f292c091..a5d66caff 100644 --- a/client/cmdlfkeri.c +++ b/client/cmdlfkeri.c @@ -32,18 +32,18 @@ static int usage_lf_keri_clone(void) { PrintAndLogEx(NORMAL, "Usage: lf keri clone [h] "); PrintAndLogEx(NORMAL, "Usage extended: lf keri clone [h] t [f ] c [Q5]"); PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " : Keri Internal ID"); - PrintAndLogEx(NORMAL, " : specify write to Q5 (t5555 instead of t55x7)"); + PrintAndLogEx(NORMAL, " h : This help"); + PrintAndLogEx(NORMAL, " : Keri Internal ID"); + PrintAndLogEx(NORMAL, " : specify write to Q5 (t5555 instead of t55x7)"); // New format - PrintAndLogEx(NORMAL, " [m|i] : Type. m - MS, i - Internal ID"); - PrintAndLogEx(NORMAL, " : Facility Code"); - PrintAndLogEx(NORMAL, " : Card ID"); + PrintAndLogEx(NORMAL, " [m|i] : Type. m - MS, i - Internal ID"); + PrintAndLogEx(NORMAL, " : Facility Code"); + PrintAndLogEx(NORMAL, " : Card ID"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf keri clone 112233"); - PrintAndLogEx(NORMAL, " lf keri clone type ms fc 6 id 12345"); - PrintAndLogEx(NORMAL, " lf keri clone t m f 6 i 12345"); + PrintAndLogEx(NORMAL, " lf keri clone type ms fc 6 cardid 12345"); + PrintAndLogEx(NORMAL, " lf keri clone t m f 6 c 12345"); return PM3_SUCCESS; } From dfe36a2d606f41898867103ba509a48add38fecf Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Sun, 22 Mar 2020 11:55:38 +1100 Subject: [PATCH 4/5] Update cmdlfkeri.c Code clean and tune --- client/cmdlfkeri.c | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/client/cmdlfkeri.c b/client/cmdlfkeri.c index a5d66caff..8bc3c7e54 100644 --- a/client/cmdlfkeri.c +++ b/client/cmdlfkeri.c @@ -197,15 +197,6 @@ static int CmdKeriDemod(const char *Cmd) { CmdKeriMSScramble (Descramble,&fc,&cardid,&raw2); PrintAndLogEx (SUCCESS,"Descrambled MS : FC %d - Card ID %d\n",fc,cardid); - -/* - Scamble: For dev testing only, will/should move to the create keri-ms code when added. - */ - // uint32_t testCard = 0; - // CmdKeriMSScramble (Scramble,&fc,&cardid,&testCard); - - -// End Descramble test if (invert) { PrintAndLogEx(INFO, "Had to Invert - probably KERI"); @@ -224,11 +215,10 @@ static int CmdKeriRead(const char *Cmd) { static int CmdKeriClone(const char *Cmd) { - uint8_t cmdptr = 0; - char format = 'i'; // default to raw + uint8_t cmdidx = 0; + char keritype = 'i'; // default to internalid uint32_t fc = 0; uint32_t cid = 0; - uint32_t cardid = 0; uint32_t internalid = 0; uint32_t blocks[3] = { T55x7_TESTMODE_DISABLED | @@ -250,22 +240,21 @@ static int CmdKeriClone(const char *Cmd) { cid = param_get32ex(Cmd, 0, 0, 10); // find other options - while (param_getchar(Cmd, cmdptr) != 0x00) { // && !errors) { - PrintAndLogEx (SUCCESS,"[%c]",param_getchar(Cmd, cmdptr)); - switch (tolower(param_getchar(Cmd, cmdptr))) { + while (param_getchar(Cmd, cmdidx) != 0x00) { // && !errors) { + switch (tolower(param_getchar(Cmd, cmdidx))) { case 'h': // help return usage_lf_keri_clone(); case 't': // format type - format = tolower(param_getchar(Cmd,cmdptr+1)); - cmdptr += 2; + keritype = tolower(param_getchar(Cmd,cmdidx+1)); + cmdidx += 2; break; case 'f': // fc - fc = param_get32ex(Cmd,cmdptr+1,0,10); - cmdptr += 2; + fc = param_get32ex(Cmd,cmdidx+1,0,10); + cmdidx += 2; break; case 'c': // cardid - cid = param_get32ex(Cmd,cmdptr+1,0,10); - cmdptr += 2; + cid = param_get32ex(Cmd,cmdidx+1,0,10); + cmdidx += 2; break; case 'q': // q5 blocks[0] = @@ -273,11 +262,11 @@ static int CmdKeriClone(const char *Cmd) { T5555_SET_BITRATE(128) | T5555_PSK_RF_2 | 2 << T5555_MAXBLOCK_SHIFT; - cmdptr++; + cmdidx++; break; default: // Skip unknown - cmdptr++; + cmdidx++; } } @@ -295,15 +284,13 @@ static int CmdKeriClone(const char *Cmd) { } */ // Setup card data/build internal id - switch (format) { + switch (keritype) { case 'i' : // Internal ID // MSB is ONE internalid = cid | 0x80000000; break; case 'm' : // MS - cardid = 0; - CmdKeriMSScramble (Scramble,&fc,&cid,&cardid); - internalid = 0xE000000000000000 + cardid; + CmdKeriMSScramble (Scramble,&fc,&cid,&internalid); break; } From 1df6782312b61332a9a438e857527093585d75bc Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Sun, 22 Mar 2020 17:47:35 +1100 Subject: [PATCH 5/5] Update cmdlfkeri.c Card ID change to CN/Card Number --- client/cmdlfkeri.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/cmdlfkeri.c b/client/cmdlfkeri.c index 8bc3c7e54..ced67ad86 100644 --- a/client/cmdlfkeri.c +++ b/client/cmdlfkeri.c @@ -38,11 +38,11 @@ static int usage_lf_keri_clone(void) { // New format PrintAndLogEx(NORMAL, " [m|i] : Type. m - MS, i - Internal ID"); PrintAndLogEx(NORMAL, " : Facility Code"); - PrintAndLogEx(NORMAL, " : Card ID"); + PrintAndLogEx(NORMAL, " : Card Number"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf keri clone 112233"); - PrintAndLogEx(NORMAL, " lf keri clone type ms fc 6 cardid 12345"); + PrintAndLogEx(NORMAL, " lf keri clone type ms fc 6 cn 12345"); PrintAndLogEx(NORMAL, " lf keri clone t m f 6 c 12345"); return PM3_SUCCESS; @@ -130,7 +130,7 @@ static int CmdKeriMSScramble (KeriMSScramble_t Action, uint32_t *FC, uint32_t *I // Bit 31 was fixed but not in check/parity bits *CardID |= (1 << 31); - PrintAndLogEx(SUCCESS, "Scrambled MS : FC %d - Card ID %d to RAW : E0000000%08X",*FC,*ID,*CardID); + PrintAndLogEx(SUCCESS, "Scrambled MS : FC %d - CN %d to RAW : E0000000%08X",*FC,*ID,*CardID); } return PM3_SUCCESS; } @@ -196,7 +196,7 @@ static int CmdKeriDemod(const char *Cmd) { // Just need to the low 32 bits without the 111 trailer CmdKeriMSScramble (Descramble,&fc,&cardid,&raw2); - PrintAndLogEx (SUCCESS,"Descrambled MS : FC %d - Card ID %d\n",fc,cardid); + PrintAndLogEx (SUCCESS,"Descrambled MS : FC %d - CN %d\n",fc,cardid); if (invert) { PrintAndLogEx(INFO, "Had to Invert - probably KERI");