1 00:00:03,460 --> 00:00:08,800 Hi DevCom, how's it going? So thank you guys for joining to this presentation. 2 00:00:09,880 --> 00:00:16,060 Contactless Overflow, where we're gonna discuss about code execution issues in 3 00:00:16,060 --> 00:00:24,120 NFC readers that are used in point-of-sales and ATMs. So short introduction about 4 00:00:24,120 --> 00:00:29,260 myself, I'm a principal security consultant at IOactive, so I'm a guy that 5 00:00:29,260 --> 00:00:33,680 most of his time is doing reverse engineering, basically from bare metal 6 00:00:33,680 --> 00:00:40,260 framework operating system, whatever that can be reverse engineered. Also I do 7 00:00:40,260 --> 00:00:44,880 some hardware hacking as well, code review also a lot for framework operating 8 00:00:44,880 --> 00:00:51,160 systems, applications, whatever. So basically I'm a guy that likes to break 9 00:00:51,160 --> 00:00:58,540 stuff and learn new things, but also I enjoy to find mitigations and 10 00:00:58,540 --> 00:00:59,240 solutions for those issues. So I'm a guy that likes to find mitigations and solutions for 11 00:00:59,240 --> 00:01:03,100 those findings because sometimes it's quite challenging as well. 12 00:01:05,260 --> 00:01:09,420 So this is the agenda for the presentation where we're going to have some interaction 13 00:01:09,710 --> 00:01:17,940 and then we will describe with technical details some of the code execution issues and then 14 00:01:17,940 --> 00:01:22,200 we'll also talk about the ATM scenario more in particular. 15 00:01:23,820 --> 00:01:29,560 So one important thing to take into account here is that all the issues that we will see 16 00:01:29,560 --> 00:01:34,200 here are in different scenarios or devices. 17 00:01:34,580 --> 00:01:42,660 For instance, this typical portable or mobile payment device that you use to pay in restaurants 18 00:01:42,660 --> 00:01:49,020 or shops are affected, as we will see later, but also in devices like to pay for the bus 19 00:01:49,020 --> 00:01:50,620 or the train station. 20 00:01:50,920 --> 00:01:52,080 In ATMs. 21 00:01:52,080 --> 00:01:54,940 In ATMs as well, parking machines or even vending machines. 22 00:01:55,240 --> 00:01:59,280 So a lot of different scenarios we have these devices. 23 00:02:00,460 --> 00:02:06,220 Also for previous research, I wanted to see if there were any research paper or whatever 24 00:02:07,120 --> 00:02:13,160 that was possible to compromise the firmware of the device over NFC and I couldn't see 25 00:02:13,160 --> 00:02:14,460 anything like that. 26 00:02:14,640 --> 00:02:19,100 So at least back then I couldn't find anything like this in this case. 27 00:02:20,900 --> 00:02:21,460 So... 28 00:02:22,180 --> 00:02:23,660 How do these devices work? 29 00:02:23,920 --> 00:02:28,620 I'm going to use as an example this device that you have there on the screen. 30 00:02:29,020 --> 00:02:33,340 In this case it's the IDtech Kiosk 3, as you can see here. 31 00:02:34,300 --> 00:02:40,220 I started with this device during my research because I have many years of experience working 32 00:02:40,220 --> 00:02:45,580 with ATMs and I knew that this device, this reader, is using most of the ATMs in the world, 33 00:02:45,640 --> 00:02:47,140 in the most important ATM vendors. 34 00:02:48,760 --> 00:02:51,980 So basically we have here this case. 35 00:02:52,080 --> 00:02:55,600 This is where we have the NFC antenna and also the NFC chip. 36 00:02:55,940 --> 00:03:02,580 And then with this serial cable connects to this board where we have the microcontroller 37 00:03:02,580 --> 00:03:07,200 that handles all the parsing of the credit card or debit card information. 38 00:03:07,780 --> 00:03:15,680 But also this microcontroller is responsible for the USB communications because this board 39 00:03:15,680 --> 00:03:21,640 is connected with this USB cable to a host computer in this, with this device which could 40 00:03:21,640 --> 00:03:24,900 be a Windows computer or Linux computer. 41 00:03:25,840 --> 00:03:27,880 In this case it would be the ATM computer. 42 00:03:30,200 --> 00:03:36,540 So what we really want to compromise is this microcontroller that is where all the UC stuff 43 00:03:36,540 --> 00:03:37,080 is happening. 44 00:03:37,320 --> 00:03:39,280 And in this case through the contactless interface. 45 00:03:43,960 --> 00:03:49,760 So we don't need to be experts in EMV transactions and all the details about the protocol, but 46 00:03:49,760 --> 00:03:50,900 we just need to know. 47 00:03:50,900 --> 00:03:56,900 At least that between a transaction when we are using the contactless interface, the 48 00:03:56,900 --> 00:03:59,540 reader is the one that starts the communication. 49 00:04:00,000 --> 00:04:03,940 And then the card in this case will respond back. 50 00:04:04,200 --> 00:04:07,660 And then we have this communication back and forth between them. 51 00:04:08,100 --> 00:04:15,560 And where we need to focus on is the data that, in this case the credit card, the data 52 00:04:15,560 --> 00:04:20,280 that sends to the reader because we want to send something in particular that allows us 53 00:04:20,280 --> 00:04:22,640 to get code execution in the framework of the NFC reader. 54 00:04:24,400 --> 00:04:28,420 So at the application layer we have what is called APDUs. 55 00:04:28,720 --> 00:04:33,520 So basically at the application layer is what the credit card in this case is sending 56 00:04:33,520 --> 00:04:34,300 to the reader. 57 00:04:34,660 --> 00:04:38,340 And this is based on TLV, so tag length value. 58 00:04:38,560 --> 00:04:44,440 So basically we have one byte that indicates the tag, one byte that indicates the length 59 00:04:44,440 --> 00:04:46,520 of the packet, and then the value itself. 60 00:04:46,780 --> 00:04:49,660 So it's pretty easy to understand the grammar of the code. 61 00:04:50,280 --> 00:04:52,940 Of these packets, of these APDUs. 62 00:04:53,860 --> 00:04:59,940 There are tools out there where, for instance, this is an APDU for a transaction where you 63 00:04:59,940 --> 00:05:05,540 can see like the first byte SF indicates the file control information, then the second 64 00:05:05,540 --> 00:05:11,800 byte 6A is the size of the entire packet in this case, and then the 84 byte in this 65 00:05:11,800 --> 00:05:13,540 case is the next tag. 66 00:05:13,740 --> 00:05:16,520 So that's how more or less it works. 67 00:05:16,740 --> 00:05:19,960 But again, like I said, we don't need to dig. 68 00:05:20,280 --> 00:05:24,480 We don't need too much in the EMV protocol in this case for EMV transactions. 69 00:05:27,060 --> 00:05:32,720 So yeah, if you sniff the communications like with the Proxmox for instance, this is what 70 00:05:32,720 --> 00:05:39,780 you get during a transaction where you have the NFC low level protocol on commands, and 71 00:05:39,780 --> 00:05:47,000 then you have the APDUs that the communications between the reader and the card at the application 72 00:05:47,000 --> 00:05:47,320 layer. 73 00:05:49,220 --> 00:05:49,780 Okay. 74 00:05:49,780 --> 00:05:55,160 So one of the first things that we need to do is to emulate the card because we want 75 00:05:55,160 --> 00:05:59,400 to, you know, attack the reader emulating a card and send something specific. 76 00:05:59,840 --> 00:06:08,320 So at first what I used was this device, the ACR122 device, which contains the NXP 77 00:06:08,920 --> 00:06:10,800 PM532 chip that allows emulation. 78 00:06:13,320 --> 00:06:18,260 So yeah, you connect that reader to your laptop over USB, and then with some Python framework, 79 00:06:18,260 --> 00:06:23,060 you can send some commands like start the emulation mode for that reader. 80 00:06:23,280 --> 00:06:29,900 And then with Python as well, you can interact with the APDU layer, with the application 81 00:06:29,900 --> 00:06:35,640 layer with the reader, and you can send APDUs to the reader and receive the APDUs from the 82 00:06:35,640 --> 00:06:36,120 reader as well. 83 00:06:37,900 --> 00:06:45,520 In this case, I was using this framework, the RFID IoT, which is very useful for this. 84 00:06:46,220 --> 00:06:48,240 But also there's another approach, which is the RFID IoT. 85 00:06:48,260 --> 00:06:54,360 In this case, you create your own Android application using host card emulation that 86 00:06:54,360 --> 00:06:58,780 allows you to also interact with, emulate a card and interact at the application layer 87 00:06:58,780 --> 00:07:00,540 with NFC reader in this case. 88 00:07:02,860 --> 00:07:07,400 So before jumping to the issues, let's talk about ID Tech. 89 00:07:07,520 --> 00:07:13,000 Like I said before, I started with this reader, the ID Tech Kiosk 3 device, because it was 90 00:07:13,780 --> 00:07:16,900 present in every ATM that has contactless capabilities. 91 00:07:18,260 --> 00:07:24,960 So ID Tech is a global leader in payment devices, where they make a lot of different 92 00:07:24,960 --> 00:07:26,780 devices, not only this Kiosk 3 device. 93 00:07:27,920 --> 00:07:35,580 They also make pin pads, touch screens, displays, and other devices for payment devices. 94 00:07:37,120 --> 00:07:42,220 And something important to understand here, as we will see later, that all devices from 95 00:07:42,220 --> 00:07:46,960 ID Tech are vulnerable to these code execution issues, because they basically use the same 96 00:07:46,960 --> 00:07:48,240 code base for the finger. 97 00:07:49,640 --> 00:07:55,880 So this particular one device, the Kiosk 3, I bought it in happyATMs.com website, where 98 00:07:55,880 --> 00:07:59,360 you can buy parts from ATMs that have been in production. 99 00:07:59,700 --> 00:08:01,800 You can also buy this in eBay. 100 00:08:03,240 --> 00:08:05,860 So this actually was using an ATM. 101 00:08:06,800 --> 00:08:12,420 But also I bought brand new devices from ID Tech as well, to make sure that they were 102 00:08:12,420 --> 00:08:15,780 also, with the newest version of finger, they were also vulnerable. 103 00:08:16,060 --> 00:08:16,620 Okay. 104 00:08:19,200 --> 00:08:24,700 So yeah, as you can see here in this picture, in the ATMs, for instance, the only part that 105 00:08:24,700 --> 00:08:28,780 is exposed to the user, obviously, is this case where the NFC antenna is. 106 00:08:31,520 --> 00:08:37,240 But also these ID Tech devices are not only in ATMs, they are also in parking machines, 107 00:08:37,620 --> 00:08:38,100 vending machines. 108 00:08:38,760 --> 00:08:43,920 They have also this device, which is also vulnerable in retail and also hospitality. 109 00:08:44,540 --> 00:08:47,260 So basically it's using a lot of different systems. 110 00:08:49,740 --> 00:08:50,220 Okay. 111 00:08:50,820 --> 00:08:53,040 So let's jump to the issues. 112 00:08:53,420 --> 00:08:59,120 So first, when I got this device from that website, happyATMs.com, what I wanted to check 113 00:08:59,120 --> 00:09:00,540 if JTAG was enabled. 114 00:09:00,720 --> 00:09:06,460 So I was able to, surprisingly, it was enabled, and I was able to extract the finger and gain 115 00:09:06,460 --> 00:09:11,680 debugging capabilities with GDB, which is also great, because for the reverse engineering 116 00:09:11,680 --> 00:09:16,220 process is really helpful, but also for the exploit development process. 117 00:09:16,460 --> 00:09:16,680 Okay. 118 00:09:18,260 --> 00:09:22,860 So in the devices that I bought from ID Tech, JTAG was enabled as well, which is not great, 119 00:09:23,000 --> 00:09:27,100 but yeah, basically JTAG is enabled in all of these devices. 120 00:09:28,660 --> 00:09:34,360 So then once I'm able to extract the finger from the microcontroller of this device, I 121 00:09:34,360 --> 00:09:35,820 started to reverse engineer the finger. 122 00:09:36,240 --> 00:09:41,360 In this case, it's a bare metal finger, where we don't have an operating system, there is 123 00:09:41,360 --> 00:09:47,200 no symbols and no strings, and it has more or less around 1,600 functions, so it's more 124 00:09:47,200 --> 00:09:47,600 or less big. 125 00:09:48,260 --> 00:09:51,600 So yeah, it's a bit hard to reverse engineer this kind of finger. 126 00:09:53,700 --> 00:10:00,920 So my first goal here is locate in the finger, in the code of the finger, where it starts 127 00:10:01,940 --> 00:10:04,460 reading the content of the credit card in this case. 128 00:10:05,000 --> 00:10:10,740 So there are different approaches here, but what I did basically is that when I was learning 129 00:10:10,740 --> 00:10:16,380 more about EMV transactions, I knew that there was something called proximity payment system 130 00:10:16,380 --> 00:10:16,740 environment. 131 00:10:18,260 --> 00:10:21,800 So basically these bytes, as you can see here, that the reader is sending to the card 132 00:10:21,800 --> 00:10:22,900 in the very first communication. 133 00:10:25,140 --> 00:10:30,220 So I just needed to find those bytes in the code, and I found it, as you can see here, 134 00:10:30,320 --> 00:10:34,520 and then start from here to reverse engineer and understand what the code was doing. 135 00:10:35,920 --> 00:10:41,320 Then after some hours, I identified, as you can see here, I changed the name of this function 136 00:10:41,320 --> 00:10:47,240 because there were no symbols as receive card, because I found that in this function is the 137 00:10:47,240 --> 00:10:50,980 function where it starts reading from the card over the NFC interface. 138 00:10:53,440 --> 00:11:01,280 So something important to understand also here is that standard APDUs are up to 255 bytes 139 00:11:01,280 --> 00:11:01,860 size. 140 00:11:02,060 --> 00:11:02,980 That's the maximum size. 141 00:11:03,860 --> 00:11:08,560 So as you can see here, the code was, you know, checking the byte that indicates the 142 00:11:08,560 --> 00:11:09,220 length of the packet. 143 00:11:09,440 --> 00:11:13,640 So it's only one byte because it's only 255 bytes as maximum. 144 00:11:14,180 --> 00:11:15,300 So yeah. 145 00:11:15,400 --> 00:11:17,220 I was getting more familiar with the code. 146 00:11:17,240 --> 00:11:24,280 But also I was a bit concerned because, you know, with only 255 bytes, you can end up 147 00:11:24,280 --> 00:11:26,740 in a situation where you have a stack buffer overflow, for instance. 148 00:11:27,860 --> 00:11:35,480 But with that size, 255 as maximum, maybe you can't overflow the other variables in 149 00:11:35,480 --> 00:11:39,960 the stack and then overwrite the saved return address in the stack. 150 00:11:40,280 --> 00:11:45,360 Of course, you can maybe overwrite some of the other local variables in the stack and 151 00:11:45,360 --> 00:11:47,100 achieve code execution in that way. 152 00:11:47,100 --> 00:11:48,520 But normally it's harder. 153 00:11:49,280 --> 00:11:53,200 You know, I was talks about why I was a bit concerned because of that. 154 00:11:54,240 --> 00:11:58,360 But then when I was getting more familiar with the code, I realized that as you can 155 00:11:58,360 --> 00:12:04,620 see here in these lines, the framework of the code in the framework was checking if 156 00:12:04,620 --> 00:12:11,700 the second byte of the APDU is the byte 82 in x, then it was getting two bytes from 157 00:12:11,700 --> 00:12:13,160 the APDU as the size. 158 00:12:13,940 --> 00:12:14,420 Meaning. 159 00:12:14,540 --> 00:12:14,760 That. 160 00:12:14,760 --> 00:12:15,080 Then. 161 00:12:17,100 --> 00:12:23,580 then we can have ffff a size which is 65,000 more or less bytes that was a bit 162 00:12:23,580 --> 00:12:28,480 I didn't understand at the beginning because as far as I knew the maximum 163 00:12:28,480 --> 00:12:36,940 size of an APDU was 255 bytes but then doing some searching about this and I 164 00:12:36,940 --> 00:12:42,300 found that there is something called extended APDUs which indeed are up to 165 00:12:42,300 --> 00:12:48,600 65,000 bytes and indeed they use two bytes to indicate the size of that APDU 166 00:12:48,600 --> 00:12:55,020 so that was great news because now I can send I can try to use these extended APDUs 167 00:12:56,300 --> 00:13:02,300 then I realized in this case that the function that reads the contents of the 168 00:13:02,300 --> 00:13:08,240 card it's using to store that APDU in this stack buffer and if we can set a 169 00:13:08,880 --> 00:13:12,220 buffer bigger than 138 hex which is 170 00:13:12,220 --> 00:13:19,540 312 bytes if I remember correctly then you would overflow this buffer and then 171 00:13:20,360 --> 00:13:25,860 get a stack buffer overflow so I saw this statically reversing it in the firmware 172 00:13:25,860 --> 00:13:30,480 but I needed to you know to be able to send an extended APDU and prove 173 00:13:30,480 --> 00:13:35,800 that it was possible but the problem was that the reader I was using to 174 00:13:35,800 --> 00:13:41,780 emulate a card didn't support extended APDUs by hardware so I couldn't use that and I 175 00:13:41,780 --> 00:13:41,980 was 176 00:13:42,220 --> 00:13:46,080 you know looking on the internet like how can I emulate a card but also be 177 00:13:46,080 --> 00:13:52,860 able to send an extended APDU and the the only solution I saw so back then was 178 00:13:52,860 --> 00:13:58,940 that I found in some Google forums that Google some Google pixel phones had 179 00:13:58,940 --> 00:14:03,640 support hardware support for extended APDUs and also Google released an 180 00:14:03,640 --> 00:14:11,780 Android version with support also for extended APDUs so at least a 181 00:14:12,220 --> 00:14:16,460 I found something that allowed me to to send those extended APDUs so this is 182 00:14:16,460 --> 00:14:21,020 part of the Android application that they created and here you have the APDU 183 00:14:21,020 --> 00:14:25,080 that I'm sending which is this initial bytes are following the protocol but 184 00:14:25,080 --> 00:14:28,520 then the other the rest of the packet as you can see are 414141 the 185 00:14:28,520 --> 00:14:33,880 typical A's in ASCII you know for the proof of concept typical proof of 186 00:14:33,880 --> 00:14:41,840 concept so so yeah as soon as I try the the POC with the reader 187 00:14:41,840 --> 00:14:47,180 as I was expecting as you can see here in the output of GDB the stack overflow 188 00:14:47,180 --> 00:14:52,580 was working and I was able to have control of the PC register so so in this 189 00:14:52,580 --> 00:14:58,240 case of code execution is possible in in this framework with through the NFC 190 00:14:58,240 --> 00:15:02,960 interface but also it's important to clarify that in this particular devices 191 00:15:02,960 --> 00:15:08,700 from ID tech in this case the kiosk 3 there is no exploit mitigation at all 192 00:15:08,700 --> 00:15:11,520 which makes hard easier the the exploitation 193 00:15:11,840 --> 00:15:17,440 of this but also there is no secure boot so you can make it persistent which 194 00:15:17,440 --> 00:15:21,860 is also better from the attackers perspective and also since we are using 195 00:15:21,860 --> 00:15:28,240 the extended APDUs which are can be 65,000 bytes big and then you have 196 00:15:28,240 --> 00:15:33,920 plenty of bytes that you can use for your own arm instructions to you know to 197 00:15:33,920 --> 00:15:37,760 create your own to inject your own malware in different part of the device 198 00:15:46,020 --> 00:15:50,440 so also this stack buffer flow is personally not in another 21 different 199 00:15:50,440 --> 00:15:54,520 functions in the same firmware that are reachable on other stages of the 200 00:15:54,520 --> 00:16:00,280 transaction but I just needed one but yeah I kept looking and then I found 21 201 00:16:00,280 --> 00:16:04,400 more so let me show you a video of this 202 00:16:10,740 --> 00:16:11,340 so 203 00:16:11,840 --> 00:16:18,760 let me make this bigger all right so here we have the kiosk 3 device I'm 204 00:16:18,760 --> 00:16:22,860 attached with the JTAG interface so we can see the crash in GDB in real time 205 00:16:22,860 --> 00:16:28,660 and also you can see the USB cable is connected to this laptop and in the 206 00:16:28,660 --> 00:16:34,640 laptop is where the in this case the ID tech SDK the application is running and 207 00:16:34,640 --> 00:16:39,280 it's sending the commands through the USB cable to the to the reader to start 208 00:16:39,280 --> 00:16:39,820 the transaction 209 00:16:40,980 --> 00:16:41,800 and in the 210 00:16:41,840 --> 00:16:48,820 right side we have the GDB so first I'm gonna start a transaction here and then 211 00:16:48,820 --> 00:16:55,780 I'm gonna use a credit card there is no sound apparently but you should hear a 212 00:16:55,780 --> 00:16:58,480 beep there and then we can see the credit card information in the 213 00:16:58,480 --> 00:17:03,780 application so it works the transaction and now if I use my proof of concept in 214 00:17:03,780 --> 00:17:10,540 this case well in this case there is no sound but you you wouldn't hear a beep 215 00:17:10,540 --> 00:17:11,820 because the the feedback will start every single transaction once we get this recorded, right? So there is no sound, but you you would hear a beep because the 216 00:17:11,840 --> 00:17:19,160 where it's crashing before trying to make the beep, and then we can see the crashing in GDB. 217 00:17:21,440 --> 00:17:29,900 So here we can see that the LR register is with our 4141 bytes, but also if we execute the 218 00:17:29,900 --> 00:17:37,240 backtrace command we can see that the return address is 414141 as well. So there's the 219 00:17:38,280 --> 00:17:49,020 bug working in this case in the GDB. And like I said before, the other ID tech devices were 220 00:17:49,760 --> 00:17:53,800 having the same exact issue because they were using the same code base, at least at that 221 00:17:53,800 --> 00:18:05,100 particular layer of the parsing. Okay. So at this point, I was thinking, like, okay, 222 00:18:05,140 --> 00:18:06,540 this is pretty clear that 223 00:18:07,240 --> 00:18:12,040 the problem here is that this device by hardware and software supports those extended PDUs, 224 00:18:12,260 --> 00:18:17,560 but the developers didn't take into account that, yeah, the device can receive more than, 225 00:18:17,600 --> 00:18:24,620 in this case, 312 bytes. That was the size of that buffer that was overflowed with the stack 226 00:18:24,620 --> 00:18:29,700 buffer overflow. So I was thinking, like, okay, so maybe this issue is present in other vendors. 227 00:18:29,780 --> 00:18:36,020 They are having the same problem because it's pretty easy to have that mistake. And indeed, 228 00:18:36,220 --> 00:18:36,980 many vendors 229 00:18:37,240 --> 00:18:42,380 were having the same issue. So basically what I was doing is using the same proof of concept that 230 00:18:42,380 --> 00:18:48,560 I created for this ID tech reader. I was testing it with other vendors. Most of them, they were 231 00:18:49,080 --> 00:18:54,920 crashing as well. Some of them were stack buffer overflows. Some other were heap buffer overflows 232 00:18:55,440 --> 00:18:59,400 because we were dealing sometimes with bare metal firmware like this one, but also sometimes 233 00:18:59,400 --> 00:19:03,440 there were real-time operating systems or Android systems or even Linux systems. 234 00:19:06,180 --> 00:19:13,380 So one of the vendors affected is Ingenico. I don't know how to pronounce that in English, 235 00:19:13,500 --> 00:19:18,900 but basically it's a very famous vendor in the world for payment devices and payment 236 00:19:19,800 --> 00:19:23,620 applications. And I have another video here to show you. 237 00:19:31,020 --> 00:19:33,000 So basically, since 238 00:19:33,440 --> 00:19:36,940 sometimes it's hard to get access to these devices actually in a production environment 239 00:19:36,940 --> 00:19:42,940 where it works and you can perform a transaction and everything, what I did in this case, I have a 240 00:19:42,940 --> 00:19:48,840 friend in Spain where he owns a shop and he has these devices. So he allowed me to test it, 241 00:19:48,900 --> 00:19:54,360 the proof of concept. So basically, as you can see here, the device was charging me for 39 euros. 242 00:19:55,640 --> 00:20:00,120 And then as soon as I tap my phone, you can see reboot in progress. 243 00:20:07,500 --> 00:20:12,080 So basically, in this case, it was rebooting because in this case, it's a Linux system. 244 00:20:12,300 --> 00:20:18,600 So the issue is in a particular library. And so the operating system was detecting the crash and 245 00:20:18,600 --> 00:20:23,620 rebooting. But my proof of concept was just crashing it. It wasn't weaponized in this case. 246 00:20:25,280 --> 00:20:31,940 So yeah. And I was doing this with another device and another and another reader and all of them 247 00:20:31,940 --> 00:20:32,940 were crashing. Like... 248 00:20:33,440 --> 00:20:35,240 Every device was crashing like this. 249 00:20:37,620 --> 00:20:38,580 Okay. So... 250 00:20:42,900 --> 00:20:47,980 Verifone as well. Several Verifone devices affected. I was testing them and crashing. 251 00:20:48,540 --> 00:20:53,620 Sorry, I forgot to mention that my approach was also like once I found that the device was 252 00:20:53,620 --> 00:20:59,620 crashing, then I was trying to buy one and get debug capabilities or log access so I can see 253 00:20:59,620 --> 00:21:02,820 if it's a stack buffer overflow or heap buffer overflow. 254 00:21:03,440 --> 00:21:03,620 It was similar to вже enterprise. I learned it from my classmate who was camping there. 255 00:21:03,620 --> 00:21:05,380 And this is for everyone who really likeslungen, And then contact the vendor, of course. 256 00:21:06,200 --> 00:21:13,140 So, Verifone as well as I was saying. Crimp payment innovations. Well, several devices from 257 00:21:13,140 --> 00:21:14,660 them, they were affected. 258 00:21:15,180 --> 00:21:20,520 This is a very big company as well where they have everywhere readers. 259 00:21:21,120 --> 00:21:24,180 They were several of these devices were affected. 260 00:21:25,320 --> 00:21:31,000 We MUQUEDICY with, in this case, a Chinese company but they have devices everywhere in the world. 261 00:21:31,560 --> 00:21:33,420 Several of their devices were updated time and time again. And they are in this case what I said before. 262 00:21:33,420 --> 00:21:37,800 affected and next go in this case as well another Chinese vendor but again 263 00:21:37,800 --> 00:21:44,060 you can find these devices everywhere okay so let's talk about the impact like 264 00:21:44,060 --> 00:21:47,940 what the attack the attacker can actually do with these these attacks 265 00:21:47,940 --> 00:21:55,600 right with once the the firmware of the device is compromised so but it's always 266 00:21:55,600 --> 00:21:59,080 up to the imagination of the attacker but at least in my imagination I have 267 00:21:59,080 --> 00:22:07,720 these approaches so the very first one is to remember we have code execution in 268 00:22:07,720 --> 00:22:11,620 the in the microcontroller of the reader through the NFC the contactless 269 00:22:11,620 --> 00:22:16,020 interface we have full control so we can inject and install our own malware here 270 00:22:16,020 --> 00:22:21,000 so what we can do is typically in a transaction as you saw in the other 271 00:22:21,000 --> 00:22:25,880 video is that the host the the Windows computer in this case sends the start 272 00:22:25,880 --> 00:22:28,780 transaction command over USB to this guy and the price 273 00:22:28,780 --> 00:22:33,060 for the transaction, but my malware in this case that is running here 274 00:22:33,060 --> 00:22:36,940 because this device has been already compromised, I can change that price 275 00:22:36,940 --> 00:22:44,920 instead of $500 for 50 cents, you know, but even the receipt and if the device 276 00:22:44,920 --> 00:22:49,060 has a display, in this case this device doesn't have a display but the other 277 00:22:49,060 --> 00:22:54,560 devices have display, you can put the $500 but in the end in the background 278 00:22:54,560 --> 00:22:59,100 is charging you for 50 cents and since you can make this persistent then 279 00:22:59,100 --> 00:23:03,080 every future transaction will be 50 cents if you want or one cent or 280 00:23:03,080 --> 00:23:08,060 whatever you want to make it so that would be one possible attack 281 00:23:08,060 --> 00:23:12,380 that the attackers could do with this. Another thing that the attacker could do 282 00:23:12,380 --> 00:23:18,560 is in the US especially there's something called 283 00:23:18,560 --> 00:23:24,540 contactless magnetic stripe data transactions, where the number of 284 00:23:24,540 --> 00:23:28,420 of the full number of the credit card and the expiration date is sent in 285 00:23:28,420 --> 00:23:33,060 clear text to the reader, to the NFC reader, so that would be in clear 286 00:23:33,060 --> 00:23:37,320 text in the memory of the NFC reader in this case. So what my malware could 287 00:23:37,320 --> 00:23:44,880 do in this device is to, once the device is compromised, then every future credit 288 00:23:44,880 --> 00:23:49,520 card that will be using that type of contactless transaction, the magnetic 289 00:23:49,520 --> 00:23:54,620 strike data transaction my malware will store those credit card 290 00:23:54,620 --> 00:23:58,440 numbers in the memory or in the flash. And then if the device has internet 291 00:23:58,440 --> 00:24:01,840 connection, then send those credit card numbers to my server on the internet. 292 00:24:02,680 --> 00:24:07,100 But also if the device doesn't have internet connection, what the attacker 293 00:24:07,100 --> 00:24:11,640 could do is then after a few days or hours come back to the reader, send a 294 00:24:11,640 --> 00:24:16,700 special command to the malware that is actually running in the NFC 295 00:24:16,700 --> 00:24:19,300 reader and exfiltrate those credit card numbers 296 00:24:19,300 --> 00:24:19,500 automatically, and'd fire it in the reader. 297 00:24:19,520 --> 00:24:29,620 the NFC interface. So now I have here a demo of a weaponized exploit. So in this 298 00:24:29,620 --> 00:24:36,660 case it's an Android device but as you can see that I can't show you some parts 299 00:24:36,660 --> 00:24:42,360 of the of the graphical interface because I can show the name of the bank 300 00:24:42,360 --> 00:24:48,460 and some other details, but you will see the POC without the blurry image. 301 00:24:48,980 --> 00:24:53,660 But basically this is an Android device in this case and the weaponized exploit 302 00:24:53,660 --> 00:24:57,160 what we will do to prove that call execution is possible in this case and 303 00:24:57,160 --> 00:25:00,520 manipulate the firmware is going to show a message on the screen as you will see. 304 00:25:01,100 --> 00:25:08,080 So first we're using a regular credit card. I don't know why there's no sound 305 00:25:08,080 --> 00:25:10,740 but you should hear there like how the receipt is 306 00:25:11,600 --> 00:25:12,240 you know 307 00:25:12,240 --> 00:25:17,420 giving me that receipt but I don't know sorry but the sound is not working but 308 00:25:17,420 --> 00:25:23,140 yeah and after that then the device is ready for another transaction and I'm 309 00:25:23,140 --> 00:25:27,880 gonna use the proof of concept the weaponized exploit in this case and then 310 00:25:27,880 --> 00:25:32,700 you will see basically I will change the the the exploit will change the screen with 311 00:25:32,700 --> 00:25:37,820 an iOactive logo and like saying hey this device has been compromised blah 312 00:25:37,820 --> 00:25:42,060 blah you know just to there you go so 313 00:25:42,060 --> 00:25:43,620 that would be 314 00:25:51,440 --> 00:25:59,500 Okay and the last thing which is probably the most interesting one is that like okay 315 00:25:59,500 --> 00:26:05,860 now the malware that is installed in this microcontroller what if we can attack the 316 00:26:05,860 --> 00:26:10,640 host that is connected over USB and in this case could be the the Windows computer that 317 00:26:10,640 --> 00:26:11,360 is in the ATM. 318 00:26:11,600 --> 00:26:12,040 Okay. 319 00:26:12,060 --> 00:26:19,640 remember we have a USB cable that is connected to the host machine okay so to 320 00:26:19,640 --> 00:26:26,440 do that what I did was in the case of the ID tech device I I detect they 321 00:26:26,440 --> 00:26:31,780 provide the their life leap ID tech SDK to their customers so they can interact 322 00:26:31,780 --> 00:26:35,760 with the device and perform transactions so what I wanted to do is you know 323 00:26:35,760 --> 00:26:39,260 reversing the near this SDK and see if there they have issues so we can 324 00:26:39,260 --> 00:26:45,700 compromise the the host over USB so basically the idea here is that the SDK 325 00:26:45,700 --> 00:26:49,880 in the Windows computer will send the command over usually to the reader and my 326 00:26:49,880 --> 00:26:53,400 malware that is already there in them in the in the finger of the reader will 327 00:26:53,400 --> 00:26:58,700 send as a response a particular payload that allows me to get code execution in 328 00:26:58,700 --> 00:27:08,380 the in the Windows computer so for that the SDK provides several api's in this 329 00:27:08,380 --> 00:27:08,640 case 330 00:27:09,260 --> 00:27:15,320 when I was getting familiar with those api's I focused in the device in it API 331 00:27:15,320 --> 00:27:19,560 because this this particular one is always used because it's the one that is 332 00:27:19,560 --> 00:27:24,480 used for in it to initialize the device I mean before doing in a transaction so 333 00:27:24,480 --> 00:27:31,960 I was sure there that this one is it was an important one so so yeah I 334 00:27:31,960 --> 00:27:38,740 started to reverse engineer this API in the DLL of the SDK and I found in in the 335 00:27:38,740 --> 00:27:39,240 code of the SDK that I was able to reverse engineer this API in the DLL of the SDK and I found in the code of the 336 00:27:39,260 --> 00:27:46,560 the API were the the function where it's adversity usb payload from from the 337 00:27:46,560 --> 00:27:52,220 reader and in this case as you can see here there was this memcpy 338 00:27:52,220 --> 00:27:56,860 where the size of the même copy are two bytes that are coming from the USB 339 00:27:56,860 --> 00:28:02,120 payload for from from the reader so we can control the set of the main copy 340 00:28:02,120 --> 00:28:06,480 with two bytes and there were no sanity checks alone and the source of the 341 00:28:06,480 --> 00:28:09,000 memcpy was the actual usb payload ... 342 00:28:09,260 --> 00:28:15,300 it was receiving the from the from the nfc reader uh so we i just needed to to make sure that the 343 00:28:15,300 --> 00:28:23,460 destination buffer uh it wasn't too big so i was able to overflow it so in this case the buffer in 344 00:28:23,460 --> 00:28:29,620 this case was pretty small it was 56 hex bytes and i was able to overflow the buffer but also the 345 00:28:29,620 --> 00:28:35,520 other local variables in the stack and then overwrite the saved return others in in the 346 00:28:35,520 --> 00:28:40,900 stack and you know a straightforward stack buffer or flow to to get code execution in in the host 347 00:28:43,240 --> 00:28:48,880 so again so in this case we have to change two attacks right so we have first to compromise the 348 00:28:48,880 --> 00:28:53,840 finger of the reader through the nfc as we saw and then we inject that malware in the finger 349 00:28:54,390 --> 00:28:59,580 and then that malware that is running the nfc reader will receive a usb command from the windows 350 00:28:59,580 --> 00:29:05,140 computer and then my malware will send a specific payload to achieve code execution through that 351 00:29:05,140 --> 00:29:05,500 main code 352 00:29:05,520 --> 00:29:14,360 that we saw in in the in the code of the of the library so to to create a proof of concept of 353 00:29:14,360 --> 00:29:19,760 this what i did was instead of creating my own malware and and doing it with the nfc reader 354 00:29:19,760 --> 00:29:26,680 which takes uh some reasonable time i just uh to make it quick i use a raspberry pi with gadget fs 355 00:29:26,680 --> 00:29:32,400 which allows me to emulate any usb device so this raspberry pi was acting as the nfc reader 356 00:29:35,520 --> 00:29:41,080 so so yeah with the gadget fs i was able you know to provide the like the endpoint information and 357 00:29:41,080 --> 00:29:47,280 the id vendor the id product of the usb device so in this case i was emulating the nfc reader 358 00:29:47,280 --> 00:29:54,000 as a usb device and with python you can also you know send over usb whatever you want and receive 359 00:29:54,700 --> 00:30:00,900 whatever the in this case the sdk running in the host is sending you and this is actual 360 00:30:01,260 --> 00:30:03,860 this is actually the the proof of concept that was 361 00:30:05,680 --> 00:30:13,540 triggered in the stack buffer overflow and as you can see here in uh in the windows computer in 362 00:30:13,540 --> 00:30:20,720 this case with uh win win debug you can see how is it was actually crashing with that mem copy issue 363 00:30:21,130 --> 00:30:27,820 uh the return others uh as you can see here is 41 41 41 so it's basically my my payload uh so 364 00:30:27,820 --> 00:30:35,260 yeah so this is the way i found um a code execution in the sdk that uh idtech provides to 365 00:30:35,260 --> 00:30:43,720 their customers to to communicate with the device and remember that um uh so this this uh sdk from 366 00:30:43,720 --> 00:30:50,440 idtech uh it's it's present in in some atms in this case because it is the sdk that they provide to 367 00:30:50,440 --> 00:30:58,940 to communicate with the nfc reader so also this sdk is pretty pretty vulnerable they have more 368 00:30:58,940 --> 00:31:03,900 than 20 exploitable stack buffer flows like the the one i described that we don't have time to 369 00:31:03,900 --> 00:31:05,120 talk about all of them but 370 00:31:05,260 --> 00:31:08,640 uh but yeah it was pretty pretty bad 371 00:31:11,160 --> 00:31:20,540 okay so let's talk about the atm scenario so like i said i have many years of experience 372 00:31:20,540 --> 00:31:30,600 working with atm with atms i've been reversing during atms drivers also the atm devices firmware 373 00:31:30,600 --> 00:31:35,100 like for instance the gas dispenser and other devices also doing some usb 374 00:31:35,260 --> 00:31:42,160 hacking with atms and also i have experience working with xfs xfs is the middleware that 375 00:31:42,160 --> 00:31:46,480 most of the atms in the world they use to communicate with the hardware of the atm like 376 00:31:46,480 --> 00:31:51,480 for instance the cas dispenser and using some particular apas you can interact with the hardware 377 00:31:51,480 --> 00:31:57,520 and perform for instance a cash out um and again remember that uh 378 00:31:57,520 --> 00:32:05,060 this particular reader the id tech kiosk 3 is present in in most of the atm brands in the world 379 00:32:05,260 --> 00:32:10,900 most important brands, like some of them, NCR, Wincor, Diable, Fujitsu, Hayasun, and maybe 380 00:32:10,900 --> 00:32:20,680 more. At least I was able to confirm those some years ago. So what the attacker can do in the 381 00:32:20,680 --> 00:32:27,300 ATM in this particular case? So one of the first things, like before, is like, especially in 382 00:32:27,300 --> 00:32:32,680 the U.S. in this case, if the card supports MSD, magnetic strike data, contactless 383 00:32:32,680 --> 00:32:39,260 transactions, then the clear text, the full number of the credit card will be in the clear text 384 00:32:39,260 --> 00:32:45,400 and expiration date in the memory of the device. So the attacker could do is compromise the 385 00:32:45,400 --> 00:32:53,380 firmware of the reader first over NFC, like we saw, and install the malware. And then, since in 386 00:32:53,380 --> 00:32:58,420 the ATMs, these devices doesn't have internet connection, what the attacker would need is to 387 00:32:58,900 --> 00:33:02,660 leave the area, then come back after a few hours or days, or whatever the case may be, and 388 00:33:02,660 --> 00:33:06,720 then go back to the server, and then exfiltrate those credit card numbers from the memory of the 389 00:33:06,720 --> 00:33:11,340 device, using the malware that he already installed, like sending a special command to the 390 00:33:11,340 --> 00:33:17,280 malware, for instance, and then the malware will send you back to your phone the credit card 391 00:33:17,280 --> 00:33:25,100 numbers that have been used in the reader in those days. But then we also have the ATM 392 00:33:25,100 --> 00:33:32,640 jacobo scenario. So the idea here is like, once we have our malware installed, we have the 393 00:33:32,660 --> 00:33:40,000 driver running in the NFC reader, microcontroller, we want to, as we saw before, compromise the 394 00:33:40,000 --> 00:33:46,100 ATM computer. If it's running the IDTech SDK, we know it's possible. If it's running another driver 395 00:33:46,100 --> 00:33:52,200 for whatever reason, then you need to, of course, to find if the driver that is using it is 396 00:33:52,200 --> 00:33:58,040 vulnerable, if there's any memory corruption, and then exploit that. And then once you have code 397 00:33:58,040 --> 00:34:02,640 execution in the ATM computer, then you need, as you will see in the next slides, you need to 398 00:34:02,660 --> 00:34:08,620 be in a special payload or a program, in this case, to interact with the hardware of the ATM, 399 00:34:08,740 --> 00:34:13,520 like the cash dispenser, in this case, to perform the cash out, the jackpot. 400 00:34:16,760 --> 00:34:25,220 So yeah, one important thing also to take into account here is that we don't only, if we're 401 00:34:25,220 --> 00:34:32,120 working with an ATM in this case, we are not only limited to the driver or SDK that is used for the 402 00:34:32,120 --> 00:34:32,640 NFC reader. 403 00:34:32,660 --> 00:34:39,220 Because since we have full control of the microcontroller of the reader, we can modify the 404 00:34:39,220 --> 00:34:46,160 firmware to act as another USB device. Let's say I want to act as the USB camera, and I know that 405 00:34:46,160 --> 00:34:53,060 there is a USB camera driver in the Windows ATM computer, and I want to, and it's vulnerable, so I 406 00:34:53,060 --> 00:34:56,860 want to target that and attack that, so that would be another possible approach. 407 00:35:01,800 --> 00:35:10,500 So then once you have code execution in the ATM computer, through the ID Tech SDK or other driver, 408 00:35:13,120 --> 00:35:21,060 there are, like, if you guys, someone has experience working with ATMs, you probably know that once 409 00:35:21,060 --> 00:35:25,600 you have full control of the ATM computer, with admin rights, in this case, because normally it's Windows, 410 00:35:27,860 --> 00:35:35,120 there's just a matter of time to be able to perform the jackpot, because the way they are designed, it's 411 00:35:35,120 --> 00:35:42,340 impossible to make this impossible, basically. Of course, sometimes they put some mitigations, like, as 412 00:35:42,340 --> 00:35:47,860 we'll see, if you're using XFS, maybe there's some sort of authentication, making sure that your 413 00:35:48,660 --> 00:35:56,160 application can't use those XFS APIs and so on, but in the end, it's always, you know, a matter of 414 00:35:56,160 --> 00:36:01,900 time to find a way to do it, because the way it's designed, it's impossible to make it 100% secure. 415 00:36:04,120 --> 00:36:12,420 So this XFS, as I was saying before, it's a middleware that is basically in every ATM, that it provides 416 00:36:12,420 --> 00:36:22,800 several APIs that you can use to interact with the hardware of the ATM. So in this case, here, as you can see 417 00:36:22,800 --> 00:36:28,980 an example, this is one of my XFS programs that I use many times in ATMs to, you know, perform the cash out. 418 00:36:30,060 --> 00:36:36,540 In this case, for instance, as an example, you can see here, we are using the WFS open API to open a session with 419 00:36:36,540 --> 00:36:42,560 the device. In this case, the device is the cash dispenser, and then we provide several details, like the 420 00:36:42,560 --> 00:36:49,480 number of bills and the number of the cassette and some other details, and then we use, after this, other APIs, 421 00:36:49,700 --> 00:36:52,780 like, to execute the actual command and then perform the jackpot. 422 00:36:56,860 --> 00:37:04,300 So, as this point, you might be wondering, okay, so did you try this with an ATM? 423 00:37:05,340 --> 00:37:13,140 So, yes, I tried, and it was working, but it was in a lab environment, and there are some NDAs involved, so I can't 424 00:37:13,140 --> 00:37:18,780 show you videos about it, and I also can't tell you which ATM brand was this particular one. 425 00:37:19,720 --> 00:37:22,780 But if you have doubts or concerns about this, you can ask me. 426 00:37:22,800 --> 00:37:29,780 I think here you have enough technical details, so you can do it by yourself if you have the motivation. 427 00:37:30,320 --> 00:37:37,680 But also, if you have specifically concerns about this because you are working in an ATM security team or whatever, 428 00:37:38,220 --> 00:37:45,420 my recommendation here is that, first, make sure that the finger of this reader in the ATM is already patched, 429 00:37:45,420 --> 00:37:48,060 because there are available patches for these issues. 430 00:37:49,160 --> 00:37:52,780 And also check and make sure that the driver of the ATM is already patched. 431 00:37:52,780 --> 00:37:56,840 If the driver or SDK that is using the ATM computer doesn't have any memory corruptions. 432 00:37:57,040 --> 00:38:03,100 But the most important thing, obviously, is to make sure that the finger of this reader is already patched, 433 00:38:03,180 --> 00:38:08,960 because if the attacker can't compromise this over NFC, then more or less the problem is solved, right? 434 00:38:09,020 --> 00:38:14,860 Like, it's going to be really hard to compromise the ATM in this way. 435 00:38:19,040 --> 00:38:20,400 So, regarding disclosure. 436 00:38:20,400 --> 00:38:24,000 So, yeah, we contacted all these affected vendors. 437 00:38:24,080 --> 00:38:25,300 As you saw, there were many. 438 00:38:26,260 --> 00:38:28,680 All of them told us that they fixed the issues. 439 00:38:29,660 --> 00:38:36,860 Some of them, they provided us the fixes, and we tested that, and we were able to confirm that the fix was okay. 440 00:38:37,340 --> 00:38:43,460 But not all of them provided us these fixes, so we don't know for some others what happened. 441 00:38:44,740 --> 00:38:50,020 And, yeah, in this case, we waited almost two years, because this research, I mean, 442 00:38:50,020 --> 00:38:51,940 started almost two years ago. 443 00:38:52,380 --> 00:38:56,100 Because the problem was that, as you saw, many parties were involved here. 444 00:38:56,340 --> 00:39:01,940 And the problem is, like, since I was testing my proof of concept with another device, 445 00:39:02,080 --> 00:39:03,420 oh, this vendor is also vulnerable. 446 00:39:03,680 --> 00:39:04,360 Shit, again. 447 00:39:04,580 --> 00:39:05,220 And another. 448 00:39:05,480 --> 00:39:05,840 And another. 449 00:39:06,160 --> 00:39:08,980 So, you know, we had to wait time. 450 00:39:09,160 --> 00:39:13,640 But also, the problem is that many of these devices, they don't have remote update capabilities. 451 00:39:14,900 --> 00:39:20,000 So, sometimes they have to go physically there to, you know, to update the finger of this device. 452 00:39:20,900 --> 00:39:23,200 Which is a problem, right? 453 00:39:23,940 --> 00:39:27,580 So, yeah, that's a problem. 454 00:39:30,080 --> 00:39:32,180 So, yeah, I think that's everything. 455 00:39:32,680 --> 00:39:34,660 If you have any questions, I'll be around. 456 00:39:34,800 --> 00:39:35,040 Thank you.