1 00:00:00,000 --> 00:00:07,360 attack NFC platforms using quite basic components. So what is NFC? Mainly it's to 2 00:00:07,360 --> 00:00:11,800 do with opening doors or paying for things or accessing the underground 3 00:00:11,800 --> 00:00:18,240 train system and yeah it's basically one card being spoken to by a reader that 4 00:00:18,240 --> 00:00:23,420 illuminates it with a field using induction and communicates with it. Why 5 00:00:23,420 --> 00:00:27,280 would we attack NFC? Well as I said before it's used in payment systems, door 6 00:00:27,280 --> 00:00:33,220 access control systems and metro lines and it can be found anywhere and it's 7 00:00:33,220 --> 00:00:37,020 a type of protocol that is quite insecure with most of the 8 00:00:37,020 --> 00:00:42,320 security relying on very weak encryption or the fact that there is a very very 9 00:00:42,320 --> 00:00:48,860 low range for the tags and the readers. So as I said before we're going to talk 10 00:00:48,860 --> 00:00:54,060 about the protocols involved and how you build tools to work with them and 11 00:00:54,060 --> 00:00:57,040 from there we're going to talk about the main standard which is 12 00:00:57,040 --> 00:01:03,700 used which is ISO 14443. Now this is the 13.56 megahertz protocol which is for 13 00:01:03,700 --> 00:01:08,100 my fair classic cards and ultralight cards which are generally used for hotel 14 00:01:08,100 --> 00:01:15,760 room keys or door controls. It defines characteristics as ISO 14443A which is 15 00:01:15,760 --> 00:01:20,220 the most common and 4443B which is slightly less used. From there we're 16 00:01:20,220 --> 00:01:25,760 going to build a tool that will analyze and emulate a my fair classic tag using 17 00:01:25,760 --> 00:01:26,820 these protocols. 18 00:01:27,940 --> 00:01:31,460 So low-level communication wise tags are powered by an electromagnetic 19 00:01:31,460 --> 00:01:38,180 inductor from the reader which basically powers it through the inductors so that 20 00:01:38,180 --> 00:01:44,000 the card can communicate back and forth using that power to communicate via 21 00:01:44,000 --> 00:01:48,540 drawing load from the reader. The reader uses a modified Miller encoding 22 00:01:48,540 --> 00:01:51,720 this is a kind of encoding which basically has a large amount of space 23 00:01:51,720 --> 00:01:56,860 between bits so that there's not too much power loss or glitching due to the 24 00:01:57,040 --> 00:02:01,520 communication being involved and as and responses are sent by Manchester 25 00:02:01,520 --> 00:02:06,440 coding which is a radio encoding scheme which is basically for keeping track of 26 00:02:06,440 --> 00:02:12,880 data quite simply and with a high level of timing issues. So modified Miller as 27 00:02:12,880 --> 00:02:16,280 I said before it's basically disabling the field at certain intervals making 28 00:02:16,280 --> 00:02:20,480 sure that the tag has enough power to still run but to also receive data so 29 00:02:20,480 --> 00:02:25,280 it's defined as a 0.0 bit being a low transition followed by high for 30 00:02:25,280 --> 00:02:26,100 the rest of the transmission. 31 00:02:27,040 --> 00:02:31,600 bit after one being high for the entire transmission and a one bit just being 32 00:02:31,600 --> 00:02:34,960 high for the first half of the transmission a small dip and then back 33 00:02:34,960 --> 00:02:39,040 up again and this is completely designed so that there is never a really small 34 00:02:39,040 --> 00:02:43,260 gap between power losses and that the communication works well. Manchester 35 00:02:43,260 --> 00:02:47,860 coding is performed by modifying the phase of a signal using a sub carrier 36 00:02:47,860 --> 00:02:51,980 this is done by basically drawing loads from the reader so that you can 37 00:02:51,980 --> 00:02:54,800 analyze that to see what the tag is saying and this is done so that there 38 00:02:54,800 --> 00:02:59,240 doesn't need to be some kind of proper two-way communication. So how basic 39 00:02:59,240 --> 00:03:03,320 enumeration works is the reader always starts off the transaction and the tag 40 00:03:03,320 --> 00:03:08,740 always responds so it usually starts off with the reader giving a request or wake 41 00:03:08,740 --> 00:03:14,520 up command which the tag then responds with a response defining the basics of 42 00:03:14,520 --> 00:03:21,220 what the tag does. The reader then tries to select a tag by requesting any tags 43 00:03:21,220 --> 00:03:24,400 in the field to send their unique identifying number now this can be four 44 00:03:24,400 --> 00:03:24,780 bytes, three bytes, three bytes, three bytes, three bytes, three bytes, three bytes, three bytes. 45 00:03:24,780 --> 00:03:31,880 seven bytes or nine bytes and then the reader can then select using that ID and 46 00:03:31,880 --> 00:03:36,980 the end of that transaction is the tag sending the SAK response which is the 47 00:03:36,980 --> 00:03:41,040 very specific definition of what kind of tag it is. From there the reader can then 48 00:03:41,040 --> 00:03:43,360 try and authenticate or communicate with the tag in the way that it's meant to. 49 00:03:44,440 --> 00:03:48,700 There is an extra section which is called anti collision this is performed when 50 00:03:48,700 --> 00:03:52,120 there's more than one tag on a reader at the same time and they haven't yet 51 00:03:52,120 --> 00:03:52,740 enumerated properly. 52 00:03:52,740 --> 00:03:57,640 It involves the requesting responses based on partial UIDs so when the reader 53 00:03:57,640 --> 00:04:01,140 sends a request for all the UIDs in the field it will often get garbled 54 00:04:01,140 --> 00:04:04,920 communication back because the communication being sent is from two 55 00:04:04,920 --> 00:04:08,640 tags at the same time so what it does is it tries to differentiate between the 56 00:04:08,640 --> 00:04:12,920 two using small amounts of the unique identifiers that are used. Increasing 57 00:04:12,920 --> 00:04:17,640 number of bits as it goes along will mean it eventually finds a set of unique identifier 58 00:04:17,640 --> 00:04:22,680 bits that do not match on both tags and then it can select that unique identifier and 59 00:04:22,680 --> 00:04:23,860 then go through to the next one. 60 00:04:25,720 --> 00:04:29,620 So we're going to talk about a few different kinds of tags there are so the first one is 61 00:04:29,620 --> 00:04:34,540 my fraught flight which is the most simple there is. So that uses an authentication key 62 00:04:34,540 --> 00:04:37,960 which is sent to the tag in the plane. Usually there are other ways that it can be done 63 00:04:37,960 --> 00:04:42,700 but this is the most basic way. If the key is accurate the reader has authenticated and 64 00:04:42,700 --> 00:04:46,980 then send communication which isn't encrypted and all the communication can be performed. 65 00:04:47,600 --> 00:04:51,440 If it's wrong then usually the tag will log the failed communication and lock after a 66 00:04:51,440 --> 00:04:51,540 while. 67 00:04:51,540 --> 00:04:56,200 So that tag can never be used again. It can also be set up to use no 68 00:04:56,200 --> 00:05:01,480 authentication which is quite insecure. It has support for a few 69 00:05:01,480 --> 00:05:03,880 different other authentication techniques especially in newer versions 70 00:05:03,880 --> 00:05:08,420 such as my fraught flight C but usually these aren't used and more complex and 71 00:05:08,420 --> 00:05:12,940 secure methods are used at that point. There's my fair classic which is 72 00:05:12,940 --> 00:05:16,220 probably the most common you'll see anywhere in the world so this is used 73 00:05:16,220 --> 00:05:20,120 everywhere and is one of the most insecure protocols there are and yet 74 00:05:20,120 --> 00:05:20,860 it's still used everywhere. 75 00:05:21,540 --> 00:05:26,300 It utilizes the crypto one algorithm which is known to be broken in a huge number of 76 00:05:26,300 --> 00:05:31,380 ways. Basically the reader requests authentication for a sector of the tag. The tag responds with 77 00:05:31,380 --> 00:05:36,440 a unique four byte value. The reader responds with a brand new value followed by a value 78 00:05:36,440 --> 00:05:42,520 generated by the original random value sent by the tag which is then encrypted and the 79 00:05:42,520 --> 00:05:46,220 tag responds with an encrypted number generated from that value. All further communication 80 00:05:46,220 --> 00:05:50,020 is then encrypted using this algorithm from that authentication. 81 00:05:51,540 --> 00:05:56,260 Each sector of the tag can have two keys and they can be completely unique to 82 00:05:56,260 --> 00:06:01,380 that section of the tag. Then finally there's my fair death fire which is 83 00:06:01,380 --> 00:06:08,660 interesting because it is not broken yet in any reasonable manner so it's 84 00:06:08,660 --> 00:06:12,780 based on different application IDs and it can authenticate based on DES, triple 85 00:06:12,780 --> 00:06:16,660 DES and AES depending on how it's set up. Multiple keys can be used for 86 00:06:16,660 --> 00:06:21,400 authentication and it can be authenticated. The authentication works similarly to my 87 00:06:21,400 --> 00:06:25,240 fair classic. The reason it's not been broken in the same way is due to the fact that my 88 00:06:25,240 --> 00:06:29,180 fair classic's weaknesses lie in the encryption used and as my fair death fire is using slightly 89 00:06:29,180 --> 00:06:32,180 more complex encryption it's more secure against these attacks. 90 00:06:34,580 --> 00:06:38,760 So first we're going to talk about creating analysis tools for hacking NFC. So usually 91 00:06:38,760 --> 00:06:42,460 when you think of these things you think of like the proxmark or maybe more complex tools 92 00:06:42,460 --> 00:06:46,220 like the ESRP and I decided to try and make tools out of the most basic components I could 93 00:06:46,220 --> 00:06:50,780 find. So anything that I could get as raw components or as a very small tool. 94 00:06:52,280 --> 00:06:56,000 So here's a list of some of the existing tools. So you have the proxmark and the 95 00:06:56,000 --> 00:06:58,980 chameleon mini which are the most well known and the most commonly used for 96 00:06:58,980 --> 00:07:02,820 actual engagements and tests. The proxmark 3 being able to be a reader, a 97 00:07:02,820 --> 00:07:06,860 tag or just passively sniff the communication. There is hydro NFC, simple 98 00:07:06,860 --> 00:07:12,000 NFC and emu tag which are more hobbyist level projects and are very interesting 99 00:07:12,000 --> 00:07:14,640 in their own way because they can perform communication with small tools 100 00:07:14,640 --> 00:07:20,320 especially the same as some of the tools I've created today are. So firstly how do 101 00:07:20,320 --> 00:07:21,340 you detect an NFC field? 102 00:07:21,400 --> 00:07:25,920 Well you can detect it with just an LED and a coil of wire. If you put that circuit as 103 00:07:25,920 --> 00:07:30,220 small as it is into an NFC field that LED will light up and tell you when communication 104 00:07:30,220 --> 00:07:34,400 is occurring. It's very useful for detecting whether the field is active but apart from 105 00:07:34,400 --> 00:07:36,660 that it's just interesting to see how simply it can work. 106 00:07:37,980 --> 00:07:41,840 First thing I wanted to do though was create a passive sniffing tool so basically so I 107 00:07:41,840 --> 00:07:47,380 could see the communication between a reader and a tag and view how the communication goes 108 00:07:47,380 --> 00:07:51,160 on and see where the attacks can lie. So I used an RCL SDR which is a 109 00:07:51,400 --> 00:07:58,800 basic and most cheap SDR tool you can buy. It can tune between 25 MHz and 1700 MHz, it's 110 00:07:58,800 --> 00:08:02,480 got quite a strong sample rate that can be configured quite well and there's a huge 111 00:08:02,480 --> 00:08:05,720 number of libraries that can work with it. There are a few problems for what we were 112 00:08:05,720 --> 00:08:10,340 doing though as it couldn't tune all the way down to 13.56 MHz without some hardware 113 00:08:10,340 --> 00:08:14,640 modifications and the low sample rates used by the communication between the tag and 114 00:08:14,640 --> 00:08:18,720 the reader it was just too high for so I'd have to find a way around that. It's also 115 00:08:18,720 --> 00:08:21,240 bundled with some weak hardware including the weak antenna and it's also bundled with 116 00:08:21,400 --> 00:08:23,620 the weak antenna and it's not really built for a specific purpose which is the main 117 00:08:23,620 --> 00:08:29,620 problem with software defined radios. So I managed to get past most of these limitations 118 00:08:29,620 --> 00:08:37,000 by using little tricks with no hardware modifications necessary. So firstly in order to read the 119 00:08:37,000 --> 00:08:42,600 communication from a reader I tuned up to 27.12 MHz which is the harmonic frequency 120 00:08:43,140 --> 00:08:50,720 of 13.56 MHz. Due to the fact that there's a huge amount of raw power going through a 121 00:08:51,400 --> 00:08:54,720 device to communicate with a tag it's possible to pick up all the harmonic frequencies and 122 00:08:54,720 --> 00:08:58,960 all the noise coming and use that to get the signal and the definition as it's going through. 123 00:08:59,460 --> 00:09:05,400 I could synchronise with the sample rate twice what it needs to be so I set it to 1.695 124 00:09:05,400 --> 00:09:11,900 MHz which is double the 847.5 kHz required for communication. Antenna modifications weren't 125 00:09:11,900 --> 00:09:19,600 required as I took that first circuit, the LED in the coil and put it around the antenna 126 00:09:19,600 --> 00:09:20,320 that came with it. 127 00:09:21,400 --> 00:09:25,560 Due to the fact that when a reader detects any tags in the field it ramps up the power 128 00:09:25,560 --> 00:09:29,640 being used I managed to pick up the signal from that. As there was a constant signal 129 00:09:29,640 --> 00:09:33,320 I could also use automatic gain control which meant it could be very easily analysed as 130 00:09:33,320 --> 00:09:38,260 things were going on. I managed to get real time analysis of communication from a reader 131 00:09:38,260 --> 00:09:42,820 to a tag but not the other way around. Due to the fact that I was using a harmonic frequency 132 00:09:42,820 --> 00:09:44,540 it wasn't possible to get it the other way around. 133 00:09:45,020 --> 00:09:49,860 So here's a dump of the output as it came from the reader. So first we start with a 134 00:09:49,860 --> 00:09:50,500 wake up command. 135 00:09:51,400 --> 00:09:55,600 It's basically saying any tags that haven't been spoken to yet please talk to me. A selection 136 00:09:55,600 --> 00:09:59,800 because it already knew the tag that was in place and a halt command saying it doesn't 137 00:09:59,800 --> 00:10:04,400 want to communicate anymore. And then another request in order to see if there are any other 138 00:10:04,400 --> 00:10:08,840 tags on the reader and a wake up to speak to the tag it had already spoken to again. 139 00:10:09,840 --> 00:10:14,400 From here I wanted to build a Myfair Classic tag from scratch in a way where I could do 140 00:10:14,400 --> 00:10:18,580 completely raw communication with it and modify any parts of the protocol I needed to. So 141 00:10:18,580 --> 00:10:20,720 I wanted to do it without any abstract hardware whatsoever. 142 00:10:21,400 --> 00:10:26,300 No NFC chipsets, I just wanted to use a microcontroller and any hardware I could make. I wanted to 143 00:10:26,300 --> 00:10:29,860 use minimal components and cheap components so that I could make it really reproducible 144 00:10:29,860 --> 00:10:35,020 and also because if I take that concept and make it really simple I can then add complex 145 00:10:35,020 --> 00:10:39,040 features to it later. It would require me to implement the crypto one authentication 146 00:10:39,040 --> 00:10:44,520 in a way which is usable and add complexity to the project when it was going on. By fully 147 00:10:44,520 --> 00:10:48,400 implementing this protocol though I'd be able to find weaknesses in it and also create tools 148 00:10:48,400 --> 00:10:49,120 to attack them. 149 00:10:51,400 --> 00:10:56,120 Inductive coupling, exactly the same as the LED in the coil or anything else. This signal 150 00:10:56,120 --> 00:10:59,720 would need to be demodulated by amplitude. This would not be possible on the microcontroller 151 00:10:59,720 --> 00:11:03,380 so it would need to be done in hardware. And I would need a microcontroller which was 152 00:11:03,380 --> 00:11:09,180 fast enough and powerful enough to run at 13.56 megahertz accurately. This would also 153 00:11:09,180 --> 00:11:13,220 require complex encryption calculations which would need to be done sufficiently quickly 154 00:11:13,620 --> 00:11:15,320 and it would need enough memory to do them as well. 155 00:11:16,380 --> 00:11:20,480 So let's start with the circuit. So I started with an LC circuit. This is just an inductor 156 00:11:20,480 --> 00:11:21,160 and a capacitor together. 157 00:11:21,400 --> 00:11:28,920 Which is used to tune to the reader's inductive coupling. I could just test with a big coil 158 00:11:28,920 --> 00:11:33,180 of wire and multiple different capacitors until in a logic analyzer I got a frequency 159 00:11:33,180 --> 00:11:36,860 that matched digitally. Due to the amount of power being put through it's possible just 160 00:11:36,860 --> 00:11:39,640 to check with a logic analyzer rather than a scope or anything more complex. 161 00:11:42,040 --> 00:11:46,040 I then added an envelope detector which can be made from a diode, resistor and capacitor. 162 00:11:46,420 --> 00:11:51,120 Now this is used commonly for decoding AM radio signals. 163 00:11:51,400 --> 00:11:55,660 Especially when they're using binary and amplitude shift key. And it literally works 164 00:11:55,660 --> 00:11:59,560 by rectifying the signal and then smoothing it until you get the exact signal that was 165 00:11:59,560 --> 00:12:04,620 actually being modulated rather than the original version. The values can be guessed 166 00:12:04,620 --> 00:12:10,300 by trial and error and I got it to a 1K resistor and a 220 pico farad capacitor. All I needed 167 00:12:10,300 --> 00:12:14,780 to do was create this circuit and again run it through a logic analyzer and if I got the 168 00:12:14,780 --> 00:12:19,140 modified Miller communication, which I did see as shown there, I would be able to work 169 00:12:19,140 --> 00:12:19,380 with it. 170 00:12:21,400 --> 00:12:25,540 circuit that was required and all that needed to happen was one of those pins would go to ground 171 00:12:25,540 --> 00:12:30,000 and the other would go to an input pin which could then allow me to receive on a microcontroller 172 00:12:31,180 --> 00:12:36,260 i decided to go for the 80 tiny 84 microcontroller because it's extremely simple extremely cheap 173 00:12:36,260 --> 00:12:40,340 and it's quite easy to work with from a programming perspective it has eight kilobytes 174 00:12:40,340 --> 00:12:47,020 of ram and 512 bytes of ram 8k of flash it can be programmed using an arduino or a dedicated 175 00:12:47,020 --> 00:12:54,060 programmer and it can use excel crystals really well to do tuning to a correct frequency so i put 176 00:12:54,060 --> 00:12:58,960 a 13.56 megahertz crystal there the dip package means it'd be really easy to build from a hobbyist 177 00:12:58,960 --> 00:13:04,840 perspective it can be done on a breadboard or anything and it would be nice to it's very easy 178 00:13:04,840 --> 00:13:09,400 to work with the gpios on it it does have good support for interrupts and timers which came to 179 00:13:09,400 --> 00:13:14,880 be very important later but very bad support for the debugging also the 8-bit architecture on it 180 00:13:14,880 --> 00:13:17,000 meant that it was very bad for debugging 181 00:13:17,020 --> 00:13:17,880 doing encryption calculations 182 00:13:20,160 --> 00:13:24,420 i added the 13.56 megahertz crystal which meant it ran in sync with the reader 183 00:13:24,900 --> 00:13:30,200 i added the receiving circuit just to one pin which received the data and then tied another 184 00:13:30,200 --> 00:13:36,140 pin to it to send data back using pulse with module modulation basically creating load on that 185 00:13:36,140 --> 00:13:41,540 pin as it's receiving in order to get the data back due to uart on it which is the usual thing 186 00:13:41,540 --> 00:13:45,020 you'd use for debugging on this particular platform not being feasible as the clock was 187 00:13:45,020 --> 00:13:46,940 non-standard i basically dumped 188 00:13:47,020 --> 00:13:49,900 out debug strings and debug data via software software-based 189 00:13:50,760 --> 00:13:56,020 sbi just to another dev board so i could analyze the data i added an led which was attached to 190 00:13:56,020 --> 00:14:00,680 confirm the device was working and i basically set up the state machine as you would see it 191 00:14:00,680 --> 00:14:06,060 on a appropriate my fair classic tag so sending responses for selection and authentication when it 192 00:14:06,060 --> 00:14:11,280 is meant to be done there are a few timing issues that came across the first thing i did when i was 193 00:14:11,280 --> 00:14:16,640 running this was basically trying to receive data at a rate of 847 and a half kilohertz 194 00:14:17,020 --> 00:14:20,140 now this should have allowed me to receive the modified miller data as it was going along 195 00:14:20,140 --> 00:14:25,200 at predefined intervals but due to the fact that it had a huge amount of clock drift due to heat 196 00:14:25,200 --> 00:14:29,520 time and power issues it meant that the thing would get out of sync very quickly and i'd only 197 00:14:29,520 --> 00:14:34,180 receive about 50 of the transmissions instead what i did was basically check the difference 198 00:14:34,180 --> 00:14:38,720 in time between each drop in the signal and use that to receive the data and that gave me a very 199 00:14:38,720 --> 00:14:45,420 high accuracy enough to make the tag behave appropriately i then had to implement crypto 1 and 200 00:14:47,020 --> 00:14:49,520 despite the fact that people don't want you to know about it. 201 00:14:49,780 --> 00:14:51,940 The main library that's used is called Crapto1, 202 00:14:52,120 --> 00:14:55,720 which is a great way of saying that it's a terrible encryption library, 203 00:14:55,880 --> 00:14:58,220 and there's a huge amount of papers about how it works. 204 00:14:58,520 --> 00:15:00,940 It's found to be based on 48-bit keys 205 00:15:00,940 --> 00:15:03,140 that are basically split into two 24-bit keys 206 00:15:03,140 --> 00:15:05,220 and just swapped between during authentication, 207 00:15:05,860 --> 00:15:08,780 and due to the amount of bit shifts and calculations involved, 208 00:15:09,160 --> 00:15:12,020 the 8-bit microcontroller will just have a few problems with it, 209 00:15:12,180 --> 00:15:16,700 the main one being that bit shifts on the AVR microcontrollers, 210 00:15:16,700 --> 00:15:19,700 the AT-Tinies, have to be done one at a time, 211 00:15:19,760 --> 00:15:23,140 meaning if you want to do a 16-bit shift, that's 16 operations, 212 00:15:24,100 --> 00:15:26,060 or sometimes if it's optimized, a lot quicker. 213 00:15:26,940 --> 00:15:29,340 The main culprit for this issue was the filter function, 214 00:15:29,500 --> 00:15:31,940 which is used to generate the encrypted bits as it went along. 215 00:15:32,960 --> 00:15:34,940 This is the main filter function, and as you can see, 216 00:15:35,000 --> 00:15:37,440 there's a lot of bit shifts, a lot of large numbers 217 00:15:37,440 --> 00:15:41,100 that are larger than 8-bit, and lots of other calculations. 218 00:15:42,020 --> 00:15:43,480 So we have these bit shifts, 219 00:15:43,560 --> 00:15:46,080 which would need to be converted into much more efficient bit shifts, 220 00:15:46,700 --> 00:15:48,140 we had these 20-bit values, 221 00:15:48,360 --> 00:15:52,400 which are being calculated in C as 32-bit values, 222 00:15:52,540 --> 00:15:55,080 but could be calculated as 20-bit if we did it in assembly, 223 00:15:55,280 --> 00:15:58,900 and we had one 32-bit value, which had a few complications. 224 00:16:00,440 --> 00:16:02,640 What I ended up doing was taking all the CryptoOne code 225 00:16:02,640 --> 00:16:05,460 and converting it to AVR assembly in order to optimize it. 226 00:16:05,680 --> 00:16:08,440 So I wrote from scratch all these filter functions and calculations 227 00:16:08,440 --> 00:16:10,700 in order to find the efficiency where I could. 228 00:16:10,920 --> 00:16:14,200 I used the SimAVR emulator because it's much easier to debug, 229 00:16:14,360 --> 00:16:16,520 and put it right against the main CryptoOne, 230 00:16:16,700 --> 00:16:18,520 and then I did a little authentication and basically did a unit test 231 00:16:18,520 --> 00:16:20,420 to check that they were putting out the same data. 232 00:16:21,180 --> 00:16:22,860 All the calculations could be sped up, 233 00:16:22,920 --> 00:16:24,560 the most complex of which being the bit shifts, 234 00:16:24,800 --> 00:16:28,600 which I could do by basically modifying how it performed those. 235 00:16:28,780 --> 00:16:31,180 So if for 16-bit shifts, dropping the data down, 236 00:16:31,380 --> 00:16:33,540 8-bit shifts, dropping it down slightly less, 237 00:16:33,800 --> 00:16:36,480 4-bit shifts, swapping the upper and lower nibbles of the data, 238 00:16:36,600 --> 00:16:39,140 and then just doing standard bit shifts when it was necessary. 239 00:16:40,000 --> 00:16:42,020 This made the thing about 10 times faster, 240 00:16:42,180 --> 00:16:46,240 meaning that it could now behave as a proper MyFair Classic tag with any reader. 241 00:16:47,680 --> 00:16:49,740 This is the horrendous assembly that was used. 242 00:16:51,540 --> 00:16:53,720 It's very quick, but not very well written. 243 00:16:54,660 --> 00:16:56,100 And this is the final product. 244 00:16:56,240 --> 00:16:58,240 Now, as you can see, it's a very, very simple circuit. 245 00:16:58,520 --> 00:17:02,260 The lower one is everything you need to emulate a MyFair Classic tag on this platform, 246 00:17:02,420 --> 00:17:07,020 and do it in raw in a way which will allow you to perform attacks on it, 247 00:17:07,100 --> 00:17:08,860 or modify the authentication. 248 00:17:10,440 --> 00:17:12,380 If we could play demo one now, that would be excellent. 249 00:17:12,480 --> 00:17:12,860 Please. 250 00:17:20,940 --> 00:17:24,100 I found that that reader that I was using, Afro Border from Taobao, 251 00:17:24,180 --> 00:17:27,220 was also used in Beijing Airport, which was very exciting to take through customs. 252 00:17:28,220 --> 00:17:31,320 But it did get through. 253 00:17:32,760 --> 00:17:34,600 As said before, there were hardware limitations. 254 00:17:34,680 --> 00:17:39,560 Due to the fact that it was 8K of flash and 512 bytes of RAM, 255 00:17:39,720 --> 00:17:42,920 there wasn't enough room left to do anything more complex 256 00:17:42,920 --> 00:17:45,600 with the authentication or encryption or assessment. 257 00:17:45,600 --> 00:17:50,680 I couldn't add extra tooling to it, and just due to the fact that the hardware was not up to scratch, 258 00:17:50,800 --> 00:17:54,020 I decided to make something a bit more complex in order to make a proper analysis tool. 259 00:17:54,760 --> 00:17:58,300 Due to the fact that it had really slow responses, there were some readers which weren't compatible, 260 00:17:58,720 --> 00:18:02,820 but I found that these readers often weren't compatible with Proxmarks or Chameleon minis either. 261 00:18:04,320 --> 00:18:08,500 So I decided to build a bigger and better device using an STM32 microcontroller. 262 00:18:08,600 --> 00:18:11,380 Now, these can be bought very cheaply in development boards, 263 00:18:11,560 --> 00:18:15,160 have great support for debugging, and huge amounts of memory to work with. 264 00:18:15,600 --> 00:18:22,520 The one I used was the STM32L496, which has one megabyte of flash and 320 kilobytes of RAM, 265 00:18:22,680 --> 00:18:25,940 which is 640 times more than the ATtiny. 266 00:18:26,260 --> 00:18:30,700 The clock speed could go up to 80 megahertz, but it could also tune to 72 megahertz, 267 00:18:30,800 --> 00:18:32,660 which became very important later. 268 00:18:33,220 --> 00:18:36,360 Also, the fact that it was using a 32-bit architecture and it was ARM 269 00:18:36,360 --> 00:18:39,460 meant that encryption calculations were much, much easier to work with. 270 00:18:40,020 --> 00:18:43,200 It also has a large number of useful peripherals, including USB and UART, 271 00:18:43,260 --> 00:18:45,580 meaning it was easier to basically dump data out of it. 272 00:18:45,600 --> 00:18:46,300 So it's not as complicated as it is going on. 273 00:18:47,800 --> 00:18:51,080 I set it up using the STM32 cube, which is a very useful tool 274 00:18:51,080 --> 00:18:53,860 that basically lets you use hardware extraction to set things up. 275 00:18:54,380 --> 00:18:58,020 And then I could just copy a lot of the core code from the ATtiny version into it, 276 00:18:58,100 --> 00:19:03,540 apart from the data for sending responses and receiving data from the reader. 277 00:19:04,140 --> 00:19:05,920 There were going to be synchronization issues, though, 278 00:19:05,980 --> 00:19:10,660 because it couldn't tune to the specific clock rate that it needed to, the 13.56 megahertz. 279 00:19:11,800 --> 00:19:14,100 The internal clock of the chip is quite configurable 280 00:19:14,100 --> 00:19:16,800 and can go from a huge number of frequencies, 281 00:19:16,880 --> 00:19:20,920 due to the fact that the STM32 cube will take a value you give it 282 00:19:20,920 --> 00:19:24,440 and work out exactly what it needs to do to get the clock that fast. 283 00:19:26,520 --> 00:19:30,020 This could have caused problems with transmitting data but not receiving it, 284 00:19:30,100 --> 00:19:34,160 because the spaces in time between each signal would still be fairly slow 285 00:19:34,160 --> 00:19:35,860 and allow you to pick up the differences between them. 286 00:19:36,240 --> 00:19:38,960 I didn't want to use an external crystal, because it would add complexity to the board, 287 00:19:39,020 --> 00:19:41,300 and on a development board, this can also cause a few problems. 288 00:19:42,520 --> 00:19:43,720 Without an accurate clock, though, 289 00:19:43,780 --> 00:19:44,080 we could have a lot of problems with the clock, 290 00:19:44,080 --> 00:19:44,880 and we couldn't do much work with it, 291 00:19:44,940 --> 00:19:46,500 so I had to find a way to get in sync with it. 292 00:19:47,360 --> 00:19:49,640 What I ended up doing was finding every frequency 293 00:19:49,640 --> 00:19:54,020 that was within about 10% accuracy against 13.56 megahertz 294 00:19:54,020 --> 00:19:59,120 in order to find one which could then be within range for the Manchester coding to still work. 295 00:19:59,580 --> 00:20:01,380 I basically processed through these frequencies 296 00:20:01,380 --> 00:20:06,300 and found that 72 megahertz was the fastest and most efficient frequency that could be used for this. 297 00:20:07,840 --> 00:20:10,660 This is the same circuit as before, just built onto the development board. 298 00:20:10,860 --> 00:20:13,980 It's got a big coil of wire, the tuned LC circuit, 299 00:20:14,080 --> 00:20:17,140 and the envelope detector just attached to two pins and the ground. 300 00:20:18,400 --> 00:20:21,560 That's all you need to emulate a MyFair Classic tag in hardware. 301 00:20:23,340 --> 00:20:26,880 Because it was so efficient, so fast, and it had so much flash and RAM available, 302 00:20:27,160 --> 00:20:29,280 I could implement a huge number of new features. 303 00:20:29,760 --> 00:20:32,840 The first one I did was implement support for multiple tags. 304 00:20:33,180 --> 00:20:36,040 This would mean if you had a reader that could support multiple tags, 305 00:20:36,140 --> 00:20:39,280 you could make it pretend to be one, two, three, or more different kinds of tags. 306 00:20:41,120 --> 00:20:43,580 These multiple requests can be used to cause exploits, 307 00:20:43,580 --> 00:20:47,400 or just for making things more efficient when you're working with them. 308 00:20:47,580 --> 00:20:50,540 All I needed to do was set up the same state machines over and over again, 309 00:20:50,660 --> 00:20:54,540 and make it process through them as data was going through. 310 00:20:56,060 --> 00:20:59,280 I could add dynamic key generation, so I could make the UIDs, 311 00:20:59,280 --> 00:21:02,500 which are completely randomized on my device, 312 00:21:03,120 --> 00:21:06,180 generate correct keys for the different readers. 313 00:21:06,340 --> 00:21:09,320 So if you can generate a huge number of different UIDs, 314 00:21:09,320 --> 00:21:12,820 you can get all the different keys that can be made using CryptoOne Attacks. 315 00:21:12,820 --> 00:21:16,760 And then work with those to try and reverse-engineer how those keys are generated. 316 00:21:18,800 --> 00:21:20,400 I started implementing DesFire. 317 00:21:20,620 --> 00:21:23,660 Now, DesFire, the only place that I've seen it used is back in England, 318 00:21:23,780 --> 00:21:25,780 where it's used for Oyster Cards in London. 319 00:21:26,580 --> 00:21:30,420 It's an incredibly powerful protocol with very strong encryption, 320 00:21:30,680 --> 00:21:33,980 but it's also not been implemented very often in other devices, 321 00:21:34,020 --> 00:21:35,760 just because it is highly complex. 322 00:21:36,160 --> 00:21:40,780 So what I ended up doing was taking my phone, which has a tool for doing my fare, DesFire, 323 00:21:40,900 --> 00:21:42,800 and taped it to the tag that I had created. 324 00:21:42,820 --> 00:21:45,420 And then went through the different communications, 325 00:21:45,600 --> 00:21:47,300 sending responses appropriately as it went along. 326 00:21:47,500 --> 00:21:49,760 And from there, I could build up to the point of doing authentication, 327 00:21:50,140 --> 00:21:53,140 which works similarly to how it works in MyFair Classic, 328 00:21:53,360 --> 00:21:55,140 but with much more robust and strong encryption. 329 00:21:56,860 --> 00:21:58,580 There it is, just attached to the tag, 330 00:21:58,680 --> 00:22:00,380 and that's all I needed to do to communicate with it. 331 00:22:02,140 --> 00:22:04,580 So let's talk about some security weaknesses in NFC now, 332 00:22:04,680 --> 00:22:06,680 now that we've built the appropriate tools for it. 333 00:22:08,340 --> 00:22:11,080 So CryptoOne, as I've said before, is very, very weak. 334 00:22:12,820 --> 00:22:16,340 So the attacks were shown in Dismantling MyFair Classic, 335 00:22:16,560 --> 00:22:19,700 a very old paper which basically went through every single weakness possible 336 00:22:19,700 --> 00:22:21,840 from the tag side, reader side, et cetera. 337 00:22:23,080 --> 00:22:27,040 These included the fact that it uses a 48-bit key split into two, 338 00:22:27,120 --> 00:22:28,240 which can then be processed separately. 339 00:22:28,940 --> 00:22:30,500 Authentication is vulnerable to replay attacks 340 00:22:30,500 --> 00:22:32,500 because of the weak random number generated on the tag. 341 00:22:32,760 --> 00:22:37,440 The nonces can be used to recover a keystream, 342 00:22:37,580 --> 00:22:38,940 which can then be used on brute-force attacks. 343 00:22:39,260 --> 00:22:41,960 And it can be rolled back to the start of the authentication, 344 00:22:42,160 --> 00:22:42,800 in order to get the report back. 345 00:22:42,800 --> 00:22:49,200 original keys. So in order to do this, what you need to do is start authentication with 346 00:22:49,200 --> 00:22:54,020 my tag or any other one or a proxmark until the point where the reader has sent back the 347 00:22:54,020 --> 00:22:58,860 8-bit response from the original nonce. This response contains the random values and the 348 00:22:58,860 --> 00:23:04,560 ones generated from the tag. And this can be used to be XORed with the original nonce 349 00:23:04,560 --> 00:23:09,900 because it's a deterministic value in order to generate 32 bits of keystream. Basically 350 00:23:09,900 --> 00:23:15,420 then, you can separate those two 32 bits of keystream into 16 bits of keystream, which 351 00:23:15,420 --> 00:23:20,760 can then be handled separately. So what you would do is take one of the keys and process 352 00:23:20,760 --> 00:23:25,480 through 16 of those bits and find every single value out of the 24 bits that matches that 353 00:23:25,480 --> 00:23:30,140 keystream and then do it for the other 16 bits as well. This in one way, so going from 354 00:23:30,140 --> 00:23:33,940 the first bit of the keystream to the end, this would create 200,000 values from the 355 00:23:33,940 --> 00:23:39,880 original 16 million. If you did it backwards, you'd get 30,000 different keys from the 356 00:23:39,880 --> 00:23:43,320 original for both the 24 bits of encryption, which can then be used to work together. 357 00:23:43,720 --> 00:23:48,520 These matching key pairs then can be processed together just via brute force very quickly 358 00:23:48,520 --> 00:23:54,780 and you can end up cracking the keys in about 10 minutes with this process. So that's the 359 00:23:54,780 --> 00:24:00,240 authentication request. That's the nonce response from the tag. That's the random value 360 00:24:00,240 --> 00:24:06,040 and that is the encrypted value generated from that original value. This can be used 361 00:24:06,040 --> 00:24:09,280 to perform offline cracking. You just need two reads from a tag and nothing else. 362 00:24:10,620 --> 00:24:15,100 And it can be used much more efficiently than reader-based attacks when it comes to 363 00:24:15,100 --> 00:24:19,200 a tag. So rather than trying to pickpocket someone to do attacks on the tag, you can 364 00:24:19,200 --> 00:24:22,400 just walk up to the reader and do it. And because it's using offline cracking, you just 365 00:24:22,400 --> 00:24:26,220 go home and wait for the keys to be cracked. This functionality is available on other devices, 366 00:24:26,280 --> 00:24:31,200 but it's never used because it's very, very inefficient to work with. It's just not very 367 00:24:31,200 --> 00:24:31,580 practical. 368 00:24:32,900 --> 00:24:39,700 So I decided to implement this attack taking a Japanese video game, which has a USB reader 369 00:24:40,240 --> 00:24:46,520 on it and basically has no research whatsoever so far. So I wouldn't be able to just guess 370 00:24:46,520 --> 00:24:50,760 the keys in order to perform this attack. I'd have to use this process in order to authenticate 371 00:24:50,760 --> 00:24:51,120 with them. 372 00:24:51,620 --> 00:24:55,920 So I worked out the USB protocol just by using a BeagleBone Black and the USB proxy tool 373 00:24:55,920 --> 00:25:00,480 to man in the middle of the communication and then made it just dump the tag UIDs and 374 00:25:00,480 --> 00:25:04,620 request data, which would then create authentication. The reader was found to be compatible with 375 00:25:04,620 --> 00:25:08,860 the Proxmark. It wasn't found to be compatible with the Proxmark just because the speed of 376 00:25:08,860 --> 00:25:09,700 the response is expected. 377 00:25:09,880 --> 00:25:12,820 So I'd say from the reader to the tag and the amount that's going on on that device. 378 00:25:15,260 --> 00:25:19,100 So there's the tag. Just attach the reader and if we could do demo number two now, please. 379 00:25:23,160 --> 00:25:27,860 So we just placed it on the reader and it just generates these authentication tokens. 380 00:25:30,380 --> 00:25:34,340 And that's the UID and it's just sending authentication data, which can then be processed 381 00:25:34,340 --> 00:25:34,660 later. 382 00:25:37,860 --> 00:25:39,860 I basically dumped these out. 383 00:25:39,860 --> 00:25:47,900 So via UART on the device and then put it through a program on my laptop, which just ran through the keys and generated the keys from them. 384 00:25:49,140 --> 00:25:51,560 And as you can see, it was done in 10 minutes. 385 00:25:52,000 --> 00:25:57,380 And this was very consistent as I processed through different types of keys and different UIDs. 386 00:25:58,800 --> 00:26:03,280 Some of the improvements that could be made to CryptoOne is first, we increased the key size to something much larger. 387 00:26:03,280 --> 00:26:11,420 This would have some problems with, obviously, efficiency when it came to the tags, because there's not a lot of complex circuitry in there for doing encryption. 388 00:26:12,300 --> 00:26:13,700 But it would have made it more secure. 389 00:26:13,840 --> 00:26:16,440 Even up to 64 bits would have made it a huge amount more secure. 390 00:26:17,100 --> 00:26:25,700 The usage of a single large key that was processed through would be much better than just having two keys that are processed together, because there wouldn't be that separation that could be used for the attack. 391 00:26:26,060 --> 00:26:29,920 And an improved random number generator would be just so much better for this. 392 00:26:30,200 --> 00:26:33,260 And as this weakness was because of known plaintext. 393 00:26:33,280 --> 00:26:34,820 Because of tags, it was just much better. 394 00:26:37,000 --> 00:26:38,740 So let's talk about some raw protocol weaknesses. 395 00:26:39,000 --> 00:26:51,620 Now, this is very important, because most other attack tools, aside from the more complex ones, the more expensive ones, like the Proxmark, the Chameleon Mini, et cetera, require complex NFC-based chipsets. 396 00:26:51,720 --> 00:26:55,520 Which means it can't go down to the raw communication level in order to perform attacks. 397 00:26:56,040 --> 00:27:02,820 This means that these tags, usually, you feed it a UID, and it handles all the communication for you, apart from some of the authentication. 398 00:27:04,040 --> 00:27:10,040 As I could change any part of the communication by doing this raw communication, I could do anything I wanted to it. 399 00:27:10,480 --> 00:27:16,520 The greatest weakness I found was denial of service using the anti-collision procedures which happened at the initial enumeration. 400 00:27:18,060 --> 00:27:21,000 So here's a quote from the Texas Instruments documentation on this. 401 00:27:21,560 --> 00:27:26,340 So, due to the recursive nature of the anti-collision algorithm, there is a risk of a stack overflow. 402 00:27:26,740 --> 00:27:29,000 I found this to be very true in a huge number of readers. 403 00:27:29,220 --> 00:27:33,260 And what people generally do is just never implement this anti-collision feature because of it. 404 00:27:33,260 --> 00:27:35,920 But when do they do it? They often get it wrong. 405 00:27:37,500 --> 00:27:47,160 So, every time the reader sent a request to my tag, I would send completely messy responses back that looked like there were two tags on the reader sending a response. 406 00:27:47,520 --> 00:27:50,400 I constantly did this, despite it trying to request more and more bits. 407 00:27:50,660 --> 00:27:55,400 And the tag never limited how much data was being sent back. 408 00:27:55,620 --> 00:27:59,660 So the reader would then basically constantly try and find the unique UID. 409 00:28:00,460 --> 00:28:03,240 Even past the maximum size of UID. 410 00:28:03,260 --> 00:28:04,020 And this is a very common feature that can be found in the reader. 411 00:28:05,260 --> 00:28:09,720 This weakness is known about, but it's really not found anywhere because no one really implements this feature. 412 00:28:09,860 --> 00:28:12,820 But it can be used to crash readers when you use it. 413 00:28:13,960 --> 00:28:15,820 There's a few high-level protocol weaknesses. 414 00:28:16,140 --> 00:28:24,420 For instance, each tag type uses things called NDEF data or block data, etc., which has different sizes and different methods for communicating. 415 00:28:24,800 --> 00:28:30,380 And each of these have weaknesses in the buffers and size just from how they work. 416 00:28:31,640 --> 00:28:33,120 The authentication mechanism. 417 00:28:33,260 --> 00:28:37,540 Often have weaknesses, as demonstrated before, in the My Fair Classic tag. 418 00:28:37,920 --> 00:28:42,880 But it's extremely easy to identify them in other things as well. 419 00:28:43,380 --> 00:28:49,640 Weaknesses in things like the My Fair Ultralight, where it just sends a plain text key, is obviously very simple to sniff. 420 00:28:49,960 --> 00:28:56,800 The reason that Deathfire, etc., is much more secure is because it's using authentication, which just doesn't have these weaknesses in it. 421 00:28:58,860 --> 00:29:03,240 I decided to compile all this research up into one tool for testing. 422 00:29:03,260 --> 00:29:04,340 Proper testing purposes. 423 00:29:04,440 --> 00:29:09,340 I decided to take everything that I'd learned, everything I'd built, and put it inside a toy sonic screwdriver. 424 00:29:10,560 --> 00:29:19,840 And basically take all the tools and the exploits and put them one by one in a device so I can click through them at will in order to do different attacks. 425 00:29:20,240 --> 00:29:21,840 The first one would be fuzzing. 426 00:29:22,180 --> 00:29:25,160 Second, it transmits the authentication data via RF. 427 00:29:30,460 --> 00:29:32,540 Yeah, can we play demonstration in video three? 428 00:29:46,160 --> 00:29:50,140 So what that was doing is basically randomizing its unique identifiers. 429 00:29:50,280 --> 00:29:58,060 And as it was processing through them, essentially sending that data via RF to my computer via an RTL-SDR. 430 00:29:58,260 --> 00:30:02,160 So what it basically has is an ASK transmitter, as shown in the pictures. 431 00:30:03,260 --> 00:30:08,080 It's what you generally use for opening a garage door, but it's very useful for communicating small amounts of data in a project. 432 00:30:08,440 --> 00:30:11,380 And I could then use that to crack that data offline remotely. 433 00:30:12,420 --> 00:30:14,800 Can we play demonstration four just to demonstrate that, please? 434 00:30:21,520 --> 00:30:27,140 So yeah, literally just sending data to my computer via the RTL-SDR again, which is very simple. 435 00:30:28,880 --> 00:30:31,720 This tool came to be very useful, and I'm still adding features to it. 436 00:30:31,780 --> 00:30:33,240 But I think after a while, it'll be quite useful. 437 00:30:33,260 --> 00:30:38,400 I think I'm going to put it in a different case, but I definitely think it's got some merit. 438 00:30:41,100 --> 00:30:45,260 So what I'm going to be doing now is basically releasing all the source code, all the designs and everything, 439 00:30:45,440 --> 00:30:49,120 so you can look through them and see what you want about them. 440 00:30:49,260 --> 00:30:55,080 The most important of these would be the STM32 tools, which have the most credibility for future work, 441 00:30:55,220 --> 00:30:57,260 as it's very powerful and can be used for a lot of different things. 442 00:30:57,540 --> 00:31:02,560 I'm going to set up the boards to be a bit more complex and a little bit more tolerant of errors and that sort of thing. 443 00:31:03,260 --> 00:31:05,280 And I'm going to start implementing DESFire properly. 444 00:31:05,500 --> 00:31:10,560 So if we can implement this entire protocol and feature, then the weaknesses can be identified in it much better. 445 00:31:10,760 --> 00:31:16,460 And we'll be able to find exploits and weaknesses in the encryption, which can then be further used in order to perform attacks on it. 446 00:31:18,860 --> 00:31:20,860 There's my GitHub if you want to go look for the code. 447 00:31:21,160 --> 00:31:22,540 And thank you very much. 448 00:31:33,940 --> 00:31:34,880 Thank you very much.