mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
smart commands - most use cliparser, moved sim fw file to RESOURCES
This commit is contained in:
parent
e96cfa94b6
commit
0983ad806f
3 changed files with 97 additions and 133 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
#include "crc16.h" // crc
|
#include "crc16.h" // crc
|
||||||
|
#include "cliparser.h" // cliparsing
|
||||||
|
|
||||||
static int CmdHelp(const char *Cmd);
|
static int CmdHelp(const char *Cmd);
|
||||||
|
|
||||||
|
@ -42,43 +43,7 @@ static int usage_sm_raw(void) {
|
||||||
PrintAndLogEx(NORMAL, " smart raw 0 t d 00a4040007a0000000031010 - Visa");
|
PrintAndLogEx(NORMAL, " smart raw 0 t d 00a4040007a0000000031010 - Visa");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
static int usage_sm_reader(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: smart reader [h|s]");
|
|
||||||
PrintAndLogEx(NORMAL, " h : this help");
|
|
||||||
PrintAndLogEx(NORMAL, " s : silent (no messages)");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, " smart reader");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
static int usage_sm_info(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: smart info [h|s]");
|
|
||||||
PrintAndLogEx(NORMAL, " h : this help");
|
|
||||||
PrintAndLogEx(NORMAL, " s : silent (no messages)");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, " smart info");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
static int usage_sm_upgrade(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Upgrade RDV4.0 Sim module firmware");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: smart upgrade f <file name>");
|
|
||||||
PrintAndLogEx(NORMAL, " h : this help");
|
|
||||||
PrintAndLogEx(NORMAL, " f <filename> : firmware file name");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, " smart upgrade f ../tools/simmodule/sim011.bin");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
static int usage_sm_setclock(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: smart setclock [h] c <clockspeed>");
|
|
||||||
PrintAndLogEx(NORMAL, " h : this help");
|
|
||||||
PrintAndLogEx(NORMAL, " c <> : clockspeed (0 = 16MHz, 1=8MHz, 2=4MHz) ");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, " smart setclock c 2");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
static int usage_sm_brute(void) {
|
static int usage_sm_brute(void) {
|
||||||
PrintAndLogEx(NORMAL, "Tries to bruteforce SFI, using a known list of AID's ");
|
PrintAndLogEx(NORMAL, "Tries to bruteforce SFI, using a known list of AID's ");
|
||||||
PrintAndLogEx(NORMAL, "Usage: smart brute [h]");
|
PrintAndLogEx(NORMAL, "Usage: smart brute [h]");
|
||||||
|
@ -524,36 +489,29 @@ static int CmdSmartRaw(const char *Cmd) {
|
||||||
|
|
||||||
static int CmdSmartUpgrade(const char *Cmd) {
|
static int CmdSmartUpgrade(const char *Cmd) {
|
||||||
|
|
||||||
PrintAndLogEx(WARNING, "WARNING - Sim module firmware upgrade.");
|
|
||||||
PrintAndLogEx(WARNING, "A dangerous command, do wrong and you could brick the sim module");
|
PrintAndLogEx(INFO, "-------------------------------------------------------------------");
|
||||||
|
PrintAndLogEx(WARNING, _RED_("WARNING") " - sim module firmware upgrade");
|
||||||
|
PrintAndLogEx(WARNING, _RED_("A dangerous command, do wrong and you could brick the sim module"));
|
||||||
|
PrintAndLogEx(INFO, "-------------------------------------------------------------------");
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
|
||||||
|
CLIParserContext *ctx;
|
||||||
|
CLIParserInit(&ctx, "smart upgrade",
|
||||||
|
"Upgrade RDV4.0 sim module firmware",
|
||||||
|
"smart upgrade -f sim011.bin"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_str1("f", "file", "<filename>", "firmware file name"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
int fnlen = 0;
|
||||||
char filename[FILE_PATH_SIZE] = {0};
|
char filename[FILE_PATH_SIZE] = {0};
|
||||||
uint8_t cmdp = 0;
|
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, sizeof(filename), &fnlen);
|
||||||
bool errors = false;
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
|
||||||
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 'h':
|
|
||||||
return usage_sm_upgrade();
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Validations
|
|
||||||
if (errors || cmdp == 0) return usage_sm_upgrade();
|
|
||||||
|
|
||||||
|
|
||||||
char *bin_extension = filename;
|
char *bin_extension = filename;
|
||||||
char *dot_position = NULL;
|
char *dot_position = NULL;
|
||||||
|
@ -623,7 +581,8 @@ static int CmdSmartUpgrade(const char *Cmd) {
|
||||||
}
|
}
|
||||||
free(hashstring);
|
free(hashstring);
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "Sim module firmware uploading to PM3");
|
PrintAndLogEx(INFO, _GREEN_("Don\'t turn off your PM3!"));
|
||||||
|
PrintAndLogEx(SUCCESS, "Sim module firmware uploading to PM3...");
|
||||||
|
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
|
|
||||||
|
@ -669,7 +628,7 @@ static int CmdSmartUpgrade(const char *Cmd) {
|
||||||
PrintAndLogEx(INPLACE, "%d bytes sent", bytes_sent);
|
PrintAndLogEx(INPLACE, "%d bytes sent", bytes_sent);
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(SUCCESS, "Sim module firmware updating, don\'t turn off your PM3!");
|
PrintAndLogEx(SUCCESS, "Sim module firmware updating...");
|
||||||
|
|
||||||
// trigger the firmware upgrade
|
// trigger the firmware upgrade
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
|
@ -700,37 +659,35 @@ static int CmdSmartUpgrade(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdSmartInfo(const char *Cmd) {
|
static int CmdSmartInfo(const char *Cmd) {
|
||||||
uint8_t cmdp = 0;
|
CLIParserContext *ctx;
|
||||||
bool errors = false, silent = false;
|
CLIParserInit(&ctx, "smart info",
|
||||||
|
"Extract more detailed information from smart card.",
|
||||||
|
"smart info -v"
|
||||||
|
);
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
void *argtable[] = {
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
arg_param_begin,
|
||||||
case 'h':
|
arg_lit0("v", "verbose", "verbose"),
|
||||||
return usage_sm_info();
|
arg_param_end
|
||||||
case 's':
|
};
|
||||||
silent = true;
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
break;
|
bool verbose = arg_get_lit(ctx, 1);
|
||||||
default:
|
CLIParserFree(ctx);
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cmdp++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Validations
|
|
||||||
if (errors) return usage_sm_info();
|
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_SMART_ATR, NULL, 0);
|
SendCommandNG(CMD_SMART_ATR, NULL, 0);
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_SMART_ATR, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_SMART_ATR, &resp, 2500)) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
if (verbose) {
|
||||||
|
PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
|
}
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.status != PM3_SUCCESS) {
|
if (resp.status != PM3_SUCCESS) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
if (verbose) {
|
||||||
|
PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
|
}
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -772,37 +729,36 @@ static int CmdSmartInfo(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdSmartReader(const char *Cmd) {
|
static int CmdSmartReader(const char *Cmd) {
|
||||||
uint8_t cmdp = 0;
|
|
||||||
bool errors = false, silent = false;
|
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
CLIParserContext *ctx;
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
CLIParserInit(&ctx, "smart reader",
|
||||||
case 'h':
|
"Act as a smart card reader.",
|
||||||
return usage_sm_reader();
|
"smart reader"
|
||||||
case 's':
|
);
|
||||||
silent = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cmdp++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Validations
|
void *argtable[] = {
|
||||||
if (errors) return usage_sm_reader();
|
arg_param_begin,
|
||||||
|
arg_lit0("v", "verbose", "verbose"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
bool verbose = arg_get_lit(ctx, 1);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_SMART_ATR, NULL, 0);
|
SendCommandNG(CMD_SMART_ATR, NULL, 0);
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_SMART_ATR, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_SMART_ATR, &resp, 2500)) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
if (verbose) {
|
||||||
|
PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
|
}
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.status != PM3_SUCCESS) {
|
if (resp.status != PM3_SUCCESS) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
if (verbose) {
|
||||||
|
PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
|
}
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
smart_card_atr_t card;
|
smart_card_atr_t card;
|
||||||
|
@ -813,34 +769,42 @@ static int CmdSmartReader(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdSmartSetClock(const char *Cmd) {
|
static int CmdSmartSetClock(const char *Cmd) {
|
||||||
uint8_t cmdp = 0;
|
|
||||||
bool errors = false;
|
|
||||||
uint8_t new_clk = 0;
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
|
||||||
case 'h':
|
|
||||||
return usage_sm_setclock();
|
|
||||||
case 'c':
|
|
||||||
new_clk = param_get8ex(Cmd, cmdp + 1, 2, 10);
|
|
||||||
if (new_clk > 2)
|
|
||||||
errors = true;
|
|
||||||
|
|
||||||
cmdp += 2;
|
CLIParserContext *ctx;
|
||||||
break;
|
CLIParserInit(&ctx, "smart setclock",
|
||||||
default:
|
"Set clock speed for smart card interface.",
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
"smart setclock --4mhz\n"
|
||||||
errors = true;
|
"smart setclock --16mhz"
|
||||||
break;
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Validations
|
void *argtable[] = {
|
||||||
if (errors || cmdp == 0) return usage_sm_setclock();
|
arg_param_begin,
|
||||||
|
arg_lit0(NULL, "16mhz", "16 MHz clock speed"),
|
||||||
|
arg_lit0(NULL, "8mhz", "8 MHz clock speed"),
|
||||||
|
arg_lit0(NULL, "4mhz", "4 MHz clock speed"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||||
|
bool c16 = arg_get_lit(ctx, 1);
|
||||||
|
bool c8 = arg_get_lit(ctx, 2);
|
||||||
|
bool c4 = arg_get_lit(ctx, 3);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
|
if ((c16 + c8 + c4) > 1 ) {
|
||||||
|
PrintAndLogEx(WARNING, "Only one clock speed can be used at a time");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint32_t new_clk;
|
uint32_t new_clk;
|
||||||
} PACKED payload;
|
} PACKED payload;
|
||||||
payload.new_clk = new_clk;
|
|
||||||
|
if (c16)
|
||||||
|
payload.new_clk = 0;
|
||||||
|
else if (c8)
|
||||||
|
payload.new_clk = 1;
|
||||||
|
else if (c4)
|
||||||
|
payload.new_clk = 2;
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_SMART_SETCLOCK, (uint8_t *)&payload, sizeof(payload));
|
SendCommandNG(CMD_SMART_SETCLOCK, (uint8_t *)&payload, sizeof(payload));
|
||||||
|
@ -855,15 +819,15 @@ static int CmdSmartSetClock(const char *Cmd) {
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (new_clk) {
|
switch (payload.new_clk) {
|
||||||
case 0:
|
case 0:
|
||||||
PrintAndLogEx(SUCCESS, "Clock changed to 16MHz giving 10800 baudrate");
|
PrintAndLogEx(SUCCESS, "Clock changed to " _GREEN_("16") " MHz giving " _GREEN_("10800") " baudrate");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
PrintAndLogEx(SUCCESS, "Clock changed to 8MHz giving 21600 baudrate");
|
PrintAndLogEx(SUCCESS, "Clock changed to " _GREEN_("8") " MHz giving " _GREEN_("21600") " baudrate");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
PrintAndLogEx(SUCCESS, "Clock changed to 4MHz giving 86400 baudrate");
|
PrintAndLogEx(SUCCESS, "Clock changed to " _GREEN_("4") " MHz giving " _GREEN_("86400") " baudrate");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue