1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2020 Michael Farrell <micolous+git@gmail.com>
3 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // See LICENSE.txt for the text of the license.
16 //-----------------------------------------------------------------------------
17 // main code for standalone HF/iso14a Sniff to flash
18 //-----------------------------------------------------------------------------
21 * `hf_14asniff` passively sniffs ISO14a frames, and stores them in internal
22 * flash. It requires RDV4 hardware (for flash and battery).
24 * This module is similar to hf_bog (which only logs ULC/NTAG/ULEV1 auth).
26 * On entering stand-alone mode, this module will start sniffing ISO14a frames.
27 * This will be stored in the normal trace buffer (ie: in RAM -- will be lost
30 * Short-pressing the button again will stop sniffing, and at _this_ point
31 * append trace data from RAM to a file in flash (hf_14asniff.trace) and unmount.
33 * Once the data is saved, standalone mode will exit.
37 * - LED2: sniffed tag command, turns off when finished sniffing reader command
38 * - LED3: sniffed reader command, turns off when finished sniffing tag command
39 * - LED4: unmounting/sync'ing flash (normally < 100ms)
41 * To retrieve trace data from flash:
43 * 1. mem spiffs dump -s hf_14asniff.trace -d hf_14asniff.trace
44 * Copies trace data file from flash to your PC.
46 * 2. trace load -f hf_14asniff.trace
47 * Loads trace data from a file into PC-side buffers.
49 * 3. For ISO14a: trace list -t 14a -1
50 * For MIFARE Classic: trace list -t mf -1
52 * Lists trace data from buffer without requesting it from PM3.
54 * This module emits debug strings during normal operation -- so try it out in
55 * the lab connected to PM3 client before taking it into the field.
57 * To delete the trace data from flash:
58 * mem spiffs remove -f hf_14asniff.trace
61 * - Trace buffer will be cleared on starting stand-alone mode. Data in flash
62 * will remain unless explicitly deleted.
63 * - This module will terminate if the trace buffer is full (and save data to
65 * - Like normal sniffing mode, timestamps overflow after 5 min 16 sec.
66 * However, the trace buffer is sequential, so will be in the correct order.
69 #include "standalone.h" // standalone definitions
70 #include "proxmark3_arm.h"
71 #include "iso14443a.h"
79 #define HF_14ASNIFF_LOGFILE "hf_14asniff.trace"
81 static void DownloadTraceInstructions(void) {
83 Dbprintf("To get the trace from flash and display it:");
84 Dbprintf("1. mem spiffs dump -s "HF_14ASNIFF_LOGFILE
" -d hf_14asniff.trace");
85 Dbprintf("2. trace load -f hf_14asniff.trace");
86 Dbprintf("3. trace list -t 14a -1");
90 DbpString(" HF 14A SNIFF, a ISO14443a sniffer with storing in flashmem");
91 DownloadTraceInstructions();
97 Dbprintf(_YELLOW_("HF 14A SNIFF started"));
99 rdv40_spiffs_lazy_mount();
104 Dbprintf("Stopped sniffing");
107 uint32_t trace_len
= BigBuf_get_traceLen();
109 // Keep stuff in BigBuf for USB/BT dumping
111 Dbprintf("[!] Trace length (bytes) = %u", trace_len
);
113 // Write stuff to spiffs logfile
115 Dbprintf("[!] Trace length (bytes) = %u", trace_len
);
117 uint8_t *trace_buffer
= BigBuf_get_addr();
118 if (!exists_in_spiffs(HF_14ASNIFF_LOGFILE
)) {
120 HF_14ASNIFF_LOGFILE
, trace_buffer
, trace_len
, RDV40_SPIFFS_SAFETY_SAFE
);
121 Dbprintf("[!] Wrote trace to "HF_14ASNIFF_LOGFILE
);
124 HF_14ASNIFF_LOGFILE
, trace_buffer
, trace_len
, RDV40_SPIFFS_SAFETY_SAFE
);
125 Dbprintf("[!] Appended trace to "HF_14ASNIFF_LOGFILE
);
128 Dbprintf("[!] Trace buffer is empty, nothing to write!");
132 rdv40_spiffs_lazy_unmount();
135 SpinErr(LED_A
, 200, 5);
139 Dbprintf("-=[ exit ]=-");
142 DownloadTraceInstructions();