make style

This commit is contained in:
Philippe Teuwen committed 2026-04-13 09:35:02 +02:00
1 parent 06bedd410e
commit 88d20bd4f2
31 files changed
+369 -329

No files matched your search

+2 -2
View File
@@ -301,14 +301,14 @@ void RunMod(void) {
if (iso14443a_select_card(NULL, &card_a_info, NULL, true, 0, false)) {
DbpString(_YELLOW_("+") "Found ISO 14443 Type A!");
chktoken = false;
for (uint8_t i = 0; i < 4; i++) {
if (i == 3 && chktoken) {
break; // Tag 57 was already found in GPO, no need to issue READ RECORD
}
LED_C_OFF();
LED_B_ON();
uint8_t apdulen = iso14_apdu(apdus[i], (uint16_t) apduslen[i], false, apdubuffer, sizeof(apdubuffer), NULL);
+4 -4
View File
@@ -105,8 +105,8 @@ int tearoff_hook(void) {
if (g_tearoff_enabled == false) {
return PM3_SUCCESS;
}
}
// tear off is happening...
if (g_tearoff_delay_us == 0) {
@@ -2477,8 +2477,8 @@ static void PacketReceived(PacketCommandNG *packet) {
// sanity checks
if (payload->bytes_in_packet > sizeof(payload->data) ||
payload->idx > BigBuf_get_size() ||
payload->idx + payload->bytes_in_packet > BigBuf_get_size()) {
payload->idx > BigBuf_get_size() ||
payload->idx + payload->bytes_in_packet > BigBuf_get_size()) {
reply_ng(CMD_SMART_UPLOAD, PM3_EOVFLOW, NULL, 0);
break;
}
+3 -3
View File
@@ -540,8 +540,8 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
// in emulator memory. We pick it up at the start of each anti-collision
// cycle so the reader sees the new identity from the very first SELECT.
if ((simulationMode == ICLASS_SIM_MODE_FULL ||
simulationMode == ICLASS_SIM_MODE_FULL_GLITCH ||
simulationMode == ICLASS_SIM_MODE_FULL_GLITCH_KEY) &&
simulationMode == ICLASS_SIM_MODE_FULL_GLITCH ||
simulationMode == ICLASS_SIM_MODE_FULL_GLITCH_KEY) &&
emulator[32 * 8] != 0) {
emulator[32 * 8] = 0; // consume the flag
@@ -1429,7 +1429,7 @@ static bool select_iclass_tag_ex(picopass_hdr_t *hdr, bool use_credit_key, uint3
AddCrc(pagesel + 1, 1);
bool pagesel_res = iclass_send_cmd_with_retries(pagesel, sizeof(pagesel), pagesel_resp, sizeof(resp),
10, 2, &start_time, ICLASS_READER_TIMEOUT_OTHERS, eof_time, shallow_mod);
10, 2, &start_time, ICLASS_READER_TIMEOUT_OTHERS, eof_time, shallow_mod);
if (pagesel_res == false) {
return false;
+29 -29
View File
@@ -1498,7 +1498,7 @@ bool SimulateIso14443aInit(uint8_t tagType, uint16_t flags, uint8_t *data,
}
// Apply SAK override before it is encoded into rSAKc1/2/3.
if ( (flags & FLAG_SAK_IN_DATA) == FLAG_SAK_IN_DATA) {
if ((flags & FLAG_SAK_IN_DATA) == FLAG_SAK_IN_DATA) {
sak = s_sak_override;
}
@@ -2322,24 +2322,24 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u
EmSend4bit(CARD_ACK);
Dbprintf("MFP Perso Key | %04X | %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
page,
receivedCmd[3],
receivedCmd[4],
receivedCmd[5],
receivedCmd[6],
receivedCmd[7],
receivedCmd[8],
receivedCmd[9],
receivedCmd[10],
receivedCmd[11],
receivedCmd[12],
receivedCmd[13],
receivedCmd[14],
receivedCmd[15],
receivedCmd[16],
receivedCmd[17],
receivedCmd[18]
);
page,
receivedCmd[3],
receivedCmd[4],
receivedCmd[5],
receivedCmd[6],
receivedCmd[7],
receivedCmd[8],
receivedCmd[9],
receivedCmd[10],
receivedCmd[11],
receivedCmd[12],
receivedCmd[13],
receivedCmd[14],
receivedCmd[15],
receivedCmd[16],
receivedCmd[17],
receivedCmd[18]
);
numReads++; // Increment number of times reader requested a block
@@ -3836,7 +3836,7 @@ void ReaderIso14443a(PacketCommandNG *c) {
// Force explicit parity
lenbits = len * 8;
}
if (lenbits > 0) {
// want to send a specific number of bits (e.g. short commands)
@@ -3847,12 +3847,12 @@ void ReaderIso14443a(PacketCommandNG *c) {
uint16_t i = 0;
// first byte is always short (7bits) and no parity
ReaderTransmitBitsPar(&cmd[i++], MIN(bits_to_send, 7), NULL, NULL);
ReaderTransmitBitsPar(&cmd[i++], MIN(bits_to_send, 7), NULL, NULL);
bits_to_send -= 7;
while (bits_to_send > 0) {
// following bytes are 8 bit and no parity
ReaderTransmitBitsPar(&cmd[i++], MIN(bits_to_send, 8), NULL, NULL);
ReaderTransmitBitsPar(&cmd[i++], MIN(bits_to_send, 8), NULL, NULL);
bits_to_send -= 8;
}
@@ -3862,28 +3862,28 @@ void ReaderIso14443a(PacketCommandNG *c) {
mf_crypto1_encrypt(&crypto1_state, cmd, len, parity_array);
}
// bytes are 8 bit with odd parity
ReaderTransmitBitsPar(cmd, lenbits, parity_array, NULL);
ReaderTransmitBitsPar(cmd, lenbits, parity_array, NULL);
}
} else {
// want to send complete bytes only
if ((param & ISO14A_TOPAZMODE) == ISO14A_TOPAZMODE) {
size_t i = 0;
// first byte: 7 bits, no paritiy
ReaderTransmitBitsPar(&cmd[i++], 7, NULL, NULL);
ReaderTransmitBitsPar(&cmd[i++], 7, NULL, NULL);
while (i < len) {
// following bytes: 8 bits, no paritiy
ReaderTransmitBitsPar(&cmd[i++], 8, NULL, NULL);
ReaderTransmitBitsPar(&cmd[i++], 8, NULL, NULL);
}
} else {
// 8 bits, odd parity
ReaderTransmit(cmd, len, NULL);
ReaderTransmit(cmd, len, NULL);
}
}
+1 -1
View File
@@ -219,7 +219,7 @@ extern iso14a_polling_parameters_t REQA_POLLING_PARAMETERS;
#define DELAY_READER_AIR2ARM_AS_SNIFFER (2 + 3 + 8)
// Maximum ISO 14443A protocol timeout in field cycles (1/13.56 MHz).
#define MAX_ISO14A_TIMEOUT 524288
#define MAX_ISO14A_TIMEOUT 524288
// this timeout is in MS
#endif /* __ISO14443A_H */
+17 -33
View File
@@ -771,8 +771,7 @@ static int RAMFUNC Handle15693FSKSamplesFromTag(uint8_t freq, DecodeTagFSK_t *De
DecodeTag->count = 1;
} else if (FREQ_IS_424(freq) && !MAX_COUNT(DecodeTag->count, recv_speed)) { // still in SOF at 424
DecodeTag->count++;
}
else { // SOF failed, roll back
} else { // SOF failed, roll back
#ifdef DEBUG
if (DEBUG) {
Dbprintf("SOF_424 failed: freq=%d, count=%d, recv_speed=%d", freq, DecodeTag->count, recv_speed);
@@ -788,8 +787,7 @@ static int RAMFUNC Handle15693FSKSamplesFromTag(uint8_t freq, DecodeTagFSK_t *De
DecodeTag->count = 1;
} else if (FREQ_IS_484(freq) && !MAX_COUNT(DecodeTag->count, recv_speed)) { // still in SOF_END_484
DecodeTag->count++;
}
else { // SOF failed, roll back
} else { // SOF failed, roll back
#ifdef DEBUG
if (DEBUG) {
Dbprintf("SOF_END_484 failed: freq=%d, count=%d, recv_speed=%d", freq, DecodeTag->count, recv_speed);
@@ -813,8 +811,7 @@ static int RAMFUNC Handle15693FSKSamplesFromTag(uint8_t freq, DecodeTagFSK_t *De
LED_C_ON();
} else if (FREQ_IS_424(freq) && !MAX_COUNT(DecodeTag->count, recv_speed)) { // still in SOF_END_424
DecodeTag->count++;
}
else { // SOF failed, roll back
} else { // SOF failed, roll back
#ifdef DEBUG
if (DEBUG) {
Dbprintf("SOF_END_424 failed: freq=%d, count=%d, recv_speed=%d", freq, DecodeTag->count, recv_speed);
@@ -940,8 +937,7 @@ static int RAMFUNC Handle15693FSKSamplesFromTag(uint8_t freq, DecodeTagFSK_t *De
DecodeTag->count = 2;
} else if (FREQ_IS_484(freq) && !MAX_COUNT(DecodeTag->count, recv_speed)) { // still at 484
DecodeTag->count++;
}
else { // error
} else { // error
#ifdef DEBUG
if (DEBUG) {
Dbprintf("RECEIVING_DATA_484 error: freq=%d, count=%d, recv_speed=%d, lastbit=%d, state=%d", freq, DecodeTag->count, recv_speed, DecodeTag->lastBit, DecodeTag->state);
@@ -1572,7 +1568,7 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
}
if ((dr->state == STATE_READER_UNSYNCD ||
dr->state == STATE_READER_AWAIT_1ST_FALLING_EDGE_OF_SOF) &&
dr->state == STATE_READER_AWAIT_1ST_FALLING_EDGE_OF_SOF) &&
data_available()) {
dr->byteCount = -2;
break;
@@ -2046,8 +2042,7 @@ static void DbdecodeIso15693Answer(int n, const uint8_t *d) {
if (CheckCrc15(d, n)) {
strncat(status, "[+] crc ( " _GREEN_("ok") " )", DBD15STATLEN - strlen(status));
}
else {
} else {
strncat(status, "[!] crc ( " _RED_("fail") " )", DBD15STATLEN - strlen(status));
}
@@ -2468,8 +2463,7 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
pageNum = cmd[cmdCpt++];
if (pageNum >= tag->pagesCount) {
error = ISO15_ERROR_BLOCK_UNAVAILABLE;
}
else {
} else {
recv[0] = ISO15_NOERROR;
recvLen = 1;
if ((cmd[0] & ISO15_REQ_OPTION) == ISO15_REQ_OPTION) { // ask for lock status
@@ -2489,8 +2483,7 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
pageNum = cmd[cmdCpt++];
if (pageNum >= tag->pagesCount) {
error = ISO15_ERROR_BLOCK_UNAVAILABLE;
}
else {
} else {
for (uint8_t i = 0 ; i < tag->bytesPerPage ; i++) {
tag->data[(pageNum * tag->bytesPerPage) + i] = cmd[i + cmdCpt];
}
@@ -2505,11 +2498,9 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
pageNum = cmd[cmdCpt++];
if (pageNum >= tag->pagesCount) {
error = ISO15_ERROR_BLOCK_UNAVAILABLE;
}
else if (tag->locks[pageNum]) {
} else if (tag->locks[pageNum]) {
error = ISO15_ERROR_BLOCK_LOCKED_ALREADY;
}
else {
} else {
tag->locks[pageNum] = 1;
recv[0] = ISO15_NOERROR;
recvLen = 1;
@@ -2523,8 +2514,7 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
nbPages = cmd[cmdCpt++];
if (pageNum + nbPages >= tag->pagesCount) {
error = ISO15_ERROR_BLOCK_UNAVAILABLE;
}
else {
} else {
recv[0] = ISO15_NOERROR;
recvLen = 1;
for (int i = 0 ; i < (nbPages + 1) * tag->bytesPerPage && \
@@ -2545,8 +2535,7 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
}
if (tag->afiLock) {
error = ISO15_ERROR_BLOCK_LOCKED;
}
else {
} else {
tag->afi = cmd[cmdCpt++];
recv[0] = ISO15_NOERROR;
recvLen = 1;
@@ -2558,8 +2547,7 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
}
if (tag->afiLock) {
error = ISO15_ERROR_BLOCK_LOCKED_ALREADY;
}
else {
} else {
tag->afiLock = true;
recv[0] = ISO15_NOERROR;
recvLen = 1;
@@ -2571,8 +2559,7 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
}
if (tag->dsfidLock) {
error = ISO15_ERROR_BLOCK_LOCKED;
}
else {
} else {
tag->dsfid = cmd[cmdCpt++];
recv[0] = ISO15_NOERROR;
recvLen = 1;
@@ -2584,8 +2571,7 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
}
if (tag->dsfidLock) {
error = ISO15_ERROR_BLOCK_LOCKED_ALREADY;
}
else {
} else {
tag->dsfidLock = true;
recv[0] = ISO15_NOERROR;
recvLen = 1;
@@ -2629,8 +2615,7 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
nbPages = cmd[cmdCpt++];
if (pageNum + nbPages >= tag->pagesCount) {
error = ISO15_ERROR_BLOCK_UNAVAILABLE;
}
else {
} else {
recv[0] = ISO15_NOERROR;
recvLen = 1;
for (uint8_t i = 0 ; i < nbPages + 1 ; i++) {
@@ -3319,8 +3304,7 @@ static uint32_t pass_protect_EASAFI_15693_Slix(uint32_t start_time, uint32_t *eo
if (set_option_flag) {
flags = ISO15_REQ_DATARATE_HIGH | ISO15_REQ_OPTION;
}
else {
} else {
flags = ISO15_REQ_DATARATE_HIGH;
}
+1 -1
View File
@@ -179,7 +179,7 @@ uint16_t mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t
}
if (pcs && (crypted == CRYPT_ALL)) {
if (len == 1) {
uint16_t res = 0;
res |= (crypto1_bit(pcs, 0, 0) ^ BIT(answer[0], 0)) << 0;
+17 -8
View File
@@ -142,7 +142,8 @@ static void scp02_get_base_key(uint8_t type, uint8_t *out16) {
// 0x01,0x81=DEK). The session counter is from the current INIT UPDATE.
static void derive_scp02_session_key(const uint8_t *base_key16, uint8_t c0, uint8_t c1, uint16_t sc, uint8_t *out16) {
uint8_t deriv[16] = {c0, c1, (uint8_t)(sc >> 8), (uint8_t)(sc & 0xFF),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
uint8_t iv[8] = {0};
tdes_nxp_send(deriv, out16, 16, base_key16, iv, 2);
}
@@ -226,12 +227,17 @@ static void compute_host_cryptogram(const uint8_t *s_enc, uint8_t *out) {
// C-MAC = Retail-MAC(S-MAC, {84 82 sec_level 00 10 || HostCrypto(8) || 80 00 00})
static void compute_ext_auth_cmac(const uint8_t *s_mac, uint8_t sec_level,
const uint8_t *host_crypto, uint8_t *out) {
const uint8_t *host_crypto, uint8_t *out) {
uint8_t data[16];
data[0] = 0x84; data[1] = 0x82; data[2] = sec_level;
data[3] = 0x00; data[4] = 0x10;
data[0] = 0x84;
data[1] = 0x82;
data[2] = sec_level;
data[3] = 0x00;
data[4] = 0x10;
memcpy(data + 5, host_crypto, 8);
data[13] = 0x80; data[14] = 0x00; data[15] = 0x00;
data[13] = 0x80;
data[14] = 0x00;
data[15] = 0x00;
scp02_retail_mac(s_mac, data, 2, out);
}
@@ -336,9 +342,11 @@ bool hid_config_card_handle_iblock(const uint8_t *cmd, int len, tag_response_inf
if (memcmp(host_crypto_exp, host_crypto, 8) != 0 ||
memcmp(cmac_exp, cmac_recv, 8) != 0) {
rsp[0] = 0x63; rsp[1] = 0x00; // Authentication failed
rsp[0] = 0x63;
rsp[1] = 0x00; // Authentication failed
} else {
rsp[0] = 0x90; rsp[1] = 0x00;
rsp[0] = 0x90;
rsp[1] = 0x00;
}
ri->response_n = off + 2;
return true;
@@ -349,7 +357,8 @@ bool hid_config_card_handle_iblock(const uint8_t *cmd, int len, tag_response_inf
memcpy(rsp, s_default_resp, s_default_resp_len);
ri->response_n = off + s_default_resp_len;
} else {
rsp[0] = 0x90; rsp[1] = 0x00;
rsp[0] = 0x90;
rsp[1] = 0x00;
ri->response_n = off + 2;
}
return true;
+3 -3
View File
@@ -59,9 +59,9 @@ typedef struct {
uint8_t sak; // SAK override
uint8_t scp02_key[16]; // SCP02 master key (from JSON "SCP02Key")
uint8_t kdd[10]; // 10-byte Key Diversification Data returned in INITIALIZE UPDATE.
// All-zero = legacy "no diversification" mode (scp02_key used directly).
// Any non-zero value enables VISA-2 diversification of scp02_key per
// SCP02 type (0x01=ENC, 0x02=MAC) on every handshake.
// All-zero = legacy "no diversification" mode (scp02_key used directly).
// Any non-zero value enables VISA-2 diversification of scp02_key per
// SCP02 type (0x01=ENC, 0x02=MAC) on every handshake.
uint8_t kvn; // Key Version Number emitted in INIT UPDATE response (JSON "KVN", default 0x01).
uint8_t ats[20]; // ATS bytes without CRC (from JSON "ATS")
uint8_t ats_len; // actual number of valid bytes in ats[]
+5 -5
View File
@@ -372,13 +372,13 @@ void SimulateSeos(seos_emulate_req_t *msg) {
while (tlv_offset + 2 <= received_tlv_len) {
uint8_t tag = received_tlv[tlv_offset++];
uint8_t length = received_tlv[tlv_offset++];
if (length > received_tlv_len - tlv_offset) {
break;
}
uint8_t *value = &received_tlv[tlv_offset];
if (tag == 0x06) {
if (length == msg->oid_len && memcmp(value, msg->oid, length) == 0) {
@@ -631,9 +631,9 @@ void SimulateSeos(seos_emulate_req_t *msg) {
// Check all requested OIDs and see if we support any
uint8_t tlv_offset = 0;
while (tlv_offset + 2 <= received_tlv_len) {
uint8_t tag = received_tlv[tlv_offset];
uint8_t length = received_tlv[tlv_offset + 1];
if (length > received_tlv_len - tlv_offset - 2) {
break;
@@ -649,7 +649,7 @@ void SimulateSeos(seos_emulate_req_t *msg) {
recvd_cmac_length = length;
recvd_cmac_offset = tlv_offset;
}
tlv_offset += 2 + length;
}
+2 -2
View File
@@ -72,7 +72,7 @@ function main(args)
if o == 'w' then width = a end
end
-- sanitize lua args parsing
-- sanitize lua args parsing
data = data or '01020304'
width = width or 0
search = search or 0
@@ -110,7 +110,7 @@ function main(args)
results[#results+1] = {i, a1, a2, a3, a4, a5, a6}
for _, v in ipairs({a1, a2, a3, a4, a5, a6}) do
if #v > maxlen then
if #v > maxlen then
maxlen = #v
end
end
+8 -8
View File
@@ -67,7 +67,7 @@ def read_counter(counter_numb):
counter_bytes = bytes.fromhex(counter)
counter_int = int.from_bytes(counter_bytes, byteorder='little')
return counter, counter_int
def enable_tearoff(delay):
p.console(f"hw tearoff --delay {delay}")
p.console("hw tearoff --on", capture=True)
@@ -96,12 +96,12 @@ def some_tests(counter_numb):
except:
print(f"[{color('!', 'red')}] Support only Mifare UL EV1 cards")
return False
tearing = check_tearing_event(counter_number)[1]
if tearing != "00" and tearing != "BD":
print(f"[{color('!', 'red')}] Looks like you're card doesn't support CHECK_TEARING_EVENT")
return False
counter_str, counter = read_counter(counter_number)
if counter == 16777215:
print(f"[{color('!', 'red')}] The counter value is at its maximum, it cannot be reset")
@@ -109,7 +109,7 @@ def some_tests(counter_numb):
elif counter == 0:
print(f"[{color('!', 'red')}] The counter value is already at the minimum level")
return False
if counter_str[:4] == "0000":
print(f"\n[{color('+', 'green')}] First two bytes set to 00, skip")
byte = 3
@@ -123,7 +123,7 @@ if __name__ == "__main__":
if not args.force and not some_tests(counter_number):
print(f"[{color('?', 'goldenrod')}] Try `{color(f'script run {ProgramName} -f True', 'goldenrod')}` if this is a script bug", end="")
sys.exit(0)
if args.DelayBD == None:
for Delay_BD in range(1000, 5000, args.inc):
initial_counter_str, initial_counter_int = read_counter(counter_number)
@@ -153,7 +153,7 @@ if __name__ == "__main__":
else:
Delay_00 = args.Delay00
print(f"[{color('+', 'green')}] Work delay for 00: {color(Delay_00, 'green')} us")
constant_counter_int = read_counter(counter_number)[1]
while True:
initial_counter_str, initial_counter_int = read_counter(counter_number)
@@ -171,7 +171,7 @@ if __name__ == "__main__":
final_counter_str, final_counter_int = read_counter(counter_number)
check_tearing, check_tearing_clear = check_tearing_event(counter_number)
attempt+=1
print(f"\r[{color('=', 'goldenrod')}] Attempt: {color(attempt, 'green')} | Delay BD/00: {color(Delay_BD, 'yellow')}/{color(Delay_00, 'yellow')} us | Check tearing: {color(check_tearing_clear, 'yellow')} | Counter changing: {color(initial_counter_str.upper(), 'red') if initial_counter_int <= final_counter_int else color(initial_counter_str.upper(), 'green')}==>{color(final_counter_str.upper(), 'red') if initial_counter_int <= final_counter_int else color(final_counter_str.upper(), 'green')}", end="", flush=True)
@@ -221,4 +221,4 @@ if __name__ == "__main__":
print(f"[{color('+', 'green')}] Check tearing: {color(check_tearing_clear, 'green')}")
print(f"\n[{color('+', 'green')}] Exploit successfull\n[{color('=', 'goldenrod')}] - Initial counter: {initial_counter_str.upper()}\n[{color('=', 'goldenrod')}] - Final counter: {color(final_counter_str.upper(), 'green')}\n[{color('=', 'goldenrod')}] - Counter changing: {initial_counter_int - final_counter_int}\n[{color('=', 'goldenrod')}] - Check tearing: {color(check_tearing_clear, 'green')}", end="")
sys.exit(0)
sys.exit(0)
+1 -1
View File
@@ -946,7 +946,7 @@ static int StCheckSig(uint8_t *uid) {
uint8_t signature[16];
size_t signature_len = 0;
hexstr_to_byte_array(signature_hex, signature, &signature_len);
uint8_t uid_swap[ISO15693_UID_LENGTH];
reverse_array_copy(uid, ISO15693_UID_LENGTH, uid_swap);
+61 -61
View File
@@ -180,12 +180,12 @@ typedef struct {
typedef int (*felica_node_discovery_visitor_t)(const felica_discovered_node_t *node, void *ctx);
typedef bool (*felica_node_discovery_runner_t)(uint8_t *flags,
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status);
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status);
typedef struct {
felica_node_discovery_method_t method;
@@ -221,29 +221,29 @@ typedef enum {
static int CmdHelp(const char *Cmd);
static void clear_and_send_command(uint8_t flags, uint16_t datalen, uint8_t *data, bool verbose);
static int send_felica_payload_with_retries(uint8_t flags, uint16_t datalen, uint8_t *data, bool verbose,
int expected_response_cmd, uint32_t timeout_ms, uint32_t retries, uint32_t backoff_ms, bool logging,
PacketResponseNG *resp, const char *request_name);
int expected_response_cmd, uint32_t timeout_ms, uint32_t retries, uint32_t backoff_ms, bool logging,
PacketResponseNG *resp, const char *request_name);
static bool felica_discover_nodes_with_request_code_list(uint8_t *flags,
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status);
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status);
static bool felica_discover_nodes_with_search_service_code(uint8_t *flags,
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status);
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status);
static bool felica_discover_nodes_with_request_service(uint8_t *flags,
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status);
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status);
static bool felica_discover_nodes_with_read_without_encryption(uint8_t *flags,
const uint8_t *idm,
uint32_t retry_count,
@@ -956,7 +956,7 @@ static int CmdHFFelicaReader(const char *Cmd) {
if (cm) {
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " to exit");
}
return read_felica_uid(cm, verbose);
}
@@ -1461,8 +1461,8 @@ static void print_read_without_encryption_response(felica_read_without_encryptio
* @return PM3_SUCCESS on success
*/
static int send_felica_payload_with_retries(uint8_t flags, uint16_t datalen, uint8_t *data, bool verbose,
int expected_response_cmd, uint32_t timeout_ms, uint32_t retries, uint32_t backoff_ms, bool logging,
PacketResponseNG *resp, const char *request_name) {
int expected_response_cmd, uint32_t timeout_ms, uint32_t retries, uint32_t backoff_ms, bool logging,
PacketResponseNG *resp, const char *request_name) {
for (uint32_t attempt = 0; attempt <= retries; attempt++) {
if (attempt > 0) {
if (logging) {
@@ -1526,10 +1526,10 @@ int send_request_service(uint8_t flags, uint16_t datalen, uint8_t *data, bool ve
}
PacketResponseNG resp;
if (send_felica_payload_with_retries(flags, datalen, data, verbose,
0x03,
FELICA_DEFAULT_TIMEOUT_MS, 0,
0, true,
&resp, "request service") != PM3_SUCCESS) {
0x03,
FELICA_DEFAULT_TIMEOUT_MS, 0,
0, true,
&resp, "request service") != PM3_SUCCESS) {
PrintAndLogEx(ERR, "\nGot no response from card");
return PM3_ERFTRANS;
}
@@ -1882,12 +1882,12 @@ static void felica_print_node_discovery_method_used(felica_node_discovery_method
}
static bool felica_discover_nodes_with_request_code_list(uint8_t *flags,
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status) {
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status) {
uint8_t data[14] = {0};
data[0] = sizeof(data);
@@ -2000,12 +2000,12 @@ static bool felica_discover_nodes_with_request_code_list(uint8_t *flags,
}
static bool felica_discover_nodes_with_search_service_code(uint8_t *flags,
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status) {
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status) {
uint8_t data[12] = {0};
data[0] = sizeof(data);
@@ -2069,16 +2069,16 @@ static bool felica_discover_nodes_with_search_service_code(uint8_t *flags,
}
static bool felica_request_service_send_probe_batch(uint8_t *flags,
const uint8_t *idm,
uint32_t retry_count,
const uint16_t *node_codes_le,
const bool *is_area_nodes,
size_t node_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
bool *supported,
uint32_t *discovered_count,
int *stop_status) {
const uint8_t *idm,
uint32_t retry_count,
const uint16_t *node_codes_le,
const bool *is_area_nodes,
size_t node_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
bool *supported,
uint32_t *discovered_count,
int *stop_status) {
if (node_count == 0 || node_count > FELICA_REQUEST_SERVICE_DISCOVERY_BATCH_SIZE) {
return false;
}
@@ -2149,12 +2149,12 @@ static bool felica_request_service_send_probe_batch(uint8_t *flags,
}
static bool felica_discover_nodes_with_request_service(uint8_t *flags,
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status) {
const uint8_t *idm,
uint32_t retry_count,
felica_node_discovery_visitor_t visitor,
void *ctx,
uint32_t *discovered_count,
int *stop_status) {
bool supported = false;
uint32_t local_count = 0;
+2 -2
View File
@@ -875,7 +875,7 @@ static int hfgal_read_desfire_card(uint32_t aid, uint8_t *site_key, bool verbose
", card number: " _GREEN_("%u")
", issue level: " _GREEN_("%u"),
current_aid,
'A' + creds.region_code,
'A' + creds.region_code,
creds.region_code,
creds.facility_code,
creds.card_number,
@@ -1699,7 +1699,7 @@ static int CmdGallagherDecode(const char *cmd) {
", facility: " _GREEN_("%u")
", card number: " _GREEN_("%u")
", issue level: " _GREEN_("%u"),
'A' + creds.region_code,
'A' + creds.region_code,
creds.region_code,
creds.facility_code,
creds.card_number,
+2 -1
View File
@@ -1615,7 +1615,8 @@ static int gst_selftest_zlib(void) {
};
static const uint8_t loyalty_object_id[] = {0x04, 0x21, 0xC9, 0x4A, 0x51, 0x01, 0xE2, 0x5E, 0xAA};
static const uint8_t customer_id[] = {0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const size_t sample_decompressed_len = 1312;
static const size_t service_value_record_1_len = 1224;
static const size_t loyalty_record_len = 1206;
+100 -71
View File
@@ -1374,7 +1374,10 @@ static int CmdHFiClassTagSim(const char *Cmd) {
dump[1] = (uint8_t)((fc >> 4) ^ (cn & 0xFF) ^ 0x5C);
dump[2] = (uint8_t)((cn >> 16) ^ fc ^ 0x7F);
dump[3] = (uint8_t)((cn >> 8) ^ (fc << 3) ^ 0xE9);
dump[4] = 0xF7; dump[5] = 0xFF; dump[6] = 0x12; dump[7] = 0xE0;
dump[4] = 0xF7;
dump[5] = 0xFF;
dump[6] = 0x12;
dump[7] = 0xE0;
}
memcpy(csn, dump, 8);
@@ -1527,12 +1530,23 @@ static int CmdHFiClassTagSim(const char *Cmd) {
if (k == TAGSIM_KEY_NONE) { continue; }
switch (k) {
case TAGSIM_KEY_FC_INC: card.FacilityCode++; break;
case TAGSIM_KEY_FC_DEC: card.FacilityCode--; break;
case TAGSIM_KEY_CN_INC: card.CardNumber++; break;
case TAGSIM_KEY_CN_DEC: card.CardNumber--; break;
case TAGSIM_KEY_ABORT: running = false; break;
case TAGSIM_KEY_NONE: break;
case TAGSIM_KEY_FC_INC:
card.FacilityCode++;
break;
case TAGSIM_KEY_FC_DEC:
card.FacilityCode--;
break;
case TAGSIM_KEY_CN_INC:
card.CardNumber++;
break;
case TAGSIM_KEY_CN_DEC:
card.CardNumber--;
break;
case TAGSIM_KEY_ABORT:
running = false;
break;
case TAGSIM_KEY_NONE:
break;
}
// Rebuild CSN deterministically from new FC/CN
@@ -1543,7 +1557,10 @@ static int CmdHFiClassTagSim(const char *Cmd) {
csn[1] = (uint8_t)((fc >> 4) ^ (cn & 0xFF) ^ 0x5C);
csn[2] = (uint8_t)((cn >> 16) ^ fc ^ 0x7F);
csn[3] = (uint8_t)((cn >> 8) ^ (fc << 3) ^ 0xE9);
csn[4] = 0xF7; csn[5] = 0xFF; csn[6] = 0x12; csn[7] = 0xE0;
csn[4] = 0xF7;
csn[5] = 0xFF;
csn[6] = 0x12;
csn[7] = 0xE0;
}
// New diversified KD/KC for the new CSN
@@ -3841,7 +3858,7 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
return PM3_EINVARG;
}
} else {
PrintAndLogEx(SUCCESS, "Using Key... " _GREEN_("%s"), sprint_hex_inrow(key, sizeof(key)));
PrintAndLogEx(SUCCESS, "Using Key... " _GREEN_("%s"), sprint_hex_inrow(key, sizeof(key)));
}
if (data_len && data_len != 8) {
@@ -3906,7 +3923,7 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
if (shallow_mod) {
payload_rdr.flags |= FLAG_ICLASS_READER_SHALLOW_MOD;
}
clearCommandBuffer();
PacketResponseNG resp;
SendCommandNG(CMD_HF_ICLASS_READER, (uint8_t *)&payload_rdr, sizeof(iclass_card_select_t));
@@ -4308,28 +4325,28 @@ out:
static void iclass_read_interesting_data(uint8_t *key, uint8_t keyType, bool elite, bool rawkey, bool use_replay,
bool verbose, bool shallow_mod) {
bool auth = false;
uint8_t blockno = 3;
uint8_t kd_read[8] = {0};
iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, auth, shallow_mod, kd_read, false, false);
bool auth = false;
uint8_t blockno = 3;
uint8_t kd_read[8] = {0};
iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, auth, shallow_mod, kd_read, false, false);
blockno = 4;
uint8_t kc_read[8] = {0};
iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, auth, shallow_mod, kc_read, false, false);
blockno = 4;
uint8_t kc_read[8] = {0};
iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, auth, shallow_mod, kc_read, false, false);
PrintAndLogEx(SUCCESS, "Raw Debit Key.............. " _YELLOW_("%s"), sprint_hex_inrow(kd_read, sizeof(kd_read)));
PrintAndLogEx(SUCCESS, "Raw Credit Key............. " _YELLOW_("%s"), sprint_hex_inrow(kc_read, sizeof(kc_read)));
PrintAndLogEx(SUCCESS, "Raw Debit Key.............. " _YELLOW_("%s"), sprint_hex_inrow(kd_read, sizeof(kd_read)));
PrintAndLogEx(SUCCESS, "Raw Credit Key............. " _YELLOW_("%s"), sprint_hex_inrow(kc_read, sizeof(kc_read)));
// read dump data here and print (SIO , wiegand)
uint16_t n = 0;
uint8_t d[0x100 * PICOPASS_BLOCK_SIZE] = {0};
iclass_dump_non_secure(shallow_mod, d, &n);
// read dump data here and print (SIO , wiegand)
uint16_t n = 0;
uint8_t d[0x100 * PICOPASS_BLOCK_SIZE] = {0};
iclass_dump_non_secure(shallow_mod, d, &n);
DropField();
DropField();
iclass_decode_credentials(d);
iclass_decode_credentials(d);
// We should send it to SAM if we detect one installed, and get the FC/CN out
// We should send it to SAM if we detect one installed, and get the FC/CN out
}
static int CmdHFiClass_BlackTears(const char *Cmd) {
@@ -4441,7 +4458,7 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
keyType = ICLASS_CREDIT_KEYTYPE;
} else {
PrintAndLogEx(SUCCESS, "Using " _YELLOW_("debit") " key");
}
}
if (tearoff_loop > 1) {
PrintAndLogEx(SUCCESS, _YELLOW_("%u") " attempts / tearoff", tearoff_loop);
@@ -4507,13 +4524,13 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
goto out;
}
#define TEAR_NON_SECURE_MODE 0x2C
#define TEAR_INITAL 0x3C
#define TEAR_PERSO 0xAC
#define TEAR_NON_SECURE_MODE 0x2C
#define TEAR_INITAL 0x3C
#define TEAR_PERSO 0xAC
#define TEAR_IS_PERSO_SET(x) (((x) & 0x80) == 0x80)
#define TEAR_IS_NONSECURE_SET(x) ((((x) & 0x18) >> 3) == PICOPASS_NON_SECURE_PAGEMODE)
#define TEAR_BAD(x) (((x) & 0x01) == 0)
#define TEAR_IS_PERSO_SET(x) (((x) & 0x80) == 0x80)
#define TEAR_IS_NONSECURE_SET(x) ((((x) & 0x18) >> 3) == PICOPASS_NON_SECURE_PAGEMODE)
#define TEAR_BAD(x) (((x) & 0x01) == 0)
// perform initial read here, repeat if failed or 00s
@@ -4615,7 +4632,7 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
}
// skip authentication for config block
read_auth = false;
read_auth = false;
res = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, read_auth, shallow_mod, data_read, false, false);
if (res == PM3_SUCCESS && !reread) {
@@ -4744,7 +4761,7 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
isok = PM3_SUCCESS;
goto_out = true;
}
if (goto_out) {
goto out;
@@ -4758,9 +4775,9 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "Read: " _GREEN_("%s") " %s"
, sprint_hex_inrow(data_read, sizeof(data_read)),
(expected_values) ? _GREEN_(" -> Expected values!") : ""
);
, sprint_hex_inrow(data_read, sizeof(data_read)),
(expected_values) ? _GREEN_(" -> Expected values!") : ""
);
}
loop_count++;
@@ -4797,9 +4814,9 @@ out:
PrintAndLogEx(NORMAL, "");
clearCommandBuffer();
read_auth = false;
uint8_t data_read[8]= {0};
read_auth = false;
uint8_t data_read[8] = {0};
int res = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, read_auth, shallow_mod, data_read, false, false);
if (res != PM3_SUCCESS) {
return res;
@@ -4807,35 +4824,35 @@ out:
uint8_t b7 = data_read[7];
if ( b7 == TEAR_INITAL) {
PrintAndLogEx(INFO, _YELLOW_("Fuses unchanged. Try again if the OTP is unchanged"));
// check for OTP change?
if (b7 == TEAR_INITAL) {
PrintAndLogEx(INFO, _YELLOW_("Fuses unchanged. Try again if the OTP is unchanged"));
// check for OTP change?
} else if (TEAR_IS_NONSECURE_SET(b7)) {
// don't do anything as this is ok
PrintAndLogEx(SUCCESS, "Detected fuse: " _GREEN_("0x%02X")" _non secure memory_ ( %s )", data_read[7], _GREEN_("ok"));
// don't do anything as this is ok
PrintAndLogEx(SUCCESS, "Detected fuse: " _GREEN_("0x%02X")" _non secure memory_ ( %s )", data_read[7], _GREEN_("ok"));
iclass_read_interesting_data(key, keyType, elite, rawkey, use_replay, verbose, shallow_mod);
iclass_read_interesting_data(key, keyType, elite, rawkey, use_replay, verbose, shallow_mod);
} else if (TEAR_IS_PERSO_SET(b7)) {
PrintAndLogEx(SUCCESS, "Detected fuse: " _GREEN_("0x%02X") " set non-secure memory: " _YELLOW_("0xAC"), data_read[7]);
PrintAndLogEx(SUCCESS, "Detected fuse: " _GREEN_("0x%02X") " set non-secure memory: " _YELLOW_("0xAC"), data_read[7]);
memcpy(data, data_read, PICOPASS_BLOCK_SIZE);
data[7] = TEAR_NON_SECURE_MODE;
memcpy(data, data_read, PICOPASS_BLOCK_SIZE);
data[7] = TEAR_NON_SECURE_MODE;
// set non-secure memory with 0xAC, in this state it will always succeed
if(do_not_stabilize) {
PrintAndLogEx(INFO, "Not stabilizing the bits...");
} else {
PrintAndLogEx(INFO, "Stabilizing the bits...");
iclass_write_block(blockno, data, mac, key, use_credit_key, elite, rawkey, use_replay, false, auth, shallow_mod);
}
// set non-secure memory with 0xAC, in this state it will always succeed
if (do_not_stabilize) {
PrintAndLogEx(INFO, "Not stabilizing the bits...");
} else {
PrintAndLogEx(INFO, "Stabilizing the bits...");
iclass_write_block(blockno, data, mac, key, use_credit_key, elite, rawkey, use_replay, false, auth, shallow_mod);
}
iclass_read_interesting_data(key, keyType, elite, rawkey, use_replay, verbose, shallow_mod);
iclass_read_interesting_data(key, keyType, elite, rawkey, use_replay, verbose, shallow_mod);
} else if (TEAR_BAD(b7)) {
PrintAndLogEx(WARNING, "Bad fuse state detected: " _RED_("0x%02X") ", cannot proceed", b7);
return PM3_EFAILED;
} else {
PrintAndLogEx(INFO, _YELLOW_("Did not detect " _YELLOW_("0xBC") " or " _YELLOW_("0xBE") " or " _YELLOW_("0x9C") " fuse, might need manual intervention!"));
PrintAndLogEx(INFO, _YELLOW_("Did not detect " _YELLOW_("0xBC") " or " _YELLOW_("0xBE") " or " _YELLOW_("0x9C") " fuse, might need manual intervention!"));
}
return isok;
@@ -5011,18 +5028,30 @@ static void print_iclass_sio_decoded(uint8_t *sio, size_t sio_len) {
} else if (itag == 0x81 && ilen == 1) {
const char *ktype;
switch (ival[0]) {
case 0x00: ktype = "Elite keyed"; break;
case 0x01: ktype = "Standard keyed"; break;
default: ktype = "Custom keyed"; break;
case 0x00:
ktype = "Elite keyed";
break;
case 0x01:
ktype = "Standard keyed";
break;
default:
ktype = "Custom keyed";
break;
}
PrintAndLogEx(INFO, " Key Reference ID : " _YELLOW_("0x%02X") " ( %s )", ival[0], ktype);
} else if (itag == 0x04 && ilen >= 1) {
uint8_t ctype = ival[ilen - 1];
const char *cname;
switch (ctype) {
case 0x08: cname = "EAX"; break;
case 0x09: cname = "EAX'"; break;
default: cname = "Unknown"; break;
case 0x08:
cname = "EAX";
break;
case 0x09:
cname = "EAX'";
break;
default:
cname = "Unknown";
break;
}
PrintAndLogEx(INFO, " Crypto Suite : " _YELLOW_("%s") " ( %s )", sprint_hex_inrow(ival, ilen), cname);
}
@@ -5979,7 +6008,7 @@ static int iclass_recover(uint8_t key[8], uint32_t index_start, uint32_t loop, u
while (repeat == true) {
uint32_t payload_size = sizeof(iclass_recover_req_t);
iclass_recover_req_t *payload = calloc(1, payload_size);
if (payload == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
@@ -6227,8 +6256,8 @@ static int CmdHFiClassLegBrute_MT(uint8_t epurse[8], uint8_t macs[8], uint8_t ma
memcpy(args[i].startingKey, startingKey, 8);
args[i].index_start = index + (uint64_t)i * slice;
args[i].index_end = (i == thread_count - 1)
? index + keyspace // last thread absorbs remainder
: index + (uint64_t)(i + 1) * slice;
? index + keyspace // last thread absorbs remainder
: index + (uint64_t)(i + 1) * slice;
memcpy(args[i].CCNR1, CCNR, 12);
memcpy(args[i].MAC_TAG1, MAC_TAG, 4);
memcpy(args[i].CCNR2, CCNR2, 12);
@@ -7185,14 +7214,14 @@ static void generate(uint8_t *data, uint8_t len) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return;
}
uint8_t *pkey = calloc(len, sizeof(uint8_t));
if (pkey == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
free(key);
return;
}
PrintAndLogEx(SUCCESS, "input key...... %s", sprint_hex_inrow(data, len));
permute(data, len, pkey);
PrintAndLogEx(SUCCESS, "permuted key... %s", sprint_hex_inrow(pkey, len));
@@ -8022,7 +8051,7 @@ int info_iclass(bool shallow_mod) {
bool found_aa2 = false;
uint8_t aa1_idx = 0;
uint8_t key[PICOPASS_KEY_SIZE] = {0};
for (uint8_t i = 0; i < ARRAYLEN(iClass_Key_Table); i++) {
memcpy(key, iClass_Key_Table[i], sizeof(key));
+4 -4
View File
@@ -873,12 +873,12 @@ static int mf_analyse_st_block(uint8_t blockno, uint8_t *block, bool force) {
uint8_t bar = 4;
for (uint8_t foo = 0; foo < bar; foo++) {
if (mfReadOnlyAccessConditions(foo, &block[6])) {
// WARNING: Sectors 33+ assume ACLs apply to groups of 4 blocks, not 1 block.
// The code as-is is bugged and actually wastes iterations. If you have 16 blocks, it'll run all 16 but only error out like it's a 4-block sector.
if (blockno<128)
// WARNING: Sectors 33+ assume ACLs apply to groups of 4 blocks, not 1 block.
// The code as-is is bugged and actually wastes iterations. If you have 16 blocks, it'll run all 16 but only error out like it's a 4-block sector.
if (blockno < 128)
PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on block " _YELLOW_("%u") " detected", blockno - bar + 1 + foo);
else
PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on blocks " _YELLOW_("%u-%u") " detected", blockno - bar*4 + 1 + foo*5, blockno - bar*4 + 1 + foo*5 + 4);
PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on blocks " _YELLOW_("%u-%u") " detected", blockno - bar * 4 + 1 + foo * 5, blockno - bar * 4 + 1 + foo * 5 + 4);
ro_detected = true;
}
}
+5 -5
View File
@@ -714,7 +714,7 @@ static uint64_t num_keys_tested = 0;
static statelist_t *candidates = NULL;
static int add_nonce(uint32_t nonce_enc, uint8_t par_enc) {
uint8_t first_byte = nonce_enc >> 24;
noncelistentry_t *p1 = nonces[first_byte].first;
noncelistentry_t *p2 = NULL;
@@ -912,10 +912,10 @@ static void update_allbitflips_array(void) {
if (nonces[i].all_bitflips_dirty[odd_even]) {
uint32_t old_count = num_all_bitflips_bitarray[odd_even];
num_all_bitflips_bitarray[odd_even] = count_bitarray_low20_AND(all_bitflips_bitarray[odd_even], nonces[i].states_bitarray[odd_even]);
nonces[i].all_bitflips_dirty[odd_even] = false;
if (num_all_bitflips_bitarray[odd_even] != old_count) {
all_bitflips_bitarray_dirty[odd_even] = true;
}
@@ -1556,7 +1556,7 @@ static int simulate_acquire_nonces(void) {
simulate_MFplus_RNG(cuid, known_target_key, &nt_enc, &par_enc);
int add_res = add_nonce(nt_enc, par_enc);
if ( add_res == PM3_EMALLOC) {
if (add_res == PM3_EMALLOC) {
return add_res;
}
num_acquired_nonces += add_res;
@@ -1701,7 +1701,7 @@ static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_
DropField();
return add_res;
}
num_acquired_nonces += add_res;
// PrintAndLogEx(INFO, "Encrypted nonce: %08x, encrypted_parity: %02x\n", nt_enc2, par_enc & 0x0f);
+5 -5
View File
@@ -1199,12 +1199,12 @@ static int mfp_analyse_st_block(uint8_t blockno, uint8_t *block, bool force) {
uint8_t bar = 4;
for (uint8_t foo = 0; foo < bar; foo++) {
if (mfReadOnlyAccessConditions(foo, &block[6])) {
// WARNING: Sectors 33+ assume ACLs apply to groups of 4 blocks, not 1 block.
// The code as-is is bugged and actually wastes iterations. If you have 16 blocks, it'll run all 16 but only error out like it's a 4-block sector.
if (blockno<128)
// WARNING: Sectors 33+ assume ACLs apply to groups of 4 blocks, not 1 block.
// The code as-is is bugged and actually wastes iterations. If you have 16 blocks, it'll run all 16 but only error out like it's a 4-block sector.
if (blockno < 128)
PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on block " _YELLOW_("%u") " detected", blockno - bar + 1 + foo);
else
PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on blocks " _YELLOW_("%u-%u") " detected", blockno - bar*4 + 1 + foo*5, blockno - bar*4 + 1 + foo*5 + 4);
PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on blocks " _YELLOW_("%u-%u") " detected", blockno - bar * 4 + 1 + foo * 5, blockno - bar * 4 + 1 + foo * 5 + 4);
ro_detected = true;
}
}
@@ -1259,7 +1259,7 @@ static int CmdHFMFPWrbl(const char *Cmd) {
int keylen = 0;
CLIGetHexWithReturn(ctx, 7, key, &keylen);
bool force = arg_get_lit(ctx, 8);
CLIParserFree(ctx);
uint8_t keyn[2] = {0};
+2 -2
View File
@@ -1752,13 +1752,13 @@ typedef struct {
static mfu_otp_identify_t mfu_otp_ident_table[] = {
{ "SALTO Systems card", 12, 4, "534C544F", ul_c_otpgenA, "report to iceman!" },
{ NULL, 0, 0, NULL , NULL, NULL} // must be the last item
{ NULL, 0, 0, NULL, NULL, NULL} // must be the last item
};
static mfu_otp_identify_t *mfu_match_otp_fingerprint(uint8_t *uid, uint8_t *data) {
uint8_t i = 0;
do {
if ( mfu_otp_ident_table[i].desc == NULL) {
if (mfu_otp_ident_table[i].desc == NULL) {
break;
}
int ml = 0;
+5 -5
View File
@@ -476,11 +476,11 @@ static int CmdHFHIDConfigSim(const char *Cmd) {
strncpy(uid_str, sprint_hex_inrow(uid, uidlen), sizeof(uid_str) - 1);
uid_str[sizeof(uid_str) - 1] = '\0';
PrintAndLogEx(INFO, "HID Config Card sim:"
" UID " _YELLOW_("%s")
" AID " _YELLOW_("%s")
" ATS len " _YELLOW_("%d")
" APDU overrides " _YELLOW_("%u")
" default resp " _YELLOW_("%s"),
" UID " _YELLOW_("%s")
" AID " _YELLOW_("%s")
" ATS len " _YELLOW_("%d")
" APDU overrides " _YELLOW_("%u")
" default resp " _YELLOW_("%s"),
uid_str, aid_str, ats_len, apdu_count,
has_default_resp ? sprint_hex_inrow(default_resp, default_resp_len_sz) : "9000 (builtin)");
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("<Enter>") " to abort simulation");
+15 -15
View File
@@ -361,9 +361,9 @@ static int seos_get_data(uint8_t *rndICC, uint8_t *rndIFD, uint8_t *diversified_
uint8_t responseCode[2] = {0};
uint8_t mac[8] = {0};
size_t cryptogram_length = 0;
// Parse the response to extract the three tags
for (int i = 0; i < resplen - 2; ) {
for (int i = 0; i < resplen - 2;) {
if (response[i] == 0x85) {
// Cryptogram tag
size_t offset = i + 1;
@@ -384,7 +384,7 @@ static int seos_get_data(uint8_t *rndICC, uint8_t *rndIFD, uint8_t *diversified_
i += 2 + response[i + 1];
}
}
// ------------------- Cryptogram Response -------------------
if (cryptogram_length > 0) {
uint8_t decrypted[cryptogram_length];
@@ -392,15 +392,15 @@ static int seos_get_data(uint8_t *rndICC, uint8_t *rndIFD, uint8_t *diversified_
// Decrypt the response
decrypt_cryptogram(diversified_enc_key, cryptogram, decrypted, cryptogram_length, encryption_algorithm);
//PrintAndLogEx(SUCCESS, "Cryptogram....................... " _YELLOW_("%s"), sprint_hex_inrow(cryptogram, cryptogram_length));
//PrintAndLogEx(SUCCESS, "Decrypted........................ " _YELLOW_("%s"), sprint_hex_inrow(decrypted, cryptogram_length));
// Parse TLV: tag can be 1 or 2 bytes
int offset = 0;
uint8_t tag[2] = {0x00, 0x00};
int tag_len = 1;
// Check if it's a 2-byte tag (first byte has bits 5-1 all set to 1)
if ((decrypted[offset] & 0x1F) == 0x1F) {
tag[0] = decrypted[offset];
@@ -411,28 +411,28 @@ static int seos_get_data(uint8_t *rndICC, uint8_t *rndIFD, uint8_t *diversified_
tag[0] = decrypted[offset];
offset += 1;
}
// Get length byte
uint8_t length_byte = decrypted[offset];
offset += 1;
// Extract the value
getDataSize = length_byte;
memcpy(sioOutput, decrypted + offset, getDataSize);
*sio_size = getDataSize;
PrintAndLogEx(SUCCESS, "Tag.............................. " _YELLOW_("%s"), sprint_hex_inrow(tag, tag_len));
PrintAndLogEx(SUCCESS, "Value............................ " _YELLOW_("%s"), sprint_hex_inrow(sioOutput, getDataSize));
}
if (responseCode[0] != 0x00 || responseCode[1] != 0x00) {
PrintAndLogEx(SUCCESS, "Response Code.................... " _YELLOW_("%s"), sprint_hex_inrow(responseCode, ARRAYLEN(responseCode)));
}
// if (mac[0] != 0x00) {
// PrintAndLogEx(SUCCESS, "MAC.............................. " _YELLOW_("%s"), sprint_hex_inrow(mac, sizeof(mac)));
// }
return PM3_SUCCESS;
};
@@ -874,9 +874,9 @@ static int select_df_decode(uint8_t *response, uint8_t response_length, int *ALG
}
if (plaintext_adf == false) {
if (plaintext_adf == false) {
PrintAndLogEx(SUCCESS, "CRYPTOGRAM Encrypted Data........ " _YELLOW_("%s"), sprint_hex_inrow(CRYPTOGRAM_encrypted_data, 64));
}
if (plaintext_adf == false) {
PrintAndLogEx(SUCCESS, "CRYPTOGRAM Encrypted Data........ " _YELLOW_("%s"), sprint_hex_inrow(CRYPTOGRAM_encrypted_data, 64));
}
}
// PrintAndLogEx(SUCCESS, "MAC.............................. " _YELLOW_("%s"), sprint_hex_inrow(MAC_value, 8));
+8 -8
View File
@@ -632,8 +632,8 @@ typedef struct {
} vas_reader_key_t;
static void VasReaderCleanup(vas_reader_key_t *keys, int keys_initialized,
char **key_values, int key_count,
char **pid_values, int pid_count) {
char **key_values, int key_count,
char **pid_values, int pid_count) {
for (int i = 0; keys != NULL && i < keys_initialized; i++) {
mbedtls_ecp_keypair_free(&keys[i].key);
}
@@ -758,9 +758,9 @@ static int VASGetData(const char *passIdentifier, const uint8_t *pidHash, bool h
}
static int VASRead(bool has_pid, size_t request_count,
char *const *pid_values, const char *url, int urllen,
uint8_t vas_mode, bool verbose,
vas_reader_key_t *keys, int key_count) {
char *const *pid_values, const char *url, int urllen,
uint8_t vas_mode, bool verbose,
vas_reader_key_t *keys, int key_count) {
uint16_t select_status = VAS_STATUS_NOT_AVAILABLE;
if (VASSelectOse(&select_status, verbose) != PM3_SUCCESS) {
PrintVASFailureReason(select_status, VAS_STATUS_NOT_AVAILABLE);
@@ -975,12 +975,12 @@ static int CmdVASReader(const char *Cmd) {
continue;
}
int iter_res = VASRead(has_pid, request_count, pid_values,
url, urllen, vas_mode, verbose,
keys, key_count);
url, urllen, vas_mode, verbose,
keys, key_count);
if (iter_res != PM3_SUCCESS && final_res == PM3_SUCCESS) {
final_res = iter_res;
}
if (continuous) {
// Drop field so that iPhone displays the checkmark or a pass
DropField();
+14 -14
View File
@@ -1824,17 +1824,17 @@ static int lf_relay_rdr(const char *ip, uint16_t port) {
int CmdLFRelay(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf relay",
"Relay LF signal between two Proxmark3 devices over TCP.\n"
"By default it uses PORT 8000 and uses 40000 samples from Graphbuffer\n"
" --rdr : Reading device, act as IP client and reads LF tag and sends data\n"
" --tag : Simulation device, act as IP server and simulates relayed data\n",
_WHITE_("Device A, reading LF tag, client") "\n"
"lf relay --rdr --ip 192.168.1.141 -> Client, connect to IP 192.168.1.141:8000\n"
"lf relay --rdr --ip 192.168.1.141 -p 18111 -> Client, connect to IP 192.168.1.141:18111 \n\n"
_WHITE_("Device B, simulate LF tag, server") "\n"
"lf relay --tag -p 8111 -> Server listening port 8111, recv 40000 samples\n"
"lf relay --tag -s 10000 -> Server listening port 8000, recv 10000 samples\n"
);
"Relay LF signal between two Proxmark3 devices over TCP.\n"
"By default it uses PORT 8000 and uses 40000 samples from Graphbuffer\n"
" --rdr : Reading device, act as IP client and reads LF tag and sends data\n"
" --tag : Simulation device, act as IP server and simulates relayed data\n",
_WHITE_("Device A, reading LF tag, client") "\n"
"lf relay --rdr --ip 192.168.1.141 -> Client, connect to IP 192.168.1.141:8000\n"
"lf relay --rdr --ip 192.168.1.141 -p 18111 -> Client, connect to IP 192.168.1.141:18111 \n\n"
_WHITE_("Device B, simulate LF tag, server") "\n"
"lf relay --tag -p 8111 -> Server listening port 8111, recv 40000 samples\n"
"lf relay --tag -s 10000 -> Server listening port 8000, recv 10000 samples\n"
);
void *argtable[] = {
arg_param_begin,
@@ -1876,7 +1876,7 @@ int CmdLFRelay(const char *Cmd) {
if (is_tag) {
return lf_relay_tag(samples, port);
}
if (is_rdr) {
return lf_relay_rdr(ip, port);
}
@@ -1986,13 +1986,13 @@ int CmdLFfind(const char *Cmd) {
// identify chipset
bool lf_special_search = check_chiptype(is_online);
if ( lf_special_search ) {
if (lf_special_search) {
found++;
} else {
PrintAndLogEx(DEBUG, "Automatic chip type detection " _RED_("failed"));
}
if ( found == 0) {
if (found == 0) {
PrintAndLogEx(HINT, "Hint: try `" _YELLOW_("hf search") "` - since tag might not be LF");
}
+5 -5
View File
@@ -145,11 +145,11 @@ static int mqtt_receive(const char *addr, const char *port, const char *topic, c
char cid[20] = "pm3_";
snprintf(cid + strlen(cid), sizeof(cid) - 4, "%02x%02x%02x%02x"
, rand() % 0xFF
, rand() % 0xFF
, rand() % 0xFF
, rand() % 0xFF
);
, rand() % 0xFF
, rand() % 0xFF
, rand() % 0xFF
, rand() % 0xFF
);
// Ensure we have a clean session
uint8_t connect_flags = MQTT_CONNECT_CLEAN_SESSION;
+30 -15
View File
@@ -181,13 +181,20 @@ void doMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) {
static void suc_bytes(const uint8_t *k, State_t *s, const uint8_t *in, int length) {
for (int i = 0; i < length; i++) {
uint8_t b = in[i];
successor(k, s, b); b >>= 1;
successor(k, s, b); b >>= 1;
successor(k, s, b); b >>= 1;
successor(k, s, b); b >>= 1;
successor(k, s, b); b >>= 1;
successor(k, s, b); b >>= 1;
successor(k, s, b); b >>= 1;
successor(k, s, b);
b >>= 1;
successor(k, s, b);
b >>= 1;
successor(k, s, b);
b >>= 1;
successor(k, s, b);
b >>= 1;
successor(k, s, b);
b >>= 1;
successor(k, s, b);
b >>= 1;
successor(k, s, b);
b >>= 1;
successor(k, s, b);
}
}
@@ -197,14 +204,22 @@ static void suc_bytes(const uint8_t *k, State_t *s, const uint8_t *in, int lengt
static void output_bytes(const uint8_t *k, State_t *s, uint8_t *out, int nbytes) {
for (int i = 0; i < nbytes; i++) {
uint8_t bout = 0;
bout |= (s->r & 0x4) >> 2; successor(k, s, 0);
bout |= (s->r & 0x4) >> 1; successor(k, s, 0);
bout |= (s->r & 0x4); successor(k, s, 0);
bout |= (s->r & 0x4) << 1; successor(k, s, 0);
bout |= (s->r & 0x4) << 2; successor(k, s, 0);
bout |= (s->r & 0x4) << 3; successor(k, s, 0);
bout |= (s->r & 0x4) << 4; successor(k, s, 0);
bout |= (s->r & 0x4) << 5; successor(k, s, 0);
bout |= (s->r & 0x4) >> 2;
successor(k, s, 0);
bout |= (s->r & 0x4) >> 1;
successor(k, s, 0);
bout |= (s->r & 0x4);
successor(k, s, 0);
bout |= (s->r & 0x4) << 1;
successor(k, s, 0);
bout |= (s->r & 0x4) << 2;
successor(k, s, 0);
bout |= (s->r & 0x4) << 3;
successor(k, s, 0);
bout |= (s->r & 0x4) << 4;
successor(k, s, 0);
bout |= (s->r & 0x4) << 5;
successor(k, s, 0);
out[i] = bout;
}
}
+1 -1
View File
@@ -303,7 +303,7 @@ void print_gallagher_creds(GallagherCredentials_t *creds) {
", facility: " _GREEN_("%u")
", card number: " _GREEN_("%u")
", issue level: " _GREEN_("%u"),
'A' + creds->region_code,
'A' + creds->region_code,
creds->region_code,
creds->facility_code,
creds->card_number,
+1 -1
View File
@@ -683,7 +683,7 @@ int parse_uint32_hex_or_dec(const char *text, uint32_t *out) {
base = 16;
} else {
for (const char *p = text; *p; p++) {
if (isalpha((unsigned char)*p)) {
if (isalpha((unsigned char) * p)) {
base = 16;
break;
}
+7 -7
View File
@@ -391,7 +391,7 @@ int mfc_algo_mizip_one(const uint8_t *uid, uint8_t sector, uint8_t keytype, uint
if (keytype == 0) {
*key = 0xA0A1A2A3A4A5U; // A
} else {
} else {
*key = 0xB4C132439eefU; // B
}
@@ -629,24 +629,24 @@ int mfc_algo_snapmaker_all(uint8_t *uid, uint8_t *keys) {
int mfc_algo_vanderbilt_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *key) {
if (key == NULL) return PM3_EINVARG;
if (sector > 39) return PM3_EINVARG;
// Base pattern: "Acces" in ASCII = 0x4163636573
// For each sector, we generate keys for all 4 blocks (or 16 for sector 32+)
// Key format: 41 63 63 65 73 XX where XX is the block number
uint8_t first_block = (sector < 32) ? (sector * 4) : (128 + (sector - 32) * 16);
uint8_t block_id = first_block + 3; // Use sector trailer block ID
// Both key A and B use the same pattern with block ID
uint8_t key_bytes[6] = {0x41, 0x63, 0x63, 0x65, 0x73, block_id};
*key = bytes_to_num(key_bytes, 6);
return PM3_SUCCESS;
}
int mfc_algo_vanderbilt_all(uint8_t *uid, uint8_t *keys) {
if (keys == NULL) return PM3_EINVARG;
// Generate keys for all sectors (40 sectors for 4K card)
for (int keytype = 0; keytype < 2; keytype++) {
for (int sector = 0; sector < 40; sector++) {
@@ -655,7 +655,7 @@ int mfc_algo_vanderbilt_all(uint8_t *uid, uint8_t *keys) {
num_to_bytes(key, 6, keys + (keytype * 40 * 6) + (sector * 6));
}
}
return PM3_SUCCESS;
}
+9 -7
View File
@@ -3658,9 +3658,10 @@
"-z, --dense dense dump output style",
"--force force unsecure card read",
"--shallow use shallow (ASK) reader modulation instead of OOK",
"--ns no save to file"
"--ns no save to file",
"--page <dec> which page to dump from"
],
"usage": "hf iclass dump [-hz] [-f <fn>] [-k <hex>] [--ki <dec>] [--credit <hex>] [--ci <dec>] [--elite] [--raw] [--nr] [--force] [--shallow] [--ns]"
"usage": "hf iclass dump [-hz] [-f <fn>] [-k <hex>] [--ki <dec>] [--credit <hex>] [--ci <dec>] [--elite] [--raw] [--nr] [--force] [--shallow] [--ns] [--page <dec>]"
},
"hf iclass eload": {
"command": "hf iclass eload",
@@ -7289,7 +7290,7 @@
"description": "Print decoded MIFARE Plus access rights (ACL), A = key A B = key B AB = both key A and B ACCESS = access bytes inside sector trailer block Increment, decrement, transfer, restore is for value blocks",
"notes": [
"hf mf acl",
"hf mf acl -d FF0780"
"hf mf acl -d 0FFF0780"
],
"offline": true,
"options": [
@@ -7600,9 +7601,10 @@
"-p, --plain Do not use encrypted transmission",
"--nmr Do not expect MAC in response",
"-d, --data <hex> Data, 16 hex bytes",
"-k, --key <hex> Key, 16 hex bytes"
"-k, --key <hex> Key, 16 hex bytes",
"--force Override warnings"
],
"usage": "hf mfp wrbl [-hvbp] --blk <0..255> [--nmr] -d <hex> [-k <hex>]"
"usage": "hf mfp wrbl [-hvbp] --blk <0..255> [--nmr] -d <hex> [-k <hex>] [--force]"
},
"hf mfp wrp": {
"command": "hf mfp wrp",
@@ -8453,7 +8455,7 @@
"offline": false,
"options": [
"-h, --help This help",
"-f, --file <fn> JSON file with UID, AID, SCP02Key (without .json extension)",
"-f, --file <fn> JSON file with UID, AID, SCP02Key, optional KDD/KVN (no .json ext)",
"-n, --num <dec> Exit after <n> reader interactions. 0 = infinite"
],
"usage": "hf secc sim [-h] -f <fn> [-n <dec>]"
@@ -14440,6 +14442,6 @@
"metadata": {
"commands_extracted": 819,
"extracted_by": "PM3Help2JSON v1.00",
"extracted_on": "2026-04-11T02:04:09"
"extracted_on": "2026-04-13T07:31:01"
}
}