Merge branch 'master' into t55xx_config_recompute_block0
This commit is contained in:
@@ -1696,7 +1696,7 @@ static int CmdHFiClassRestore(const char *Cmd) {
|
||||
CLIParserInit(&ctx, "hf iclass restore",
|
||||
"Restore data from dumpfile onto a iCLASS tag",
|
||||
"hf iclass restore -f hf-iclass-AA162D30F8FF12F1-dump.bin --first 6 --last 18 --ki 0\n"
|
||||
"hf iclass restore -f hf-iclass-AA162D30F8FF12F1-dump.bin --first 6 --last 18 --ki 0 --elite"
|
||||
"hf iclass restore -f hf-iclass-AA162D30F8FF12F1-dump.bin --first 6 --last 18 --ki 0 --elite\n"
|
||||
"hf iclass restore -f hf-iclass-AA162D30F8FF12F1-dump.bin --first 6 --last 18 -k 1122334455667788 --elite\n"
|
||||
);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "cliparser.h"
|
||||
#include "cmdparser.h" // command_t
|
||||
#include "comms.h"
|
||||
#include "cmdtrace.h"
|
||||
@@ -22,28 +22,6 @@
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
static int usage_thinfilm_info(void) {
|
||||
PrintAndLogEx(NORMAL, "Usage: hf thinfilm info [h]");
|
||||
PrintAndLogEx(NORMAL, "Options:");
|
||||
PrintAndLogEx(NORMAL, " h this help");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, " hf thinfilm info");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int usage_thinfilm_sim(void) {
|
||||
PrintAndLogEx(NORMAL, "Usage: hf thinfilm sim [h] [d <data>]");
|
||||
PrintAndLogEx(NORMAL, "Options:");
|
||||
PrintAndLogEx(NORMAL, " h this help");
|
||||
PrintAndLogEx(NORMAL, " d <bytes> bytes to send, in hex");
|
||||
PrintAndLogEx(NORMAL, " r raw, provided bytes should include CRC");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, " hf thinfilm sim d B70470726f786d61726b2e636f6d");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// Printing function based upon the code in libnfc
|
||||
// ref
|
||||
// https://github.com/nfc-tools/libnfc/blob/master/utils/nfc-barcode.c
|
||||
@@ -119,25 +97,16 @@ static int print_barcode(uint8_t *barcode, const size_t barcode_len, bool verbos
|
||||
}
|
||||
|
||||
static int CmdHfThinFilmInfo(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf thinfilm info",
|
||||
"Get info from Thinfilm tags",
|
||||
"hf thinfilm info");
|
||||
|
||||
uint8_t cmdp = 0;
|
||||
bool errors = false;
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h':
|
||||
return usage_thinfilm_info();
|
||||
default:
|
||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Validations
|
||||
if (errors) {
|
||||
usage_thinfilm_info();
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
return infoThinFilm(true);
|
||||
}
|
||||
@@ -168,45 +137,40 @@ int infoThinFilm(bool verbose) {
|
||||
}
|
||||
|
||||
static int CmdHfThinFilmSim(const char *Cmd) {
|
||||
uint8_t cmdp = 0;
|
||||
uint8_t data[512];
|
||||
int datalen = 0;
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf thinfilm sim",
|
||||
"Simulate Thinfilm tag",
|
||||
"hf thinfilm sim -d B70470726f786d61726b2e636f6d");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1("d", "data", "<hex>", "bytes to send"),
|
||||
arg_lit0(NULL, "raw", "raw, provided bytes should include CRC"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
int data_len = 0;
|
||||
uint8_t data[512] = {0};
|
||||
CLIGetHexWithReturn(ctx, 1, data, &data_len);
|
||||
|
||||
bool addcrc = true;
|
||||
bool errors = false;
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h':
|
||||
return usage_thinfilm_sim();
|
||||
case 'd':
|
||||
// Retrieve the data
|
||||
param_gethex_ex(Cmd, cmdp + 1, data, &datalen);
|
||||
datalen >>= 1;
|
||||
cmdp += 2;
|
||||
break;
|
||||
case 'r':
|
||||
addcrc = false;
|
||||
cmdp++;
|
||||
break;
|
||||
default:
|
||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
if (arg_get_lit(ctx, 2)) {
|
||||
addcrc = false;
|
||||
}
|
||||
|
||||
//Validations
|
||||
if (errors || cmdp == 0 || datalen == 0 || datalen > 512) return usage_thinfilm_sim();
|
||||
if (addcrc && datalen <= 510) {
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (addcrc && data_len <= 510) {
|
||||
uint8_t b1, b2;
|
||||
compute_crc(CRC_14443_A, data, datalen, &b1, &b2);
|
||||
data[datalen++] = b2;
|
||||
data[datalen++] = b1;
|
||||
compute_crc(CRC_14443_A, data, data_len, &b1, &b2);
|
||||
data[data_len++] = b2;
|
||||
data[data_len++] = b1;
|
||||
}
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_THINFILM_SIMULATE, (uint8_t *)&data, datalen);
|
||||
SendCommandNG(CMD_HF_THINFILM_SIMULATE, (uint8_t *)&data, data_len);
|
||||
PacketResponseNG resp;
|
||||
PrintAndLogEx(SUCCESS, "press pm3-button to abort simulation");
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include "cliparser.h"
|
||||
#include "cmdparser.h" // command_t
|
||||
#include "comms.h"
|
||||
#include "cmdtrace.h"
|
||||
@@ -393,21 +394,42 @@ static int topaz_print_NDEF(uint8_t *data, size_t maxsize) {
|
||||
}
|
||||
|
||||
static int CmdHFTopazReader(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf topaz reader",
|
||||
"Read UID from Topaz tags",
|
||||
"hf topaz reader");
|
||||
|
||||
bool verbose = true;
|
||||
char ctmp = tolower(param_getchar(Cmd, 0));
|
||||
if (ctmp == 's') verbose = false;
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0("v", "verbose", "verbose output"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
bool verbose = arg_get_lit(ctx, 1);
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
return readTopazUid(verbose);
|
||||
}
|
||||
|
||||
// read a Topaz tag and print some useful information
|
||||
static int CmdHFTopazInfo(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf topaz info",
|
||||
"Get info from Topaz tags",
|
||||
"hf topaz info");
|
||||
|
||||
bool verbose = true;
|
||||
char ctmp = tolower(param_getchar(Cmd, 0));
|
||||
if (ctmp == 's') verbose = false;
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0("v", "verbose", "verbose output"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
bool verbose = arg_get_lit(ctx, 1);
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
int status = readTopazUid(verbose);
|
||||
if (status != PM3_SUCCESS)
|
||||
@@ -469,13 +491,34 @@ static int CmdHFTopazInfo(const char *Cmd) {
|
||||
}
|
||||
|
||||
static int CmdHFTopazSim(const char *Cmd) {
|
||||
(void)Cmd; // Cmd is not used so far
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf topaz sim",
|
||||
"Simulate a Topaz tag",
|
||||
"hf topaz sim <- Not yet implemented");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
CLIParserFree(ctx);
|
||||
PrintAndLogEx(INFO, "not yet implemented");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int CmdHFTopazCmdRaw(const char *Cmd) {
|
||||
(void)Cmd; // Cmd is not used so far
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf topaz raw",
|
||||
"Send raw hex data to Topaz tags",
|
||||
"hf topaz raw <- Not yet implemented");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
PrintAndLogEx(INFO, "not yet implemented. Use hf 14 raw with option -T.");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
@@ -490,6 +533,25 @@ static int CmdHFTopazList(const char *Cmd) {
|
||||
return CmdTraceList(args);
|
||||
}
|
||||
|
||||
static int CmdHFTopazSniff(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf topaz sniff",
|
||||
"Sniff Topaz reader-tag communication",
|
||||
"hf topaz sniff");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
uint8_t param = 0;
|
||||
SendCommandNG(CMD_HF_ISO14443A_SNIFF, (uint8_t *)¶m, sizeof(uint8_t));
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
@@ -498,7 +560,7 @@ static command_t CommandTable[] = {
|
||||
{"info", CmdHFTopazInfo, IfPm3Iso14443a, "Tag information"},
|
||||
{"reader", CmdHFTopazReader, IfPm3Iso14443a, "Act like a Topaz reader"},
|
||||
{"sim", CmdHFTopazSim, IfPm3Iso14443a, "<UID> -- Simulate Topaz tag"},
|
||||
{"sniff", CmdHF14ASniff, IfPm3Iso14443a, "Sniff Topaz reader-tag communication"},
|
||||
{"sniff", CmdHFTopazSniff, IfPm3Iso14443a, "Sniff Topaz reader-tag communication"},
|
||||
{"raw", CmdHFTopazCmdRaw, IfPm3Iso14443a, "Send raw hex data to tag"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,20 +11,27 @@
|
||||
#ifndef CMDLFEM4X50_H__
|
||||
#define CMDLFEM4X50_H__
|
||||
|
||||
#include"common.h"
|
||||
#include "em4x50.h"
|
||||
|
||||
int CmdLFEM4X50(const char *Cmd);
|
||||
|
||||
int read_em4x50_uid(void);
|
||||
bool detect_4x50_block(void);
|
||||
int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose);
|
||||
int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out);
|
||||
|
||||
int CmdEM4x50Info(const char *Cmd);
|
||||
int CmdEM4x50Write(const char *Cmd);
|
||||
int CmdEM4x50WritePassword(const char *Cmd);
|
||||
int CmdEM4x50WritePwd(const char *Cmd);
|
||||
int CmdEM4x50Read(const char *Cmd);
|
||||
int CmdEM4x50Dump(const char *Cmd);
|
||||
int CmdEM4x50Wipe(const char *Cmd);
|
||||
int CmdEM4x50Brute(const char *Cmd);
|
||||
int CmdEM4x50Login(const char *Cmd);
|
||||
int CmdEM4x50Restore(const char *Cmd);
|
||||
int CmdEM4x50Sim(const char *Cmd);
|
||||
int CmdEM4x50Reader(const char *Cmd);
|
||||
int CmdEM4x50ELoad(const char *Cmd);
|
||||
int CmdEM4x50ESave(const char *Cmd);
|
||||
int CmdEM4x50Chk(const char *Cmd);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -521,6 +521,20 @@ int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case jsfEM4x50: {
|
||||
JsonSaveStr(root, "FileType", "EM4X50");
|
||||
JsonSaveBufAsHexCompact(root, "$.Card.Protection", data + (1 * 4), 4);
|
||||
JsonSaveBufAsHexCompact(root, "$.Card.Config", data + (2 * 4), 4);
|
||||
JsonSaveBufAsHexCompact(root, "$.Card.Serial", data + (32 * 4), 4);
|
||||
JsonSaveBufAsHexCompact(root, "$.Card.UID", data + (33 * 4), 4);
|
||||
|
||||
for (size_t i = 0; i < (datalen / 4); i++) {
|
||||
char path[PATH_MAX_LENGTH] = {0};
|
||||
sprintf(path, "$.blocks.%zu", i);
|
||||
JsonSaveBufAsHexCompact(root, path, data + (i * 4), 4);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case jsfMfPlusKeys: {
|
||||
JsonSaveStr(root, "FileType", "mfp");
|
||||
JsonSaveBufAsHexCompact(root, "$.Card.UID", &data[0], 7);
|
||||
@@ -1139,6 +1153,27 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
|
||||
*datalen = sptr;
|
||||
}
|
||||
|
||||
if (!strcmp(ctype, "EM4X50")) {
|
||||
size_t sptr = 0;
|
||||
for (size_t i = 0; i < (maxdatalen / 4); i++) {
|
||||
if (sptr + 4 > maxdatalen) {
|
||||
retval = PM3_EMALLOC;
|
||||
goto out;
|
||||
}
|
||||
|
||||
char blocks[30] = {0};
|
||||
sprintf(blocks, "$.blocks.%zu", i);
|
||||
|
||||
size_t len = 0;
|
||||
JsonLoadBufAsHex(root, blocks, &udata[sptr], 4, &len);
|
||||
if (!len)
|
||||
break;
|
||||
|
||||
sptr += len;
|
||||
}
|
||||
*datalen = sptr;
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
if (callback != NULL) {
|
||||
|
||||
@@ -66,6 +66,7 @@ typedef enum {
|
||||
jsfMfDesfireKeys,
|
||||
jsfEM4x05,
|
||||
jsfEM4x69,
|
||||
jsfEM4x50,
|
||||
} JSONFileType;
|
||||
|
||||
typedef enum {
|
||||
|
||||
@@ -1146,8 +1146,7 @@ static int l_em4x50_read(lua_State *L) {
|
||||
em4x50_data_t etd;
|
||||
memset(&etd, 0x00, sizeof(em4x50_data_t));
|
||||
etd.addr_given = true;
|
||||
etd.address = addr & 0xFF;
|
||||
etd.newpwd_given = false;
|
||||
etd.addresses = addr & 0xFF;
|
||||
|
||||
// get password
|
||||
const char *p_pwd = luaL_checkstring(L, 2);
|
||||
@@ -1162,31 +1161,29 @@ static int l_em4x50_read(lua_State *L) {
|
||||
|
||||
PrintAndLogEx(DEBUG, " Pwd %08X", pwd);
|
||||
|
||||
etd.password[0] = pwd & 0xFF;
|
||||
etd.password[1] = (pwd >> 8) & 0xFF;
|
||||
etd.password[2] = (pwd >> 16) & 0xFF;
|
||||
etd.password[3] = (pwd >> 24) & 0xFF;
|
||||
etd.password1 = pwd;
|
||||
etd.pwd_given = true;
|
||||
}
|
||||
|
||||
PrintAndLogEx(DEBUG, "Addr %u", etd.address);
|
||||
PrintAndLogEx(DEBUG, "Addr %u", etd.addresses & 0xFF);
|
||||
if (etd.pwd_given)
|
||||
PrintAndLogEx(DEBUG, " Pwd %s", sprint_hex(etd.password, sizeof(etd.password)));
|
||||
PrintAndLogEx(DEBUG, " Pwd %08x", etd.password1);
|
||||
|
||||
em4x50_word_t words[EM4X50_NO_WORDS];
|
||||
|
||||
int res = em4x50_read(&etd, words, false);
|
||||
int res = em4x50_read(&etd, words);
|
||||
if (res != PM3_SUCCESS) {
|
||||
return returnToLuaWithError(L, "Failed to read EM4x50 data");
|
||||
}
|
||||
|
||||
uint32_t word = (
|
||||
words[etd.address].byte[0] << 24 |
|
||||
words[etd.address].byte[1] << 16 |
|
||||
words[etd.address].byte[2] << 8 |
|
||||
words[etd.address].byte[3]
|
||||
words[etd.addresses & 0xFF].byte[0] << 24 |
|
||||
words[etd.addresses & 0xFF].byte[1] << 16 |
|
||||
words[etd.addresses & 0xFF].byte[2] << 8 |
|
||||
words[etd.addresses & 0xFF].byte[3]
|
||||
);
|
||||
lua_pushinteger(L, word);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user