From 956a1e9eaec4cf03c50dfbaaa9b946cd51347385 Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Sun, 8 Dec 2024 22:03:37 -0800 Subject: [PATCH] Move key derivation script to its own .py file --- TagSniffing.md | 16 ---------------- deriveKeys.py | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 deriveKeys.py diff --git a/TagSniffing.md b/TagSniffing.md index f98a34e..52edee4 100644 --- a/TagSniffing.md +++ b/TagSniffing.md @@ -28,22 +28,6 @@ The Bambu Lab AMS Lite RFID readers are located at the base of each spool holder You must place your Proxmark3 device between the reader and the spool. -## Key Derivation - -As of 2024-11-19, keys can now be derived from the UID of a tag. - -```python -from Cryptodome.Protocol.KDF import HKDF -from Cryptodome.Hash import SHA256 - -uid = bytes([0x02,0x3b,0x44,0x74]) # Replace this with the tag's UID -master = bytes([0x9a,0x75,0x9c,0xf2,0xc4,0xf7,0xca,0xff,0x22,0x2c,0xb9,0x76,0x9b,0x41,0xbc,0x96]) - -keys = HKDF(uid, 6, master, SHA256, 16, context=b"RFID-A\0") - -print([a.hex() for a in keys]) -``` - ## Dump RFID Contents (.bin) 1. **Run ProxMark3 Software** diff --git a/deriveKeys.py b/deriveKeys.py new file mode 100644 index 0000000..60ac788 --- /dev/null +++ b/deriveKeys.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +# Python script to generate keys for Bambu Lab RFID tags +# Created for https://github.com/Bambu-Research-Group/RFID-Tag-Guide +# Written by thekakester (https://github.com/thekakester) and Vinyl Da.i'gyu-Kazotetsu (www.queengoob.org), 2024 + +import sys +from Cryptodome.Protocol.KDF import HKDF +from Cryptodome.Hash import SHA256 + +if not sys.version_info >= (3, 6): + print("Python 3.6 or higher is required!") + exit(-1) + +def kdf(uid): + master = bytes([0x9a,0x75,0x9c,0xf2,0xc4,0xf7,0xca,0xff,0x22,0x2c,0xb9,0x76,0x9b,0x41,0xbc,0x96]) + return HKDF(uid, 6, master, SHA256, 16, context=b"RFID-A\0") + +if __name__ == '__main__': + uid = bytes.fromhex(sys.argv[1]) + keys = kdf(uid) + + output = [a.hex().upper() for a in keys] + print("\n".join(output))