]>
Commit | Line | Data |
---|---|---|
3ad48540 | 1 | /***************************************************************************** |
d60418a0 MHS |
2 | * WARNING |
3 | * | |
4 | * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. | |
5 | * | |
6 | * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL | |
7 | * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, | |
8 | * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. | |
9 | * | |
10 | * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. | |
11 | * | |
12 | ***************************************************************************** | |
13 | * | |
14 | * This file is part of loclass. It is a reconstructon of the cipher engine | |
3ad48540 MHS |
15 | * used in iClass, and RFID techology. |
16 | * | |
17 | * The implementation is based on the work performed by | |
18 | * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and | |
19 | * Milosch Meriac in the paper "Dismantling IClass". | |
20 | * | |
21 | * Copyright (C) 2014 Martin Holst Swende | |
22 | * | |
23 | * This is free software: you can redistribute it and/or modify | |
24 | * it under the terms of the GNU General Public License version 2 as published | |
25 | * by the Free Software Foundation. | |
26 | * | |
27 | * This file is distributed in the hope that it will be useful, | |
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30 | * GNU General Public License for more details. | |
31 | * | |
32 | * You should have received a copy of the GNU General Public License | |
d60418a0 MHS |
33 | * along with loclass. If not, see <http://www.gnu.org/licenses/>. |
34 | * | |
35 | * | |
36 | * | |
3ad48540 MHS |
37 | ****************************************************************************/ |
38 | ||
d60418a0 | 39 | |
3ad48540 | 40 | #include <stdio.h> |
3ad48540 MHS |
41 | #include <stdint.h> |
42 | #include <stdbool.h> | |
43 | #include <string.h> | |
44 | #include <unistd.h> | |
45 | #include <ctype.h> | |
46 | #include "cipherutils.h" | |
47 | #include "cipher.h" | |
48 | #include "ikeys.h" | |
49 | #include "fileutils.h" | |
50 | #include "elite_crack.h" | |
51 | ||
52 | int unitTests() | |
53 | { | |
54 | int errors = testCipherUtils(); | |
55 | errors += testMAC(); | |
56 | errors += doKeyTests(0); | |
57 | errors += testElite(); | |
d60418a0 MHS |
58 | if(errors) |
59 | { | |
60 | prnlog("OBS! There were errors!!!"); | |
61 | } | |
3ad48540 MHS |
62 | return errors; |
63 | } | |
64 | int showHelp() | |
65 | { | |
d60418a0 | 66 | prnlog("Usage: loclass [options]"); |
3ad48540 MHS |
67 | prnlog("Options:"); |
68 | prnlog("-t Perform self-test"); | |
69 | prnlog("-h Show this help"); | |
70 | prnlog("-f <filename> Bruteforce iclass dumpfile"); | |
71 | prnlog(" An iclass dumpfile is assumed to consist of an arbitrary number of malicious CSNs, and their protocol responses"); | |
b8140ab1 | 72 | prnlog(" The binary format of the file is expected to be as follows: "); |
3ad48540 MHS |
73 | prnlog(" <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>"); |
74 | prnlog(" <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>"); | |
75 | prnlog(" <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>"); | |
76 | prnlog(" ... totalling N*24 bytes"); | |
77 | prnlog(" Check iclass_dump.bin for an example"); | |
78 | ||
79 | return 0; | |
80 | } | |
81 | ||
82 | int main (int argc, char **argv) | |
83 | { | |
84 | prnlog("IClass Cipher version 1.2, Copyright (C) 2014 Martin Holst Swende\n"); | |
85 | prnlog("Comes with ABSOLUTELY NO WARRANTY"); | |
d60418a0 MHS |
86 | prnlog("Released as GPLv2\n"); |
87 | prnlog("WARNING"); | |
88 | prnlog(""); | |
89 | prnlog("THIS TOOL IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. "); | |
90 | prnlog(""); | |
91 | prnlog("USAGE OF THIS TOOL IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL "); | |
92 | prnlog("PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, "); | |
93 | prnlog("AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. "); | |
94 | prnlog(""); | |
95 | prnlog("THIS TOOL SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. "); | |
96 | ||
97 | ||
3ad48540 MHS |
98 | char *fileName = NULL; |
99 | int c; | |
100 | while ((c = getopt (argc, argv, "thf:")) != -1) | |
101 | switch (c) | |
102 | { | |
103 | case 't': | |
104 | return unitTests(); | |
105 | case 'h': | |
106 | return showHelp(); | |
107 | case 'f': | |
108 | fileName = optarg; | |
109 | return bruteforceFileNoKeys(fileName); | |
110 | case '?': | |
111 | if (optopt == 'f') | |
112 | fprintf (stderr, "Option -%c requires an argument.\n", optopt); | |
113 | else if (isprint (optopt)) | |
114 | fprintf (stderr, "Unknown option `-%c'.\n", optopt); | |
115 | else | |
116 | fprintf (stderr, | |
117 | "Unknown option character `\\x%x'.\n", | |
118 | optopt); | |
119 | return 1; | |
120 | //default: | |
121 | //showHelp(); | |
122 | } | |
123 | showHelp(); | |
124 | return 0; | |
125 | } | |
126 |