mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-03 19:43:09 +08:00
Merge pull request #1132 from tcprst/epa_cliparser
hf epa - now use cliparser
This commit is contained in:
commit
83eea0532c
3 changed files with 90 additions and 90 deletions
|
@ -15,7 +15,7 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h> // tolower
|
||||
|
||||
#include "cliparser.h"
|
||||
#include "cmdparser.h" // command_t
|
||||
#include "commonutil.h" // ARRAYLEN
|
||||
#include "comms.h" // clearCommandBuffer
|
||||
|
@ -24,35 +24,28 @@
|
|||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
static int usage_epa_collect(void) {
|
||||
PrintAndLogEx(NORMAL, "Tries to collect nonces when doing part of PACE protocol.\n"
|
||||
"\n"
|
||||
"Usage: hf epa cnonces <m> <n> <d>\n"
|
||||
"Options:\n"
|
||||
"\t<m> nonce size\n"
|
||||
"\t<n> number of nonces to collect\n"
|
||||
"\t<d> delay between\n"
|
||||
"\n"
|
||||
"Example:\n"
|
||||
_YELLOW_("\thf epa cnonces 4 4 1")
|
||||
);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// Perform (part of) the PACE protocol
|
||||
static int CmdHFEPACollectPACENonces(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf epa cnonces",
|
||||
"Tries to collect nonces when doing part of PACE protocol.",
|
||||
"hf epa cnonces --size 4 --num 4 --delay 1");
|
||||
|
||||
char cmdp = tolower(param_getchar(Cmd, 0));
|
||||
if (cmdp == 'h') return usage_epa_collect();
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_int1(NULL, "size", "<dec>", "nonce size"),
|
||||
arg_int1(NULL, "num", "<dec>", "number of nonces to collect"),
|
||||
arg_int1("d", "delay", "<dec>", "delay between attempts"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
// requested nonce size
|
||||
uint32_t m = 0;
|
||||
// requested number of Nonces
|
||||
uint32_t n = 0;
|
||||
// delay between requests
|
||||
uint32_t d = 0;
|
||||
|
||||
sscanf(Cmd, "%u %u %u", &m, &n, &d);
|
||||
int m = arg_get_int_def(ctx, 1, 0);
|
||||
int n = arg_get_int_def(ctx, 2, 0);
|
||||
int d = arg_get_int_def(ctx, 3, 0);
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// values are expected to be > 0
|
||||
m = m > 0 ? m : 1;
|
||||
|
@ -99,54 +92,51 @@ static int CmdHFEPACollectPACENonces(const char *Cmd) {
|
|||
|
||||
// perform the PACE protocol by replaying APDUs
|
||||
static int CmdHFEPAPACEReplay(const char *Cmd) {
|
||||
// the 4 APDUs which are replayed + their lengths
|
||||
uint8_t msesa_apdu[41] = {0}, gn_apdu[8] = {0}, map_apdu[75] = {0};
|
||||
uint8_t pka_apdu[75] = {0}, ma_apdu[18] = {0}, apdu_lengths[5] = {0};
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf epa preplay",
|
||||
"Perform PACE protocol by replaying given APDUs",
|
||||
"hf epa preplay --mse 0022C1A4 --get 1068000000 --map 1086000002 --pka 1234ABCDEF --ma 1A2B3C4D");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1(NULL, "mse", "<hex>", "msesa APDU"),
|
||||
arg_str1(NULL, "get", "<hex>", "gn APDU"),
|
||||
arg_str1(NULL, "map", "<hex>", "map APDU"),
|
||||
arg_str1(NULL, "pka", "<hex>", "pka APDU"),
|
||||
arg_str1(NULL, "ma", "<hex>", "ma APDU"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
int msesa_len = 0;
|
||||
uint8_t msesa_apdu[41] = {0};
|
||||
CLIGetHexWithReturn(ctx, 1, msesa_apdu, &msesa_len);
|
||||
|
||||
int gn_len = 0;
|
||||
uint8_t gn_apdu[8] = {0};
|
||||
CLIGetHexWithReturn(ctx, 2, gn_apdu, &gn_len);
|
||||
|
||||
int map_len = 0;
|
||||
uint8_t map_apdu[75] = {0};
|
||||
CLIGetHexWithReturn(ctx, 3, map_apdu, &map_len);
|
||||
|
||||
int pka_len = 0;
|
||||
uint8_t pka_apdu[75] = {0};
|
||||
CLIGetHexWithReturn(ctx, 4, pka_apdu, &pka_len);
|
||||
|
||||
int ma_len = 0;
|
||||
uint8_t ma_apdu[18] = {0};
|
||||
CLIGetHexWithReturn(ctx, 5, ma_apdu, &ma_len);
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
uint8_t apdu_lengths[5] = {msesa_len, gn_len, map_len, pka_len, ma_len};
|
||||
// pointers to the arrays to be able to iterate
|
||||
uint8_t *apdus[] = {msesa_apdu, gn_apdu, map_apdu, pka_apdu, ma_apdu};
|
||||
|
||||
// usage message
|
||||
static const char *usage_msg =
|
||||
"Please specify 5 APDUs separated by spaces. "
|
||||
"Example:\n preplay 0022C1A4 1068000000 1086000002 1234ABCDEF 1A2B3C4D";
|
||||
|
||||
// Proxmark response
|
||||
PacketResponseNG resp;
|
||||
|
||||
int skip = 0, skip_add = 0, scan_return;
|
||||
// for each APDU
|
||||
for (int i = 0; i < ARRAYLEN(apdu_lengths); i++) {
|
||||
// scan to next space or end of string
|
||||
while (Cmd[skip] != ' ' && Cmd[skip] != '\0') {
|
||||
// convert
|
||||
scan_return = sscanf(Cmd + skip,
|
||||
"%2" SCNx8 "%n",
|
||||
apdus[i] + apdu_lengths[i],
|
||||
&skip_add
|
||||
);
|
||||
|
||||
if (scan_return < 1) {
|
||||
PrintAndLogEx(INFO, (char *)usage_msg);
|
||||
PrintAndLogEx(WARNING, "Not enough APDUs! Try again!");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
skip += skip_add;
|
||||
apdu_lengths[i]++;
|
||||
}
|
||||
|
||||
// break on EOF
|
||||
if (Cmd[skip] == '\0') {
|
||||
if (i < ARRAYLEN(apdu_lengths) - 1) {
|
||||
|
||||
PrintAndLogEx(INFO, (char *)usage_msg);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// skip the space
|
||||
skip++;
|
||||
}
|
||||
|
||||
// transfer the APDUs to the Proxmark
|
||||
uint8_t data[PM3_CMD_DATA_SIZE];
|
||||
// fast push mode
|
||||
|
@ -205,8 +195,8 @@ static int CmdHFEPAPACEReplay(const char *Cmd) {
|
|||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
{"cnonces", CmdHFEPACollectPACENonces, IfPm3Iso14443, "<m> <n> <d> Acquire n>0 encrypted PACE nonces of size m>0 with d sec pauses"},
|
||||
{"preplay", CmdHFEPAPACEReplay, IfPm3Iso14443, "<mse> <get> <map> <pka> <ma> Perform PACE protocol by replaying given APDUs"},
|
||||
{"cnonces", CmdHFEPACollectPACENonces, IfPm3Iso14443, "Acquire encrypted PACE nonces of specific size"},
|
||||
{"preplay", CmdHFEPAPACEReplay, IfPm3Iso14443, "Perform PACE protocol by replaying given APDUs"},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -56,8 +56,6 @@ hf 15 restore
|
|||
hf 15 wrbl
|
||||
hf 15 writeafi
|
||||
hf 15 writedsfid
|
||||
hf epa cnonces
|
||||
hf epa preplay
|
||||
hf felica reader
|
||||
hf felica sniff
|
||||
hf felica raw
|
||||
|
|
|
@ -126,7 +126,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf 14a
|
||||
|
||||
{ ISO14443A RFIDs... }
|
||||
{ ISO14443A RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -147,7 +147,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf 14b
|
||||
|
||||
{ ISO14443B RFIDs... }
|
||||
{ ISO14443B RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -167,7 +167,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf 15
|
||||
|
||||
{ ISO15693 RFIDs... }
|
||||
{ ISO15693 RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -193,18 +193,30 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf epa
|
||||
|
||||
{ German Identification Card... }
|
||||
{ German Identification Card... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|`hf epa help `|Y |`This help`
|
||||
|`hf epa cnonces `|N |`<m> <n> <d> Acquire n>0 encrypted PACE nonces of size m>0 with d sec pauses`
|
||||
|`hf epa preplay `|N |`<mse> <get> <map> <pka> <ma> Perform PACE protocol by replaying given APDUs`
|
||||
|`hf epa cnonces `|N |`Acquire encrypted PACE nonces of specific size`
|
||||
|`hf epa preplay `|N |`Perform PACE protocol by replaying given APDUs`
|
||||
|
||||
|
||||
### hf emrtd
|
||||
|
||||
{ Machine Readable Travel Document... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|`hf emrtd help `|Y |`This help`
|
||||
|`hf emrtd dump `|N |`Dump eMRTD files to binary files`
|
||||
|`hf emrtd info `|Y |`Display info about an eMRTD`
|
||||
|`hf emrtd list `|Y |`List ISO 14443A/7816 history`
|
||||
|
||||
|
||||
### hf felica
|
||||
|
||||
{ ISO18092 / FeliCa RFIDs... }
|
||||
{ ISO18092 / FeliCa RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -229,7 +241,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf fido
|
||||
|
||||
{ FIDO and FIDO2 authenticators... }
|
||||
{ FIDO and FIDO2 authenticators... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -244,7 +256,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf iclass
|
||||
|
||||
{ ICLASS RFIDs... }
|
||||
{ ICLASS RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -275,7 +287,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf legic
|
||||
|
||||
{ LEGIC RFIDs... }
|
||||
{ LEGIC RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -296,7 +308,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf lto
|
||||
|
||||
{ LTO Cartridge Memory RFIDs... }
|
||||
{ LTO Cartridge Memory RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -311,7 +323,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf mf
|
||||
|
||||
{ MIFARE RFIDs... }
|
||||
{ MIFARE RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -363,7 +375,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf mfp
|
||||
|
||||
{ MIFARE Plus RFIDs... }
|
||||
{ MIFARE Plus RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -383,7 +395,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf mfu
|
||||
|
||||
{ MIFARE Ultralight RFIDs... }
|
||||
{ MIFARE Ultralight RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -406,7 +418,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf mfdes
|
||||
|
||||
{ MIFARE Desfire RFIDs... }
|
||||
{ MIFARE Desfire RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -436,7 +448,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf st
|
||||
|
||||
{ ST Rothult RFIDs... }
|
||||
{ ST Rothult RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -451,7 +463,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf thinfilm
|
||||
|
||||
{ Thinfilm RFIDs... }
|
||||
{ Thinfilm RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -463,7 +475,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf topaz
|
||||
|
||||
{ TOPAZ (NFC Type 1) RFIDs... }
|
||||
{ TOPAZ (NFC Type 1) RFIDs... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
@ -478,7 +490,7 @@ Check column "offline" for their availability.
|
|||
|
||||
### hf waveshare
|
||||
|
||||
{ Waveshare NFC ePaper... }
|
||||
{ Waveshare NFC ePaper... }
|
||||
|
||||
|command |offline |description
|
||||
|------- |------- |-----------
|
||||
|
|
Loading…
Reference in a new issue