mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-21 05:43:23 -07:00
Merged latest trunk changes into scripting-branch
This commit is contained in:
commit
cda2a4c0a5
18 changed files with 646 additions and 550 deletions
|
@ -32,6 +32,8 @@ else
|
|||
CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O4
|
||||
QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
|
||||
MOC = $(shell pkg-config --variable=moc_location QtCore)
|
||||
# Below is a variant you can use if you have problems compiling with QT5 on ubuntu. see http://www.proxmark.org/forum/viewtopic.php?id=1661 for more info.
|
||||
#MOC = /usr/lib/x86_64-linux-gnu/qt4/bin/moc
|
||||
LUAPLATFORM = linux
|
||||
endif
|
||||
|
||||
|
@ -46,7 +48,8 @@ endif
|
|||
|
||||
CORESRCS = uart.c \
|
||||
util.c \
|
||||
sleep.c \
|
||||
sleep.c
|
||||
|
||||
|
||||
CMDSRCS = nonce2key/crapto1.c\
|
||||
nonce2key/crypto1.c\
|
||||
|
|
|
@ -393,46 +393,43 @@ int CmdGrid(const char *Cmd)
|
|||
|
||||
int CmdHexsamples(const char *Cmd)
|
||||
{
|
||||
int n;
|
||||
int i, j;
|
||||
int requested = 0;
|
||||
int offset = 0;
|
||||
char string_buf[25];
|
||||
char* string_ptr = string_buf;
|
||||
uint8_t got[40000];
|
||||
|
||||
sscanf(Cmd, "%i %i", &requested, &offset);
|
||||
|
||||
int delivered = 0;
|
||||
uint8_t got[40000];
|
||||
|
||||
/* round up to nearest 8 bytes so the printed data is all valid */
|
||||
if (requested < 8) {
|
||||
/* if no args send something */
|
||||
if (requested == 0) {
|
||||
requested = 8;
|
||||
}
|
||||
if (requested % 8 != 0) {
|
||||
int remainder = requested % 8;
|
||||
requested = requested + 8 - remainder;
|
||||
}
|
||||
if (offset + requested > sizeof(got)) {
|
||||
PrintAndLog("Tried to read past end of buffer, <bytes> + <offset> > 40000");
|
||||
return 0;
|
||||
} else {
|
||||
n = requested;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GetFromBigBuf(got,n,offset);
|
||||
GetFromBigBuf(got,requested,offset);
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
|
||||
for (int j = 0; j < n; j += 8) {
|
||||
PrintAndLog("%02x %02x %02x %02x %02x %02x %02x %02x",
|
||||
sample_buf[j+0],
|
||||
sample_buf[j+1],
|
||||
sample_buf[j+2],
|
||||
sample_buf[j+3],
|
||||
sample_buf[j+4],
|
||||
sample_buf[j+5],
|
||||
sample_buf[j+6],
|
||||
sample_buf[j+7]
|
||||
);
|
||||
delivered += 8;
|
||||
if (delivered >= requested)
|
||||
break;
|
||||
i = 0;
|
||||
for (j = 0; j < requested; j++) {
|
||||
i++;
|
||||
string_ptr += sprintf(string_ptr, "%02x ", got[j]);
|
||||
if (i == 8) {
|
||||
*(string_ptr - 1) = '\0'; // remove the trailing space
|
||||
PrintAndLog("%s", string_buf);
|
||||
string_buf[0] = '\0';
|
||||
string_ptr = string_buf;
|
||||
i = 0;
|
||||
}
|
||||
if (j == requested - 1 && string_buf[0] != '\0') { // print any remaining bytes
|
||||
*(string_ptr - 1) = '\0';
|
||||
PrintAndLog("%s", string_buf);
|
||||
string_buf[0] = '\0';
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "cmdhf14b.h"
|
||||
#include "cmdmain.h"
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
|
@ -267,6 +268,116 @@ int CmdSrix4kRead(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdHF14BCmdRaw (const char *cmd) {
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_14443B_COMMAND, {0, 0, 0}}; // len,recv?
|
||||
uint8_t reply=1;
|
||||
uint8_t crc=0;
|
||||
uint8_t power=0;
|
||||
char buf[5]="";
|
||||
int i=0;
|
||||
uint8_t data[100];
|
||||
unsigned int datalen=0, temp;
|
||||
char *hexout;
|
||||
|
||||
if (strlen(cmd)<3) {
|
||||
PrintAndLog("Usage: hf 14b raw [-r] [-c] [-p] <0A 0B 0C ... hex>");
|
||||
PrintAndLog(" -r do not read response");
|
||||
PrintAndLog(" -c calculate and append CRC");
|
||||
PrintAndLog(" -p leave the field on after receive");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// strip
|
||||
while (*cmd==' ' || *cmd=='\t') cmd++;
|
||||
|
||||
while (cmd[i]!='\0') {
|
||||
if (cmd[i]==' ' || cmd[i]=='\t') { i++; continue; }
|
||||
if (cmd[i]=='-') {
|
||||
switch (cmd[i+1]) {
|
||||
case 'r':
|
||||
case 'R':
|
||||
reply=0;
|
||||
break;
|
||||
case 'c':
|
||||
case 'C':
|
||||
crc=1;
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
power=1;
|
||||
break;
|
||||
default:
|
||||
PrintAndLog("Invalid option");
|
||||
return 0;
|
||||
}
|
||||
i+=2;
|
||||
continue;
|
||||
}
|
||||
if ((cmd[i]>='0' && cmd[i]<='9') ||
|
||||
(cmd[i]>='a' && cmd[i]<='f') ||
|
||||
(cmd[i]>='A' && cmd[i]<='F') ) {
|
||||
buf[strlen(buf)+1]=0;
|
||||
buf[strlen(buf)]=cmd[i];
|
||||
i++;
|
||||
|
||||
if (strlen(buf)>=2) {
|
||||
sscanf(buf,"%x",&temp);
|
||||
data[datalen]=(uint8_t)(temp & 0xff);
|
||||
datalen++;
|
||||
*buf=0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
PrintAndLog("Invalid char on input");
|
||||
return 0;
|
||||
}
|
||||
if(crc)
|
||||
{
|
||||
uint8_t first, second;
|
||||
ComputeCrc14443(CRC_14443_B, data, datalen, &first, &second);
|
||||
data[datalen++] = first;
|
||||
data[datalen++] = second;
|
||||
}
|
||||
|
||||
c.arg[0] = datalen;
|
||||
c.arg[1] = reply;
|
||||
c.arg[2] = power;
|
||||
memcpy(c.d.asBytes,data,datalen);
|
||||
|
||||
SendCommand(&c);
|
||||
|
||||
if (reply) {
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
|
||||
recv = resp.d.asBytes;
|
||||
PrintAndLog("received %i octets",resp.arg[0]);
|
||||
if(!resp.arg[0])
|
||||
return 0;
|
||||
hexout = (char *)malloc(resp.arg[0] * 3 + 1);
|
||||
if (hexout != NULL) {
|
||||
uint8_t first, second;
|
||||
for (int i = 0; i < resp.arg[0]; i++) { // data in hex
|
||||
sprintf(&hexout[i * 3], "%02hX ", recv[i]);
|
||||
}
|
||||
PrintAndLog("%s", hexout);
|
||||
free(hexout);
|
||||
ComputeCrc14443(CRC_14443_B, recv, resp.arg[0]-2, &first, &second);
|
||||
if(recv[resp.arg[0]-2]==first && recv[resp.arg[0]-1]==second) {
|
||||
PrintAndLog("CRC OK");
|
||||
} else {
|
||||
PrintAndLog("CRC failed");
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("malloc failed your client has low memory?");
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("timeout while waiting for reply.");
|
||||
}
|
||||
} // if reply
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
|
@ -276,8 +387,9 @@ static command_t CommandTable[] =
|
|||
{"sim", CmdHF14Sim, 0, "Fake ISO 14443 tag"},
|
||||
{"simlisten", CmdHFSimlisten, 0, "Get HF samples as fake tag"},
|
||||
{"snoop", CmdHF14BSnoop, 0, "Eavesdrop ISO 14443"},
|
||||
{"sri512read", CmdSri512Read, 0, "<int> -- Read contents of a SRI512 tag"},
|
||||
{"srix4kread", CmdSrix4kRead, 0, "<int> -- Read contents of a SRIX4K tag"},
|
||||
{"sri512read", CmdSri512Read, 0, "Read contents of a SRI512 tag"},
|
||||
{"srix4kread", CmdSrix4kRead, 0, "Read contents of a SRIX4K tag"},
|
||||
{"raw", CmdHF14BCmdRaw, 0, "Send raw hex data to tag"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -52,35 +52,20 @@ int CmdHelp(const char *Cmd)
|
|||
*/
|
||||
int CmdLegicDecode(const char *Cmd)
|
||||
{
|
||||
int h, i, j, k, n;
|
||||
int i, j, k, n;
|
||||
int segment_len = 0;
|
||||
int segment_flag = 0;
|
||||
int stamp_len = 0;
|
||||
int crc = 0;
|
||||
int wrp = 0;
|
||||
int wrc = 0;
|
||||
int data_buf[1032]; // receiver buffer
|
||||
uint8_t data_buf[1024]; // receiver buffer
|
||||
char out_string[3076]; // just use big buffer - bad practice
|
||||
char token_type[4];
|
||||
int delivered = 0;
|
||||
|
||||
h = 0;
|
||||
|
||||
// copy data from proxmark into buffer
|
||||
for (i = 0; i < 256; i += 12, h += 48) {
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, NULL);
|
||||
|
||||
for (j = 0; j < 48; j += 8) {
|
||||
for (k = 0; k < 8; k++) {
|
||||
data_buf[h+j+k] = sample_buf[j+k];
|
||||
}
|
||||
delivered += 8;
|
||||
if (delivered >= 1024)
|
||||
break;
|
||||
}
|
||||
}
|
||||
GetFromBigBuf(data_buf,sizeof(data_buf),0);
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
|
||||
// Output CDF System area (9 bytes) plus remaining header area (12 bytes)
|
||||
|
||||
|
@ -264,51 +249,50 @@ int CmdLegicLoad(const char *Cmd)
|
|||
|
||||
int CmdLegicSave(const char *Cmd)
|
||||
{
|
||||
int n;
|
||||
int requested = 1024;
|
||||
int offset = 0;
|
||||
int delivered = 0;
|
||||
char filename[1024];
|
||||
uint8_t got[1024];
|
||||
|
||||
sscanf(Cmd, " %s %i %i", filename, &requested, &offset);
|
||||
if (offset % 4 != 0) {
|
||||
PrintAndLog("Offset must be a multiple of 4");
|
||||
|
||||
/* If no length given save entire legic read buffer */
|
||||
/* round up to nearest 8 bytes so the saved data can be used with legicload */
|
||||
if (requested == 0) {
|
||||
requested = 1024;
|
||||
}
|
||||
if (requested % 8 != 0) {
|
||||
int remainder = requested % 8;
|
||||
requested = requested + 8 - remainder;
|
||||
}
|
||||
|
||||
if (offset + requested > sizeof(got)) {
|
||||
PrintAndLog("Tried to read past end of buffer, <bytes> + <offset> > 1024");
|
||||
return 0;
|
||||
}
|
||||
offset = offset/4;
|
||||
|
||||
int delivered = 0;
|
||||
|
||||
if (requested == 0) {
|
||||
n = 12;
|
||||
requested = 12;
|
||||
} else {
|
||||
n = requested/4;
|
||||
}
|
||||
|
||||
|
||||
FILE *f = fopen(filename, "w");
|
||||
if(!f) {
|
||||
PrintAndLog("couldn't open '%s'", Cmd+1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = offset; i < n+offset; i += 12) {
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, NULL);
|
||||
for (int j = 0; j < 48; j += 8) {
|
||||
fprintf(f, "%02x %02x %02x %02x %02x %02x %02x %02x\n",
|
||||
sample_buf[j+0],
|
||||
sample_buf[j+1],
|
||||
sample_buf[j+2],
|
||||
sample_buf[j+3],
|
||||
sample_buf[j+4],
|
||||
sample_buf[j+5],
|
||||
sample_buf[j+6],
|
||||
sample_buf[j+7]
|
||||
);
|
||||
delivered += 8;
|
||||
if (delivered >= requested)
|
||||
break;
|
||||
}
|
||||
GetFromBigBuf(got,requested,offset);
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
|
||||
for (int j = 0; j < requested; j += 8) {
|
||||
fprintf(f, "%02x %02x %02x %02x %02x %02x %02x %02x\n",
|
||||
got[j+0],
|
||||
got[j+1],
|
||||
got[j+2],
|
||||
got[j+3],
|
||||
got[j+4],
|
||||
got[j+5],
|
||||
got[j+6],
|
||||
got[j+7]
|
||||
);
|
||||
delivered += 8;
|
||||
if (delivered >= requested)
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -15,33 +15,31 @@ static int CmdHelp(const char *Cmd);
|
|||
int CmdHF14AMifare(const char *Cmd)
|
||||
{
|
||||
uint32_t uid = 0;
|
||||
uint32_t nt = 0;
|
||||
uint32_t nt = 0, nr = 0;
|
||||
uint64_t par_list = 0, ks_list = 0, r_key = 0;
|
||||
uint8_t isOK = 0;
|
||||
uint8_t keyBlock[8] = {0};
|
||||
|
||||
if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, keyBlock, 8)) {
|
||||
PrintAndLog("Nt must include 8 HEX symbols");
|
||||
return 1;
|
||||
}
|
||||
UsbCommand c = {CMD_READER_MIFARE, {true, 0, 0}};
|
||||
|
||||
// message
|
||||
printf("-------------------------------------------------------------------------\n");
|
||||
printf("Executing command. Expected execution time: 25sec on average :-)\n");
|
||||
printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");
|
||||
printf("-------------------------------------------------------------------------\n");
|
||||
|
||||
|
||||
UsbCommand c = {CMD_READER_MIFARE, {(uint32_t)bytes_to_num(keyBlock, 4), 0, 0}};
|
||||
start:
|
||||
SendCommand(&c);
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
//flush queue
|
||||
while (ukbhit()) getchar();
|
||||
|
||||
// message
|
||||
printf("-------------------------------------------------------------------------\n");
|
||||
printf("Executing command. It may take up to 30 min.\n");
|
||||
printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");
|
||||
printf("-------------------------------------------------------------------------\n");
|
||||
|
||||
// wait cycle
|
||||
while (true) {
|
||||
printf(".");
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
if (ukbhit()) {
|
||||
getchar();
|
||||
|
@ -50,27 +48,26 @@ start:
|
|||
}
|
||||
|
||||
UsbCommand resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,2000)) {
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
|
||||
isOK = resp.arg[0] & 0xff;
|
||||
|
||||
uid = (uint32_t)bytes_to_num(resp.d.asBytes + 0, 4);
|
||||
nt = (uint32_t)bytes_to_num(resp.d.asBytes + 4, 4);
|
||||
par_list = bytes_to_num(resp.d.asBytes + 8, 8);
|
||||
ks_list = bytes_to_num(resp.d.asBytes + 16, 8);
|
||||
|
||||
nr = bytes_to_num(resp.d.asBytes + 24, 4);
|
||||
printf("\n\n");
|
||||
PrintAndLog("isOk:%02x", isOK);
|
||||
if (!isOK) PrintAndLog("Proxmark can't get statistic info. Execution aborted.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
// error
|
||||
if (isOK != 1) return 1;
|
||||
|
||||
// execute original function from util nonce2key
|
||||
if (nonce2key(uid, nt, par_list, ks_list, &r_key))
|
||||
if (nonce2key(uid, nt, nr, par_list, ks_list, &r_key))
|
||||
{
|
||||
isOK = 2;
|
||||
PrintAndLog("Key not found (lfsr_common_prefix list is null). Nt=%08x", nt);
|
||||
|
@ -85,8 +82,9 @@ start:
|
|||
PrintAndLog("Found valid key:%012"llx, r_key);
|
||||
else
|
||||
{
|
||||
if (isOK != 2) PrintAndLog("Found invalid key. ( Nt=%08x ,Trying use it to run again...", nt);
|
||||
c.arg[0] = nt;
|
||||
if (isOK != 2) PrintAndLog("Found invalid key. ");
|
||||
PrintAndLog("Failing is expected to happen in 25%% of all cases. Trying again with a different reader nonce...");
|
||||
c.arg[0] = false;
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "util.h"
|
||||
#include "cmdscript.h"
|
||||
|
||||
|
||||
unsigned int current_command = CMD_UNKNOWN;
|
||||
//unsigned int received_command = CMD_UNKNOWN;
|
||||
//UsbCommand current_response;
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
#include "nonce2key.h"
|
||||
#include "ui.h"
|
||||
|
||||
int nonce2key(uint32_t uid, uint32_t nt, uint64_t par_info, uint64_t ks_info, uint64_t * key) {
|
||||
int nonce2key(uint32_t uid, uint32_t nt, uint32_t nr, uint64_t par_info, uint64_t ks_info, uint64_t * key) {
|
||||
struct Crypto1State *state, *state_s;
|
||||
uint32_t pos, nr, rr, nr_diff;//, ks1, ks2;
|
||||
uint32_t pos, rr, nr_diff;//, ks1, ks2;
|
||||
byte_t bt, i, ks3x[8], par[8][8];
|
||||
uint64_t key_recovered;
|
||||
nr = rr = 0;
|
||||
rr = 0;
|
||||
|
||||
// Reset the last three significant bits of the reader nonce
|
||||
nr &= 0xffffff1f;
|
||||
|
|
|
@ -18,6 +18,6 @@
|
|||
#include "crapto1.h"
|
||||
#include "common.h"
|
||||
|
||||
int nonce2key(uint32_t uid, uint32_t nt, uint64_t par_info, uint64_t ks_info, uint64_t * key);
|
||||
int nonce2key(uint32_t uid, uint32_t nt, uint32_t nr, uint64_t par_info, uint64_t ks_info, uint64_t * key);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
static serial_port sp;
|
||||
static UsbCommand txcmd;
|
||||
static volatile bool txcmd_pending = false;
|
||||
volatile static bool txcmd_pending = false;
|
||||
|
||||
void SendCommand(UsbCommand *c) {
|
||||
#if 0
|
||||
|
|
|
@ -266,7 +266,7 @@ bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen) {
|
|||
if (res < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Read time-out
|
||||
if (res == 0) {
|
||||
if (*pszRxLen == 0) {
|
||||
|
@ -277,21 +277,24 @@ bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen) {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Retrieve the count of the incoming bytes
|
||||
res = ioctl(((serial_port_unix*)sp)->fd, FIONREAD, &byteCount);
|
||||
if (res < 0) return false;
|
||||
|
||||
|
||||
// There is something available, read the data
|
||||
res = read(((serial_port_unix*)sp)->fd,pbtRx+(*pszRxLen),byteCount);
|
||||
|
||||
|
||||
// Stop if the OS has some troubles reading the data
|
||||
if (res <= 0) return false;
|
||||
|
||||
|
||||
*pszRxLen += res;
|
||||
|
||||
if(res==byteCount)
|
||||
return true;
|
||||
|
||||
} while (byteCount);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue