1 00:00:00,000 --> 00:00:12,860 Howdy y'all. Who enjoys neighborliness? So wireless sensors are small little computers 2 00:00:12,860 --> 00:00:21,260 which can be connected over very low power radios so that you don't need a long battery life in 3 00:00:21,260 --> 00:00:25,580 order to keep them running. So if you have a laptop, it's called wireless and will run for 4 00:00:25,580 --> 00:00:31,500 a couple of hours without power but that's useless if you want it to run on its own. So while it's 5 00:00:31,500 --> 00:00:43,960 helpful for you, is there a reason why this one isn't working? Ah, see, so it goes. So anyways, 6 00:00:44,060 --> 00:00:50,020 while your laptop is useful to you without continuous power, it would be useless if you 7 00:00:50,020 --> 00:00:55,240 intended for it to act as a server somewhere. But you don't always need that much computational 8 00:00:55,240 --> 00:00:55,560 power. So you can run it for a couple of hours without power. So you can run it for a couple 9 00:00:55,560 --> 00:00:59,420 of hours without power. You don't need a full disk. You don't need many of these things. You 10 00:00:59,420 --> 00:01:04,480 don't even need to be awake all the time. So the idea is that you can have a very small computer, 11 00:01:04,600 --> 00:01:09,880 like a microcontroller, sitting with a radio. So it's still accessible in the network. It can run 12 00:01:09,880 --> 00:01:16,500 IPv6. It can run Zigbee. It can run all these different networks. And then you can adjust its 13 00:01:16,500 --> 00:01:24,300 lifetime and its power cycling to do very useful things. But the question comes about exactly how 14 00:01:24,300 --> 00:01:25,540 secure are these things. And the answer to that question is, how secure are these things? And 15 00:01:25,540 --> 00:01:32,020 how can you take them apart? How can you exploit them? So in this lecture, I cover several 16 00:01:32,020 --> 00:01:38,940 different ways to do these things. And I'll be adding some recent news as well in the commentary. 17 00:01:39,260 --> 00:01:45,340 And then at the end, we'll go into the session room for the questions. But instead of questions, 18 00:01:45,740 --> 00:01:50,100 I'm going to bring my entire toolkit. And we can plug up to things and start breaking into them. 19 00:01:51,060 --> 00:01:52,440 And that'll be very neighborly. 20 00:01:56,360 --> 00:01:57,980 Oh, gotta switch this on. 21 00:02:03,700 --> 00:02:05,180 At some point, this'll work. 22 00:02:09,040 --> 00:02:09,960 Ah, bloody hell. 23 00:02:15,680 --> 00:02:16,640 Two, five. 24 00:02:19,260 --> 00:02:21,140 Just for the record, I hate open office. 25 00:02:24,280 --> 00:02:26,400 Please excuse the blasphemous artwork. 26 00:02:27,440 --> 00:02:30,560 I hope that none of you are offended, I sincerely do. 27 00:02:35,840 --> 00:02:37,300 Oh, congratulations. 28 00:02:38,060 --> 00:02:39,320 This is the bargain edition. 29 00:02:42,580 --> 00:02:50,120 So today we're going to discuss schematic capture, which allows you to reverse engineer the actual design of a chip. 30 00:02:50,120 --> 00:02:53,240 And why it's easier than you might otherwise expect. 31 00:02:53,520 --> 00:03:01,300 If you have a microcontroller and a radio, based upon only their part numbers, I can give you a good idea of which pins will connect to which others. 32 00:03:01,740 --> 00:03:05,420 Because they connect in the way that they are physically intended to. 33 00:03:06,360 --> 00:03:14,500 In that you have hardware accelerated serial ports on the microcontroller side, and you have a single serial port on the radio side. 34 00:03:15,120 --> 00:03:19,660 We'll also discuss the protocols themselves, like ITC and SPI. 35 00:03:19,660 --> 00:03:20,100 They're very important. 36 00:03:20,120 --> 00:03:22,100 And exactly how easy they are to sniff. 37 00:03:22,640 --> 00:03:30,500 So if traffic is going from the microcontroller to the radio, you can sniff it there, even if it's encrypted from the radio to the rest of the wireless network. 38 00:03:31,700 --> 00:03:34,060 I'll also cover methods of dumping firmware. 39 00:03:35,320 --> 00:03:43,640 Some of which are newly developed since February, and will be in the commentary rather than in the slides. 40 00:03:43,900 --> 00:03:46,020 I'll discuss how to reverse engineer the firmware. 41 00:03:46,380 --> 00:03:50,100 So once you get a copy of the code that is within a wireless network, 42 00:03:52,960 --> 00:03:56,300 you'll need to take it apart in the same way that you're used to taking apart PC software, 43 00:03:56,900 --> 00:04:02,080 except that because the architectures are more varied, you often have to rewrite them from scratch. 44 00:04:03,340 --> 00:04:06,940 So if you sit down with Pearl and you follow a few simple rules, 45 00:04:07,220 --> 00:04:13,620 it's easy to do things like identifying the starting and stopping addresses of functions. 46 00:04:14,440 --> 00:04:19,020 From that, you can easily make a call graph that shows you how the functions relate to one another. 47 00:04:20,100 --> 00:04:29,260 And I'll discuss how to simulate these chips and how to fuzz them in simulation or in hardware to come about with exploits for them. 48 00:04:30,600 --> 00:04:37,060 Including a demo of a stack overflow exploit, which allows you to inject foreign code into the microcontroller 49 00:04:37,060 --> 00:04:40,460 and run it in the same way that you would do a stack overflow on a PC. 50 00:04:41,360 --> 00:04:49,560 There are very rarely unbounded heap buffers on this platform because the heap itself isn't used. 51 00:04:49,560 --> 00:04:53,500 You'll very rarely find malloc or free anywhere within the firmware image. 52 00:04:54,200 --> 00:04:58,740 Because of that, the stack attacks are more relevant than the heap attacks, 53 00:05:00,140 --> 00:05:02,540 which might be more effective on a PC. 54 00:05:03,280 --> 00:05:09,140 And I'll discuss how to fuzz a microcontroller in hardware when you don't have a simulator available. 55 00:05:10,180 --> 00:05:14,320 How can you tell when the device has crashed if it reboots in a fraction of a second? 56 00:05:16,220 --> 00:05:18,540 And there's some neat little tricks for that. 57 00:05:19,560 --> 00:05:22,640 A wireless sensor itself is composed of a 16-bit microcontroller. 58 00:05:23,560 --> 00:05:26,880 Or occasionally an 8-bit or a 32-bit in more recent designs. 59 00:05:27,720 --> 00:05:31,760 It has RAM, ROM, flash memory, and EEPROM. 60 00:05:32,200 --> 00:05:35,440 EEPROM being optional and the same with Pure ROM. 61 00:05:35,820 --> 00:05:39,700 Pure ROM exists on the chip on the surface of it. 62 00:05:40,380 --> 00:05:42,800 And it chemically exists there. 63 00:05:42,900 --> 00:05:47,800 It's not something that you can remove by changing a state in the same way you can clear flash memory. 64 00:05:47,800 --> 00:05:50,240 Or might accidentally clear RAM. 65 00:05:52,580 --> 00:05:57,680 Because there's code in ROM that can't be removed, you can sometimes exploit that code. 66 00:05:58,420 --> 00:06:02,060 Or you can jump back to that code as a sort of return to libc attack. 67 00:06:04,760 --> 00:06:09,720 Now flash memory contains the majority of the executable code for the wireless sensor. 68 00:06:10,220 --> 00:06:13,320 Your application runs from a non-writable region. 69 00:06:15,160 --> 00:06:22,040 This means that when your application is running, it's very rare that you'll accidentally overwrite it with new executable code. 70 00:06:23,180 --> 00:06:28,420 As several attacks against the lower levels of PC software work. 71 00:06:28,800 --> 00:06:34,220 The recent SPI BIOS attacks, for example. 72 00:06:35,380 --> 00:06:42,760 Now the radio itself in the older revisions would be a ChipCon 2420 or a ChipCon 2500 or an EM250. 73 00:06:43,360 --> 00:06:45,380 Sorry, not an EM250, an EM20. 74 00:06:46,020 --> 00:06:51,300 Model numbers aside, the older radios existed separate from the microcontroller. 75 00:06:52,520 --> 00:06:55,920 There'd be a single bus connecting them and commands would flow over this bus. 76 00:06:56,680 --> 00:07:00,960 In more modern radios, you instead have the two combined into a single device. 77 00:07:01,820 --> 00:07:05,520 Those are the ones that I published attacks against at Black Hat Briefings yesterday. 78 00:07:08,040 --> 00:07:09,660 I won't be getting into those today. 79 00:07:09,820 --> 00:07:12,080 But tomorrow at 2 o'clock in the Hardware Hacking Village. 80 00:07:12,760 --> 00:07:15,180 I'll be presenting those as well. 81 00:07:16,040 --> 00:07:19,700 And we'll be playing with some of those attacks in the break room after this lecture. 82 00:07:21,240 --> 00:07:25,000 The sensors themselves are used for getting input. 83 00:07:25,160 --> 00:07:29,680 Because the original ideal for this would be that you could throw a bunch out into a field. 84 00:07:30,240 --> 00:07:34,200 And you could return the temperature at each point within that field. 85 00:07:34,840 --> 00:07:39,060 So if you're trying to do global warming experiments or things like that. 86 00:07:39,140 --> 00:07:41,820 You could just blanket an entire area with a bunch of sensors. 87 00:07:42,880 --> 00:07:45,380 Watching the temperature at each point. 88 00:07:45,500 --> 00:07:47,200 Or the infrared light at each point. 89 00:07:47,340 --> 00:07:50,240 Or anything else that can cheaply be measured. 90 00:07:51,360 --> 00:07:54,200 And with MEM sensors falling, you can also do things like acceleration. 91 00:07:54,520 --> 00:07:55,700 You can put them all around your car. 92 00:07:55,880 --> 00:07:59,500 And you can tell exactly how the car is bouncing on the road. 93 00:07:59,780 --> 00:08:01,980 If the left side is going up while the right side is going down. 94 00:08:02,300 --> 00:08:03,520 You can get all of that information. 95 00:08:05,360 --> 00:08:07,720 In airplanes, they're looking at doing fly-by-wireless. 96 00:08:08,800 --> 00:08:12,460 Using these sorts of radios in lieu of previously wired sensors. 97 00:08:12,760 --> 00:08:16,240 Because you don't have to worry about the weight or the maintenance of the wires. 98 00:08:16,680 --> 00:08:19,440 If a wireless link is going bad, you know instantly. 99 00:08:19,720 --> 00:08:22,800 You begin to see packets be lost or things like that. 100 00:08:22,880 --> 00:08:24,160 But if a wire is beginning to fray. 101 00:08:24,320 --> 00:08:27,920 You might not know until it's so late that it breaks in the middle of the air. 102 00:08:29,660 --> 00:08:31,360 And they also have serial ports. 103 00:08:31,480 --> 00:08:32,900 There's some other maintenance connector. 104 00:08:34,180 --> 00:08:37,420 Or JTAG, which is neighborly in its own right. 105 00:08:39,260 --> 00:08:42,600 Two of the most popular chips for wireless sensor networks. 106 00:08:42,760 --> 00:08:45,520 So the MSP430 and the Atmel AVR chips. 107 00:08:46,480 --> 00:08:49,240 The MSP430 is a Von Neumann chip. 108 00:08:49,420 --> 00:08:52,540 Which is the same thing that a PC is. 109 00:08:52,720 --> 00:08:56,820 In that you have pointers to either code or data. 110 00:08:57,080 --> 00:08:58,800 You have a single unified memory. 111 00:08:59,160 --> 00:09:03,760 And any pointer can be resolved without ambiguity. 112 00:09:04,320 --> 00:09:07,900 So if I give you a pointer in hexadecimal as the word width. 113 00:09:07,960 --> 00:09:09,820 If I say it's F8B4. 114 00:09:10,040 --> 00:09:12,380 On an MSP430 there's no ambiguity. 115 00:09:12,760 --> 00:09:13,640 As to where that is. 116 00:09:14,780 --> 00:09:17,460 It's different on the Harvard architecture chips. 117 00:09:17,500 --> 00:09:18,300 Such as the AVR. 118 00:09:18,520 --> 00:09:20,740 On an AVR if I give you a pointer. 119 00:09:21,020 --> 00:09:23,920 I'm either referring to code memory or to data memory. 120 00:09:24,220 --> 00:09:25,540 And you don't know which. 121 00:09:26,600 --> 00:09:28,300 If you're writing custom assembly code. 122 00:09:28,480 --> 00:09:33,020 You can ask to fetch data from code memory. 123 00:09:34,700 --> 00:09:38,240 There's no way to ask to execute code from data memory though. 124 00:09:38,700 --> 00:09:40,700 So if I send you a packet. 125 00:09:40,700 --> 00:09:42,920 I can't just give you a pointer to that packet. 126 00:09:43,600 --> 00:09:44,640 Overwriting a return pointer. 127 00:09:44,740 --> 00:09:49,880 Because there is no RAM that is executable on these chips. 128 00:09:50,140 --> 00:09:51,920 So exploiting them becomes a lot more difficult. 129 00:09:53,040 --> 00:09:56,120 We will be discussing methods with which they can be exploited though. 130 00:09:56,280 --> 00:09:58,280 These were pioneered by Aurelien Francion. 131 00:09:58,580 --> 00:10:01,780 Out at INRIA in Grenoble, France. 132 00:10:05,080 --> 00:10:07,580 There are also differences in the way the fuses work. 133 00:10:07,960 --> 00:10:09,680 The AVR uses soft fuses. 134 00:10:09,680 --> 00:10:12,940 So you have EPROM bits that can be cleared and set. 135 00:10:13,960 --> 00:10:15,260 They're set during a reset. 136 00:10:15,760 --> 00:10:17,720 When you erase everything in the chip. 137 00:10:18,040 --> 00:10:19,480 And then they're cleared individually. 138 00:10:19,880 --> 00:10:21,900 So you can remove writes but you can never add them back. 139 00:10:22,140 --> 00:10:23,300 Until you erase everything. 140 00:10:24,820 --> 00:10:27,820 And the MSP430 uses a different method. 141 00:10:27,940 --> 00:10:29,920 Or at least it did when these slides were written. 142 00:10:30,500 --> 00:10:32,760 In that it has a hardware fuse. 143 00:10:33,340 --> 00:10:36,660 And if you're trying to lock someone out by JTAG from an MSP430. 144 00:10:36,980 --> 00:10:38,460 You blow this hardware fuse. 145 00:10:38,460 --> 00:10:42,040 And then the state machine itself. 146 00:10:42,480 --> 00:10:43,620 That is used for debugging. 147 00:10:43,820 --> 00:10:44,740 The JTAG state machine. 148 00:10:45,560 --> 00:10:48,100 It refuses to move beyond the initial state. 149 00:10:50,320 --> 00:10:51,580 There are ways around this though. 150 00:10:51,800 --> 00:10:52,980 And we'll be getting into those soon. 151 00:10:53,220 --> 00:10:58,160 The soft fuses in the AVR can be broken in a different manner. 152 00:10:58,240 --> 00:10:59,460 If you change the voltage of the chip. 153 00:10:59,900 --> 00:11:01,680 Sometimes it will misread from memory. 154 00:11:03,180 --> 00:11:04,180 And if you do this quickly. 155 00:11:04,340 --> 00:11:06,960 The chip doesn't recognize that it's running at the wrong voltage. 156 00:11:08,520 --> 00:11:11,180 You're also given a considerably wide window of voltages. 157 00:11:11,240 --> 00:11:12,120 That you're allowed to run it at. 158 00:11:12,540 --> 00:11:15,180 Many of these chips will go from 1.8 to 3.3 volts. 159 00:11:15,260 --> 00:11:16,200 Or as high as 5 volts. 160 00:11:16,700 --> 00:11:19,140 And you can drastically shift between one or the other. 161 00:11:19,180 --> 00:11:25,360 Without causing any of the battery indicator warnings to fire. 162 00:11:28,920 --> 00:11:32,280 Now if I gave you a microcontroller and a radio. 163 00:11:32,640 --> 00:11:34,540 And I gave you all the documentation for them. 164 00:11:34,740 --> 00:11:35,960 And I locked you in a room. 165 00:11:36,040 --> 00:11:37,740 And I said come out with a design in which they're connected. 166 00:11:38,600 --> 00:11:40,700 You would connect them in a very specific way. 167 00:11:43,320 --> 00:11:46,280 This corner down here at the bottom right. 168 00:11:48,180 --> 00:11:50,980 You'll notice that it has pin labels. 169 00:11:54,600 --> 00:11:58,360 I see a different slide on my screen. 170 00:12:00,900 --> 00:12:02,040 Can anyone hear me? 171 00:12:03,460 --> 00:12:03,980 Alright. 172 00:12:05,580 --> 00:12:06,520 You'll see here. 173 00:12:08,420 --> 00:12:09,460 There's UTXD1. 174 00:12:10,540 --> 00:12:11,060 URXD0. 175 00:12:11,700 --> 00:12:12,220 URXD1. 176 00:12:12,780 --> 00:12:15,160 These are the names of IOPNs. 177 00:12:15,960 --> 00:12:19,460 And they're the names of IOPNs for hardware accelerated serial ports. 178 00:12:21,000 --> 00:12:22,600 So if you have a serial port. 179 00:12:22,760 --> 00:12:25,040 It is connected to this corner. 180 00:12:25,420 --> 00:12:27,760 And you have different types of serial ports. 181 00:12:27,980 --> 00:12:29,660 So in the case of the ChipCon 2420. 182 00:12:29,760 --> 00:12:31,140 You'll be connected to the SPI port. 183 00:12:32,200 --> 00:12:35,260 This chip has a single hardware accelerated SPI port. 184 00:12:35,920 --> 00:12:37,560 So when you come out of that room. 185 00:12:37,700 --> 00:12:38,640 That's where you'll connect it. 186 00:12:39,580 --> 00:12:42,340 And if I see a wireless sensor for the first time. 187 00:12:42,340 --> 00:12:43,480 That uses these two chips. 188 00:12:44,020 --> 00:12:47,140 I know that they will make the same design decision. 189 00:12:47,680 --> 00:12:48,800 Because if they don't. 190 00:12:48,800 --> 00:12:50,180 The chip runs a lot slower. 191 00:12:50,740 --> 00:12:55,680 And this performance penalty isn't worth the additional cost. 192 00:12:56,880 --> 00:12:59,660 So all implementations follow this. 193 00:12:59,720 --> 00:13:00,760 Almost without exception. 194 00:13:02,480 --> 00:13:02,920 . 195 00:13:06,840 --> 00:13:07,740 Zooming in further. 196 00:13:08,900 --> 00:13:10,200 Actually these slides are wrong. 197 00:13:10,340 --> 00:13:11,040 I apologize for that. 198 00:13:11,480 --> 00:13:13,220 These would be used to speak to a computer. 199 00:13:13,380 --> 00:13:14,460 These pins up at the top. 200 00:13:14,680 --> 00:13:17,040 The SOMI 1. 201 00:13:17,140 --> 00:13:17,920 SOMI 0. 202 00:13:19,140 --> 00:13:23,020 Those are where the radio would be connected. 203 00:13:23,340 --> 00:13:24,560 It's an oversight on my part. 204 00:13:25,340 --> 00:13:27,140 And you can watch these lines. 205 00:13:28,120 --> 00:13:30,500 Because they're intended for one device to communicate with another. 206 00:13:30,760 --> 00:13:31,820 You can stick needles into the board. 207 00:13:33,140 --> 00:13:34,820 And you can watch the traffic flow. 208 00:13:34,940 --> 00:13:37,440 In the same way that you might wire tap a telephone line. 209 00:13:37,600 --> 00:13:39,480 Or you might packet sniff an Ethernet network. 210 00:13:41,880 --> 00:13:44,620 And by this point you're probably asking yourself. 211 00:13:44,660 --> 00:13:47,040 Why it matters that it's possible to break these things physically. 212 00:13:47,200 --> 00:13:48,940 Because on a PC. 213 00:13:50,240 --> 00:13:54,460 You never believe that if your computer is in the hands of an attacker physically. 214 00:13:55,140 --> 00:13:56,640 That there's that much that you can do. 215 00:13:56,740 --> 00:13:58,400 Even encrypting the hard disk isn't sufficient. 216 00:13:59,520 --> 00:14:00,720 Here it's different though. 217 00:14:00,780 --> 00:14:03,500 Because these devices are intended to be disposable. 218 00:14:05,220 --> 00:14:07,760 So if you throw a hundred of them into a field. 219 00:14:08,540 --> 00:14:10,980 Where they're physically within reach of an attacker. 220 00:14:11,100 --> 00:14:11,740 You can grab one. 221 00:14:11,800 --> 00:14:12,460 Pop it open. 222 00:14:12,660 --> 00:14:13,740 Stick some needles in. 223 00:14:13,820 --> 00:14:14,660 Hit the reset button. 224 00:14:16,060 --> 00:14:18,200 Then as this device associates with the network. 225 00:14:18,620 --> 00:14:22,000 The attacker can watch the microcontroller talking to the radio. 226 00:14:22,420 --> 00:14:25,700 He can catch the keys going from the microcontroller to the radio. 227 00:14:26,120 --> 00:14:26,600 And then. 228 00:14:28,980 --> 00:14:29,540 The attacker can see what's going on. 229 00:14:29,880 --> 00:14:31,920 And these are such low data rate. 230 00:14:32,040 --> 00:14:35,760 That you can very cheaply buy equipment for breaking into them. 231 00:14:35,900 --> 00:14:37,220 For packet sniffing rather. 232 00:14:37,460 --> 00:14:39,180 And in the case of ITC. 233 00:14:39,280 --> 00:14:41,220 It even supports multi-master networks. 234 00:14:41,700 --> 00:14:44,480 So unless one of the CPUs is. 235 00:14:45,120 --> 00:14:47,820 One of the master devices is actually holding the lines. 236 00:14:48,140 --> 00:14:50,940 To intentionally prevent anything else from communicating. 237 00:14:52,340 --> 00:14:54,320 Other parties can participate on the same line. 238 00:14:54,320 --> 00:14:57,720 In this case I have an ITC EPROM here. 239 00:14:58,100 --> 00:15:00,900 And I have a USB to serial chip. 240 00:15:01,080 --> 00:15:02,980 Which is reading it here to the left. 241 00:15:04,040 --> 00:15:07,300 These two syringes carry an ITC signal. 242 00:15:07,580 --> 00:15:08,560 One of them does data. 243 00:15:08,640 --> 00:15:09,380 One of them does clock. 244 00:15:10,140 --> 00:15:14,560 Not only can I watch the USB to serial chip boot from the EPROM. 245 00:15:15,180 --> 00:15:18,000 But I can also dump out the contents of the EPROM. 246 00:15:18,040 --> 00:15:18,980 By speaking to it. 247 00:15:19,480 --> 00:15:22,140 While the USB to serial chip is busy with other things. 248 00:15:23,520 --> 00:15:24,300 And there's even. 249 00:15:24,300 --> 00:15:25,280 Collision avoidance. 250 00:15:25,340 --> 00:15:26,840 So I don't have to worry too much. 251 00:15:26,920 --> 00:15:28,800 If it's booting at the exact same time that I. 252 00:15:29,700 --> 00:15:30,500 Dump the firmware. 253 00:15:32,100 --> 00:15:34,060 You can use the Hackaday bus pirate. 254 00:15:34,660 --> 00:15:36,200 To do this for ITC chips. 255 00:15:36,740 --> 00:15:37,740 You build a little kit. 256 00:15:37,880 --> 00:15:38,500 You wire it up. 257 00:15:38,580 --> 00:15:39,420 And you can dump everything out. 258 00:15:40,980 --> 00:15:42,680 I've also got the GoodFet project. 259 00:15:43,160 --> 00:15:45,240 Which also implements ITC. 260 00:15:45,320 --> 00:15:46,780 And you can buy commercial devices for the same. 261 00:15:48,220 --> 00:15:51,080 The access firmware which is held within the microcontroller. 262 00:15:51,360 --> 00:15:52,880 There are often multiple methods. 263 00:15:52,880 --> 00:15:55,660 In addition to connecting to it with JTAG. 264 00:15:55,800 --> 00:15:56,920 Where it's protected by a fuse. 265 00:15:57,280 --> 00:16:00,000 You can also connect with a bootloader. 266 00:16:00,800 --> 00:16:03,280 So it will run software internally to accept an update. 267 00:16:03,740 --> 00:16:04,960 You can start the software. 268 00:16:05,180 --> 00:16:06,820 And then as the software is running. 269 00:16:07,020 --> 00:16:09,700 You perhaps need to present a password to it. 270 00:16:10,100 --> 00:16:12,380 In order to extract the contents of memory. 271 00:16:13,340 --> 00:16:14,840 And there's often a loophole here. 272 00:16:15,180 --> 00:16:17,040 Which is that you can erase everything. 273 00:16:18,060 --> 00:16:20,080 The idea being that there's nothing left for you to steal. 274 00:16:20,540 --> 00:16:22,300 And then you're allowed access. 275 00:16:22,880 --> 00:16:24,120 So you can upgrade a device. 276 00:16:24,200 --> 00:16:26,760 Even though you're not allowed to read anything out of it. 277 00:16:27,980 --> 00:16:30,860 The attack that I presented yesterday at the Black Hat briefings. 278 00:16:31,700 --> 00:16:35,920 Hinged upon being able to erase everything that was in flash memory. 279 00:16:36,780 --> 00:16:38,040 But nothing that was in RAM. 280 00:16:40,080 --> 00:16:41,280 And on a Harvard chip. 281 00:16:41,360 --> 00:16:42,900 The keys would be copied over into RAM. 282 00:16:44,040 --> 00:16:48,380 Because the Harvard chip has to move everything into RAM. 283 00:16:48,500 --> 00:16:49,860 For C pointers to be consistent. 284 00:16:49,860 --> 00:16:53,840 When you have a pointer in your C code. 285 00:16:53,980 --> 00:16:54,820 On a Harvard chip. 286 00:16:54,940 --> 00:16:56,100 It always refers to data memory. 287 00:16:56,900 --> 00:16:58,460 Unless you're calling it as a function. 288 00:17:00,900 --> 00:17:02,680 So you boot the chip up. 289 00:17:02,820 --> 00:17:05,000 You wait for the firmware to initialize. 290 00:17:05,000 --> 00:17:05,940 Loading keys into RAM. 291 00:17:07,100 --> 00:17:08,800 Then you erase everything in the chip. 292 00:17:09,940 --> 00:17:12,620 Perhaps destroying the functionality of the device in the process. 293 00:17:12,960 --> 00:17:15,280 But you can then copy keys out of RAM. 294 00:17:16,200 --> 00:17:18,000 And this works on the MSP430. 295 00:17:18,140 --> 00:17:19,320 It works on. 296 00:17:19,860 --> 00:17:21,020 The chip con radios. 297 00:17:22,020 --> 00:17:23,080 The more recent ones. 298 00:17:23,240 --> 00:17:26,180 Which combine both a microcontroller and a radio into a single package. 299 00:17:26,860 --> 00:17:28,960 Where there is no ITC line. 300 00:17:29,020 --> 00:17:31,800 Or SPI line between the microcontroller and the radio for you to tap. 301 00:17:33,740 --> 00:17:34,500 And to do this. 302 00:17:34,540 --> 00:17:35,740 All you need is a debugger. 303 00:17:36,060 --> 00:17:37,400 You can use the official debugger. 304 00:17:37,680 --> 00:17:38,880 You just send the command to erase. 305 00:17:39,120 --> 00:17:40,280 Then you send the command to dump RAM. 306 00:17:40,900 --> 00:17:42,040 And all of the keys come out. 307 00:17:48,360 --> 00:17:48,920 JTAG itself. 308 00:17:50,060 --> 00:17:51,080 Uses a fuse. 309 00:17:51,260 --> 00:17:52,360 Either one that's broken. 310 00:17:52,600 --> 00:17:55,780 Or one that exists in EPROM. 311 00:17:56,400 --> 00:17:59,720 And it used to be that EPROM chips would have a quartz crystal window on top. 312 00:18:01,100 --> 00:18:02,760 So if you want to program the ROM chip. 313 00:18:02,940 --> 00:18:03,980 You put it into your burner. 314 00:18:04,900 --> 00:18:06,460 And the EPROM cells are cleared. 315 00:18:07,580 --> 00:18:09,060 So they begin as all ones. 316 00:18:09,280 --> 00:18:10,440 And then you pick individual bits. 317 00:18:10,580 --> 00:18:12,380 And you say these bits will be cleared to zero. 318 00:18:13,000 --> 00:18:14,000 If you write it twice. 319 00:18:14,100 --> 00:18:16,740 You wind up with a bitwise AND of the two images. 320 00:18:17,880 --> 00:18:18,900 There's no way to interpret this. 321 00:18:18,900 --> 00:18:20,940 You individually turn a bit from a zero to a one. 322 00:18:21,700 --> 00:18:24,300 But you can put it under ultraviolet light. 323 00:18:24,500 --> 00:18:28,140 So you would put these chips under a light in a little box. 324 00:18:29,100 --> 00:18:30,060 Wait 20 minutes. 325 00:18:30,220 --> 00:18:31,000 And then they would be erased. 326 00:18:31,120 --> 00:18:33,980 Because the ultraviolet light would pump up the charge of each cell. 327 00:18:34,520 --> 00:18:36,300 And then later you can clear that charge out. 328 00:18:37,220 --> 00:18:39,300 Well when the fuse is implemented in EPROM. 329 00:18:39,440 --> 00:18:42,880 You can sometimes hit the fuse with ultraviolet light to knock it over. 330 00:18:44,060 --> 00:18:46,940 Or you can take a photograph of the chip at the right moment. 331 00:18:47,140 --> 00:18:48,880 And it will misread as a one when it's done. 332 00:18:48,900 --> 00:18:49,560 When it's actually a zero. 333 00:18:50,200 --> 00:18:52,060 And on some chips this will damage them. 334 00:18:54,440 --> 00:18:56,940 Some chips will have two fuses next to each other. 335 00:18:57,340 --> 00:18:59,800 One needs to be cleared while the other needs to be set. 336 00:19:00,020 --> 00:19:01,280 Or something like that. 337 00:19:01,460 --> 00:19:03,640 To keep you from hitting it with ultraviolet light. 338 00:19:04,680 --> 00:19:06,200 But others have no such protection. 339 00:19:07,000 --> 00:19:09,920 If you hit an MSP430 with a camera flash. 340 00:19:10,140 --> 00:19:11,560 It continues to execute. 341 00:19:12,200 --> 00:19:13,880 Sometimes things will mess up accidentally. 342 00:19:14,280 --> 00:19:17,220 But it doesn't set off any tamper-proofing mechanism. 343 00:19:18,900 --> 00:19:21,380 You can even use it to skip over the fuse jack sometimes. 344 00:19:21,560 --> 00:19:24,200 In that it will jump to the wrong JTAG state. 345 00:19:25,160 --> 00:19:26,700 You'll find this with a debugger. 346 00:19:27,140 --> 00:19:29,660 In that you'll accidentally start reading out ones. 347 00:19:31,640 --> 00:19:32,540 Wait long enough. 348 00:19:32,580 --> 00:19:33,880 Transfer through enough states. 349 00:19:33,980 --> 00:19:35,880 And the debugger finds itself in the proper state. 350 00:19:37,280 --> 00:19:38,760 And you've cleared out of that. 351 00:19:40,560 --> 00:19:43,040 I took this at DEF CON last year. 352 00:19:43,220 --> 00:19:45,460 Chris Tarnowski had a demo setup. 353 00:19:46,080 --> 00:19:47,900 Where he stuck a needle into a chip. 354 00:19:48,900 --> 00:19:51,340 To actually spy on the data bus. 355 00:19:51,540 --> 00:19:54,120 And he can do the same thing to skip over a fuse. 356 00:19:55,780 --> 00:19:57,400 This equipment is expensive. 357 00:19:57,580 --> 00:19:58,560 But not prohibitively so. 358 00:20:01,500 --> 00:20:02,620 Here on the left. 359 00:20:02,700 --> 00:20:04,700 You can see the needle going into the line. 360 00:20:06,240 --> 00:20:10,320 And hardly any chip is properly defended against this. 361 00:20:11,840 --> 00:20:13,360 His company Fly Logic. 362 00:20:13,480 --> 00:20:15,800 When they get chips in to play with. 363 00:20:15,800 --> 00:20:21,640 They almost never fail to find some unprotected line of the bus to tap. 364 00:20:21,800 --> 00:20:23,060 And then they can watch what's going on inside. 365 00:20:23,360 --> 00:20:24,720 But with the boards themselves. 366 00:20:25,520 --> 00:20:27,700 You have the same access between chips. 367 00:20:28,280 --> 00:20:30,280 And you have it without this expensive equipment. 368 00:20:30,900 --> 00:20:34,680 You have it without hands steady enough to move a microscopic needle. 369 00:20:35,360 --> 00:20:37,940 You have it without a chemistry lab to remove the lids from the chips. 370 00:20:38,080 --> 00:20:40,200 And to remove the top of the glass from the die. 371 00:20:41,840 --> 00:20:45,060 You can also do bootloader attacks. 372 00:20:46,500 --> 00:20:49,540 And black hat briefings last year in Las Vegas. 373 00:20:49,660 --> 00:20:53,560 I presented a timing attack against certain versions of the MSP430. 374 00:20:54,660 --> 00:21:00,320 I picked up this watch in the vendor area that contains an MSP430. 375 00:21:02,580 --> 00:21:06,180 And if you dump the bootloader from it. 376 00:21:06,240 --> 00:21:06,780 It's a program. 377 00:21:07,480 --> 00:21:10,460 And it's a program that an attacker is always free to start. 378 00:21:11,440 --> 00:21:14,180 Even in the more recent models which allow you to disable it. 379 00:21:14,180 --> 00:21:16,020 The attacker can still start the program. 380 00:21:16,140 --> 00:21:17,320 It just gets stuck near the beginning. 381 00:21:19,540 --> 00:21:21,240 And on this particular device. 382 00:21:21,380 --> 00:21:22,800 I can extract the firmware. 383 00:21:23,980 --> 00:21:27,720 In that the timing of the password is unbalanced. 384 00:21:28,760 --> 00:21:30,480 So if I present a password to it. 385 00:21:30,520 --> 00:21:34,120 It takes it longer to compare two bytes which are not equal to each other. 386 00:21:35,140 --> 00:21:37,840 Than it takes to compare two bytes which are equal to each other. 387 00:21:38,360 --> 00:21:42,920 And this difference is caused by it clearing a bit out of a register to deny access. 388 00:21:44,380 --> 00:21:47,260 So first it gives you access to the chip. 389 00:21:47,940 --> 00:21:49,460 But you have to send it a password. 390 00:21:50,020 --> 00:21:52,960 And with each byte it will disable your access again. 391 00:21:54,460 --> 00:21:55,620 If the two do not equal. 392 00:21:56,380 --> 00:21:58,360 In later versions they fixed the timing. 393 00:22:00,880 --> 00:22:03,400 And then they broke it again and now it's fixed again. 394 00:22:04,180 --> 00:22:07,280 But the point is that this program can't really be taken out. 395 00:22:08,320 --> 00:22:10,800 Because it's in flash memory you can always start it. 396 00:22:10,980 --> 00:22:11,320 . 397 00:22:12,540 --> 00:22:15,140 And you'll find similar things on many of these chips. 398 00:22:15,240 --> 00:22:19,020 Either built into masked ROM by the chip vendor. 399 00:22:19,180 --> 00:22:23,220 Or intended as an update or debugging mechanism by the product vendor. 400 00:22:25,280 --> 00:22:26,940 And you can use voltage glitching. 401 00:22:27,060 --> 00:22:30,340 You can drop and then raise VCC. 402 00:22:30,780 --> 00:22:31,640 Very quickly. 403 00:22:31,820 --> 00:22:33,360 You can skip over an instruction. 404 00:22:33,600 --> 00:22:36,680 You can make the wrong immediate value be read. 405 00:22:37,900 --> 00:22:38,860 So if I intend. 406 00:22:39,260 --> 00:22:40,180 Or if the programmer intended. 407 00:22:40,180 --> 00:22:44,060 To say compare something to something else. 408 00:22:44,300 --> 00:22:45,680 If you glitch at the right minute. 409 00:22:45,820 --> 00:22:47,740 Or the right second. 410 00:22:48,120 --> 00:22:51,600 It might compare that to all zeros or all ones by mistake. 411 00:22:52,360 --> 00:22:54,000 In the new MSP430s. 412 00:22:54,020 --> 00:22:55,100 The ones with soft fuses. 413 00:22:55,540 --> 00:22:59,260 The JTAG fuse has been replaced. 414 00:23:00,040 --> 00:23:02,600 Instead of actually having a physical device that's blown. 415 00:23:03,120 --> 00:23:05,140 There's actually a word of flash memory that's read. 416 00:23:06,020 --> 00:23:08,460 If that flash memory is all ones or all zeros. 417 00:23:08,880 --> 00:23:09,740 You're allowed access. 418 00:23:11,000 --> 00:23:12,100 If it's anything else. 419 00:23:12,720 --> 00:23:13,540 Access is denied. 420 00:23:15,740 --> 00:23:16,100 Well. 421 00:23:16,620 --> 00:23:18,700 If the voltage is rising or falling. 422 00:23:18,760 --> 00:23:20,600 The most common things that you'll accidentally read. 423 00:23:20,660 --> 00:23:21,420 Are zeros and ones. 424 00:23:24,460 --> 00:23:26,120 I've yet to get a working exploit of this. 425 00:23:26,220 --> 00:23:27,360 But believe me when I say that it's coming. 426 00:23:28,520 --> 00:23:29,100 Dankeschön, neighbor. 427 00:23:35,680 --> 00:23:36,920 Cheers for Daniel. 428 00:23:43,000 --> 00:23:45,560 This was a device that I built. 429 00:23:46,120 --> 00:23:47,600 For implementing the timing attack. 430 00:23:48,640 --> 00:23:52,380 The idea is that the board is programmed to the left. 431 00:23:52,620 --> 00:23:53,560 And on the right. 432 00:23:53,580 --> 00:23:56,420 You actually have a serial port going to the victim device. 433 00:23:58,060 --> 00:23:59,080 Then you can have buttons. 434 00:23:59,100 --> 00:24:01,340 Or you can just control it through JTAG entirely. 435 00:24:01,960 --> 00:24:03,840 This is a glitch on a scope. 436 00:24:04,780 --> 00:24:07,260 You can see the voltage falling and coming back up. 437 00:24:07,480 --> 00:24:10,540 And the entire width here is 250 nanoseconds. 438 00:24:11,520 --> 00:24:15,920 So four times this width would be a single millisecond. 439 00:24:17,440 --> 00:24:18,660 Or microsecond rather. 440 00:24:19,380 --> 00:24:20,520 And on the board itself. 441 00:24:20,820 --> 00:24:21,640 If you look at the parts. 442 00:24:21,820 --> 00:24:23,540 There's a microcontroller here. 443 00:24:23,860 --> 00:24:25,200 That implements the attack. 444 00:24:25,540 --> 00:24:26,320 And to its right. 445 00:24:26,460 --> 00:24:27,840 There are glitching registers. 446 00:24:29,600 --> 00:24:30,080 74HC4053. 447 00:24:30,800 --> 00:24:32,300 Analog bidirectional muxes. 448 00:24:33,220 --> 00:24:35,720 For those of you who aren't double E nerds. 449 00:24:36,600 --> 00:24:37,880 I'm terribly sorry. 450 00:24:38,220 --> 00:24:38,700 Yes. 451 00:24:40,020 --> 00:24:40,960 Got a question? 452 00:24:41,900 --> 00:24:42,680 Oh, never mind. 453 00:24:43,760 --> 00:24:47,300 So for those of you who don't deal with hardware directly. 454 00:24:47,440 --> 00:24:50,120 These are just switches that run from one voltage to another. 455 00:24:51,120 --> 00:24:54,980 So in the same way that a digital mux would switch between a one or a zero. 456 00:24:55,080 --> 00:24:56,240 Based upon a control line. 457 00:24:56,240 --> 00:25:01,940 These jump to either full voltage or whatever the microcontroller has decided to put out. 458 00:25:05,040 --> 00:25:10,600 You can also do voltage analysis and power analysis to make this glitching more reliable. 459 00:25:12,280 --> 00:25:18,520 This waveform here is what happens when you don't properly decouple a microcontroller from its power supply. 460 00:25:19,060 --> 00:25:21,920 So on each clock edge the chip begins to use power. 461 00:25:22,220 --> 00:25:24,220 And the available voltage drops. 462 00:25:26,460 --> 00:25:28,380 And you can see this drop here. 463 00:25:28,500 --> 00:25:31,640 So every sharp drop such as this one. 464 00:25:32,280 --> 00:25:35,260 Occurs when the chip begins to perform calculations on a clock edge. 465 00:25:35,620 --> 00:25:39,000 And a single instruction might be four or more clock edges. 466 00:25:40,360 --> 00:25:42,900 And you don't know which is rising and which is falling. 467 00:25:43,340 --> 00:25:47,460 So the chances of your getting a break on any given glitching attempt are rather small. 468 00:25:47,780 --> 00:25:50,040 But if you consider that you have infinitely many attempts. 469 00:25:50,580 --> 00:25:51,940 You can leave this running overnight. 470 00:25:53,280 --> 00:25:54,520 You come back in the morning. 471 00:25:54,700 --> 00:25:55,720 And it's. 472 00:25:55,720 --> 00:25:56,460 It's connected. 473 00:25:56,720 --> 00:25:57,360 It's logged in. 474 00:25:57,460 --> 00:25:58,480 And you have access to firmware. 475 00:26:02,520 --> 00:26:09,800 And the timing attacks depend upon mistakes in compiled C code. 476 00:26:10,680 --> 00:26:12,260 How long does a comparison take? 477 00:26:13,560 --> 00:26:14,880 In clock cycles. 478 00:26:15,320 --> 00:26:17,440 Now for any C program you've written. 479 00:26:17,520 --> 00:26:20,440 Do you actually know how long any given region runs? 480 00:26:21,000 --> 00:26:22,500 If you have an if-else statement. 481 00:26:23,720 --> 00:26:24,240 Okay. 482 00:26:24,240 --> 00:26:27,180 Not only do you have to worry about the timing of the bodies themselves. 483 00:26:27,400 --> 00:26:30,000 But you also have to worry about the timing of the conditional clause. 484 00:26:31,760 --> 00:26:35,160 In this case if the comparison takes a different amount of time. 485 00:26:35,460 --> 00:26:36,420 Then you have trouble. 486 00:26:36,580 --> 00:26:38,700 If the body takes a different amount of time. 487 00:26:38,780 --> 00:26:39,440 Then you also have trouble. 488 00:26:41,240 --> 00:26:44,000 I ran a timing simulation against this. 489 00:26:45,140 --> 00:26:48,620 So I tried a password of all repeated bytes. 490 00:26:48,880 --> 00:26:49,600 All zeros. 491 00:26:49,700 --> 00:26:50,760 All elevens. 492 00:26:50,760 --> 00:26:51,380 All three As. 493 00:26:51,600 --> 00:26:52,600 And then everything else. 494 00:26:52,600 --> 00:26:55,460 And I counted the number of clock cycles that it took. 495 00:26:57,340 --> 00:27:00,800 And most of them took 6543 clock cycles. 496 00:27:01,580 --> 00:27:06,280 This is how long it takes if every single byte of the attempt is wrong. 497 00:27:08,280 --> 00:27:10,980 These others though took less time. 498 00:27:11,140 --> 00:27:13,300 And if you take the difference in time and you divide it by two. 499 00:27:14,060 --> 00:27:16,680 You get the number of times that that byte occurs in the password. 500 00:27:18,400 --> 00:27:20,740 So you can see here that zero occurs once. 501 00:27:21,020 --> 00:27:22,400 And that's right there on the. 502 00:27:22,400 --> 00:27:23,100 On the top right. 503 00:27:24,120 --> 00:27:25,840 Eleven occurs 16 times. 504 00:27:26,340 --> 00:27:28,960 It's the more significant byte of every word. 505 00:27:29,460 --> 00:27:31,320 And three A occurs 15 times. 506 00:27:31,400 --> 00:27:32,960 Because it's in every word except for this one. 507 00:27:33,520 --> 00:27:36,360 And the reason why the password looks so predictable. 508 00:27:36,480 --> 00:27:38,900 Is that it's actually the list of interrupt handler addresses. 509 00:27:39,800 --> 00:27:42,700 So instead of a human being choosing the password. 510 00:27:42,980 --> 00:27:44,620 And getting something that's easy to guess. 511 00:27:44,820 --> 00:27:46,360 The compiler chose a password. 512 00:27:46,740 --> 00:27:48,720 And it just so happens to be something easy to guess. 513 00:27:52,400 --> 00:27:56,140 It's a paper by Becker and a few other German students. 514 00:27:56,300 --> 00:27:57,480 Where they actually looked through. 515 00:27:57,600 --> 00:27:59,660 And they figured out how long it would take to brute force these things. 516 00:28:00,380 --> 00:28:03,540 And they concluded that the average password had 40 bits of entropy. 517 00:28:04,100 --> 00:28:06,740 And that it would take 128 years to brute force it. 518 00:28:10,220 --> 00:28:11,660 Their numbers were inaccurate. 519 00:28:11,900 --> 00:28:15,660 In that they assumed that the device couldn't be overclocked. 520 00:28:16,840 --> 00:28:20,360 And they also assumed that every program was complicated. 521 00:28:20,360 --> 00:28:23,720 In this case the password is so simple. 522 00:28:24,520 --> 00:28:29,380 Because this isn't an application that's doing lots of things. 523 00:28:30,020 --> 00:28:31,840 All it's doing is starting up. 524 00:28:32,060 --> 00:28:35,260 And then it has a main function with different bodies in it. 525 00:28:35,340 --> 00:28:36,240 It has no interrupts. 526 00:28:36,840 --> 00:28:38,080 It has no timers. 527 00:28:38,140 --> 00:28:39,080 It never goes to sleep. 528 00:28:39,220 --> 00:28:39,880 It has no buttons. 529 00:28:41,860 --> 00:28:43,960 And if you write a program in this way. 530 00:28:44,340 --> 00:28:46,580 You're doing it because you're used to writing programs for a PC. 531 00:28:47,860 --> 00:28:49,660 And if you're trying to hire a C programmer. 532 00:28:49,660 --> 00:28:51,900 It's a lot easier to find one with experience in a PC. 533 00:28:52,080 --> 00:28:53,880 Than one with experience in microcontrollers. 534 00:28:55,360 --> 00:28:58,400 I expect that many such programs will have issues like this. 535 00:28:58,540 --> 00:29:01,320 They will use polling instead of interrupts. 536 00:29:01,440 --> 00:29:04,680 And therefore their password won't be as random as it might be. 537 00:29:07,300 --> 00:29:10,820 Further, 1100 is chosen because that's the bottom of flash memory on this chip. 538 00:29:12,240 --> 00:29:13,620 Everything else is the same word. 539 00:29:13,700 --> 00:29:15,420 Because they go to the default handler. 540 00:29:16,240 --> 00:29:18,080 Which in GCC is at least something. 541 00:29:18,080 --> 00:29:21,720 You at least have to guess the 3A. 542 00:29:22,980 --> 00:29:25,080 On competing compilers to save a bit of space. 543 00:29:25,400 --> 00:29:26,300 They do nothing. 544 00:29:26,460 --> 00:29:27,740 They don't handle these at all. 545 00:29:28,040 --> 00:29:29,680 So these would all be FFFF. 546 00:29:34,140 --> 00:29:35,140 Now there are complications. 547 00:29:35,700 --> 00:29:37,640 You have a start bit that you have to consider. 548 00:29:38,740 --> 00:29:40,300 The way that serial traffic works. 549 00:29:42,180 --> 00:29:42,920 Jump ahead. 550 00:29:43,120 --> 00:29:44,960 I don't have a diagram of this. 551 00:29:45,060 --> 00:29:46,460 The way that serial traffic works. 552 00:29:46,460 --> 00:29:48,880 Is that the line stays high so long as it's idle. 553 00:29:49,620 --> 00:29:53,240 Or for us 232 invert everything I'm saying about high and low. 554 00:29:53,500 --> 00:29:55,800 The line stays high so long as it's idle. 555 00:29:56,020 --> 00:29:58,940 And then you drop it low to begin a word. 556 00:29:59,880 --> 00:30:01,440 A word being a byte in this case. 557 00:30:02,200 --> 00:30:05,280 After you drop it low you send a single bit that's a zero. 558 00:30:05,480 --> 00:30:07,300 Just to indicate the beginning of that byte. 559 00:30:07,840 --> 00:30:10,100 And you follow it by the bits of the byte. 560 00:30:10,500 --> 00:30:13,960 In the least significant bit first. 561 00:30:15,000 --> 00:30:17,100 And the reason they did least significant bit first. 562 00:30:17,180 --> 00:30:19,320 Is that it allows you to send seven bits instead of eight. 563 00:30:19,920 --> 00:30:21,240 If you're trying to do ASCII. 564 00:30:22,380 --> 00:30:25,100 And then your terminal can just clear out the high bit all the time. 565 00:30:27,620 --> 00:30:34,440 This was useful for maybe a couple of years in the 50s or 60s. 566 00:30:34,800 --> 00:30:36,820 But it still hangs around because of that. 567 00:30:38,280 --> 00:30:39,860 Now when you're disassembling firmware. 568 00:30:40,260 --> 00:30:41,340 It's a very different advantage. 569 00:30:41,620 --> 00:30:43,080 It's a very different environment. 570 00:30:43,080 --> 00:30:44,580 From doing so on a PC. 571 00:30:45,040 --> 00:30:48,120 When you disassemble firmware on a microcontroller. 572 00:30:49,280 --> 00:30:50,820 You have a small address space. 573 00:30:51,680 --> 00:30:54,420 You only have 64 kilobytes of memory. 574 00:30:56,340 --> 00:30:59,660 And in the very largest chips you'll have a few times that. 575 00:30:59,780 --> 00:31:03,040 128 or maybe a quarter megabyte. 576 00:31:04,280 --> 00:31:05,680 You have a single process. 577 00:31:06,020 --> 00:31:08,460 Everything is one application linked together. 578 00:31:08,940 --> 00:31:11,940 You don't have competing applications. 579 00:31:11,940 --> 00:31:13,160 You don't have an operating system. 580 00:31:13,280 --> 00:31:14,260 You don't have system calls. 581 00:31:14,900 --> 00:31:17,220 At best you have a scheduler that calls functions. 582 00:31:18,040 --> 00:31:21,420 The most complicated you'll ever see is a scheduler that calls function pointers. 583 00:31:23,740 --> 00:31:25,240 And you have no IDA Pro support. 584 00:31:26,180 --> 00:31:30,200 There are very few high end tools to do this reverse engineering. 585 00:31:30,380 --> 00:31:33,880 Tools which you might be familiar with from the PC world. 586 00:31:35,220 --> 00:31:36,620 So you have to build your own tools. 587 00:31:36,720 --> 00:31:39,940 When you're the first one to begin reverse engineering software for one of these chips. 588 00:31:41,940 --> 00:31:46,820 So I wrote MSP430 static in late 2007 and early 2008. 589 00:31:47,380 --> 00:31:53,020 And it began as a way to generate slides from my talk about an MSP430 exploit that I'd made. 590 00:31:53,680 --> 00:31:57,180 I needed diagrams that showed how the functions flowed into one another. 591 00:31:57,880 --> 00:32:01,680 And I could either sit there for a couple of minutes doing it in open office. 592 00:32:02,100 --> 00:32:06,640 We all saw 20 minutes ago how reliable open office is. 593 00:32:06,880 --> 00:32:11,380 So instead I wrote a tool in Perl and SQLite. 594 00:32:13,380 --> 00:32:16,620 Where Perl functions are exposed to SQLite. 595 00:32:16,720 --> 00:32:22,300 And then you can request say call graphs in SQL. 596 00:32:23,460 --> 00:32:25,780 On a PC application this would be a wretched idea. 597 00:32:26,420 --> 00:32:27,860 It wouldn't be fast enough. 598 00:32:28,000 --> 00:32:29,600 It wouldn't be high performance enough. 599 00:32:29,700 --> 00:32:33,340 You'd have to use all sorts of very complicated database optimizations. 600 00:32:34,160 --> 00:32:35,840 But on a microcontroller you don't. 601 00:32:35,920 --> 00:32:37,840 You just throw it in there and it works. 602 00:32:38,340 --> 00:32:40,280 And not only does it work but it works quickly. 603 00:32:41,000 --> 00:32:45,940 The only time at which this tool is slow is when it's initially loading the application and building the tables. 604 00:32:48,120 --> 00:32:54,680 So you can select the hexadecimal address and function name of a function. 605 00:32:55,120 --> 00:32:57,060 You can order it by descending address. 606 00:32:57,240 --> 00:32:58,140 And you can ask for only five. 607 00:32:59,140 --> 00:33:01,840 This gives you the five functions at the top of memory. 608 00:33:04,180 --> 00:33:05,380 You can draw a memory map. 609 00:33:06,400 --> 00:33:08,820 And this is just a bitmap spat out by requesting 610 00:33:08,820 --> 00:33:10,600 every word of memory. 611 00:33:11,620 --> 00:33:14,520 And then seeing whether it was properly disassembled. 612 00:33:16,000 --> 00:33:18,820 Everything red here is properly disassembled. 613 00:33:18,860 --> 00:33:21,820 And everything blue is the target of an immediate pointer. 614 00:33:24,020 --> 00:33:26,640 Data is drawn in red and gray. 615 00:33:26,780 --> 00:33:28,840 Because some data looks like a valid instruction. 616 00:33:29,200 --> 00:33:31,000 And this being a Von Neumann chip, 617 00:33:31,300 --> 00:33:34,160 the machine itself can't tell the difference between 618 00:33:35,400 --> 00:33:37,420 weird data and instructions. 619 00:33:37,420 --> 00:33:40,780 Because you can always jump to data and execute it as code. 620 00:33:42,720 --> 00:33:45,840 The interrupt vector table is in green at the top right here. 621 00:33:46,020 --> 00:33:47,020 I doubt that you can see it. 622 00:33:48,380 --> 00:33:51,280 And then everything that's all ones I draw in black. 623 00:33:51,460 --> 00:33:53,060 And everything that's all zeros I draw in white. 624 00:33:53,680 --> 00:33:56,400 You see neither here because this came from a compiler 625 00:33:56,400 --> 00:33:58,020 rather than being ripped out of an image. 626 00:33:59,240 --> 00:34:00,760 If it were ripped out of a chip, 627 00:34:00,940 --> 00:34:04,500 if I had actually connected to a board and copied this particular example out, 628 00:34:04,660 --> 00:34:05,560 you would see 629 00:34:05,560 --> 00:34:08,040 the data regions appear 630 00:34:08,860 --> 00:34:11,420 if they were used for temporary variables 631 00:34:11,420 --> 00:34:12,660 as being spotted in gray. 632 00:34:13,100 --> 00:34:16,160 If you ripped the firmware out of an MSP430 JTAG adapter, 633 00:34:16,400 --> 00:34:17,260 that's what you'll find. 634 00:34:17,540 --> 00:34:19,960 And you'll also find a second application at the top 635 00:34:21,020 --> 00:34:24,100 which forwards the interrupts to the lower image. 636 00:34:25,160 --> 00:34:27,320 This is what a bootloader looks like 637 00:34:27,320 --> 00:34:28,900 and it's also what a worm looks like. 638 00:34:30,380 --> 00:34:33,000 If you were to take apart the smart grid worm 639 00:34:33,000 --> 00:34:34,340 that Mike Davis released yesterday, 640 00:34:34,340 --> 00:34:36,220 you would find something similar to that. 641 00:34:37,600 --> 00:34:39,060 And here's what that looks like. 642 00:34:39,180 --> 00:34:41,200 You've got data tables here. 643 00:34:41,440 --> 00:34:45,520 You've got the compiled code as the clean red block in the middle. 644 00:34:46,040 --> 00:34:49,100 And beneath that you've got some sort of randomized values 645 00:34:49,540 --> 00:34:50,940 for the unused parts of RAM. 646 00:34:51,720 --> 00:34:54,640 The used parts of RAM are cleared to be zero. 647 00:34:54,820 --> 00:34:56,080 And that's where you get the white. 648 00:34:56,560 --> 00:34:59,020 That's also where these blue pointers come from. 649 00:35:01,220 --> 00:35:03,700 Each object in memory, if you have, say, a string, 650 00:35:04,180 --> 00:35:06,420 you'll see a little blue dot at the beginning of that string 651 00:35:06,420 --> 00:35:09,320 and then you won't see another blue dot until the end of the string. 652 00:35:09,780 --> 00:35:15,460 You have the least significant byte of the address as your x-axis 653 00:35:15,460 --> 00:35:18,400 and the most significant byte as your y-axis. 654 00:35:19,580 --> 00:35:21,660 And you can sort of see how things are arranged here. 655 00:35:21,760 --> 00:35:23,880 You can see that flash memory is always at the top 656 00:35:23,880 --> 00:35:25,540 and it always runs to the very top 657 00:35:26,300 --> 00:35:27,900 while RAM comes beneath it. 658 00:35:28,080 --> 00:35:33,140 And then these little lines at the very bottom aren't RAM or ROM. 659 00:35:33,140 --> 00:35:33,840 They aren't flash. 660 00:35:34,640 --> 00:35:35,700 These are I.O. addresses. 661 00:35:36,820 --> 00:35:40,340 If you want to write a byte out of a serial port, 662 00:35:41,500 --> 00:35:45,440 you simply write it to the address of the hardware-accelerated serial port. 663 00:35:45,920 --> 00:35:48,120 And then it takes care of actually blasting it out. 664 00:35:48,280 --> 00:35:49,980 And then it will optionally fire an interrupt 665 00:35:49,980 --> 00:35:51,460 to tell you that the transmission is complete. 666 00:35:53,680 --> 00:35:55,800 So even though you don't have an operating system to call, 667 00:35:56,000 --> 00:35:57,240 you have hardware to call. 668 00:36:00,000 --> 00:36:01,700 And that can be searched for. 669 00:36:03,460 --> 00:36:06,540 So if I'm trying to identify functions within an application, 670 00:36:06,880 --> 00:36:08,080 I can search for these things. 671 00:36:08,640 --> 00:36:10,000 And it's very easy to automate. 672 00:36:10,960 --> 00:36:14,200 I know that all functions begin as the target of a call or a branch. 673 00:36:15,040 --> 00:36:17,020 And I know that all simple C functions, 674 00:36:17,280 --> 00:36:19,840 those that are called by a proper name instead of by a pointer, 675 00:36:20,500 --> 00:36:22,360 I know that those use immediate addressing. 676 00:36:23,360 --> 00:36:27,860 You have a 16-bit word that says call the next word as a function pointer. 677 00:36:28,340 --> 00:36:29,640 And then you have that next word. 678 00:36:30,060 --> 00:36:31,400 If you search for the first one, 679 00:36:31,400 --> 00:36:33,660 you'll get every function pointer in the image. 680 00:36:34,320 --> 00:36:37,520 Perhaps one false positive, but quite likely not. 681 00:36:38,380 --> 00:36:42,280 And you can find the exit points because they're a return i, 682 00:36:42,520 --> 00:36:43,220 a return from interrupt. 683 00:36:43,860 --> 00:36:47,440 And they're always after the last relative jump. 684 00:36:48,600 --> 00:36:50,740 So if you have an if statement, it might say, 685 00:36:51,980 --> 00:36:55,500 if this is not equal, jump over the body. 686 00:36:57,940 --> 00:36:59,740 Even if there's a return in that body, 687 00:36:59,740 --> 00:37:01,380 you know that it's jumping to the end. 688 00:37:01,620 --> 00:37:05,280 And this is true without exception as a side effect 689 00:37:05,280 --> 00:37:06,480 of the way that the compilers work. 690 00:37:09,100 --> 00:37:13,020 Now, in a call graph, every function is a vertex, 691 00:37:13,240 --> 00:37:15,320 and every function call is an edge. 692 00:37:15,480 --> 00:37:18,320 So in this case, main might call printf, which calls putc, 693 00:37:18,500 --> 00:37:20,080 and scanf, which calls getc. 694 00:37:22,840 --> 00:37:25,920 You can draw call graphs of microcontroller code, 695 00:37:26,000 --> 00:37:27,240 and you can do it very easily. 696 00:37:27,820 --> 00:37:28,960 In my case, 697 00:37:28,960 --> 00:37:32,480 I just used an SQL query to dump out a graph is dot diagram. 698 00:37:32,960 --> 00:37:35,520 Then I get a PDF, which I could print onto a wall, 699 00:37:35,660 --> 00:37:40,300 or I could zoom into it with an image viewer. 700 00:37:41,060 --> 00:37:43,080 And you can see that there are different regions to the code. 701 00:37:46,760 --> 00:37:48,960 And as far as figuring out what these functions do, 702 00:37:49,180 --> 00:37:50,780 you can look for those same I.O. ports 703 00:37:50,780 --> 00:37:51,820 that I mentioned a moment ago. 704 00:37:52,440 --> 00:37:54,340 If you want to find the function that receives a byte, 705 00:37:54,720 --> 00:37:56,600 all you have to do is look for the function 706 00:37:56,600 --> 00:37:58,940 that actually reads from the incoming code 707 00:37:58,960 --> 00:37:59,660 in the incoming serial port register. 708 00:38:00,120 --> 00:38:02,640 You can even tell which function reads from which port. 709 00:38:03,460 --> 00:38:04,880 If you have two serial ports, 710 00:38:06,080 --> 00:38:09,100 you have an incoming byte address for both of them. 711 00:38:09,280 --> 00:38:10,600 And you can just read from there. 712 00:38:13,780 --> 00:38:19,220 So, for example, in the MSP430-200 series, 713 00:38:20,500 --> 00:38:24,320 the UART0 transmit buffer is at 0x0077. 714 00:38:25,520 --> 00:38:28,280 And an example fragment of code that might write to it 715 00:38:28,960 --> 00:38:34,780 is move the byte from register 11 to memory at 0077. 716 00:38:36,660 --> 00:38:38,540 That's all that that word will ever do. 717 00:38:38,900 --> 00:38:43,460 There is no other reason to have that word of code 718 00:38:43,460 --> 00:38:44,180 within a function. 719 00:38:46,320 --> 00:38:49,400 And you can find this with MSP430 static 720 00:38:49,400 --> 00:38:51,360 or with any tool that you might throw together yourself 721 00:38:51,360 --> 00:38:54,780 for any microcontroller that you wish to take apart software for. 722 00:38:55,340 --> 00:38:57,700 By just saying, select the name from functions 723 00:38:57,700 --> 00:38:59,880 where the assembly is like 0077. 724 00:39:01,160 --> 00:39:02,380 And this always works. 725 00:39:05,760 --> 00:39:07,140 You can also do name hashing. 726 00:39:07,640 --> 00:39:10,280 This is a little project of mine for a while. 727 00:39:10,360 --> 00:39:12,540 I started collecting lots of firmware images 728 00:39:13,280 --> 00:39:14,600 and reverse engineering them. 729 00:39:14,940 --> 00:39:17,680 And then I would know the names of individual functions, 730 00:39:17,840 --> 00:39:19,460 but it would be very difficult for me to share that. 731 00:39:20,580 --> 00:39:23,100 Because if I just post a list, that's horribly boring writing. 732 00:39:24,580 --> 00:39:27,180 But you might grab a function with similar contents. 733 00:39:29,920 --> 00:39:32,340 Now, while I can't share the code with you, 734 00:39:33,680 --> 00:39:37,120 I can share the one-way hash of the code with you. 735 00:39:38,120 --> 00:39:39,560 Because that's not copyrighted. 736 00:39:41,920 --> 00:39:46,400 So, MSP430 static actually ships with a table. 737 00:39:46,580 --> 00:39:49,180 It's just function names and MD5 checksums. 738 00:39:50,480 --> 00:39:54,560 And there's a command that restores all of the function names 739 00:39:54,560 --> 00:39:56,400 that are missing from that table. 740 00:39:57,020 --> 00:39:59,460 So, if you have an image, and that image shares files 741 00:39:59,460 --> 00:40:01,080 to an image that I have, 742 00:40:01,520 --> 00:40:04,400 you can recover the names of the functions 743 00:40:04,940 --> 00:40:06,420 that exist in both of our collections. 744 00:40:09,140 --> 00:40:10,680 You could also look for call frequency. 745 00:40:11,180 --> 00:40:14,200 There are atomic start and atomic end functions 746 00:40:14,200 --> 00:40:16,820 in TinyOS, which are used for mutex. 747 00:40:17,580 --> 00:40:19,500 So, if you have two processes 748 00:40:19,500 --> 00:40:21,080 that you don't want to collide with one another, 749 00:40:21,700 --> 00:40:23,780 you call these functions, 750 00:40:23,920 --> 00:40:25,640 so everything calls these functions, 751 00:40:25,640 --> 00:40:28,620 as necessitated by pre-processing of the code. 752 00:40:30,040 --> 00:40:31,780 They're called hundreds of times. 753 00:40:32,520 --> 00:40:36,000 The majority of function calls in any given MSP430 image 754 00:40:36,000 --> 00:40:36,560 go there. 755 00:40:37,420 --> 00:40:39,000 If it's made with TinyOS. 756 00:40:40,000 --> 00:40:41,600 And you can look at the interrupt vector table 757 00:40:41,600 --> 00:40:44,260 to tell what happens when, say, a byte comes in. 758 00:40:44,560 --> 00:40:46,040 Or the chip wakes up. 759 00:40:46,920 --> 00:40:48,720 It's very easy to trace these things. 760 00:40:49,260 --> 00:40:50,220 And you have... 761 00:40:54,580 --> 00:40:56,440 Here, you can see that the interrupt vector table 762 00:40:56,440 --> 00:40:57,560 goes to these handlers. 763 00:40:58,360 --> 00:40:59,680 And then all of the unused ones 764 00:40:59,680 --> 00:41:03,700 go to this default handler, which moves on. 765 00:41:04,440 --> 00:41:07,580 And you find these things in multiple images. 766 00:41:07,800 --> 00:41:10,000 But there are also headaches 767 00:41:10,000 --> 00:41:11,200 that you don't have to deal with on a PC. 768 00:41:12,200 --> 00:41:14,560 How many times have you had an I.O. function be inlined? 769 00:41:15,780 --> 00:41:17,660 On a PC, you're not allowed to do it, 770 00:41:17,660 --> 00:41:18,460 outside of the kernel. 771 00:41:19,440 --> 00:41:22,100 You have to defer to the kernel to do your I.O. for you. 772 00:41:22,180 --> 00:41:23,180 Here, that's not true. 773 00:41:23,440 --> 00:41:25,340 If foo is only called by one parent, 774 00:41:25,980 --> 00:41:26,980 it will be inlined. 775 00:41:27,700 --> 00:41:29,700 And if it's called by many parents, then it won't be. 776 00:41:30,000 --> 00:41:32,640 And in the larger development environments, 777 00:41:32,780 --> 00:41:33,560 this is done automatically. 778 00:41:36,320 --> 00:41:39,840 You can simulate with scripts 779 00:41:39,840 --> 00:41:41,360 written in Python or Java 780 00:41:41,360 --> 00:41:43,360 to actually pretend to be the microcontroller. 781 00:41:43,580 --> 00:41:45,300 And they can run through and they can stab. 782 00:41:46,120 --> 00:41:48,020 You can do stack overflow exploits. 783 00:41:48,460 --> 00:41:49,820 In the same way that you do on a PC 784 00:41:50,260 --> 00:41:51,180 for the Von Neumann chips. 785 00:41:51,640 --> 00:41:53,300 On the Harvard chips, you have to 786 00:41:55,860 --> 00:41:57,740 actually trick the existing code 787 00:41:57,740 --> 00:41:59,500 into copying your code into flash memory. 788 00:42:01,620 --> 00:42:03,820 And where no function exists to do that, 789 00:42:03,880 --> 00:42:05,240 you have to use return-oriented programming 790 00:42:05,240 --> 00:42:07,640 to combine the tails of different functions together. 791 00:42:10,580 --> 00:42:12,720 You also have to worry about word alignment issues 792 00:42:12,720 --> 00:42:13,440 and that sort of thing. 793 00:42:14,300 --> 00:42:16,400 But once you have these simulators running, 794 00:42:16,500 --> 00:42:17,220 and once you have 795 00:42:18,660 --> 00:42:19,720 these tools written, 796 00:42:19,920 --> 00:42:23,240 you can use them to very clearly describe 797 00:42:23,240 --> 00:42:24,380 how things happen. 798 00:42:25,380 --> 00:42:27,280 So I assume that many of you are familiar 799 00:42:27,280 --> 00:42:30,740 with a standard vanilla stack pointer overflow exploit. 800 00:42:31,500 --> 00:42:33,160 This is how it works on a microcontroller. 801 00:42:33,440 --> 00:42:35,420 The program counter is at 11 DC 802 00:42:35,420 --> 00:42:36,620 in the main function. 803 00:42:36,960 --> 00:42:39,080 Main we know we'll call load, 804 00:42:39,340 --> 00:42:41,020 which does not have an overflow, 805 00:42:41,220 --> 00:42:42,460 and then load over, which does. 806 00:42:42,720 --> 00:42:44,720 And each of those is just going to copy a string. 807 00:42:45,460 --> 00:42:46,460 We can step through. 808 00:42:46,460 --> 00:42:48,380 We can see the stack grow downward 809 00:42:48,380 --> 00:42:49,780 as main calls load. 810 00:42:51,980 --> 00:42:54,200 Then we can see the stack being expanded 811 00:42:54,200 --> 00:42:55,920 to support all of the stack variables. 812 00:42:56,480 --> 00:42:58,700 And stack variables are very commonly used 813 00:42:58,700 --> 00:42:59,560 on these architectures 814 00:42:59,560 --> 00:43:01,900 because the RAM space is only used 815 00:43:01,900 --> 00:43:04,220 while the function is executing. 816 00:43:05,100 --> 00:43:07,180 You don't have to worry about running out of RAM, 817 00:43:07,300 --> 00:43:08,280 which is a very real concern 818 00:43:08,280 --> 00:43:09,980 when you only have three or four kilobytes. 819 00:43:12,720 --> 00:43:16,100 So if Cafe Babe is being copied to the stack, 820 00:43:16,100 --> 00:43:18,420 you can see the individual bytes of it appear here. 821 00:43:19,180 --> 00:43:21,080 So the BA will appear next. 822 00:43:21,300 --> 00:43:21,980 And there it goes. 823 00:43:22,100 --> 00:43:24,860 And it keeps copying until it hits a zero. 824 00:43:25,300 --> 00:43:26,880 That being the zero. 825 00:43:29,040 --> 00:43:30,820 And now that the copy is complete, 826 00:43:30,960 --> 00:43:31,880 string copy will return. 827 00:43:32,560 --> 00:43:34,120 And then load returns. 828 00:43:36,540 --> 00:43:38,580 So then inside of main, 829 00:43:38,620 --> 00:43:39,580 main calls load over. 830 00:43:39,800 --> 00:43:44,980 And this one will have the actual return pointer 831 00:43:44,980 --> 00:43:45,860 be overflown. 832 00:43:47,000 --> 00:43:48,620 You see it growing here. 833 00:43:48,800 --> 00:43:52,900 And then load over starts writing just all Fs 834 00:43:52,900 --> 00:43:54,740 or anything that's not 00 835 00:43:54,740 --> 00:43:56,740 in the case of a null terminated string. 836 00:43:57,940 --> 00:43:59,920 And this is common on a PC. 837 00:44:00,140 --> 00:44:02,340 On IT software that's being attacked daily, 838 00:44:02,520 --> 00:44:03,760 you're looking for these things 839 00:44:03,760 --> 00:44:05,800 and you're doing your best to stop them. 840 00:44:06,260 --> 00:44:08,480 Because you know that as soon as your software 841 00:44:08,480 --> 00:44:10,100 is deployed on a web server 842 00:44:10,100 --> 00:44:11,980 or in any other public place, 843 00:44:12,040 --> 00:44:12,460 that you'll be attacked. 844 00:44:13,320 --> 00:44:14,960 Here they assume that they'll never be attacked. 845 00:44:17,000 --> 00:44:18,860 So at this point, 846 00:44:18,940 --> 00:44:19,860 if I step backward a bit, 847 00:44:19,980 --> 00:44:22,760 you can see that it just keeps growing 848 00:44:22,760 --> 00:44:25,480 until the attacker gets to the main return pointer. 849 00:44:25,800 --> 00:44:28,260 And then he can list any address he likes. 850 00:44:29,040 --> 00:44:30,400 And when the function returns, 851 00:44:30,600 --> 00:44:32,040 it will jump to this word 852 00:44:32,040 --> 00:44:34,380 instead of the spot in main 853 00:44:34,380 --> 00:44:35,540 that it left off to call. 854 00:44:36,760 --> 00:44:37,580 And there we go. 855 00:44:37,720 --> 00:44:39,140 It's now pointing into RAM. 856 00:44:39,500 --> 00:44:41,200 If the packet's here, it executes. 857 00:44:43,020 --> 00:44:44,300 And everything wraps up. 858 00:44:44,960 --> 00:44:46,280 Now the program counter points to RAM. 859 00:44:47,600 --> 00:44:49,540 On a PC, this is a trivial example. 860 00:44:49,760 --> 00:44:52,060 On a PC with IT software, 861 00:44:52,400 --> 00:44:53,840 if your vendor supplies this to you, 862 00:44:54,360 --> 00:44:55,820 and I know that many of them do, 863 00:44:56,000 --> 00:44:57,600 but they're still looking 864 00:44:57,600 --> 00:44:58,620 because they're getting attacked. 865 00:45:00,500 --> 00:45:02,860 Microsoft would be incompetent 866 00:45:02,860 --> 00:45:04,520 to ship this on IIS today. 867 00:45:05,620 --> 00:45:06,840 Now, a decade ago, 868 00:45:07,060 --> 00:45:08,560 they might have had issues with it, 869 00:45:08,600 --> 00:45:09,300 but they got over it. 870 00:45:09,440 --> 00:45:10,440 And they got over it 871 00:45:10,440 --> 00:45:11,460 because they were attacked regularly. 872 00:45:12,780 --> 00:45:14,760 These wireless sensors are not being attacked 873 00:45:14,960 --> 00:45:15,320 in the field, 874 00:45:16,060 --> 00:45:18,000 which means that these vulnerabilities exist, 875 00:45:18,260 --> 00:45:19,340 but they're not being exploited. 876 00:45:20,420 --> 00:45:21,260 So they remain. 877 00:45:21,860 --> 00:45:23,320 So anyone who looks for them, 878 00:45:23,400 --> 00:45:24,880 if you look at this in your smart meter 879 00:45:24,880 --> 00:45:25,640 or your thermostat 880 00:45:25,640 --> 00:45:27,100 or your wristwatch, 881 00:45:27,960 --> 00:45:29,820 you find vulnerabilities like this, 882 00:45:29,880 --> 00:45:30,720 and they can be exploited. 883 00:45:33,500 --> 00:45:35,880 I need to wrap up in five minutes, 884 00:45:36,040 --> 00:45:38,240 but you can do fuzzing. 885 00:45:38,600 --> 00:45:40,780 And you can do fuzzing on the actual hardware. 886 00:45:42,120 --> 00:45:43,820 You can either use a simulator 887 00:45:43,820 --> 00:45:45,060 or a JTAG debugger. 888 00:45:45,260 --> 00:45:46,760 And even the JTAG debugger 889 00:45:46,760 --> 00:45:47,640 isn't strictly necessary. 890 00:45:48,940 --> 00:45:50,900 A friend and I were playing around 891 00:45:50,900 --> 00:45:53,020 with fuzzing a microcontroller, 892 00:45:53,180 --> 00:45:54,940 trying to make an automated exploit 893 00:45:54,940 --> 00:45:56,740 that would return back into the bootloader. 894 00:45:57,200 --> 00:45:58,380 And we wound up succeeding 895 00:45:58,380 --> 00:46:00,240 by watching an I.O. pin 896 00:46:00,240 --> 00:46:02,200 to see exactly when the chip reset. 897 00:46:03,160 --> 00:46:04,800 And whenever this chip reboots, 898 00:46:04,840 --> 00:46:06,820 it makes all of the pins 899 00:46:07,340 --> 00:46:08,360 go into an input state. 900 00:46:09,520 --> 00:46:10,620 In an input state, 901 00:46:10,720 --> 00:46:12,500 the chip doesn't assert a one or a zero. 902 00:46:12,500 --> 00:46:13,600 It just sort of lets it float. 903 00:46:15,360 --> 00:46:16,980 Now, later, after the chip booted, 904 00:46:17,020 --> 00:46:18,720 it would move it to an output state, 905 00:46:18,860 --> 00:46:19,780 and then it would assert a one. 906 00:46:20,500 --> 00:46:22,200 So we had a resistor pulling downward 907 00:46:22,200 --> 00:46:23,580 to make it a zero by default. 908 00:46:25,000 --> 00:46:26,540 And whenever that line dropped zero, 909 00:46:26,700 --> 00:46:28,600 we then knew that the chip had reset. 910 00:46:29,620 --> 00:46:31,180 Well, that lets you know when you got a crash. 911 00:46:32,320 --> 00:46:33,480 And if you know when you got a crash, 912 00:46:33,680 --> 00:46:35,660 then you know that the packet 913 00:46:35,660 --> 00:46:36,620 you sent just beforehand 914 00:46:36,620 --> 00:46:37,960 is doing something interesting. 915 00:46:38,400 --> 00:46:39,880 And if you start sending random addresses 916 00:46:39,880 --> 00:46:41,640 in that packet in there, 917 00:46:41,760 --> 00:46:44,020 you can occasionally jump to the wrong place. 918 00:46:44,880 --> 00:46:47,360 If you put in an address in master ROM, 919 00:46:47,500 --> 00:46:48,600 then you can make it return 920 00:46:48,600 --> 00:46:50,140 to a particular spot in a program 921 00:46:50,140 --> 00:46:50,860 that you can talk to. 922 00:46:51,600 --> 00:46:53,420 Then you know when you've overwritten 923 00:46:53,420 --> 00:46:55,220 the address perfectly. 924 00:46:56,560 --> 00:46:59,160 And you can fuzz this just as you could 925 00:46:59,160 --> 00:47:00,600 on a PC with a debugger 926 00:47:00,600 --> 00:47:01,380 attached to the application. 927 00:47:01,820 --> 00:47:03,260 You might not be able to follow 928 00:47:03,260 --> 00:47:04,540 the execution traces easily, 929 00:47:05,300 --> 00:47:07,120 especially if the JTAG fuse is blown. 930 00:47:07,120 --> 00:47:09,360 But similar attacks apply. 931 00:47:16,860 --> 00:47:20,340 So you can do all of these things. 932 00:47:21,260 --> 00:47:22,780 You can do blind injection. 933 00:47:23,880 --> 00:47:27,380 In the case of Harvard architecture chips, 934 00:47:27,580 --> 00:47:29,180 you can use return-oriented programming 935 00:47:29,180 --> 00:47:30,520 to copy things over. 936 00:47:30,640 --> 00:47:32,020 So even though you can't execute RAM easily, 937 00:47:32,220 --> 00:47:33,720 you still can execute it. 938 00:47:34,040 --> 00:47:36,580 And in the case of code 939 00:47:36,580 --> 00:47:37,300 that you don't understand, 940 00:47:37,440 --> 00:47:39,020 in case you don't have a copy 941 00:47:39,020 --> 00:47:40,120 of the image you're trying to attack, 942 00:47:40,300 --> 00:47:41,780 you could still use probabilistic 943 00:47:41,780 --> 00:47:43,000 return-oriented programming. 944 00:47:43,460 --> 00:47:44,660 I have this coming out 945 00:47:44,660 --> 00:47:46,340 at a Usenix paper in detail. 946 00:47:46,920 --> 00:47:48,920 I believe the Woot paper is available online 947 00:47:48,920 --> 00:47:49,780 if you Google for it. 948 00:47:50,140 --> 00:47:51,860 The Workshop on Offensive Technologies. 949 00:47:52,220 --> 00:47:54,020 But the gist here is that you return 950 00:47:54,020 --> 00:47:54,960 to a common gadget, 951 00:47:55,540 --> 00:47:56,860 and that gadget returns 952 00:47:56,860 --> 00:47:58,220 to a common bootloader. 953 00:47:59,240 --> 00:48:00,580 So if you wanted to, say, 954 00:48:01,360 --> 00:48:02,820 make sure that all of the bits 955 00:48:02,820 --> 00:48:03,920 in register 11 are high, 956 00:48:05,840 --> 00:48:06,560 and that you have a common 957 00:48:06,580 --> 00:48:07,380 bootloader that you're executing 958 00:48:07,380 --> 00:48:09,380 the bootloader to, say, 959 00:48:09,400 --> 00:48:10,520 elevate your access, 960 00:48:10,780 --> 00:48:13,380 which was how we extracted 961 00:48:13,380 --> 00:48:14,540 firmware from this device 962 00:48:14,540 --> 00:48:15,620 even after it was locked. 963 00:48:16,060 --> 00:48:17,960 The way you do it is you just assume 964 00:48:17,960 --> 00:48:19,300 that you're going to have a pop R11 965 00:48:19,300 --> 00:48:20,200 followed by a return. 966 00:48:21,000 --> 00:48:23,300 The odds of that are 1% 967 00:48:23,300 --> 00:48:24,740 on any given attempt. 968 00:48:25,120 --> 00:48:26,540 You attempt it 300 times, 969 00:48:26,780 --> 00:48:29,020 you succeed with three nines of accuracy. 970 00:48:31,420 --> 00:48:33,020 It won't hold up that long 971 00:48:33,020 --> 00:48:33,420 to an attack. 972 00:48:35,820 --> 00:48:37,740 You can also use an extra 973 00:48:37,740 --> 00:48:38,480 neighborly belt buckle. 974 00:48:38,820 --> 00:48:41,040 At one point, a friend and I, 975 00:48:41,100 --> 00:48:43,240 Joshua Garneau in the front line, 976 00:48:43,660 --> 00:48:45,400 he lost his virginity because 977 00:48:45,400 --> 00:48:46,040 of the belt buckle, 978 00:48:46,160 --> 00:48:46,760 and we appreciate it. 979 00:48:46,960 --> 00:48:49,040 But let's give him a hand. 980 00:48:53,380 --> 00:48:55,740 And then thanks to the technical confusion 981 00:48:55,740 --> 00:48:56,380 at the beginning, 982 00:48:56,460 --> 00:48:57,180 I've run out of time. 983 00:48:57,380 --> 00:48:58,620 But if you'd like to join me 984 00:48:58,620 --> 00:48:59,340 in the breakout room, 985 00:48:59,560 --> 00:49:02,200 we can play with some of these toys, 986 00:49:02,280 --> 00:49:03,400 and I can show you how to use them 987 00:49:03,400 --> 00:49:04,060 and how to exploit chips. 988 00:49:04,460 --> 00:49:06,340 We've got a scope and some needles here, 989 00:49:06,400 --> 00:49:07,560 and we can do all sorts of fun stuff. 990 00:49:07,840 --> 00:49:08,520 Room 105. 991 00:49:11,040 --> 00:49:11,800 Thank you.