]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfawid.c
1 //-----------------------------------------------------------------------------
2 // Authored by Craig Young <cyoung@tripwire.com> based on cmdlfhid.c structure
4 // cmdlfhid.c is Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
6 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
7 // at your option, any later version. See the LICENSE.txt file for the text of
9 //-----------------------------------------------------------------------------
10 // Low frequency AWID26 commands
11 //-----------------------------------------------------------------------------
13 #include <stdio.h> // sscanf
14 #include "proxmark3.h" // Definitions, USB controls, etc
15 #include "ui.h" // PrintAndLog
16 #include "cmdparser.h" // CmdsParse, CmdsHelp
17 #include "cmdlfawid.h" // AWID function declarations
18 #include "lfdemod.h" // parityTest
19 #include "util.h" // weigandparity
20 #include "protocols.h" // for T55xx config register definitions
24 static int CmdHelp(const char *Cmd
);
26 int usage_lf_awid_fskdemod(void) {
27 PrintAndLog("Enables AWID compatible reader mode printing details of scanned AWID26 or AWID50 tags.");
28 PrintAndLog("By default, values are printed and logged until the button is pressed or another USB command is issued.");
29 PrintAndLog("If the [1] option is provided, reader mode is exited after reading a single AWID card.");
31 PrintAndLog("Usage: lf awid fskdemod [1]");
32 PrintAndLog("Options :");
33 PrintAndLog(" 1 : (optional) stop after reading a single card");
35 PrintAndLog("Samples");
36 PrintAndLog(" lf awid fskdemod");
37 PrintAndLog(" lf awid fskdemod 1");
41 int usage_lf_awid_sim(void) {
42 PrintAndLog("Enables simulation of AWID card with specified facility-code and card number.");
43 PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
45 PrintAndLog("Usage: lf awid sim <format> <facility-code> <card-number>");
46 PrintAndLog("Options :");
47 PrintAndLog(" <format> : format length 26|50");
48 PrintAndLog(" <facility-code> : 8|16bit value facility code");
49 PrintAndLog(" <card number> : 16|32-bit value card number");
51 PrintAndLog("Samples");
52 PrintAndLog(" lf awid sim 26 224 1337");
53 PrintAndLog(" lf awid sim 50 2001 13371337");
57 int usage_lf_awid_clone(void) {
58 PrintAndLog("Enables cloning of AWID card with specified facility-code and card number onto T55x7.");
59 PrintAndLog("The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process.");
61 PrintAndLog("Usage: lf awid clone <format> <facility-code> <card-number>");
62 PrintAndLog("Options :");
63 PrintAndLog(" <format> : format length 26|50");
64 PrintAndLog(" <facility-code> : 8|16bit value facility code");
65 PrintAndLog(" <card number> : 16|32-bit value card number");
66 PrintAndLog(" Q5 : optional - clone to Q5 (T5555) instead of T55x7 chip");
68 PrintAndLog("Samples");
69 PrintAndLog(" lf awid clone 26 224 1337");
70 PrintAndLog(" lf awid clone 50 2001 13371337");
74 int usage_lf_awid_brute(void){
75 PrintAndLog("Enables bruteforce of AWID reader with specified facility-code.");
76 PrintAndLog("This is a incremental attack against reader.");
78 PrintAndLog("Usage: lf awid brute <format> <facility-code>");
79 PrintAndLog("Options :");
80 PrintAndLog(" <format> : format length 26|50");
81 PrintAndLog(" <facility-code> : 8|16bit value facility code");
83 PrintAndLog("Samples");
84 PrintAndLog(" lf awid brute 26 224");
85 PrintAndLog(" lf awid brute 50 2001");
89 int CmdAWIDDemodFSK(const char *Cmd
) {
91 if (Cmd
[0] == 'h' || Cmd
[0] == 'H') return usage_lf_awid_fskdemod();
92 if (Cmd
[0] == '1') findone
= 1;
94 UsbCommand c
= {CMD_AWID_DEMOD_FSK
, {findone
, 0, 0}};
100 //refactored by marshmellow
101 int getAWIDBits(uint8_t fmtlen
, uint32_t fc
, uint32_t cn
, uint8_t *bits
) {
103 // the return bits, preamble 0000 0001
107 memset(pre
, 0, sizeof(pre
));
110 num_to_bytebits(fmtlen
, 8, pre
);
112 // add facilitycode, cardnumber and wiegand parity bits
113 if ( fmtlen
== 26 ) {
115 num_to_bytebits(fc
, 8, wiegand
);
116 num_to_bytebits(cn
, 16, wiegand
+8);
117 wiegand_add_parity(pre
+8, wiegand
, sizeof(wiegand
));
120 num_to_bytebits(fc
, 16, wiegand
);
121 num_to_bytebits(cn
, 32, wiegand
+16);
122 wiegand_add_parity(pre
+8, wiegand
, sizeof(wiegand
));
125 // add AWID 4bit parity
126 size_t bitLen
= addParity(pre
, bits
+8, 66, 4, 1);
128 if (bitLen
!= 88) return 0;
132 int CmdAWIDSim(const char *Cmd
) {
133 uint32_t fc
= 0, cn
= 0;
137 size_t size
= sizeof(bits
);
138 memset(bs
, 0x00, size
);
140 uint64_t arg1
= ( 10 << 8 ) + 8; // fcHigh = 10, fcLow = 8
141 uint64_t arg2
= 50; // clk RF/50 invert=0
143 char cmdp
= param_getchar(Cmd
, 0);
144 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_awid_sim();
146 fmtlen
= param_get8(Cmd
, 0);
147 fc
= param_get32ex(Cmd
, 1, 0, 10);
148 cn
= param_get32ex(Cmd
, 2, 0, 10);
149 if ( !fc
|| !cn
) return usage_lf_awid_sim();
153 if ((fc
& 0xFF) != fc
) {
155 PrintAndLog("Facility-Code Truncated to 8-bits (AWID26): %u", fc
);
158 if ((cn
& 0xFFFF) != cn
) {
160 PrintAndLog("Card Number Truncated to 16-bits (AWID26): %u", cn
);
164 if ((fc
& 0xFFFF) != fc
) {
166 PrintAndLog("Facility-Code Truncated to 16-bits (AWID50): %u", fc
);
172 PrintAndLog("Emulating AWID %u -- FC: %u; CN: %u\n", fmtlen
, fc
, cn
);
173 PrintAndLog("Press pm3-button to abort simulation or run another command");
175 if (!getAWIDBits(fmtlen
, fc
, cn
, bs
)) {
176 PrintAndLog("Error with tag bitstream generation.");
179 // AWID uses: fcHigh: 10, fcLow: 8, clk: 50, invert: 0
180 // arg1 --- fcHigh<<8 + fcLow
181 // arg2 --- Inversion and clk setting
182 // 96 --- Bitstream length: 96-bits == 12 bytes
183 UsbCommand c
= {CMD_FSK_SIM_TAG
, {arg1
, arg2
, size
}};
184 memcpy(c
.d
.asBytes
, bs
, size
);
185 clearCommandBuffer();
190 int CmdAWIDClone(const char *Cmd
) {
191 uint32_t blocks
[4] = {T55x7_MODULATION_FSK2a
| T55x7_BITRATE_RF_50
| 3<<T55x7_MAXBLOCK_SHIFT
, 0, 0, 0};
192 uint32_t fc
= 0, cn
= 0;
196 memset(bs
,0,sizeof(bits
));
198 char cmdp
= param_getchar(Cmd
, 0);
199 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_awid_clone();
201 fmtlen
= param_get8(Cmd
, 0);
202 fc
= param_get32ex(Cmd
, 1, 0, 10);
203 cn
= param_get32ex(Cmd
, 2, 0, 10);
205 if ( !fc
|| !cn
) return usage_lf_awid_clone();
209 if ((fc
& 0xFFFF) != fc
) {
211 PrintAndLog("Facility-Code Truncated to 16-bits (AWID50): %u", fc
);
216 if ((fc
& 0xFF) != fc
) {
218 PrintAndLog("Facility-Code Truncated to 8-bits (AWID26): %u", fc
);
221 if ((cn
& 0xFFFF) != cn
) {
223 PrintAndLog("Card Number Truncated to 16-bits (AWID26): %u", cn
);
228 if (param_getchar(Cmd
, 4) == 'Q' || param_getchar(Cmd
, 4) == 'q')
229 blocks
[0] = T5555_MODULATION_FSK2
| T5555_INVERT_OUTPUT
| 50<<T5555_BITRATE_SHIFT
| 3<<T5555_MAXBLOCK_SHIFT
;
231 if ( !getAWIDBits(fmtlen
, fc
, cn
, bs
)) {
232 PrintAndLog("Error with tag bitstream generation.");
236 blocks
[1] = bytebits_to_byte(bs
,32);
237 blocks
[2] = bytebits_to_byte(bs
+32,32);
238 blocks
[3] = bytebits_to_byte(bs
+64,32);
240 PrintAndLog("Preparing to clone AWID %u to T55x7 with FC: %u, CN: %u", fmtlen
, fc
, cn
);
241 PrintAndLog("Blk | Data ");
242 PrintAndLog("----+------------");
243 PrintAndLog(" 00 | 0x%08x", blocks
[0]);
244 PrintAndLog(" 01 | 0x%08x", blocks
[1]);
245 PrintAndLog(" 02 | 0x%08x", blocks
[2]);
246 PrintAndLog(" 03 | 0x%08x", blocks
[3]);
249 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {0,0,0}};
251 for (uint8_t i
=0; i
<4; i
++) {
252 c
.arg
[0] = blocks
[i
];
254 clearCommandBuffer();
256 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)){
257 PrintAndLog("Error occurred, device did not respond during write operation.");
264 int CmdAWIDBrute(const char *Cmd
){
270 size_t size
= sizeof(bits
);
271 memset(bs
, 0x00, size
);
273 char cmdp
= param_getchar(Cmd
, 0);
274 if (strlen(Cmd
) > 4 || strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_awid_brute();
276 fmtlen
= param_get8(Cmd
, 0);
277 fc
= param_get32ex(Cmd
, 1, 0, 10);
278 if ( !fc
) return usage_lf_awid_brute();
282 if ((fc
& 0xFFFF) != fc
) {
284 PrintAndLog("Facility-Code Truncated to 16-bits (AWID50): %u", fc
);
288 if ((fc
& 0xFF) != fc
) {
290 PrintAndLog("Facility-Code Truncated to 8-bits (AWID26): %u", fc
);
295 PrintAndLog("Bruteforceing AWID %d Reader", fmtlen
);
296 PrintAndLog("Press pm3-button to abort simulation or run another command");
298 uint64_t arg1
= (10<<8) + 8; // fcHigh = 10, fcLow = 8
299 uint64_t arg2
= 50; // clk RF/50 invert=0
300 UsbCommand c
= {CMD_FSK_SIM_TAG
, {arg1
, arg2
, size
}};
302 for ( uint16_t cn
= 1; cn
< 0xFFFF; ++cn
){
304 PrintAndLog("aborted via keyboard!");
309 clearCommandBuffer();
314 (void)getAWIDBits(fmtlen
, fc
, cn
, bs
);
315 memcpy(c
.d
.asBytes
, bs
, size
);
316 clearCommandBuffer();
319 PrintAndLog("Trying FC: %u; CN: %u", fc
, cn
);
326 static command_t CommandTable
[] = {
327 {"help", CmdHelp
, 1, "This help"},
328 {"fskdemod", CmdAWIDDemodFSK
, 0, "['1'] Realtime AWID FSK demodulator (option '1' for one tag only)"},
329 {"sim", CmdAWIDSim
, 0, "<Facility-Code> <Card Number> -- AWID tag simulator"},
330 {"clone", CmdAWIDClone
, 0, "<Facility-Code> <Card Number> <Q5> -- Clone AWID to T55x7"},
331 {"brute", CmdAWIDBrute
, 0, "<Facility-Code> -- bruteforce card number"},
332 {NULL
, NULL
, 0, NULL
}
335 int CmdLFAWID(const char *Cmd
) {
336 clearCommandBuffer();
337 CmdsParse(CommandTable
, Cmd
);
341 int CmdHelp(const char *Cmd
) {
342 CmdsHelp(CommandTable
);