changed hf mf wrbl and view command to look for strict readonly ACL in the data.
This commit is contained in:
1 parent
05922a2d7c
commit
9888eef8dc
17 files changed
+313
-102
No files matched your search
@@ -23,7 +23,7 @@ author = 'Shain Lakin'
|
||||
version = 'v1.0.0'
|
||||
desc =[[
|
||||
|
||||
This script can be used to read blocks, write blocks, dump sectors,
|
||||
This script can be used to read blocks, write blocks, dump sectors,
|
||||
or write a files hex bytes to sector 0 or 1 on the NTAG I2C PLUS 2K tag.
|
||||
|
||||
]]
|
||||
@@ -32,7 +32,7 @@ example =[[
|
||||
|
||||
Read block 04 from sector 1:
|
||||
script run hf_i2c_plus_2k_utils -m r -s 1 -b 04
|
||||
|
||||
|
||||
Write FFFFFFFF to block A0 sector 1:
|
||||
script run hf_i2c_plus_2k_utils -m w -s 1 -b A0 -d FFFFFFFF
|
||||
|
||||
@@ -45,15 +45,15 @@ example =[[
|
||||
]]
|
||||
usage = [[
|
||||
|
||||
Read mode:
|
||||
Read mode:
|
||||
script run hf_i2c_plus_2k_utils -m r -s <sector> -b <block (hex)>
|
||||
|
||||
Write mode:
|
||||
|
||||
Write mode:
|
||||
script run hf_i2c_plus_2k_utils -m w -s <sector> -b <block (hex)> -d <data (hex)>
|
||||
|
||||
|
||||
Dump mode:
|
||||
script run hf_i2c_plus_2k_utils -m d -s <sector>
|
||||
|
||||
|
||||
File mode:
|
||||
script run hf_i2c_plus_2k_utils -m f -s <sector> -f <file>
|
||||
|
||||
@@ -124,7 +124,7 @@ end
|
||||
---
|
||||
|
||||
|
||||
--- Function to connect
|
||||
--- Function to connect
|
||||
local function connect()
|
||||
core.clearCommandBuffer()
|
||||
|
||||
@@ -189,7 +189,7 @@ local function filewriter(file,sector)
|
||||
end_char = 8
|
||||
block_counter = 4
|
||||
-- NTAG_I2C_PLUS_2K:SECTOR_0:225,SECTOR_1:255
|
||||
end_block = 225
|
||||
end_block = 225
|
||||
connect()
|
||||
select_sector(sector)
|
||||
for count = 1, len do
|
||||
@@ -296,7 +296,7 @@ local function main(args)
|
||||
elseif mode == 'd' then
|
||||
dump(sector,uid)
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
return print(usage)
|
||||
end
|
||||
|
||||
@@ -847,13 +847,13 @@ end
|
||||
-- returns true if b is the index of a sector trailer
|
||||
local function mfIsSectorTrailer(b)
|
||||
n=b+1
|
||||
if (n < 32*4 ) then
|
||||
if (n % 4 == 0) then return true
|
||||
if (n < 32*4 ) then
|
||||
if (n % 4 == 0) then return true
|
||||
else return false
|
||||
end
|
||||
end
|
||||
|
||||
if (n % 16 == 0) then return true
|
||||
if (n % 16 == 0) then return true
|
||||
end
|
||||
|
||||
return false
|
||||
|
||||
@@ -3968,7 +3968,7 @@ static int CmdHFiClassEncode(const char *Cmd) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
// iceman: only for formats w length smaller than 37.
|
||||
// iceman: only for formats w length smaller than 37.
|
||||
// Needs a check.
|
||||
|
||||
// increase length to allow setting bit just above real data
|
||||
|
||||
+67
-9
@@ -238,7 +238,7 @@ static bool mfc_value(const uint8_t *d, int32_t *val) {
|
||||
}
|
||||
|
||||
static void mf_print_block_one(uint8_t blockno, uint8_t *d, bool verbose) {
|
||||
if (blockno == 0) {
|
||||
if (blockno == 0) {
|
||||
PrintAndLogEx(INFO, "%3d | " _RED_("%s"), blockno, sprint_hex_ascii(d, MFBLOCK_SIZE));
|
||||
} else if (mfIsSectorTrailer(blockno)) {
|
||||
PrintAndLogEx(INFO, "%3d | " _YELLOW_("%s"), blockno, sprint_hex_ascii(d, MFBLOCK_SIZE));
|
||||
@@ -375,6 +375,31 @@ static bool mf_write_block(const uint8_t *key, uint8_t keytype, uint8_t blockno,
|
||||
return (resp.oldarg[0] & 0xff);
|
||||
}
|
||||
|
||||
static void mf_analyse_acl(uint16_t n, uint8_t *d) {
|
||||
|
||||
for (uint16_t b = 3; b < n; b++) {
|
||||
if (mfIsSectorTrailer(b) == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t block[MFBLOCK_SIZE] = {0x00};
|
||||
memcpy(block, d + (b * MFBLOCK_SIZE), MFBLOCK_SIZE);
|
||||
|
||||
// ensure access right isn't messed up.
|
||||
if (mfValidateAccessConditions(&block[6]) == false) {
|
||||
PrintAndLogEx(WARNING, "Invalid Access Conditions on sector " _YELLOW_("%u"), mfSectorNum(b));
|
||||
}
|
||||
|
||||
// Warn if ACL is strict read-only
|
||||
uint8_t bar = mfNumBlocksPerSector(mfSectorNum(b));
|
||||
for (uint8_t foo = 0; foo < bar; foo++) {
|
||||
if (mfReadOnlyAccessConditions(foo, &block[6])) {
|
||||
PrintAndLogEx(WARNING, _YELLOW_("s%u / b%u") " - Strict ReadOnly Access Conditions detected", mfSectorNum(b), b - bar + 1 + foo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int CmdHF14AMfAcl(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf mf acl",
|
||||
@@ -539,6 +564,32 @@ static int CmdHF14AMfWrBl(const char *Cmd) {
|
||||
|
||||
uint8_t blockno = (uint8_t)b;
|
||||
|
||||
// Warn if ACL is strict read-only
|
||||
if (mfIsSectorTrailer(blockno)) {
|
||||
PrintAndLogEx(INFO, "Sector trailer (ST) write detected");
|
||||
|
||||
// ensure access right isn't messed up.
|
||||
if (mfValidateAccessConditions(&block[6]) == false) {
|
||||
PrintAndLogEx(WARNING, "Invalid Access Conditions detected, replacing by default values");
|
||||
memcpy(block + 6, "\xFF\x07\x80\x69", 4);
|
||||
}
|
||||
|
||||
bool ro_detected = false;
|
||||
uint8_t bar = mfNumBlocksPerSector(mfSectorNum(blockno));
|
||||
for (uint8_t foo = 0; foo < bar; foo++) {
|
||||
if (mfReadOnlyAccessConditions(foo, &block[6])) {
|
||||
PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on block " _YELLOW_("%u") " detected", blockno - bar + 1 + foo);
|
||||
ro_detected = true;
|
||||
}
|
||||
}
|
||||
if (ro_detected) {
|
||||
PrintAndLogEx(INFO, "Exiting, please run `" _YELLOW_("hf mf acl -d %s") "` to understand", sprint_hex_inrow(&block[6], 3));
|
||||
return PM3_EINVARG;
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "ST passed checks, continuing...");
|
||||
}
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "Writing block no %d, key %c - %s", blockno, (keytype == MF_KEY_B) ? 'B' : 'A', sprint_hex_inrow(key, sizeof(key)));
|
||||
PrintAndLogEx(INFO, "data: %s", sprint_hex(block, sizeof(block)));
|
||||
|
||||
@@ -1172,7 +1223,7 @@ static int CmdHF14AMfRestore(const char *Cmd) {
|
||||
|
||||
PrintAndLogEx(INFO, "Restoring " _YELLOW_("%s")" to card", datafilename);
|
||||
|
||||
// main loop for restoreing.
|
||||
// main loop for restoring.
|
||||
// a bit more complicated than needed
|
||||
// this is because of two things.
|
||||
// 1. we are setting keys from a key file or using the existing ones in the dump
|
||||
@@ -1182,7 +1233,6 @@ static int CmdHF14AMfRestore(const char *Cmd) {
|
||||
for (uint8_t b = 0; b < mfNumBlocksPerSector(s); b++) {
|
||||
|
||||
uint8_t bldata[MFBLOCK_SIZE] = {0x00};
|
||||
|
||||
memcpy(bldata, dump, MFBLOCK_SIZE);
|
||||
|
||||
// if sector trailer
|
||||
@@ -1209,6 +1259,13 @@ static int CmdHF14AMfRestore(const char *Cmd) {
|
||||
PrintAndLogEx(WARNING, "Invalid Access Conditions on sector %i, replacing by default values", s);
|
||||
memcpy(bldata + 6, "\xFF\x07\x80\x69", 4);
|
||||
}
|
||||
|
||||
// Warn if ACL is strict read-only
|
||||
for (uint8_t foo = 0; foo < mfNumBlocksPerSector(s); foo++) {
|
||||
if (mfReadOnlyAccessConditions(foo, &bldata[6])) {
|
||||
PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on block " _YELLOW_("%u") " detected", foo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bytes_read) {
|
||||
@@ -6818,6 +6875,7 @@ static int CmdHF14AMfView(const char *Cmd) {
|
||||
|
||||
if (verbose) {
|
||||
mf_print_keys(block_cnt, dump);
|
||||
mf_analyse_acl(block_cnt, dump);
|
||||
}
|
||||
|
||||
int sector = DetectHID(dump, 0x4910);
|
||||
@@ -6836,7 +6894,7 @@ static int CmdHF14AMfView(const char *Cmd) {
|
||||
}
|
||||
|
||||
// allocate memory
|
||||
uint8_t* d = calloc(bytes_read, sizeof(uint8_t));
|
||||
uint8_t *d = calloc(bytes_read, sizeof(uint8_t));
|
||||
if (d == NULL) {
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
@@ -7324,8 +7382,8 @@ static int CmdHF14AGen4Save(const char *Cmd) {
|
||||
int fnlen = 0;
|
||||
char filename[FILE_PATH_SIZE];
|
||||
CLIParamStrToBuf(arg_get_str(ctx, 6), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
|
||||
|
||||
bool fill_emulator = arg_get_lit(ctx,7);
|
||||
|
||||
bool fill_emulator = arg_get_lit(ctx, 7);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// validations
|
||||
@@ -7420,12 +7478,12 @@ static int CmdHF14AGen4Save(const char *Cmd) {
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
|
||||
if (fill_emulator) {
|
||||
PrintAndLogEx(INFO, "uploading to emulator memory" NOLF);
|
||||
// fast push mode
|
||||
g_conn.block_after_ACK = true;
|
||||
|
||||
|
||||
size_t offset = 0;
|
||||
int cnt = 0;
|
||||
uint16_t bytes_left = bytes ;
|
||||
@@ -7454,7 +7512,7 @@ static int CmdHF14AGen4Save(const char *Cmd) {
|
||||
offset += MFBLOCK_SIZE;
|
||||
bytes_left -= MFBLOCK_SIZE;
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(SUCCESS, "uploaded " _YELLOW_("%d") " bytes to emulator memory", bytes);
|
||||
}
|
||||
|
||||
@@ -4154,7 +4154,7 @@ static int CmdHF14AMfuEView(const char *Cmd) {
|
||||
|
||||
if (override_end) {
|
||||
++end ;
|
||||
} else {
|
||||
} else {
|
||||
end = dump->pages ;
|
||||
}
|
||||
|
||||
|
||||
@@ -857,12 +857,12 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
||||
memcpy(htd.pwd.password, key, sizeof(htd.pwd.password));
|
||||
PrintAndLogEx(INFO, "Authenticating in password mode");
|
||||
}
|
||||
|
||||
|
||||
uint16_t cmd = CMD_LF_HITAG_READER;
|
||||
clearCommandBuffer();
|
||||
SendCommandMIX(cmd, htf, 0, 0, &htd, sizeof(htd));
|
||||
PacketResponseNG resp;
|
||||
|
||||
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
return PM3_ETIMEOUT;
|
||||
|
||||
@@ -404,7 +404,7 @@ static int CmdScriptRun(const char *Cmd) {
|
||||
PyImport_AppendInittab("_pm3", PyInit__pm3);
|
||||
#endif
|
||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 10
|
||||
Py_Initialize();
|
||||
Py_Initialize();
|
||||
#else
|
||||
PyConfig py_conf;
|
||||
PyConfig_InitIsolatedConfig(&py_conf);
|
||||
|
||||
@@ -900,16 +900,16 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
||||
|
||||
if (use_us) {
|
||||
PrintAndLogEx(NORMAL, " %10.1f | %10.1f | %s |fdt (Frame Delay Time): " _YELLOW_("%.1f"),
|
||||
(float)time1 / 13.56,
|
||||
(float)time2 / 13.56,
|
||||
" ",
|
||||
(float)(next_hdr->timestamp - end_of_transmission_timestamp) / 13.56);
|
||||
(float)time1 / 13.56,
|
||||
(float)time2 / 13.56,
|
||||
" ",
|
||||
(float)(next_hdr->timestamp - end_of_transmission_timestamp) / 13.56);
|
||||
} else {
|
||||
PrintAndLogEx(NORMAL, " %10u | %10u | %s |fdt (Frame Delay Time): " _YELLOW_("%d"),
|
||||
time1,
|
||||
time2,
|
||||
" ",
|
||||
(next_hdr->timestamp - end_of_transmission_timestamp));
|
||||
time1,
|
||||
time2,
|
||||
" ",
|
||||
(next_hdr->timestamp - end_of_transmission_timestamp));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+27
-12
@@ -74,22 +74,37 @@ AccessConditions_t MFAccessConditionsTrailer[] = {
|
||||
};
|
||||
|
||||
bool mfValidateAccessConditions(const uint8_t *data) {
|
||||
uint8_t ndata1 = (data[0]) & 0x0f;
|
||||
uint8_t ndata2 = (data[0] >> 4) & 0x0f;
|
||||
uint8_t ndata3 = (data[1]) & 0x0f;
|
||||
uint8_t data1 = (data[1] >> 4) & 0x0f;
|
||||
uint8_t data2 = (data[2]) & 0x0f;
|
||||
uint8_t data3 = (data[2] >> 4) & 0x0f;
|
||||
uint8_t nd1 = NIBBLE_LOW(data[0]);
|
||||
uint8_t nd2 = NIBBLE_HIGH(data[0]);
|
||||
uint8_t nd3 = NIBBLE_LOW(data[1]);
|
||||
uint8_t d1 = NIBBLE_HIGH(data[1]);
|
||||
uint8_t d2 = NIBBLE_LOW(data[2]);
|
||||
uint8_t d3 = NIBBLE_HIGH(data[2]);
|
||||
|
||||
return ((ndata1 == (data1 ^ 0xF)) && (ndata2 == (data2 ^ 0xF)) && (ndata3 == (data3 ^ 0xF)));
|
||||
return ((nd1 == (d1 ^ 0xF)) && (nd2 == (d2 ^ 0xF)) && (nd3 == (d3 ^ 0xF)));
|
||||
}
|
||||
bool mfReadOnlyAccessConditions(uint8_t blockn, const uint8_t *data) {
|
||||
|
||||
uint8_t d1 = NIBBLE_HIGH(data[1]) >> blockn;
|
||||
uint8_t d2 = NIBBLE_LOW(data[2]) >> blockn;
|
||||
uint8_t d3 = NIBBLE_HIGH(data[2]) >> blockn;
|
||||
uint8_t cond = (d1 & 0x01) << 2 | (d2 & 0x01) << 1 | (d3 & 0x01);
|
||||
|
||||
if (blockn == 3) {
|
||||
if ((cond == 0x02) || (cond == 0x06) || (cond == 0x07)) return true;
|
||||
} else {
|
||||
if ((cond == 0x02) || (cond == 0x05)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data) {
|
||||
uint8_t data1 = ((data[1] >> 4) & 0x0f) >> blockn;
|
||||
uint8_t data2 = ((data[2]) & 0x0f) >> blockn;
|
||||
uint8_t data3 = ((data[2] >> 4) & 0x0f) >> blockn;
|
||||
|
||||
uint8_t cond = (data1 & 0x01) << 2 | (data2 & 0x01) << 1 | (data3 & 0x01);
|
||||
const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data) {
|
||||
uint8_t d1 = NIBBLE_HIGH(data[1]) >> blockn;
|
||||
uint8_t d2 = NIBBLE_LOW(data[2]) >> blockn;
|
||||
uint8_t d3 = NIBBLE_HIGH(data[2]) >> blockn;
|
||||
|
||||
uint8_t cond = (d1 & 0x01) << 2 | (d2 & 0x01) << 1 | (d3 & 0x01);
|
||||
|
||||
if (blockn == 3) {
|
||||
for (int i = 0; i < ARRAYLEN(MFAccessConditionsTrailer); i++)
|
||||
|
||||
@@ -71,6 +71,7 @@ int MFPGetSignature(bool activateField, bool leaveSignalON, uint8_t *dataout, in
|
||||
int MFPGetVersion(bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
|
||||
|
||||
bool mfValidateAccessConditions(const uint8_t *data);
|
||||
bool mfReadOnlyAccessConditions(uint8_t blockn, const uint8_t *data);
|
||||
const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data);
|
||||
|
||||
uint8_t mfNumBlocksPerSector(uint8_t sectorNo);
|
||||
|
||||
@@ -349,6 +349,7 @@ const static vocabulory_t vocabulory[] = {
|
||||
{ 0, "hf mf gen3freeze" },
|
||||
{ 0, "hf mf ggetblk" },
|
||||
{ 0, "hf mf gload" },
|
||||
{ 0, "hf mf gsave" },
|
||||
{ 0, "hf mf gsetblk" },
|
||||
{ 0, "hf mf gview" },
|
||||
{ 0, "hf mf ndefformat" },
|
||||
@@ -736,6 +737,11 @@ const static vocabulory_t vocabulory[] = {
|
||||
{ 0, "nfc barcode read" },
|
||||
{ 0, "nfc barcode sim" },
|
||||
{ 1, "nfc barcode help" },
|
||||
{ 1, "piv help" },
|
||||
{ 0, "piv select" },
|
||||
{ 0, "piv getdata" },
|
||||
{ 0, "piv scan" },
|
||||
{ 1, "piv list" },
|
||||
{ 1, "smart help" },
|
||||
{ 1, "smart list" },
|
||||
{ 0, "smart info" },
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ typedef enum emojiMode {EMO_ALIAS, EMO_EMOJI, EMO_ALTTEXT, EMO_NONE} emojiMode_t
|
||||
typedef enum clientdebugLevel {cdbOFF, cdbSIMPLE, cdbFULL} clientdebugLevel_t;
|
||||
// typedef enum devicedebugLevel {ddbOFF, ddbERROR, ddbINFO, ddbDEBUG, ddbEXTENDED} devicedebugLevel_t;
|
||||
|
||||
// last item spItemCount used to auto map to number of files
|
||||
// last item spItemCount used to auto map to number of files
|
||||
typedef enum savePaths {spDefault, spDump, spTrace, spItemCount} savePaths_t;
|
||||
typedef struct {int x; int y; int h; int w;} qtWindow_t;
|
||||
|
||||
|
||||
Reference in new issue
Block a user