From d3e2ebdeb045c2485bee479ed0abba901c752a55 Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Tue, 28 May 2024 05:57:04 -0700 Subject: [PATCH 1/9] Update extractor to allow env variable-defined Proxmark3 path --- .gitignore | 1 + traceKeyExtractor.py | 88 +++++++++++++++++++------------------------- 2 files changed, 38 insertions(+), 51 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f8ad61c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.dic \ No newline at end of file diff --git a/traceKeyExtractor.py b/traceKeyExtractor.py index 381deff..774d3f1 100644 --- a/traceKeyExtractor.py +++ b/traceKeyExtractor.py @@ -1,9 +1,7 @@ -######################### -# CONFIGURATION (Begin) # -######################### -# Change these variables to match the install locations for your specific computer -# Some examples are provided, and you can comment/uncomment specific lines, or -# manually type them in if your computer differs from the examples +import subprocess +import os +import re +from pathlib import Path # ----------- # PM3 Program @@ -13,47 +11,25 @@ # If your computer doesn't recognize this, you may need to navigate to the actual # installation directory -#List of possible commands to try -pm3 = [ - #"pm3", #Default installation location - "/usr/local/opt/proxmark3/bin/pm3", #MAC Installataion - using BREW - "" #Windows specific install location TBD - ] - -# --------------------------------- -# Brute Force Tool (mf_nonce_brute) -# --------------------------------- -# This is a tool that comes with the PM3 program -# It is located in the "tools" directory of your PM3 installation location -mfNonceBrute = [ - "/usr/local/opt/proxmark3/share/proxmark3/tools/mf_nonce_brute", #MAC Install, using Brew - "" #Windows TBD +# List of possible directories for Proxmark3 to try +pm3_dirs = [ + os.environ.get('PROXMARK3_DIR'), ] - -######################### -# CONFIGURATION (End) # -######################### -# Do not modify anything beyond this point, unless you're a developer - - #Global variables #Default name of the dictionary file we create dictionaryFilename = "myKeyDictionary.dic" #Arbitrary filename for storing dictionary file dictionaryFilepath = "" #Calculated. Absolute path to dictionary file dictionaryFile = "" #File object for writing keys -pm3Command = ""; #Calculated. The command that works to start proxmark3 -mfNonceBruteCommand = "" #Calculated. The command to execute mfNonceBrute +pm3Location = "" #Calculated. The location of Proxmark3 +pm3Command = "bin/pm3" # The command that works to start proxmark3 +mfNonceBruteCommand = "share/proxmark3/tools/mf_nonce_brute" # The command to execute mfNonceBrute trace = ""; #Prompted during runtime. Trace filename that the user provides -import subprocess -import os -import re - def main(): - global pm3Command, mfNonceBruteCommand,dictionaryFilepath,trace + global pm3Location,dictionaryFilepath,trace print("--------------------------------------------------------") print("RFID Key Extractor v0.1 - Bambu Research Group 2024") @@ -69,16 +45,23 @@ def main(): # Find a "pm3" command that works from a list of OS-specific possibilities print("Checking program: pm3") - pm3Command = testCommands(pm3,"--help"); #Execute "pm3 --help" to test if the install location works - if pm3Command is None: - print("Failed to find working PM3 command. Modify the \"pm3\" variable in this program to match your installation location") - return; #Halt program - # Find a "mf_nonce_brute" command that works from a list of OS-specific possibilities - print("Checking program: mf_nonce_brute") - mfNonceBruteCommand = testCommands(mfNonceBrute,""); #Execute "mf_nonce_brute" to test if the install location works - if mfNonceBruteCommand is None: - print("Failed to find working mf_nonce_brute command. Modify the \"mf_nonce_brute\" variable in this program to match your installation location") + # Check for Homebrew installation + try: + # On Windows, use the shell=True argument to run the command + result = subprocess.run(["brew", "--prefix", "proxmark3"], shell=os.name == 'nt', stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # Check the return code to determine if the command was successful + if result.returncode == 0 or result.returncode == 1: + print("Found installation via Homebrew!") + pm3Location = Path(result.stdout) + except Exception as e: + # If Homebrew command failed, it's probably not installed + pass + + if pm3Location is None: + pm3Location = testCommands(pm3_dirs, "bin/pm3","--help"); #Execute "pm3 --help" to test if the install location works + if pm3Location is None: + print("Failed to find working PM3 command. You can set the Proxmark3 directory via the 'PROXMARK3_DIR' environment variable.") return; #Halt program #Create a dictionary file to store keys that we discover @@ -116,7 +99,7 @@ def discoverKeys(): #Run PM3 with the trace # -o means run without connecting to PM3 hardware # -c specifies commands within proxmark 3 software - cmd_list = [pm3Command,"-o","-c", f"trace load -f {trace}; trace list -1 -t mf -f {dictionaryFilepath}; exit"]; + cmd_list = [pm3Location / pm3Command,"-o","-c", f"trace load -f {trace}; trace list -1 -t mf -f {dictionaryFilepath}; exit"]; print(f"Viewing tracelog with {len(keyList)} discovered keys") print(" ".join(cmd_list)) result = subprocess.run(cmd_list, shell=os.name == 'nt',stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -222,7 +205,7 @@ def discoverKeys(): #Run the mf_nonce_brute program with the provided arguments to decode a key #Returns a key on success, "" otherwise def bruteForce(args): - cmd_list = [mfNonceBruteCommand] + args + cmd_list = [pm3Location / mfNonceBruteCommand] + args print(" Running bruteforce command:") print(" ",end = "") print(" ".join(cmd_list)) @@ -263,22 +246,25 @@ def strip_color_codes(input_string): # - arguments: Optional arguments to be appended to the command. Useful for programs that don't exit on their own # This returns the command (string) of the first working command we encounter # -def testCommands(commandList, arguments = ""): +def testCommands(directories, command, arguments = ""): - for command in commandList: + for directory in directories: + + if directory is None: + continue #OPTIONAL: add arguments such as "--help" to help identify programs that don't exit on their own - cmd_list = [command, arguments] + cmd_list = [directory+"/"+command, arguments] #Test if this program works - print(" Trying:", command, end=" ... ") + print(" Trying:", directory, end=" ... ") try: # On Windows, use the shell=True argument to run the command result = subprocess.run(cmd_list, shell=os.name == 'nt', stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Check the return code to determine if the command was successful if result.returncode == 0 or result.returncode == 1: print(" SUCCESS!") - return command + return Path(directory) except Exception as e: #print(e) #DEBUG print(" FAIL"); From 8b1d1777cecdb7d8fc01f79e9d803ac2544ad4e1 Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Tue, 28 May 2024 22:07:12 -0700 Subject: [PATCH 2/9] Mark Python 3.6 as minimum requirement --- traceKeyExtractor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/traceKeyExtractor.py b/traceKeyExtractor.py index 774d3f1..64dec6a 100644 --- a/traceKeyExtractor.py +++ b/traceKeyExtractor.py @@ -1,8 +1,13 @@ import subprocess import os import re +import sys from pathlib import Path +if not sys.version_info >= (3, 6): + print("Python 3.6 or higher is required!") + exit(-1) + # ----------- # PM3 Program # ----------- From a3a086fa9271e4513827510a370566b01d49da86 Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Tue, 28 May 2024 22:08:35 -0700 Subject: [PATCH 3/9] Update traceKeyExtractor.py Co-authored-by: thekakester --- traceKeyExtractor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/traceKeyExtractor.py b/traceKeyExtractor.py index 64dec6a..f8f349d 100644 --- a/traceKeyExtractor.py +++ b/traceKeyExtractor.py @@ -58,7 +58,9 @@ def main(): # Check the return code to determine if the command was successful if result.returncode == 0 or result.returncode == 1: print("Found installation via Homebrew!") - pm3Location = Path(result.stdout) + pm3Location = result.stdout.decode("utf-8") + pm3Location = pm3Location.replace("\n","").replace("\r","") + pm3Location = Path(pm3Location) except Exception as e: # If Homebrew command failed, it's probably not installed pass From ca2691c4cee277b561b85193e6e619fefe3136c9 Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Tue, 28 May 2024 22:11:02 -0700 Subject: [PATCH 4/9] Simplify pm3Location creation via Homebrew --- traceKeyExtractor.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/traceKeyExtractor.py b/traceKeyExtractor.py index f8f349d..0e0f741 100644 --- a/traceKeyExtractor.py +++ b/traceKeyExtractor.py @@ -58,9 +58,7 @@ def main(): # Check the return code to determine if the command was successful if result.returncode == 0 or result.returncode == 1: print("Found installation via Homebrew!") - pm3Location = result.stdout.decode("utf-8") - pm3Location = pm3Location.replace("\n","").replace("\r","") - pm3Location = Path(pm3Location) + pm3Location = Path(result.stdout.decode("utf-8").strip()) except Exception as e: # If Homebrew command failed, it's probably not installed pass From 6491f75288382f83f7d506b07b14d4ee0f85964f Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Tue, 28 May 2024 22:51:09 -0700 Subject: [PATCH 5/9] Create new function to get Proxmark3 path Helpful for expanding to check other package managers and such as well --- traceKeyExtractor.py | 95 ++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/traceKeyExtractor.py b/traceKeyExtractor.py index 0e0f741..8a7d355 100644 --- a/traceKeyExtractor.py +++ b/traceKeyExtractor.py @@ -8,18 +8,9 @@ if not sys.version_info >= (3, 6): print("Python 3.6 or higher is required!") exit(-1) -# ----------- -# PM3 Program -# ----------- -#The main proxmark program, for most installations, proxmark3 can be started -# with the command "pm3" in the terminal. -# If your computer doesn't recognize this, you may need to navigate to the actual -# installation directory - # List of possible directories for Proxmark3 to try -pm3_dirs = [ - os.environ.get('PROXMARK3_DIR'), -] +# XXX Populate with results for Windows +pm3_dirs = [] #Global variables #Default name of the dictionary file we create @@ -27,7 +18,7 @@ dictionaryFilename = "myKeyDictionary.dic" #Arbitrary filename for storing dict dictionaryFilepath = "" #Calculated. Absolute path to dictionary file dictionaryFile = "" #File object for writing keys -pm3Location = "" #Calculated. The location of Proxmark3 +pm3Location = None #Calculated. The location of Proxmark3 pm3Command = "bin/pm3" # The command that works to start proxmark3 mfNonceBruteCommand = "share/proxmark3/tools/mf_nonce_brute" # The command to execute mfNonceBrute @@ -48,26 +39,7 @@ def main(): print("--------------------------------------------------------") print("") - # Find a "pm3" command that works from a list of OS-specific possibilities - print("Checking program: pm3") - - # Check for Homebrew installation - try: - # On Windows, use the shell=True argument to run the command - result = subprocess.run(["brew", "--prefix", "proxmark3"], shell=os.name == 'nt', stdout=subprocess.PIPE, stderr=subprocess.PIPE) - # Check the return code to determine if the command was successful - if result.returncode == 0 or result.returncode == 1: - print("Found installation via Homebrew!") - pm3Location = Path(result.stdout.decode("utf-8").strip()) - except Exception as e: - # If Homebrew command failed, it's probably not installed - pass - - if pm3Location is None: - pm3Location = testCommands(pm3_dirs, "bin/pm3","--help"); #Execute "pm3 --help" to test if the install location works - if pm3Location is None: - print("Failed to find working PM3 command. You can set the Proxmark3 directory via the 'PROXMARK3_DIR' environment variable.") - return; #Halt program + pm3Location = get_proxmark3_location() #Create a dictionary file to store keys that we discover print(f"Creating dictionary file '{dictionaryFilename}'") @@ -243,6 +215,52 @@ def strip_color_codes(input_string): # Use the sub method to replace the escape sequences with an empty string return ansi_escape.sub('', input_string) +def get_proxmark3_location(): + # Find a "pm3" command that works from a list of OS-specific possibilities + print("Checking program: pm3") + + # Check PROXMARK3_DIR environment variable + if os.environ.get('PROXMARK3_DIR'): + if run_command(os.environ['PROXMARK3_DIR'] + "/bin/pm3", "--help"): + return os.environ['PROXMARK3_DIR'] + else: + print("Warning: PROXMARK3_DIR environment variable points to the wrong folder, ignoring") + + # Get Homebrew installation + brew_install = run_command(["brew", "--prefix", "proxmark3"]) + if brew_install: + print("Found installation via Homebrew!") + return Path(brew_install) + + # Get global installation + which_pm3 = run_command(["which", "pm3"]) + if which_pm3: + which_pm3 = Path(which_pm3) + pm3_location = which_pm3.parent.parent + print(f"Found global installation ({pm3_location})!") + return pm3_location + + # Check pm3_dirs paths + pm3_dirs_result = testCommands(pm3_dirs, "bin/pm3", "--help") + if pm3_dirs_result: + print(f"Found installation in {pm3_dirs_result}!") + return pm3_dirs_result + + # At this point, we've tried all the paths to find it + print("Failed to find working 'pm3' command. You can set the Proxmark3 directory via the 'PROXMARK3_DIR' environment variable.") + exit(-1) # Halt program + +def run_command(command): + try: + # On Windows, use the shell=True argument to run the command + result = subprocess.run(command, shell=os.name == 'nt', stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # Check the return code to determine if the command was successful + if result.returncode == 0 or result.returncode == 1: + return result.stdout.decode("utf-8").strip() + return None + except Exception as e: + return None + # Test a list of commands to see which one works # This lets us provide a list of OS-specific commands, test them # and figure out which one works on this specific computer @@ -263,17 +281,8 @@ def testCommands(directories, command, arguments = ""): #Test if this program works print(" Trying:", directory, end=" ... ") - try: - # On Windows, use the shell=True argument to run the command - result = subprocess.run(cmd_list, shell=os.name == 'nt', stdout=subprocess.PIPE, stderr=subprocess.PIPE) - # Check the return code to determine if the command was successful - if result.returncode == 0 or result.returncode == 1: - print(" SUCCESS!") - return Path(directory) - except Exception as e: - #print(e) #DEBUG - print(" FAIL"); - continue + if run_command(cmd_list): + return Path(directory) return None #We didn't find any program that worked From 4c72a97827c71cdfa8adcee07896a6f1a5e68254 Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Fri, 14 Jun 2024 19:50:12 -0700 Subject: [PATCH 6/9] Fix printing command list Apparently, `.join()` won't convert Paths to strings automatically --- traceKeyExtractor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/traceKeyExtractor.py b/traceKeyExtractor.py index 8a7d355..39a04ad 100644 --- a/traceKeyExtractor.py +++ b/traceKeyExtractor.py @@ -78,7 +78,7 @@ def discoverKeys(): # -c specifies commands within proxmark 3 software cmd_list = [pm3Location / pm3Command,"-o","-c", f"trace load -f {trace}; trace list -1 -t mf -f {dictionaryFilepath}; exit"]; print(f"Viewing tracelog with {len(keyList)} discovered keys") - print(" ".join(cmd_list)) + print(f"pm3 {" ".join(cmd_list[1:])}") result = subprocess.run(cmd_list, shell=os.name == 'nt',stdout=subprocess.PIPE, stderr=subprocess.PIPE) output = result.stdout; @@ -185,7 +185,7 @@ def bruteForce(args): cmd_list = [pm3Location / mfNonceBruteCommand] + args print(" Running bruteforce command:") print(" ",end = "") - print(" ".join(cmd_list)) + print(f"tools/mf_nonce_brute {" ".join(cmd_list[1:])}") result = subprocess.run(cmd_list, shell=os.name == 'nt', stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Parse out the key From 09c8f829b0def949d02862bc5b86dfbc30b70b1e Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Fri, 14 Jun 2024 19:50:25 -0700 Subject: [PATCH 7/9] Add additional messages and instructions --- traceKeyExtractor.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/traceKeyExtractor.py b/traceKeyExtractor.py index 39a04ad..a73447a 100644 --- a/traceKeyExtractor.py +++ b/traceKeyExtractor.py @@ -48,16 +48,23 @@ def main(): dictionaryFilepath = os.path.abspath(dictionaryFilename) print(f"Saved dictionary to {dictionaryFilepath}") + #Instruct the user to create a trace file + print() + print("Start by creating a trace file. In the proxmark terminal, execute command `hf 14a sniff -c -r`.") + print("Then, place the Proxmark3 between the RFID reader and spool.") + print("Load in filament and wait for the process to complete, then press the button on the Proxmark3.") + print("Finally, in the proxmark terminal, execute command `trace save -f [FILEPATH]` to create the trace file.") + print("See the GitHub repository for more details.") + print() + #Get the tracename/filepath from user - print(""); trace = input("Enter trace name or full trace filepath: ") - discoverKeys(); + discoverKeys() - print(f"In proxmark terminal, execute command `hf mf fchk -f {dictionaryFilepath} --dump`") - print(" to create a keyfile from this dictionary") - print() - print("Then execute `hf mf dump` to dump the contents of the RFID tag") + print("Keys obtained. Remove the spool from the AMS and place the Proxmark3 on the spool's tag.") + print(f"In proxmark terminal, execute command `hf mf fchk -f {dictionaryFilepath} --dump` to create a keyfile from this dictionary.") + print("Then, execute `hf mf dump` to dump the contents of the RFID tag.") #Loop 16 times to attempt to extract all 16 keys from the tracefile From e3180a8750d4628dcb39c3aae29f1ecfd9ed5cc7 Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Tue, 25 Jun 2024 12:36:12 -0700 Subject: [PATCH 8/9] Update key extraction steps in readme to recommend running script --- README.md | 226 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 129 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index 25edfd8..b7bb685 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ We are currently working on a way to submit the tag data in a secure way so anal # Table of contents + * [Project Summary](#project-summary) * [FAQs](#faqs) * [How do RFID tags work?](#how-do-rfid-tags-work) @@ -145,104 +146,135 @@ If you place the Proxmark in between the AMS reader and the spool, make sure tha - Load a strand of filament into the AMS. This is what triggers the AMS to attempt to read the RFID tag. - Press the button on the ProxMark to end capture after the filament has completed loading -3. **Create a Key Dictionary** - - We will discover keys one at a time and save them to a dictionary file. - - Navigate to your Proxmark3 software installation directory. This will be specific to your Operating System and Installation. - - macOS (Intel) Example: `/usr/local/Cellar/proxmark3/4.17768/share/proxmark3/` - - macOS (ARM) Eample: `/opt/homebrew/Cellar/proxmark3/4.17768/share/proxmark3/` - - Windows Example: TBD - - Linux Example: TBD - - Open a text editor and save a blank file called `myDictionary.dic` into the `dictionaries/` folder of your Proxmark3 software installation directory. +3. **Extract the Keys** + + 1. **Automatic** (recommended) + + 1. Save the trace results to a file with: `trace save -f [FILENAME]` + + 2. Open a new terminal window and run the trace key extractor script in this repository with Python 3: `python3 traceKeyExtractor.py` + + 3. Input the trace results filepath or drag and drop it into the terminal window + + 4. After the keys are extracted, return to the Proxmark3 software + + 5. Remove the spool from the AMS and hold the Proxmark3 against the RFID tag of the spool + + 6. Run `hf mf fchk -f [dictionaryFilepath] --dump` to create a key file + + - The program will report the destination of the key file that it saved. Copy this filepath to your clipboard. + + - Example: + + ``` + [+] Found keys have been dumped to /Users/mitch/hf-mf-75066B1D-key.bin + ``` + + 2. **Manual** (not recommended) + + 1. **Create a Key Dictionary** + + - We will discover keys one at a time and save them to a dictionary file. + - Navigate to your Proxmark3 software installation directory. This will be specific to your Operating System and Installation. + - macOS (Intel) Example: `/usr/local/Cellar/proxmark3/4.17768/share/proxmark3/` + - macOS (ARM) Eample: `/opt/homebrew/Cellar/proxmark3/4.17768/share/proxmark3/` + - Windows Example: TBD + - Linux Example: TBD + - Open a text editor and save a blank file called `myDictionary.dic` into the `dictionaries/` folder of your Proxmark3 software installation directory. + + (You can call this file anything you want, but for the rest of this example, we will refer to it as "myDictionary") + + - Leave this file open, we will continue to add keys to it in the next step + + 2. **Extract Keys From Trace** + - Run `trace list -t mf -f myDictionary` to view the trace that was recorded from sniffing in the previous step. + + This uses the key dictionary `myDictionary.dic` that we created in step 3. + - Read the output and look for anything that mentions a key. + - Three Possible Formats: + - `key E0B50731BE27 prng WEAK` - Follow Step 5 + - `nested probable key: 50B0318A4FE7` - Follow Step 6 + - `Nested authentication detected.` - Follow Step 7 + + - Each of these 3 entries can provide us with a valid key. Follow step 5, 6, or 7 depending on which type of key you encounter. + + 3. **First Key - Plain Text** + - Example: `key E0B50731BE27 prng WEAK` + - This is the first key that was discovered by sniffing AMS traffic. + - Copy/paste this key into the `myDictionary.dic` file that you created in step 3, then save the file. + 4. **Nested Probable Key** + - Example: `nested probable key: 50B0318A4FE7` + - Copy/paste this key into the `myDictionary.dic` file that you created in step 3, then save the file. + 5. **Nested Authentication Key** + - Example: + ``` + Nested authentication detected. + tools/mf_nonce_brute/mf_nonce_brute 75066b1d 4db2f2ac 0101 70fcdd3d 328eb1e6 1101 28b75cfd 0010 5196401C + ``` + - Open a second terminal window, and change directories into your Proxmark3 software installation directory. This is specific to your OS and PM3 installation. + - macOS/Linux: `cd $(brew --prefix proxmark3)/share/proxmark3/` + - Windows: TBD + - CD into the tools folder `cd tools/` + - Copy the command from ProxMark starting at `mf_nonce_brute`, including all the arguments (random letters/numbers) after it, and run the program from the `tools/` directory. + - Example (macOS/Linux): `./mf_nonce_brute 75066b1d 4db2f2ac 0101 70fcdd3d 328eb1e6 1101 28b75cfd 0010 5196401C` + - Example (Windows): `mf_nonce_brute.exe 75066b1d 4db2f2ac 0101 70fcdd3d 328eb1e6 1101 28b75cfd 0010 5196401C` + - The program will discover a key. Copy/paste this key into your `myDictionary.dic` file, and SAVE IT. + - Example Output: + ``` + Valid Key found [ 202efd3dcdfd ] + ``` + 6. **Check Keys (Optional)** + - If you want to check how many valid keys you've discovered, you can do this test + - This is optional, and you can choose to wait until you have discovered all of the keys + - **WARNING**: Performing a key check will erase the trace that you recorded during step 2, and will require you to re-sniff data (repeat step 2) + - If you want to save your trace to avoid re-sniffing, use `trace save -f ` and `trace load -f ` + + - Run `hf mf fchk --1k -f myDictionary` to test your keys + - Example Output (showing 11/16 keys discovered): + ``` + [+] found keys: + + [+] -----+-----+--------------+---+--------------+---- + [+] Sec | Blk | key A |res| key B |res + [+] -----+-----+--------------+---+--------------+---- + [+] 000 | 003 | E0B50731BE27 | 1 | ------------ | 0 + [+] 001 | 007 | 63654DB94D97 | 1 | ------------ | 0 + [+] 002 | 011 | 387C06EFFDC8 | 1 | ------------ | 0 + [+] 003 | 015 | 38963E577E43 | 1 | ------------ | 0 + [+] 004 | 019 | 8A3EA2564692 | 1 | ------------ | 0 + [+] 005 | 023 | 935E0F11857A | 1 | ------------ | 0 + [+] 006 | 027 | EBC8F7D23A06 | 1 | ------------ | 0 + [+] 007 | 031 | DD6128F13D4C | 1 | ------------ | 0 + [+] 008 | 035 | ------------ | 0 | ------------ | 0 + [+] 009 | 039 | 4E470B09521F | 1 | ------------ | 0 + [+] 010 | 043 | 50EB8811A69C | 1 | ------------ | 0 + [+] 011 | 047 | 4BDD25091824 | 1 | ------------ | 0 + [+] 012 | 051 | ------------ | 0 | ------------ | 0 + [+] 013 | 055 | ------------ | 0 | ------------ | 0 + [+] 014 | 059 | ------------ | 0 | ------------ | 0 + [+] 015 | 063 | ------------ | 0 | ------------ | 0 + [+] -----+-----+--------------+---+--------------+---- + [+] ( 0:Failed / 1:Success ) + ``` + + 7. **Find Remaining Keys** + - Repeat step 4 until all 16 keys are discovered + - Your dictionary may be larger than 16 entries if you accidentally copied a duplicate key or an invalid key. These invalid entries are fine, and you can ignore them + - **Recommended**: When you think you have discovered all 16 keys, perform step 8 to verify that your keys are correct. + + 8. **Convert Dictionary to Key File** + + - Remove the spool from the AMS and hold the Proxmark3 against the RFID tag of the spool + - Run `hf mf fchk --1k -f myDictionary --dump` to create a key file + - The program will report the destination of the key file that it saved. Copy this filepath to your clipboard + - Example: + ``` + [+] Found keys have been dumped to /Users/mitch/hf-mf-75066B1D-key.bin + ``` + +4. **Dump RFID Contents** - (You can call this file anything you want, but for the rest of this example, we will refer to it as "myDictionary") - - - Leave this file open, we will continue to add keys to it in the next step - -4. **Extract Keys From Trace** - - Run `trace list -t mf -f myDictionary` to view the trace that was recorded from sniffing in the previous step. - - This uses the key dictionary `myDictionary.dic` that we created in step 3. - - Read the output and look for anything that mentions a key. - - Three Possible Formats: - - `key E0B50731BE27 prng WEAK` - Follow Step 5 - - `nested probable key: 50B0318A4FE7` - Follow Step 6 - - `Nested authentication detected.` - Follow Step 7 - - - Each of these 3 entries can provide us with a valid key. Follow step 5, 6, or 7 depending on which type of key you encounter. - -5. **First Key - Plain Text** - - Example: `key E0B50731BE27 prng WEAK` - - This is the first key that was discovered by sniffing AMS traffic. - - Copy/paste this key into the `myDictionary.dic` file that you created in step 3, then save the file. -6. **Nested Probable Key** - - Example: `nested probable key: 50B0318A4FE7` - - Copy/paste this key into the `myDictionary.dic` file that you created in step 3, then save the file. -7. **Nested Authentication Key** - - Example: - ``` - Nested authentication detected. - tools/mf_nonce_brute/mf_nonce_brute 75066b1d 4db2f2ac 0101 70fcdd3d 328eb1e6 1101 28b75cfd 0010 5196401C - ``` - - Open a second terminal window, and change directories into your Proxmark3 software installation directory. This is specific to your OS and PM3 installation. - - macOS/Linux: `cd $(brew --prefix proxmark3)/share/proxmark3/` - - Windows: TBD - - CD into the tools folder `cd tools/` - - Copy the command from ProxMark starting at `mf_nonce_brute`, including all the arguments (random letters/numbers) after it, and run the program from the `tools/` directory. - - Example (macOS/Linux): `./mf_nonce_brute 75066b1d 4db2f2ac 0101 70fcdd3d 328eb1e6 1101 28b75cfd 0010 5196401C` - - Example (Windows): `mf_nonce_brute.exe 75066b1d 4db2f2ac 0101 70fcdd3d 328eb1e6 1101 28b75cfd 0010 5196401C` - - The program will discover a key. Copy/paste this key into your `myDictionary.dic` file, and SAVE IT. - - Example Output: - ``` - Valid Key found [ 202efd3dcdfd ] - ``` -8. **Check Keys (Optional)** - - If you want to check how many valid keys you've discovered, you can do this test - - This is optional, and you can choose to wait until you have discovered all of the keys - - **WARNING**: Performing a key check will erase the trace that you recorded during step 2, and will require you to re-sniff data (repeat step 2) - - If you want to save your trace to avoid re-sniffing, use `trace save -f ` and `trace load -f ` - - - Run `hf mf fchk --1k -f myDictionary` to test your keys - - Example Output (showing 11/16 keys discovered): - ``` - [+] found keys: - - [+] -----+-----+--------------+---+--------------+---- - [+] Sec | Blk | key A |res| key B |res - [+] -----+-----+--------------+---+--------------+---- - [+] 000 | 003 | E0B50731BE27 | 1 | ------------ | 0 - [+] 001 | 007 | 63654DB94D97 | 1 | ------------ | 0 - [+] 002 | 011 | 387C06EFFDC8 | 1 | ------------ | 0 - [+] 003 | 015 | 38963E577E43 | 1 | ------------ | 0 - [+] 004 | 019 | 8A3EA2564692 | 1 | ------------ | 0 - [+] 005 | 023 | 935E0F11857A | 1 | ------------ | 0 - [+] 006 | 027 | EBC8F7D23A06 | 1 | ------------ | 0 - [+] 007 | 031 | DD6128F13D4C | 1 | ------------ | 0 - [+] 008 | 035 | ------------ | 0 | ------------ | 0 - [+] 009 | 039 | 4E470B09521F | 1 | ------------ | 0 - [+] 010 | 043 | 50EB8811A69C | 1 | ------------ | 0 - [+] 011 | 047 | 4BDD25091824 | 1 | ------------ | 0 - [+] 012 | 051 | ------------ | 0 | ------------ | 0 - [+] 013 | 055 | ------------ | 0 | ------------ | 0 - [+] 014 | 059 | ------------ | 0 | ------------ | 0 - [+] 015 | 063 | ------------ | 0 | ------------ | 0 - [+] -----+-----+--------------+---+--------------+---- - [+] ( 0:Failed / 1:Success ) - ``` - -9. **Find Remaining Keys** - - Repeat step 4 until all 16 keys are discovered - - Your dictionary may be larger than 16 entries if you accidentally copied a duplicate key or an invalid key. These invalid entries are fine, and you can ignore them - - **Recommended**: When you think you have discovered all 16 keys, perform step 8 to verify that your keys are correct. - -10. **Convert Dictionary to Key File** - - Run `hf mf fchk --1k -f myDictionary --dump` to create a key file - - The program will report the destination of the key file that it saved. Copy this filepath to your clipboard - - Example: - ``` - [+] Found keys have been dumped to /Users/mitch/hf-mf-75066B1D-key.bin - ``` -11. **Dump RFID Contents** - - Run `hf mf dump -k [path-to-keyfile]` to dump the contents of the tag using the 16 keys we discovered + - Run `hf mf dump -k [path-to-keyfile]` while the Proxmark3 is on the spool's RFID tag to dump the contents of the tag using the 16 keys we discovered - There should be no errors - The output should tell you where your `.bin` file is saved - Example: From 928bc2cfd9a55a3eb91945549b211ff085aa67d1 Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Sat, 28 Sep 2024 17:30:27 -0700 Subject: [PATCH 9/9] Python 3.11 and lower require alternating quote types in f-strings --- traceKeyExtractor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/traceKeyExtractor.py b/traceKeyExtractor.py index a73447a..d60b42a 100644 --- a/traceKeyExtractor.py +++ b/traceKeyExtractor.py @@ -85,7 +85,7 @@ def discoverKeys(): # -c specifies commands within proxmark 3 software cmd_list = [pm3Location / pm3Command,"-o","-c", f"trace load -f {trace}; trace list -1 -t mf -f {dictionaryFilepath}; exit"]; print(f"Viewing tracelog with {len(keyList)} discovered keys") - print(f"pm3 {" ".join(cmd_list[1:])}") + print(f"pm3 {' '.join(cmd_list[1:])}") result = subprocess.run(cmd_list, shell=os.name == 'nt',stdout=subprocess.PIPE, stderr=subprocess.PIPE) output = result.stdout; @@ -192,7 +192,7 @@ def bruteForce(args): cmd_list = [pm3Location / mfNonceBruteCommand] + args print(" Running bruteforce command:") print(" ",end = "") - print(f"tools/mf_nonce_brute {" ".join(cmd_list[1:])}") + print(f"tools/mf_nonce_brute {' '.join(cmd_list[1:])}") result = subprocess.run(cmd_list, shell=os.name == 'nt', stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Parse out the key