mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-15 19:17:26 -07:00
remove spurious spaces & tabs at end of lines
This commit is contained in:
parent
edc19f202a
commit
60f292b18e
249 changed files with 8481 additions and 8481 deletions
|
@ -36,7 +36,7 @@ int usage_sm_reader(void) {
|
|||
PrintAndLogEx(NORMAL, " s : silent (no messages)");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, " sc reader");
|
||||
PrintAndLogEx(NORMAL, " sc reader");
|
||||
return 0;
|
||||
}
|
||||
int usage_sm_info(void) {
|
||||
|
@ -45,7 +45,7 @@ int usage_sm_info(void) {
|
|||
PrintAndLogEx(NORMAL, " s : silent (no messages)");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, " sc info");
|
||||
PrintAndLogEx(NORMAL, " sc info");
|
||||
return 0;
|
||||
}
|
||||
int usage_sm_upgrade(void) {
|
||||
|
@ -64,7 +64,7 @@ int usage_sm_setclock(void) {
|
|||
PrintAndLogEx(NORMAL, " c <> : clockspeed (0 = 16mhz, 1=8mhz, 2=4mhz) ");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, " sc setclock c 2");
|
||||
PrintAndLogEx(NORMAL, " sc setclock c 2");
|
||||
return 0;
|
||||
}
|
||||
int usage_sm_brute(void) {
|
||||
|
@ -93,29 +93,29 @@ static int smart_loadjson(const char *preferredName, const char *suffix, json_t
|
|||
*root = json_load_file(fileName, 0, &error);
|
||||
if (!*root) {
|
||||
PrintAndLogEx(ERR, "json (%s) error on line %d: %s", fileName, error.line, error.text);
|
||||
retval = 2;
|
||||
retval = 2;
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
if (!json_is_array(*root)) {
|
||||
PrintAndLogEx(ERR, "Invalid json (%s) format. root must be an array.", fileName);
|
||||
retval = 3;
|
||||
retval = 3;
|
||||
goto out;
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Loaded file (%s) OK.", fileName);
|
||||
out:
|
||||
out:
|
||||
free(fileName);
|
||||
return retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
uint8_t GetATRTA1(uint8_t *atr, size_t atrlen) {
|
||||
if (atrlen > 2) {
|
||||
if (atrlen > 2) {
|
||||
uint8_t T0 = atr[1];
|
||||
if (T0 & 0x10)
|
||||
return atr[2];
|
||||
}
|
||||
|
||||
|
||||
return 0x11; // default value is ‘0x11’, corresponding to fmax=5 MHz, Fi=372, Di=1.
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ float FArray[] = {
|
|||
|
||||
int GetATRDi(uint8_t *atr, size_t atrlen) {
|
||||
uint8_t TA1 = GetATRTA1(atr, atrlen);
|
||||
return DiArray[TA1 & 0x0F]; // The 4 low-order bits of TA1 (4th MSbit to 1st LSbit) encode Di
|
||||
return DiArray[TA1 & 0x0F]; // The 4 low-order bits of TA1 (4th MSbit to 1st LSbit) encode Di
|
||||
}
|
||||
|
||||
int GetATRFi(uint8_t *atr, size_t atrlen) {
|
||||
|
@ -192,31 +192,31 @@ float GetATRF(uint8_t *atr, size_t atrlen) {
|
|||
}
|
||||
|
||||
static int PrintATR(uint8_t *atr, size_t atrlen) {
|
||||
|
||||
|
||||
uint8_t T0 = atr[1];
|
||||
uint8_t K = T0 & 0x0F;
|
||||
uint8_t TD1 = 0, T1len = 0, TD1len = 0, TDilen = 0;
|
||||
|
||||
|
||||
if (T0 & 0x10) {
|
||||
PrintAndLog("\t- TA1 (Maximum clock frequency, proposed bit duration) [ 0x%02x ]", atr[2 + T1len]);
|
||||
T1len++;
|
||||
}
|
||||
|
||||
|
||||
if (T0 & 0x20) {
|
||||
PrintAndLog("\t- TB1 (Deprecated: VPP requirements) [ 0x%02x ]", atr[2 + T1len]);
|
||||
T1len++;
|
||||
}
|
||||
|
||||
|
||||
if (T0 & 0x40) {
|
||||
PrintAndLog("\t- TC1 (Extra delay between bytes required by card) [ 0x%02x ]", atr[2 + T1len]);
|
||||
T1len++;
|
||||
}
|
||||
|
||||
|
||||
if (T0 & 0x80) {
|
||||
TD1 = atr[2 + T1len];
|
||||
PrintAndLog("\t- TD1 (First offered transmission protocol, presence of TA2..TD2) [ 0x%02x ] Protocol T%d", TD1, TD1 & 0x0f);
|
||||
T1len++;
|
||||
|
||||
|
||||
if (TD1 & 0x10) {
|
||||
PrintAndLog("\t- TA2 (Specific protocol and parameters to be used after the ATR) [ 0x%02x ]", atr[2 + T1len + TD1len]);
|
||||
TD1len++;
|
||||
|
@ -254,7 +254,7 @@ static int PrintATR(uint8_t *atr, size_t atrlen) {
|
|||
TDi = atr[2 + T1len + TD1len + TDilen];
|
||||
PrintAndLog("\t- TD%d [ 0x%02x ] Protocol T%d", vi, TDi, TDi & 0x0f);
|
||||
TDilen++;
|
||||
|
||||
|
||||
nextCycle = true;
|
||||
vi++;
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ static int PrintATR(uint8_t *atr, size_t atrlen) {
|
|||
uint8_t vxor = 0;
|
||||
for (int i = 1; i < atrlen; i++)
|
||||
vxor ^= atr[i];
|
||||
|
||||
|
||||
if (vxor)
|
||||
PrintAndLogEx(WARNING, "Check summ error. Must be 0 got 0x%02X", vxor);
|
||||
else
|
||||
|
@ -274,26 +274,26 @@ static int PrintATR(uint8_t *atr, size_t atrlen) {
|
|||
if (atr[0] != 0x3b)
|
||||
PrintAndLogEx(WARNING, "Not a direct convention [ 0x%02x ]", atr[0]);
|
||||
|
||||
|
||||
|
||||
uint8_t calen = 2 + T1len + TD1len + TDilen + K;
|
||||
|
||||
|
||||
if (atrlen != calen && atrlen != calen + 1) // may be CRC
|
||||
PrintAndLogEx(ERR, "ATR length error. len: %d, T1len: %d, TD1len: %d, TDilen: %d, K: %d", atrlen, T1len, TD1len, TDilen, K);
|
||||
|
||||
|
||||
if (K > 0)
|
||||
PrintAndLogEx(INFO, "\nHistorical bytes | len 0x%02d | format %02x", K, atr[2 + T1len + TD1len + TDilen]);
|
||||
|
||||
|
||||
if (K > 1) {
|
||||
PrintAndLogEx(INFO, "\tHistorical bytes");
|
||||
dump_buffer(&atr[2 + T1len + TD1len + TDilen], K, NULL, 1);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool smart_select(bool silent, smart_card_atr_t *atr) {
|
||||
if (atr)
|
||||
memset(atr, 0, sizeof(smart_card_atr_t));
|
||||
memset(atr, 0, sizeof(smart_card_atr_t));
|
||||
|
||||
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
|
@ -303,21 +303,21 @@ bool smart_select(bool silent, smart_card_atr_t *atr) {
|
|||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint8_t isok = resp.arg[0] & 0xFF;
|
||||
if (!isok) {
|
||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
smart_card_atr_t card;
|
||||
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
|
||||
|
||||
if (atr)
|
||||
memcpy(atr, &card, sizeof(smart_card_atr_t));
|
||||
memcpy(atr, &card, sizeof(smart_card_atr_t));
|
||||
|
||||
if (!silent)
|
||||
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
|
||||
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -328,27 +328,27 @@ static int smart_wait(uint8_t *data, bool silent) {
|
|||
if (!silent) PrintAndLogEx(WARNING, "smart card response timeout");
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t len = resp.arg[0];
|
||||
|
||||
uint32_t len = resp.arg[0];
|
||||
if ( !len ) {
|
||||
if (!silent) PrintAndLogEx(WARNING, "smart card response failed");
|
||||
return -2;
|
||||
return -2;
|
||||
}
|
||||
memcpy(data, resp.d.asBytes, len);
|
||||
if (len >= 2) {
|
||||
if (!silent) PrintAndLogEx(SUCCESS, "%02X%02X | %s", data[len - 2], data[len - 1], GetAPDUCodeDescription(data[len - 2], data[len - 1]));
|
||||
memcpy(data, resp.d.asBytes, len);
|
||||
if (len >= 2) {
|
||||
if (!silent) PrintAndLogEx(SUCCESS, "%02X%02X | %s", data[len - 2], data[len - 1], GetAPDUCodeDescription(data[len - 2], data[len - 1]));
|
||||
} else {
|
||||
if (!silent) PrintAndLogEx(SUCCESS, " %d | %s", len, sprint_hex_inrow_ex(data, len, 8));
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int smart_responseEx(uint8_t *data, bool silent) {
|
||||
|
||||
int datalen = smart_wait(data, silent);
|
||||
|
||||
int datalen = smart_wait(data, silent);
|
||||
bool needGetData = false;
|
||||
|
||||
|
||||
if (datalen < 2 ) {
|
||||
goto out;
|
||||
}
|
||||
|
@ -359,9 +359,9 @@ static int smart_responseEx(uint8_t *data, bool silent) {
|
|||
|
||||
if (needGetData) {
|
||||
int len = data[datalen - 1];
|
||||
if (!silent) PrintAndLogEx(INFO, "Requesting 0x%02X bytes response", len);
|
||||
if (!silent) PrintAndLogEx(INFO, "Requesting 0x%02X bytes response", len);
|
||||
uint8_t getstatus[] = {0x00, ISO7816_GET_RESPONSE, 0x00, 0x00, len};
|
||||
UsbCommand cStatus = {CMD_SMART_RAW, {SC_RAW, sizeof(getstatus), 0}};
|
||||
UsbCommand cStatus = {CMD_SMART_RAW, {SC_RAW, sizeof(getstatus), 0}};
|
||||
memcpy(cStatus.d.asBytes, getstatus, sizeof(getstatus) );
|
||||
clearCommandBuffer();
|
||||
SendCommand(&cStatus);
|
||||
|
@ -371,14 +371,14 @@ static int smart_responseEx(uint8_t *data, bool silent) {
|
|||
if (datalen < 2 ) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
// data wo ACK
|
||||
if (datalen != len + 2) {
|
||||
if (datalen != len + 2) {
|
||||
// data with ACK
|
||||
if (datalen == len + 2 + 1) { // 2 - response, 1 - ACK
|
||||
if (data[0] != ISO7816_GET_RESPONSE) {
|
||||
if (!silent) {
|
||||
PrintAndLogEx(ERR, "GetResponse ACK error. len 0x%x | data[0] %02X", len, data[0]);
|
||||
PrintAndLogEx(ERR, "GetResponse ACK error. len 0x%x | data[0] %02X", len, data[0]);
|
||||
}
|
||||
datalen = 0;
|
||||
goto out;
|
||||
|
@ -389,12 +389,12 @@ static int smart_responseEx(uint8_t *data, bool silent) {
|
|||
} else {
|
||||
// wrong length
|
||||
if (!silent) {
|
||||
PrintAndLogEx(WARNING, "GetResponse wrong length. Must be 0x%02X got 0x%02X", len, datalen - 3);
|
||||
PrintAndLogEx(WARNING, "GetResponse wrong length. Must be 0x%02X got 0x%02X", len, datalen - 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
out:
|
||||
return datalen;
|
||||
}
|
||||
|
@ -407,15 +407,15 @@ int CmdSmartRaw(const char *Cmd) {
|
|||
|
||||
int hexlen = 0;
|
||||
bool active = false;
|
||||
bool active_select = false;
|
||||
bool useT0 = false;
|
||||
bool active_select = false;
|
||||
bool useT0 = false;
|
||||
uint8_t cmdp = 0;
|
||||
bool errors = false, reply = true, decodeTLV = false, breakloop = false;
|
||||
uint8_t data[USB_CMD_DATA_SIZE] = {0x00};
|
||||
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h': return usage_sm_raw();
|
||||
case 'h': return usage_sm_raw();
|
||||
case 'r':
|
||||
reply = false;
|
||||
cmdp++;
|
||||
|
@ -431,11 +431,11 @@ int CmdSmartRaw(const char *Cmd) {
|
|||
case 't':
|
||||
decodeTLV = true;
|
||||
cmdp++;
|
||||
break;
|
||||
break;
|
||||
case '0':
|
||||
useT0 = true;
|
||||
cmdp++;
|
||||
break;
|
||||
break;
|
||||
case 'd': {
|
||||
switch (param_gethex_to_eol(Cmd, cmdp+1, data, sizeof(data), &hexlen)) {
|
||||
case 1:
|
||||
|
@ -461,14 +461,14 @@ int CmdSmartRaw(const char *Cmd) {
|
|||
if ( breakloop )
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//Validations
|
||||
if (errors || cmdp == 0 ) return usage_sm_raw();
|
||||
if (errors || cmdp == 0 ) return usage_sm_raw();
|
||||
|
||||
// arg0 = RFU flags
|
||||
// arg1 = length
|
||||
UsbCommand c = {CMD_SMART_RAW, {0, hexlen, 0}};
|
||||
|
||||
UsbCommand c = {CMD_SMART_RAW, {0, hexlen, 0}};
|
||||
|
||||
if (active || active_select) {
|
||||
c.arg[0] |= SC_CONNECT;
|
||||
if (active_select)
|
||||
|
@ -480,28 +480,28 @@ int CmdSmartRaw(const char *Cmd) {
|
|||
c.arg[0] |= SC_RAW_T0;
|
||||
else
|
||||
c.arg[0] |= SC_RAW;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
memcpy(c.d.asBytes, data, hexlen );
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
SendCommand(&c);
|
||||
|
||||
// reading response from smart card
|
||||
if ( reply ) {
|
||||
|
||||
uint8_t* buf = calloc(USB_CMD_DATA_SIZE, sizeof(uint8_t));
|
||||
if ( !buf )
|
||||
return 1;
|
||||
|
||||
return 1;
|
||||
|
||||
int len = smart_response(buf);
|
||||
if ( len < 0 ) {
|
||||
free(buf);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
if ( buf[0] == 0x6C ) {
|
||||
data[4] = buf[1];
|
||||
|
||||
|
||||
memcpy(c.d.asBytes, data, sizeof(data) );
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
@ -520,54 +520,54 @@ int CmdSmartRaw(const char *Cmd) {
|
|||
|
||||
int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) {
|
||||
*dataoutlen = 0;
|
||||
|
||||
|
||||
if (activateCard)
|
||||
smart_select(false, NULL);
|
||||
|
||||
PrintAndLogEx(DEBUG, "APDU SC");
|
||||
|
||||
UsbCommand c = {CMD_SMART_RAW, {SC_RAW_T0, datainlen, 0}};
|
||||
UsbCommand c = {CMD_SMART_RAW, {SC_RAW_T0, datainlen, 0}};
|
||||
if (activateCard) {
|
||||
c.arg[0] |= SC_SELECT | SC_CONNECT;
|
||||
}
|
||||
memcpy(c.d.asBytes, datain, datainlen);
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
SendCommand(&c);
|
||||
|
||||
int len = smart_responseEx(dataout, true);
|
||||
|
||||
|
||||
if ( len < 0 ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// retry
|
||||
if (len > 1 && dataout[len - 2] == 0x6c && datainlen > 4) {
|
||||
UsbCommand c2 = {CMD_SMART_RAW, {SC_RAW_T0, datainlen, 0}};
|
||||
UsbCommand c2 = {CMD_SMART_RAW, {SC_RAW_T0, datainlen, 0}};
|
||||
memcpy(c2.d.asBytes, datain, 5);
|
||||
|
||||
|
||||
// transfer length via T=0
|
||||
c2.d.asBytes[4] = dataout[len - 1];
|
||||
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c2);
|
||||
|
||||
SendCommand(&c2);
|
||||
|
||||
len = smart_responseEx(dataout, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*dataoutlen = len;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int CmdSmartUpgrade(const char *Cmd) {
|
||||
|
||||
PrintAndLogEx(WARNING, "WARNING - Smartcard socket firmware upgrade.");
|
||||
PrintAndLogEx(WARNING, "A dangerous command, do wrong and you will brick the smart card socket");
|
||||
|
||||
|
||||
FILE *f;
|
||||
char filename[FILE_PATH_SIZE] = {0};
|
||||
uint8_t cmdp = 0;
|
||||
bool errors = false;
|
||||
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'f':
|
||||
|
@ -576,8 +576,8 @@ int CmdSmartUpgrade(const char *Cmd) {
|
|||
PrintAndLogEx(FAILED, "Filename too long");
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
cmdp += 2;
|
||||
}
|
||||
cmdp += 2;
|
||||
break;
|
||||
case 'h':
|
||||
return usage_sm_upgrade();
|
||||
|
@ -587,17 +587,17 @@ int CmdSmartUpgrade(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Validations
|
||||
if (errors || cmdp == 0 ) return usage_sm_upgrade();
|
||||
|
||||
if (errors || cmdp == 0 ) return usage_sm_upgrade();
|
||||
|
||||
// load file
|
||||
f = fopen(filename, "rb");
|
||||
if ( !f ){
|
||||
PrintAndLogEx(FAILED, "File: " _YELLOW_(%s) ": not found or locked.", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// get filesize in order to malloc memory
|
||||
fseek(f, 0, SEEK_END);
|
||||
long fsize = ftell(f);
|
||||
|
@ -608,18 +608,18 @@ int CmdSmartUpgrade(const char *Cmd) {
|
|||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
||||
if (!dump) {
|
||||
PrintAndLogDevice(WARNING, "error, cannot allocate memory ");
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
size_t bytes_read = fread(dump, 1, fsize, f);
|
||||
if (f)
|
||||
fclose(f);
|
||||
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Smartcard socket firmware uploading to PM3");
|
||||
//Send to device
|
||||
uint32_t index = 0;
|
||||
|
@ -627,20 +627,20 @@ int CmdSmartUpgrade(const char *Cmd) {
|
|||
uint32_t bytes_remaining = bytes_read;
|
||||
|
||||
while (bytes_remaining > 0){
|
||||
uint32_t bytes_in_packet = MIN(USB_CMD_DATA_SIZE, bytes_remaining);
|
||||
uint32_t bytes_in_packet = MIN(USB_CMD_DATA_SIZE, bytes_remaining);
|
||||
UsbCommand c = {CMD_SMART_UPLOAD, {index + bytes_sent, bytes_in_packet, 0}};
|
||||
|
||||
// Fill usb bytes with 0xFF
|
||||
memset(c.d.asBytes, 0xFF, USB_CMD_DATA_SIZE);
|
||||
memcpy(c.d.asBytes, dump + bytes_sent, bytes_in_packet);
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
SendCommand(&c);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2000) ) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
free(dump);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
bytes_remaining -= bytes_in_packet;
|
||||
bytes_sent += bytes_in_packet;
|
||||
printf("."); fflush(stdout);
|
||||
|
@ -648,9 +648,9 @@ int CmdSmartUpgrade(const char *Cmd) {
|
|||
free(dump);
|
||||
printf("\n");
|
||||
PrintAndLogEx(SUCCESS, "Smartcard socket firmware updating, don\'t turn off your PM3!");
|
||||
|
||||
|
||||
// trigger the firmware upgrade
|
||||
UsbCommand c = {CMD_SMART_UPGRADE, {bytes_read, 0, 0}};
|
||||
UsbCommand c = {CMD_SMART_UPGRADE, {bytes_read, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
UsbCommand resp;
|
||||
|
@ -668,13 +668,13 @@ int CmdSmartUpgrade(const char *Cmd) {
|
|||
int CmdSmartInfo(const char *Cmd){
|
||||
uint8_t cmdp = 0;
|
||||
bool errors = false, silent = false;
|
||||
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h': return usage_sm_info();
|
||||
case 's':
|
||||
case 's':
|
||||
silent = true;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
|
@ -682,10 +682,10 @@ int CmdSmartInfo(const char *Cmd){
|
|||
}
|
||||
cmdp++;
|
||||
}
|
||||
|
||||
|
||||
//Validations
|
||||
if (errors ) return usage_sm_info();
|
||||
|
||||
|
||||
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
@ -694,16 +694,16 @@ int CmdSmartInfo(const char *Cmd){
|
|||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t isok = resp.arg[0] & 0xFF;
|
||||
if (!isok) {
|
||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
smart_card_atr_t card;
|
||||
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
|
||||
|
||||
|
||||
// print header
|
||||
PrintAndLogEx(INFO, "--- Smartcard Information ---------");
|
||||
PrintAndLogEx(INFO, "-------------------------------------------------------------");
|
||||
|
@ -714,7 +714,7 @@ int CmdSmartInfo(const char *Cmd){
|
|||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "ATR");
|
||||
PrintATR(card.atr, card.atr_len);
|
||||
|
||||
|
||||
// print D/F (brom byte TA1 or defaults)
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "D/F (TA1)");
|
||||
|
@ -723,11 +723,11 @@ int CmdSmartInfo(const char *Cmd){
|
|||
float F = GetATRF(card.atr, card.atr_len);
|
||||
if (GetATRTA1(card.atr, card.atr_len) == 0x11)
|
||||
PrintAndLogEx(INFO, "Using default values...");
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "\t- Di %d", Di);
|
||||
PrintAndLogEx(NORMAL, "\t- Fi %d", Fi);
|
||||
PrintAndLogEx(NORMAL, "\t- F %.1f MHz", F);
|
||||
|
||||
|
||||
if (Di && Fi) {
|
||||
PrintAndLogEx(NORMAL, "\t- Cycles/ETU %d", Fi/Di);
|
||||
PrintAndLogEx(NORMAL, "\t- %.1f bits/sec at 4MHz", (float)4000000 / (Fi/Di));
|
||||
|
@ -742,24 +742,24 @@ int CmdSmartInfo(const char *Cmd){
|
|||
int CmdSmartReader(const char *Cmd){
|
||||
uint8_t cmdp = 0;
|
||||
bool errors = false, silent = false;
|
||||
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h': return usage_sm_reader();
|
||||
case 's':
|
||||
case 's':
|
||||
silent = true;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
cmdp++;
|
||||
cmdp++;
|
||||
}
|
||||
|
||||
|
||||
//Validations
|
||||
if (errors ) return usage_sm_reader();
|
||||
|
||||
|
||||
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
@ -768,16 +768,16 @@ int CmdSmartReader(const char *Cmd){
|
|||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t isok = resp.arg[0] & 0xFF;
|
||||
if (!isok) {
|
||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
smart_card_atr_t card;
|
||||
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
|
||||
|
||||
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
|
||||
|
||||
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -788,23 +788,23 @@ int CmdSmartSetClock(const char *Cmd){
|
|||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h': return usage_sm_setclock();
|
||||
case 'c':
|
||||
case 'c':
|
||||
clock = param_get8ex(Cmd, cmdp+1, 2, 10);
|
||||
if ( clock > 2)
|
||||
errors = true;
|
||||
|
||||
|
||||
cmdp += 2;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Validations
|
||||
if (errors || cmdp == 0) return usage_sm_setclock();
|
||||
|
||||
|
||||
UsbCommand c = {CMD_SMART_SETCLOCK, {clock, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
@ -813,15 +813,15 @@ int CmdSmartSetClock(const char *Cmd){
|
|||
PrintAndLogEx(WARNING, "smart card select failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t isok = resp.arg[0] & 0xFF;
|
||||
if (!isok) {
|
||||
PrintAndLogEx(WARNING, "smart card set clock failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
switch (clock) {
|
||||
case 0:
|
||||
case 0:
|
||||
PrintAndLogEx(SUCCESS, "Clock changed to 16mhz giving 10800 baudrate");
|
||||
break;
|
||||
case 1:
|
||||
|
@ -844,36 +844,36 @@ int CmdSmartList(const char *Cmd) {
|
|||
static void smart_brute_prim(){
|
||||
|
||||
uint8_t* buf = calloc(USB_CMD_DATA_SIZE, sizeof(uint8_t));
|
||||
if ( !buf )
|
||||
if ( !buf )
|
||||
return;
|
||||
|
||||
|
||||
int len = 0;
|
||||
uint8_t get_card_data[] = {
|
||||
uint8_t get_card_data[] = {
|
||||
0x80, 0xCA, 0x9F, 0x13, 0x00,
|
||||
0x80, 0xCA, 0x9F, 0x17, 0x00,
|
||||
0x80, 0xCA, 0x9F, 0x36, 0x00,
|
||||
0x80, 0xCA, 0x9F, 0x4f, 0x00
|
||||
};
|
||||
|
||||
UsbCommand c = {CMD_SMART_RAW, {SC_RAW_T0, 5, 0}};
|
||||
|
||||
|
||||
UsbCommand c = {CMD_SMART_RAW, {SC_RAW_T0, 5, 0}};
|
||||
|
||||
PrintAndLogEx(INFO, "Reading primitives");
|
||||
|
||||
for (int i = 0; i < sizeof(get_card_data); i += 5) {
|
||||
|
||||
|
||||
memcpy(c.d.asBytes, get_card_data+i, 5 );
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
|
||||
len = smart_responseEx(buf, true);
|
||||
|
||||
if ( len > 2 ) {
|
||||
|
||||
|
||||
//if ( decodeTLV ) {
|
||||
//if (!TLVPrintFromBuffer(buf, len-2)) {
|
||||
PrintAndLogEx(SUCCESS, "\tHEX %d |: %s", len, sprint_hex(buf, len));
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
}
|
||||
len = 0;
|
||||
}
|
||||
|
@ -883,20 +883,20 @@ static void smart_brute_prim(){
|
|||
static int smart_brute_sfi(bool decodeTLV){
|
||||
|
||||
uint8_t* buf = calloc(USB_CMD_DATA_SIZE, sizeof(uint8_t));
|
||||
if ( !buf )
|
||||
if ( !buf )
|
||||
return 1;
|
||||
|
||||
|
||||
int len = 0;
|
||||
// READ RECORD
|
||||
uint8_t READ_RECORD[] = {0x00, 0xB2, 0x00, 0x00, 0x00};
|
||||
UsbCommand c = {CMD_SMART_RAW, {SC_RAW_T0, sizeof(READ_RECORD), 0}};
|
||||
UsbCommand c = {CMD_SMART_RAW, {SC_RAW_T0, sizeof(READ_RECORD), 0}};
|
||||
|
||||
PrintAndLogEx(INFO, "Start SFI brute forcing");
|
||||
|
||||
|
||||
for (uint8_t sfi=1; sfi <= 31; sfi++) {
|
||||
|
||||
printf("."); fflush(stdout);
|
||||
|
||||
|
||||
for (uint16_t rec=1; rec <= 255; rec++) {
|
||||
|
||||
if (ukbhit()) {
|
||||
|
@ -904,40 +904,40 @@ static int smart_brute_sfi(bool decodeTLV){
|
|||
PrintAndLogEx(NORMAL, "\naborted via keyboard!\n");
|
||||
free(buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
READ_RECORD[2] = rec;
|
||||
READ_RECORD[3] = (sfi << 3) | 4;
|
||||
|
||||
memcpy(c.d.asBytes, READ_RECORD, sizeof(READ_RECORD) );
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
|
||||
len = smart_responseEx(buf, true);
|
||||
|
||||
|
||||
if ( buf[0] == 0x6C ) {
|
||||
READ_RECORD[4] = buf[1];
|
||||
|
||||
|
||||
memcpy(c.d.asBytes, READ_RECORD, sizeof(READ_RECORD) );
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
len = smart_responseEx(buf, true);
|
||||
|
||||
READ_RECORD[4] = 0;
|
||||
|
||||
READ_RECORD[4] = 0;
|
||||
}
|
||||
|
||||
|
||||
if ( len > 4 ) {
|
||||
|
||||
|
||||
PrintAndLogEx(SUCCESS, "\n\t file %02d, record %02d found", sfi, rec);
|
||||
|
||||
|
||||
uint8_t modifier = (buf[0] == 0xC0) ? 1 : 0;
|
||||
|
||||
|
||||
if ( decodeTLV ) {
|
||||
if (!TLVPrintFromBuffer(buf + modifier, len-2-modifier)) {
|
||||
PrintAndLogEx(SUCCESS, "\tHEX: %s", sprint_hex(buf, len));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
memset(buf, 0x00, USB_CMD_DATA_SIZE);
|
||||
}
|
||||
}
|
||||
|
@ -948,77 +948,77 @@ static int smart_brute_sfi(bool decodeTLV){
|
|||
static void smart_brute_options(bool decodeTLV) {
|
||||
|
||||
uint8_t* buf = calloc(USB_CMD_DATA_SIZE, sizeof(uint8_t));
|
||||
if ( !buf )
|
||||
if ( !buf )
|
||||
return;
|
||||
|
||||
|
||||
uint8_t GET_PROCESSING_OPTIONS[] = {0x80, 0xA8, 0x00, 0x00, 0x02, 0x83, 0x00, 0x00};
|
||||
|
||||
|
||||
// Get processing options command
|
||||
UsbCommand c = {CMD_SMART_RAW, {SC_RAW_T0, sizeof(GET_PROCESSING_OPTIONS), 0}};
|
||||
memcpy(c.d.asBytes, GET_PROCESSING_OPTIONS, sizeof(GET_PROCESSING_OPTIONS) );
|
||||
UsbCommand c = {CMD_SMART_RAW, {SC_RAW_T0, sizeof(GET_PROCESSING_OPTIONS), 0}};
|
||||
memcpy(c.d.asBytes, GET_PROCESSING_OPTIONS, sizeof(GET_PROCESSING_OPTIONS) );
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
|
||||
int len = smart_responseEx(buf, true);
|
||||
if ( len > 4 ) {
|
||||
PrintAndLogEx(SUCCESS, "Got processing options");
|
||||
PrintAndLogEx(SUCCESS, "Got processing options");
|
||||
if ( decodeTLV ) {
|
||||
TLVPrintFromBuffer(buf, len-2);
|
||||
}
|
||||
} else {
|
||||
PrintAndLogEx(FAILED, "Getting processing options failed");
|
||||
}
|
||||
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
int CmdSmartBruteforceSFI(const char *Cmd) {
|
||||
|
||||
uint8_t cmdp = 0;
|
||||
bool errors = false, decodeTLV = false; //, useT0 = false;
|
||||
|
||||
bool errors = false, decodeTLV = false; //, useT0 = false;
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h': return usage_sm_brute();
|
||||
case 'h': return usage_sm_brute();
|
||||
case 't':
|
||||
decodeTLV = true;
|
||||
cmdp++;
|
||||
break;
|
||||
/*
|
||||
/*
|
||||
case '0':
|
||||
useT0 = true;
|
||||
cmdp++;
|
||||
break;
|
||||
*/
|
||||
*/
|
||||
default:
|
||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Validations
|
||||
if (errors) return usage_sm_brute();
|
||||
|
||||
const char *SELECT = "00a40400%02x%s";
|
||||
|
||||
//Validations
|
||||
if (errors) return usage_sm_brute();
|
||||
|
||||
const char *SELECT = "00a40400%02x%s";
|
||||
|
||||
// uint8_t GENERATE_AC[] = {0x80, 0xAE};
|
||||
// uint8_t GET_CHALLENGE[] = {0x00, 0x84, 0x00};
|
||||
// uint8_t GET_DATA[] = {0x80, 0xCA, 0x00, 0x00, 0x00};
|
||||
// uint8_t SELECT[] = {0x00, 0xA4, 0x04, 0x00};
|
||||
// uint8_t UNBLOCK_PIN[] = {0x84, 0x24, 0x00, 0x00, 0x00};
|
||||
// uint8_t VERIFY[] = {0x00, 0x20, 0x00, 0x80};
|
||||
|
||||
|
||||
// Select AID command
|
||||
UsbCommand cAid = {CMD_SMART_RAW, {SC_RAW_T0, 0, 0}};
|
||||
|
||||
UsbCommand cAid = {CMD_SMART_RAW, {SC_RAW_T0, 0, 0}};
|
||||
|
||||
PrintAndLogEx(INFO, "Importing AID list");
|
||||
json_t *root = NULL;
|
||||
smart_loadjson("aidlist", "json", &root);
|
||||
|
||||
uint8_t* buf = calloc(USB_CMD_DATA_SIZE, sizeof(uint8_t));
|
||||
if ( !buf )
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
PrintAndLogEx(INFO, "Selecting card");
|
||||
if ( !smart_select(false, NULL) ) {
|
||||
|
@ -1027,14 +1027,14 @@ int CmdSmartBruteforceSFI(const char *Cmd) {
|
|||
}
|
||||
|
||||
char* caid = NULL;
|
||||
|
||||
|
||||
for (int i = 0; i < json_array_size(root); i++) {
|
||||
|
||||
|
||||
printf("+"); fflush(stdout);
|
||||
|
||||
if (caid)
|
||||
free(caid);
|
||||
|
||||
|
||||
json_t *data, *jaid;
|
||||
|
||||
data = json_array_get(root, i);
|
||||
|
@ -1043,47 +1043,47 @@ int CmdSmartBruteforceSFI(const char *Cmd) {
|
|||
json_decref(root);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
jaid = json_object_get(data, "AID");
|
||||
if (!json_is_string(jaid)) {
|
||||
PrintAndLogEx(ERR, "AID data [%d] is not a string", i + 1);
|
||||
json_decref(root);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
const char* aid = json_string_value(jaid);
|
||||
if ( !aid )
|
||||
if ( !aid )
|
||||
continue;
|
||||
|
||||
size_t aidlen = strlen(aid);
|
||||
caid = calloc( 8+2+aidlen+1, sizeof(uint8_t));
|
||||
snprintf(caid, 8+2+aidlen+1, SELECT, aidlen >> 1, aid);
|
||||
|
||||
snprintf(caid, 8+2+aidlen+1, SELECT, aidlen >> 1, aid);
|
||||
|
||||
int hexlen = 0;
|
||||
int res = param_gethex_to_eol(caid, 0, cAid.d.asBytes, sizeof(cAid.d.asBytes), &hexlen);
|
||||
if ( res )
|
||||
if ( res )
|
||||
continue;
|
||||
|
||||
|
||||
cAid.arg[1] = hexlen;
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommand(&cAid);
|
||||
|
||||
int len = smart_responseEx(buf, true);
|
||||
SendCommand(&cAid);
|
||||
|
||||
int len = smart_responseEx(buf, true);
|
||||
if ( len < 3 )
|
||||
continue;
|
||||
|
||||
|
||||
json_t *jvendor, *jname;
|
||||
jvendor = json_object_get(data, "Vendor");
|
||||
if (!json_is_string(jvendor)) {
|
||||
PrintAndLogEx(ERR, "Vendor data [%d] is not a string", i + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
const char* vendor = json_string_value(jvendor);
|
||||
if ( !vendor )
|
||||
continue;
|
||||
|
||||
|
||||
jname = json_object_get(data, "Name");
|
||||
if (!json_is_string(jname)) {
|
||||
PrintAndLogEx(ERR, "Name data [%d] is not a string", i + 1);
|
||||
|
@ -1104,19 +1104,19 @@ int CmdSmartBruteforceSFI(const char *Cmd) {
|
|||
PrintAndLogEx(SUCCESS, "\nSFI brute force done\n");
|
||||
}
|
||||
|
||||
if (caid)
|
||||
if (caid)
|
||||
free(caid);
|
||||
|
||||
|
||||
free(buf);
|
||||
json_decref(root);
|
||||
|
||||
|
||||
PrintAndLogEx(SUCCESS, "\nSearch completed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"list", CmdSmartList, 0, "List ISO 7816 history"},
|
||||
{"list", CmdSmartList, 0, "List ISO 7816 history"},
|
||||
{"info", CmdSmartInfo, 1, "Tag information"},
|
||||
{"reader", CmdSmartReader, 1, "Act like an IS07816 reader"},
|
||||
{"raw", CmdSmartRaw, 1, "Send raw hex data to tag"},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue