counterfeit ULC: misc tuning

This commit is contained in:
Philippe Teuwen committed 2026-06-10 00:39:46 +02:00
1 parent d9265ad813
commit 6d8ed745fd
2 files changed
+39 -26

No files matched your search

+26 -22
View File
@@ -232,13 +232,12 @@ class CrackEffect:
scramble_thread.join()
def try_unlock(num_challenges: int, erndb: str, erndarndb: str, p) -> bool:
"""Try to unlock the card by using the provided reader response
def try_unlock(num_challenges: int, dict_erndberndarndb: dict, p) -> bool:
"""Try to unlock the card by using the provided reader responses
Args:
num_challenges (int): Number of challenge reads to attempt.
erndb (str): Card challenge to look for.
erndarndb (str): Reader response to use.
dict_erndberndarndb (dict): Dictionary mapping card challenges to reader responses.
p: Proxmark3 instance used to issue raw commands and read responses.
Returns:
@@ -260,8 +259,8 @@ def try_unlock(num_challenges: int, erndb: str, erndarndb: str, p) -> bool:
if progress >= next_progress:
print(f"[=] Progress: {min(progress, 100)}%")
next_progress += 10
if hex_challenge == erndb:
p.console(f"hf 14a raw -ck AF{erndarndb}")
if hex_challenge in dict_erndberndarndb:
p.console(f"hf 14a raw -ck AF{dict_erndberndarndb[hex_challenge]}")
response = p.grabbed_output.split()
if (len(response) > 8) and (response[1] == "00"):
print("[+] Unlock successful!")
@@ -389,13 +388,11 @@ def is_known_counterfeit(p) -> bool:
return False
def collect(num_challenges: int, p, debug: bool, force: bool = False,
erndarndb: Optional[str] = None) -> Optional[dict]:
def collect(p, debug: bool, force: bool = False) -> Optional[dict]:
"""
Collect challenges from the card and check if it is vulnerable.
Args:
num_challenges (int): Number of challenges to collect.
p: Proxmark3 instance.
debug (bool): Enable debug mode.
force (bool): Force the attack even if the card does not appear vulnerable (dangerous!).
@@ -541,29 +538,30 @@ def main():
help='Use CUDA implementation')
parser.add_argument('--force', action='store_true',
help='Force the attack even if the card does not appear vulnerable (dangerous!)')
parser.add_argument('--get_frequent_chal', action='store_true',
parser.add_argument('--get_frequent_chals', action='store_true',
help='Collect a "gold" challenge to perform an unlock, and quit afterwards')
parser.add_argument('--unlock', help='Unlock a card with a "gold" challenge/response pair',
type=str, metavar='ERndB,ERndARndB\'')
parser.add_argument('--unlock', help='Unlock a card with a list of "gold" challenge/response pairs, '
'separated by commas, in the format ERndB:ERndARndB\'',
type=str, metavar='ERndB:ERndARndB,...\'')
args = parser.parse_args()
debug = args.debug
num_challenges = args.challenges
offline = args.offline
use_cuda = args.cuda
force = args.force
get_frequent_chal = args.get_frequent_chal
erndb, erndarndb = args.unlock.split(',') if args.unlock else (None, None)
get_frequent_chals = args.get_frequent_chals
list_erndberndarndb = args.unlock.split(',') if args.unlock else []
brute_tool = tools["mfulc_des_brute_cuda"] if use_cuda else tools["mfulc_des_brute"]
if get_frequent_chal and (offline or args.json or force or use_cuda):
if get_frequent_chals and (offline or args.json or force or use_cuda):
print("[-] Error: --get_frequent_chal can only be combined with --challenges")
return
if (erndb or erndarndb) and offline:
if list_erndberndarndb and offline:
print("[-] Error: --unlock can'n be combined with --offline")
return
if get_frequent_chal:
if get_frequent_chals:
import pm3
p = pm3.pm3()
uid = get_ulc_uid(p)
@@ -602,12 +600,18 @@ def main():
if not offline:
import pm3
p = pm3.pm3()
if erndb and erndarndb:
erndb = erndb.upper()
erndarndb = erndarndb.upper()
if not try_unlock(num_challenges, erndb, erndarndb, p):
if len(list_erndberndarndb) > 0:
dict_erndberndarndb = {}
for pair in list_erndberndarndb:
try:
erndb, erndarndb = pair.split(':')
dict_erndberndarndb[erndb.upper()] = erndarndb.upper()
except ValueError:
print(f"[-] Error: Invalid format for --unlock pair '{pair}'. Expected format is ERndB:ERndARndB'")
return
if not try_unlock(num_challenges, dict_erndberndarndb, p):
return
challenges = collect(num_challenges, p, debug, force, erndarndb)
challenges = collect(p, debug, force)
if challenges is None:
return
if args.json:
+13 -4
View File
@@ -4495,7 +4495,6 @@ static uint32_t acquire_ul3p_nonces(uint8_t keytype, uint32_t num_nonces_to_acqu
}
if (resp.status != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "Failure to collect tag nonces");
return num_acquired_nonces;
}
@@ -4523,12 +4522,17 @@ static int collect_and_stat_nonces(uint32_t collect_nonces) {
}
uint32_t num_sampled_nonces = acquire_ul3p_nonces(1, collect_nonces, nonces);
if (num_sampled_nonces == 0) {
PrintAndLogEx(WARNING, "Failed to acquire nonces");
free(nonces);
return PM3_ESOFT;
}
for (uint16_t i = 0; i < num_sampled_nonces; i++) {
PrintAndLogEx(DEBUG, "Encrypted nonce: %016" PRIx64 "\n", nonces[i]);
}
if (num_sampled_nonces != collect_nonces) {
PrintAndLogEx(WARNING, "Failed to acquire all nonces");
PrintAndLogEx(WARNING, "Failed to acquire all nonces, got %u/%u", num_sampled_nonces, collect_nonces);
}
// Count nonce frequencies
@@ -4544,11 +4548,15 @@ static int collect_and_stat_nonces(uint32_t collect_nonces) {
return PM3_EMALLOC;
}
uint32_t unique_count = 0;
uint32_t recurring_count = 0;
for (uint32_t i = 0; i < num_sampled_nonces; i++) {
bool found = false;
for (uint32_t j = 0; j < unique_count; j++) {
if (counts[j].nonce == nonces[i]) {
if (counts[j].count == 1) {
recurring_count++;
}
counts[j].count++;
found = true;
break;
@@ -4572,8 +4580,9 @@ static int collect_and_stat_nonces(uint32_t collect_nonces) {
}
}
// Show top 10
uint32_t show_count = unique_count < 10 ? unique_count : 10;
// Show top N
uint8_t topn = 10;
uint32_t show_count = recurring_count < topn ? recurring_count : topn;
if (counts[0].count == 1) {
PrintAndLogEx(INFO, "All %u collected nonces are unique.", num_sampled_nonces);
free(nonces);