00:00:00.033 --> 00:00:03.403 >>So we'll start off today with introductory, youll kind of 00:00:03.403 --> 00:00:08.175 get there's a theme to today's talk. First lets introduce 00:00:08.175 --> 00:00:12.980 our clergy. Theres me, I'm Joe Fitzpatrick, -- 00:00:12.980 --> 00:00:20.120 blah-blah-blah -- yeah, sorry -- I have electrical engineering 00:00:20.120 --> 00:00:22.723 education, with a focus on computer science and information 00:00:22.723 --> 00:00:27.327 security. Ten years spending time doing hardware debug and 00:00:27.327 --> 00:00:31.198 hardware stuff. Right now I spend time teaching classes on 00:00:31.198 --> 00:00:35.602 low level physical attacks on systems. I teach a new class 00:00:35.602 --> 00:00:39.640 coming up on applied physical attacks on systems which should 00:00:39.640 --> 00:00:42.543 be fun, too. I also did not sleep last night trying to get 00:00:42.543 --> 00:00:44.544 this demo working. I was drinking most of the time and at 00:00:44.544 --> 00:00:46.546 the end tried to get the demo working. There's also Matt. 00:00:46.546 --> 00:00:54.254 >>Right, Im Matt. I started out as hardware engineer, so I 00:00:54.254 --> 00:01:00.193 spent a lot of my time working on JPEG stuff so I've been 00:01:03.330 --> 00:01:06.633 dealing with this for a very long time. >>Cant hear you. 00:01:06.633 --> 00:01:09.102 >>Oh. There we go. Just wasnt close enough. I'm 00:01:09.102 --> 00:01:13.640 Matt, spent a lot of time designing and building and 00:01:13.640 --> 00:01:18.745 testing with JTAG. I'm sure there's more than one person in 00:01:18.745 --> 00:01:22.950 the audience using some of my JTAG. I'm really disappointed 00:01:22.950 --> 00:01:25.152 with the transcription of Joes mumbling, they said 00:01:25.152 --> 00:01:31.158 blah-blah-blah, they didn't get it. >>Really like, Matt did all 00:01:34.261 --> 00:01:37.264 of the work for this talk, so we should give him applause when he 00:01:37.264 --> 00:01:41.368 does this stuff, don't applaud for me at all. NSA Playset, 00:01:41.368 --> 00:01:46.139 basically you go to website, nsaplayset.org, and you have a 00:01:46.139 --> 00:01:51.411 bunch of these little projects we're making. There was an ANT 00:01:51.411 --> 00:01:54.281 catalog leaked and reimplementing them in 00:01:54.281 --> 00:01:58.185 open-source hardware and software. The idea is if NSA can 00:01:58.185 --> 00:02:01.955 do it, why can't we, right? There's a few of the toys, not 00:02:01.955 --> 00:02:06.827 this one, but some of the other toys for sale at the hacker 00:02:06.827 --> 00:02:09.596 warehouse in the vendor, tomorrow, Sunday. Tomorrows 00:02:09.596 --> 00:02:13.500 Sunday, right? If I don't count the days I didn't sleep this 00:02:13.500 --> 00:02:18.739 week I think it's still Wednesday for me. So, let's 00:02:18.739 --> 00:02:22.242 start off, this is a page, GODSURGE, you're probably not 00:02:22.242 --> 00:02:27.481 going to get fired for looking at this page, it's leaked 00:02:27.481 --> 00:02:30.884 classified document though. Basically GODSURGE, I hope you 00:02:30.884 --> 00:02:34.688 can see it because I cant really see it. GODSURGE runs on 00:02:34.688 --> 00:02:38.959 the FLUXBABBIT, hardware implant. It provides software 00:02:38.959 --> 00:02:43.630 application persistence on Dell power edged server by exploiting 00:02:43.630 --> 00:02:47.734 JTAG debugging interface of the servers processors. It sounds 00:02:47.734 --> 00:02:51.104 like lots of fun doesnt it? JTAG never sounds like fun, 00:02:51.104 --> 00:02:53.106 especially when youre doing it, but this makes it sound like 00:02:53.106 --> 00:03:00.981 fun. We'd like to tell you more about GODSURGE and our take on 00:03:00.981 --> 00:03:04.284 GODSURGE. And so we'll start out with, the liturgy of D word, 00:03:04.284 --> 00:03:10.290 talk about JTAG. >> So JTAG was originally developed. Big 00:03:17.497 --> 00:03:24.771 committee in the 80's when they were working on this. Idea was 00:03:24.771 --> 00:03:28.375 joint test action group. Got together. They needed a 00:03:28.375 --> 00:03:34.047 standard for hardware to do testing of integrated circuits. 00:03:34.047 --> 00:03:37.718 If you want to build a chip and build something with a bunch of 00:03:37.718 --> 00:03:41.088 chips on it, you need to be able to test it to make sure it works 00:03:41.088 --> 00:03:45.425 before you sell it to somebody, people don't like to buy stuff 00:03:45.425 --> 00:03:49.229 that doesn't work. Goal was to come up with standard so all 00:03:49.229 --> 00:03:53.433 these chips can use the same test interface, test all of them 00:03:53.433 --> 00:03:57.404 at once and actually not have to hook up different devices to 00:03:57.404 --> 00:04:00.974 different chips on computer to make sure it works. Developing 00:04:00.974 --> 00:04:04.311 software is hard,might as well change the hardware, that would 00:04:04.311 --> 00:04:10.550 be easier. You're laughing, I'm not kidding. >>Where are my 00:04:10.550 --> 00:04:16.556 speaker notes? I don't know. Nope, it's this button. Turn 00:04:19.793 --> 00:04:25.799 on -- and it disappears. There we go. All right. >>So we have 00:04:34.608 --> 00:04:39.312 a passage from the we need to read verbatim. Have I to 00:04:39.312 --> 00:04:45.318 passage to read, this is I triple E 1149 spec. Section 00:04:56.496 --> 00:04:59.399 1.2.4. The Use of the Spec to Achieve Other Test Goals. In 00:04:59.399 --> 00:05:01.334 addition to application and testing printing circuit 00:05:01.334 --> 00:05:03.336 assembly and other products containing multiple components, 00:05:03.336 --> 00:05:05.672 the test logic defined by this standard can be used to provide 00:05:05.672 --> 00:05:08.608 access to a wide range of design for test features built into 00:05:08.608 --> 00:05:10.610 components themselves. Such features might include internal 00:05:10.610 --> 00:05:12.612 scan pats, self test functions or other support functions. 00:05:12.612 --> 00:05:15.382 Designed with test features such as these can be accessed 00:05:15.382 --> 00:05:18.585 and controlled using data path between serial test pins, 00:05:18.585 --> 00:05:25.559 instructions that cause internal reconfiguration of component 00:05:25.559 --> 00:05:29.462 system logic such that the test operation is enabled may be 00:05:29.462 --> 00:05:34.501 shifted into the component through the tab. So -- >> 00:05:34.501 --> 00:05:40.240 That's pretty insightful, thank you. >> This is the most 00:05:40.240 --> 00:05:42.242 interesting part of the spec too. [Laughter] >> Good thing 00:05:42.242 --> 00:05:48.248 we have 50 minutes. >> So, what is this? So, hopefully, people 00:05:52.419 --> 00:05:56.990 are familiar with OSI model. Defines physical interface, an 00:05:56.990 --> 00:05:59.926 application interface, how do you communicate using this 00:05:59.926 --> 00:06:05.031 protocol. We tried to map how JTAG works to provide a frame of 00:06:05.031 --> 00:06:09.369 reference for people who do software and want to use this 00:06:09.369 --> 00:06:12.505 for something interesting and who arent really concerned 00:06:12.505 --> 00:06:15.675 with all fancy electrical interface. If you're doing 00:06:15.675 --> 00:06:18.445 debug you don't care so much about hardware side of this, you 00:06:18.445 --> 00:06:22.449 just want to know how to use it to do debug. At physical level 00:06:22.449 --> 00:06:28.455 we have 5 wires. Data in, data out, mode select, clock and 00:06:31.157 --> 00:06:34.094 reset. And they have to put test in front of these because 00:06:34.094 --> 00:06:40.367 it's test interface. So, what does that look like? You really, 00:06:40.367 --> 00:06:43.637 if you have JTAG header on your device, you have these 5 pins 00:06:43.637 --> 00:06:49.542 and probably a ground, you'll have components on your PCP, 00:06:49.542 --> 00:06:54.614 connected. And you're going to chain them together, take data 00:06:54.614 --> 00:06:58.585 out from each one, connect to data in from the next one and 00:06:58.585 --> 00:07:03.089 create longer and longer serial scan chain, when you put data in 00:07:03.089 --> 00:07:07.494 and data out, flows through all devices and comes out the other 00:07:07.494 --> 00:07:12.966 end and gives access to wide range of internal registers they 00:07:12.966 --> 00:07:17.003 build inside these things with low over head. Control logic 00:07:17.003 --> 00:07:19.939 for this is really small. And this gets used for a lot of 00:07:19.939 --> 00:07:24.077 things, odds are this will always work, it doesn't come out 00:07:24.077 --> 00:07:28.982 and something not working on it, probably your tap will work and 00:07:28.982 --> 00:07:32.585 you get whatever register you put in there test it, debug it 00:07:32.585 --> 00:07:37.924 and figure out and make sure it works before you sell it. >> So 00:07:37.924 --> 00:07:42.896 this is what I refer to the golden rule of JTAG. And that 00:07:42.896 --> 00:07:49.502 is TDO, on to others, as others TDI on to you. Think about 00:07:49.502 --> 00:07:55.208 that. If you want to go back a slide. We have this circle of 00:07:55.208 --> 00:07:59.813 every inter connected device and only way this circle works if 00:07:59.813 --> 00:08:03.650 you pay it forward. Pass on the TDI you receive to the next 00:08:03.650 --> 00:08:08.355 device with your TDO and pass it on and pass it on. There's a 00:08:08.355 --> 00:08:12.325 lot of deep inner messages we can extract from this JTAG 00:08:12.325 --> 00:08:18.264 stuff, really I swear. >> Im not responsible for the puns in 00:08:18.264 --> 00:08:24.270 this. Okay, we've got 5 wires. What do we put on them? So the, 00:08:27.006 --> 00:08:31.778 there's a state machine define, it uses mode select, signal to 00:08:31.778 --> 00:08:35.882 control what is happening with the TDI and TDO signals any 00:08:35.882 --> 00:08:41.287 time. There's a state machine. There's a bunch of states in 00:08:41.287 --> 00:08:46.359 there, most to deal with all sorts limitations on either the 00:08:46.359 --> 00:08:51.164 device you're using or devices that driving JTAG, a lot of 00:08:51.164 --> 00:08:54.901 redundancy here, this is old, complicated and what they put in 00:08:54.901 --> 00:08:59.005 original speck. So newer simplified version, if you want 00:08:59.005 --> 00:09:01.841 to think about what's going on here, you're either writing 00:09:01.841 --> 00:09:07.247 instruction or reading writing data. Either waiting idle for 00:09:07.247 --> 00:09:11.017 new command or writing an instruction, for whatevers 00:09:11.017 --> 00:09:13.520 writing your tap interface or your new instruction and that 00:09:13.520 --> 00:09:16.756 determines what data you're going to read and write. This 00:09:16.756 --> 00:09:21.428 is really what the state machine is trying to get you to. How do 00:09:21.428 --> 00:09:27.167 you access these registers. Okay, so, we can use the state 00:09:27.167 --> 00:09:29.803 machine, we can get to this instruction in the data 00:09:29.803 --> 00:09:36.776 register, how does that look in the system. And, it's really a 00:09:36.776 --> 00:09:39.579 pretty simple picture. You write the instruction register 00:09:39.579 --> 00:09:43.283 and that selects one of data registers in system for you to 00:09:43.283 --> 00:09:46.586 read and write. Most of these data registers there's a couple 00:09:46.586 --> 00:09:48.922 requires, bypass is required one, most things implement ID 00:09:48.922 --> 00:09:50.924 code register that lets you identify the device. Almost all 00:09:50.924 --> 00:09:52.992 the rest of these, if you have 8 bit instruction you can have up 00:09:52.992 --> 00:09:58.998 to 255 other registers in here for test purposes. They can be 00:10:04.604 --> 00:10:07.640 anything. Whatever the manufacturer of device put in 00:10:07.640 --> 00:10:11.778 there to test it. Can have access to external pins, its 00:10:11.778 --> 00:10:15.515 called boundary scan. They can access to internal scan, they 00:10:15.515 --> 00:10:19.652 have special commands and send to a micro controller, so you 00:10:19.652 --> 00:10:23.056 can control how its executing. This is all really 00:10:23.056 --> 00:10:25.892 really device specific, its whatever they implemented. 00:10:25.892 --> 00:10:28.661 Point-of-view of person using it, you're picking which 00:10:28.661 --> 00:10:32.232 register you want to access either putting data in or 00:10:32.232 --> 00:10:36.336 reading out. You get status information or control 00:10:36.336 --> 00:10:42.342 information you can put in the device. So, once we built up 00:10:46.079 --> 00:10:49.082 that lower level, those physical layers we need to move on and 00:10:49.082 --> 00:10:53.887 get up higher in the sack and move more into the host layers 00:10:53.887 --> 00:10:58.091 of this if it were OSI network type situation. This is where 00:10:58.091 --> 00:11:03.196 we find target specific stuff. This one table, exert from 00:11:03.196 --> 00:11:10.904 speck for CPU, what you can see, tells you you have a couple 00:11:10.904 --> 00:11:14.040 different instruction registers. And they have a number 00:11:14.040 --> 00:11:17.610 associated with them and have a purpose. Read description. We 00:11:17.610 --> 00:11:25.385 look down, 001, ID code, number it spits out. We know we're 00:11:25.385 --> 00:11:31.257 talking to CPU, network adamant ter, this model, arm core,stuff 00:11:31.257 --> 00:11:37.830 like that. Further down below, it says address -- very hard, I 00:11:37.830 --> 00:11:44.737 have narrow range to point -- address, and data, and control, 00:11:44.737 --> 00:11:48.141 and basically, 3 registers we stuff in there, and that gives 00:11:48.141 --> 00:11:52.679 access to internal BUS of system. Its going to let us 00:11:52.679 --> 00:11:56.716 interface with the hardware we're hooked up to. This is 00:11:56.716 --> 00:12:01.988 nice, these aren't the rules though. This is all fitting 00:12:01.988 --> 00:12:07.293 into the JTAG umbrella this is just nips. Its part of the 00:12:07.293 --> 00:12:13.166 JTAG that applies to most of the nips platforms. And t's not 00:12:13.166 --> 00:12:15.935 going to be like that for everybody else. Architectures 00:12:15.935 --> 00:12:20.773 define their different customs in order to debug their chips. 00:12:20.773 --> 00:12:25.545 So its different for X 86, different forearm, and different 00:12:25.545 --> 00:12:30.383 for different versions of other chips. So like RB7 core that 00:12:30.383 --> 00:12:33.019 gets manufactured it might be different from one manufacturer 00:12:33.019 --> 00:12:35.021 to another manufacturer. Sometimes were lucky and we 00:12:35.021 --> 00:12:38.024 get some similarity. But when we get to this point, were no 00:12:38.024 --> 00:12:43.663 longer talking about JTAG speck stuff, we're talking about 00:12:43.663 --> 00:12:47.333 manufacturer's implementation of their debugging in face over 00:12:47.333 --> 00:12:52.238 JTAG. And you know we have to have a verse to relate that to 00:12:52.238 --> 00:12:55.742 this, Romans 212:2 Do not confirm to the pattern of this 00:12:55.742 --> 00:12:58.911 world. And you know, some people take this to heart. 00:12:58.911 --> 00:13:03.316 Really, this is the NIB version of the Bible but Maybe we should 00:13:03.316 --> 00:13:07.520 call it NIH version. Remember that verse. Maybe write it in 00:13:07.520 --> 00:13:10.256 your cube or something that way you can remember it when you 00:13:10.256 --> 00:13:16.796 need to reuse something. No, do not conform. Let's move up up 00:13:16.796 --> 00:13:24.570 the stack. Back to OSI model. JTAGs, wait okay, who has, who 00:13:24.570 --> 00:13:27.206 has written stuff like Stevens, networking book app, like 00:13:27.206 --> 00:13:29.342 something like that? Like actually written a networking 00:13:29.342 --> 00:13:31.611 application , right? Whos written stuff that uses 00:13:31.611 --> 00:13:36.349 presentation layer? Anybody? See what I was going to say 00:13:36.349 --> 00:13:38.351 raise your hand if youve written something in the 00:13:38.351 --> 00:13:40.353 presentation layer, then I was going to say, and put your hand 00:13:40.353 --> 00:13:44.324 down if it was academic assignment. And oh see nobody? 00:13:44.324 --> 00:13:48.995 But maybe, maybe academia is catching up. Nobody uses this 00:13:48.995 --> 00:13:54.701 crap. So, yeah. Let's, move on. Weve got a second 00:13:54.701 --> 00:13:59.939 reading. From the second e-mail from Joe to people with JTAG yes 00:13:59.939 --> 00:14:05.878 questions. And, Joe, tell me, what is JTAG for, I understand 00:14:08.381 --> 00:14:11.951 all these wires and hook things up and have registers, what do I 00:14:11.951 --> 00:14:15.988 do with it, what's the power of understanding this great 00:14:15.988 --> 00:14:21.327 information. When we go up the stack we get to what best 00:14:21.327 --> 00:14:24.063 relates to application scanner. We have boundary scan, run 00:14:24.063 --> 00:14:27.633 control and memory access. These are all fun things, 00:14:27.633 --> 00:14:33.372 sometimes. So, some of these things are mandatory. Which 00:14:33.372 --> 00:14:36.843 means if you have JTAG you must have this. Some are optional. 00:14:36.843 --> 00:14:39.545 Which means some manufacturers choose to implement that, some 00:14:39.545 --> 00:14:42.715 don't don't. Some undocumented, which means manufacturer 00:14:42.715 --> 00:14:48.454 implements them and doesn't tell you. Lets talk about 00:14:48.454 --> 00:14:52.792 boundary scan. We have same picture as before, remember 00:14:52.792 --> 00:14:58.798 golden rule, what is it? ok good, good, good. I think a few 00:15:00.900 --> 00:15:05.238 remembered it. Try to keep it in your mind of we have data in 00:15:05.238 --> 00:15:11.010 and goes through this, we have a bunch of ones and zeros. This is 00:15:11.010 --> 00:15:15.882 JTAG, one wire, one bit at a time. And, we send those bits 00:15:15.882 --> 00:15:20.253 through, on that third chip, we have traces on motherboard that 00:15:20.253 --> 00:15:27.393 hook up to LED's or some device. We're going to animate this 00:15:27.393 --> 00:15:33.399 slide. Ready? Oh, yeah. Watch it go. There we go. Thank you 00:15:35.434 --> 00:15:38.504 Matt for animating that. Because like I said, Matt did all the 00:15:38.504 --> 00:15:45.011 real work for this. I just make the puns. So, what we're doing 00:15:45.011 --> 00:15:49.916 is modifying what the output pins of this device are. The 00:15:49.916 --> 00:15:54.554 scan chain goes through external pins in the device and we can 00:15:54.554 --> 00:15:59.125 stimulate them or send them. Send data out or in. This is 00:15:59.125 --> 00:16:02.995 useful if testing a board. If you have started a BGA board 00:16:02.995 --> 00:16:07.366 that had like 10 billion pins on the board, you want to make sure 00:16:07.366 --> 00:16:10.069 they're all connected. You can get a sauntering iron and a 00:16:10.069 --> 00:16:13.606 X-ray machine and look through. If you use boundary scan you 00:16:13.606 --> 00:16:16.943 can just enter all those pins and look for outputs on the 00:16:16.943 --> 00:16:20.079 other end you and you know not only pins are wired together, 00:16:20.079 --> 00:16:24.016 chips are driving properly and youll also know that your 00:16:24.016 --> 00:16:27.286 trace is going through and working properly. This is really 00:16:27.286 --> 00:16:33.192 powerful for the test. Test is one thing, hacking things even 00:16:33.192 --> 00:16:37.663 more fun. So we have scenario like this, where you have a SOC 00:16:37.663 --> 00:16:41.467 connected flash, if you use boundary scan. Boundary scan is 00:16:41.467 --> 00:16:45.071 a required feature of JTAG. Any JTAG device is supposed to have 00:16:45.071 --> 00:16:48.207 JTAG, especially with Boundary scan. So if you can take the 00:16:48.207 --> 00:16:51.010 time to sit there with multi meter and just spit one's out of 00:16:51.010 --> 00:16:56.849 these boundary scans, you should map out which part of data 00:16:56.849 --> 00:17:02.221 register and result of that figure out which finishes 00:17:02.221 --> 00:17:07.760 connected to your flash chip. Instead of soldering 20 wires, 00:17:07.760 --> 00:17:10.930 you write software that shifts all bits in, and connect your 00:17:10.930 --> 00:17:14.233 flash for you, you have to set the right bits at the right 00:17:14.233 --> 00:17:17.103 time, wait a cycle. Set of different bits, wait a cycle. 00:17:17.103 --> 00:17:22.341 It's JTAG, old school, one bit at a time. So with one bit every 00:17:22.341 --> 00:17:25.511 time, with editing one bit at a time on every single package, 00:17:25.511 --> 00:17:28.648 with every single half cycle, of every single access. It 00:17:28.648 --> 00:17:35.955 takes a long time but cool, you can do quite a bit of stuff with 00:17:35.955 --> 00:17:40.927 this. Next neat feature of JTAG, is run control. So 00:17:40.927 --> 00:17:45.598 basically when you've got, when your program is running it's 00:17:45.598 --> 00:17:53.005 run, run, run, but sometime you want to halt. Stop control. 00:17:53.005 --> 00:17:57.443 What's great about this. This is the point in time we can do 00:17:57.443 --> 00:18:00.446 the neat stuff, modify registers, write to memory, go 00:18:00.446 --> 00:18:07.653 back to running,run, run, run, run, and halt, okay, check 00:18:07.653 --> 00:18:11.691 contents in memory, what did we put in there let's modify code 00:18:11.691 --> 00:18:16.662 and let's make something not behave properly, change where it 00:18:16.662 --> 00:18:23.970 runs and that would be cool -- like, yeah you run again and run 00:18:23.970 --> 00:18:27.573 stuff. Run, run control, run and stop, anything to add Matt?. 00:18:31.444 --> 00:18:35.481 >> So the run control is really processor specific, everyone 00:18:35.481 --> 00:18:39.051 implements this differently, never seen any CPU, 00:18:39.051 --> 00:18:44.590 micro-controller. Any type of general processing element that 00:18:44.590 --> 00:18:50.596 does not implement rudimentary form of run control. If you 00:18:50.596 --> 00:18:54.834 don't have kernel mode debugger and don't have JTAG you're 00:18:54.834 --> 00:18:58.971 debugging blind. This is how you debug your firmware on 00:18:58.971 --> 00:19:02.274 pretty much everything. Until you have OS running and you can 00:19:02.274 --> 00:19:07.213 do something in software. >> Okay, so lets move on. Its 00:19:07.213 --> 00:19:13.152 time for the gospel. Selected reading from the international 00:19:13.152 --> 00:19:17.223 journal, exploits sit lonely forgot on the shelf. Your 00:19:17.223 --> 00:19:21.427 friendly neighbors at POC or GTFO proudly present pastor 00:19:21.427 --> 00:19:26.565 export control church newsletter. I've been reading 00:19:26.565 --> 00:19:34.073 exert from rant or a sacramental wine about [indiscernible] 00:19:34.073 --> 00:19:38.477 heretic says we are, we turn our bail vl and envious eye toward 00:19:38.477 --> 00:19:42.615 hallow hauls of science. There are a number of people under 00:19:42.615 --> 00:19:46.185 curious spell. They must talk of things not known to 00:19:46.185 --> 00:19:51.991 multitudes, that's what we call 0 day or not listened to by 00:19:51.991 --> 00:19:57.797 their peers. What we call a 0 day they call a discovery or a 00:19:57.797 --> 00:20:01.300 publication. It's weird how advancement among them is meant 00:20:01.300 --> 00:20:03.302 to be predicted that they can discover and publish. And free 00:20:03.302 --> 00:20:10.743 to pursue discovery for private ends after few distinguished 0 00:20:10.743 --> 00:20:14.513 days are published unnoted. What happy ideallick picture, 00:20:14.513 --> 00:20:16.749 for that who might or might not have been helped by those that 00:20:16.749 --> 00:20:19.618 are suavants those after the weird people in robes tended to 00:20:19.618 --> 00:20:21.620 be sure prided [static-inaudible] who had fancy 00:20:21.620 --> 00:20:24.356 to leave alone and to occasionally listen to their 00:20:24.356 --> 00:20:28.094 babbling. Neighbors this lesson took centuries and do we not 00:20:28.094 --> 00:20:34.100 have any Goddamn robes? So, of course, you know we need to move 00:20:36.635 --> 00:20:42.174 on to a little homily, which, this is a pretty old writing. 00:20:42.174 --> 00:20:48.147 It's thousands of hours old. (Laughter) and we, to current 00:20:48.147 --> 00:20:55.921 day, what are we talking about? Oh, JTAG. Who knows about 00:20:55.921 --> 00:20:59.091 Wasstinar?. Okay. Really I should spend more time talking 00:20:59.091 --> 00:21:02.027 about it but I won't. You should read about it. Wasstinar 00:21:02.027 --> 00:21:08.033 Regulates a lot of other things. We relate this to the fact in 00:21:14.807 --> 00:21:19.645 some cases this will regulate the tools to test and debug and 00:21:19.645 --> 00:21:23.415 do security testing. If we go further, like what are we doing, 00:21:23.415 --> 00:21:26.152 what is JTAG for in the beginning? What is JTAG? A test 00:21:26.152 --> 00:21:30.623 interface, because in the beginning all of functionality 00:21:30.623 --> 00:21:33.292 is created with intended purpose. Sometimes not 00:21:33.292 --> 00:21:35.694 intended. But created with purpose and sometimes unintended 00:21:35.694 --> 00:21:41.133 consequences. Its really out of morality and choice that we 00:21:41.133 --> 00:21:46.872 have to decide whether we want to use JTAG for debug or 00:21:46.872 --> 00:21:52.878 exploitation, think about that. >> BGA. >> So, you know how 00:22:00.719 --> 00:22:04.190 can we do this. Talk about ways we use boundary scan, we talk 00:22:04.190 --> 00:22:08.227 about to give boundary scans to talk to flash chips and modify 00:22:08.227 --> 00:22:13.199 contents, you can have lock this, lock that, and have 00:22:13.199 --> 00:22:16.569 signatures and all that crap but if you use run control to halt 00:22:16.569 --> 00:22:20.873 processor and modify binary in memory, signature that's already 00:22:20.873 --> 00:22:27.279 been checked. You won. So let's start off with a little 00:22:27.279 --> 00:22:33.285 demonstration -- in this theme. >> I can't tell if you can see 00:22:35.287 --> 00:22:39.325 this, but I can. How do I invert the colors? Preferences. 00:22:39.325 --> 00:22:45.331 There we go. Style. Oh, actually -- no. There we go. 00:22:52.805 --> 00:22:58.811 >> Yeah yeah yeah yeah yeah yeah. (Applause) that concluded 00:23:27.473 --> 00:23:33.479 demo (Laughter). >> So, -- sorry to interrupt -- 00:24:02.174 --> 00:24:08.180 (Laughter). >> So, okay. Does everybody know what's going on 00:24:19.625 --> 00:24:25.631 here? I, the last track I asked that question, one guy goes no, 00:24:32.971 --> 00:24:39.278 so we actually brought him up on stage. Anyway. So, even though 00:24:39.278 --> 00:24:43.882 there's a little bit of slow down there, are these guys doing 00:24:43.882 --> 00:24:49.888 a good job? Awesome. (Applause) To our first time speakers -- 00:24:59.098 --> 00:25:05.037 cheers. (Applause) I haven't been drinking for like 12 hours. 00:25:08.440 --> 00:25:15.914 >> Now everything will work, and if it doesn't, we know who's 00:25:15.914 --> 00:25:22.855 fault it is. >> Okay, on the right-hand side, this is our 00:25:22.855 --> 00:25:25.391 little target platform. We have JTAG plugged into it. It's not 00:25:25.391 --> 00:25:27.393 terribly interesting. We're going to. >> What kind of 00:25:27.393 --> 00:25:33.399 shell? >> I told you I'm not responsible for the puns. Over 00:25:43.008 --> 00:25:47.880 here we're going to open up JTAG debug program and there we go. 00:25:47.880 --> 00:25:53.886 So then we should be able to connect to it, and we can see, 00:25:56.655 --> 00:26:01.894 hey look we're connected to something. So we have an SOC 00:26:01.894 --> 00:26:07.900 tap and X 86 core tap. And our target over here, still running, 00:26:11.236 --> 00:26:17.242 and we can do a halt. And it stops running. So then we can 00:26:19.478 --> 00:26:24.950 do things like -- display the registers. It will show the 00:26:24.950 --> 00:26:30.956 contents of all registers. We can we can dump memory. So 00:26:39.898 --> 00:26:45.904 here is the beginning of Linux memory. We can dump some more 00:26:53.479 --> 00:26:59.918 memory. This is the instruction that controls return code for 00:26:59.918 --> 00:27:04.957 file system access control. We'll come back to that. Dun 00:27:04.957 --> 00:27:10.963 dun dun, so we can skip, so, all right. We looked at things, we 00:27:13.966 --> 00:27:19.071 can resume, target [static-inaudible] this is where 00:27:19.071 --> 00:27:23.008 you start to get into the fun part of target specific stuff 00:27:23.008 --> 00:27:27.880 and how they implement things differently. Some of the 00:27:27.880 --> 00:27:31.617 actions don't immediately take effect. Sometimes you have to 00:27:31.617 --> 00:27:36.355 drive the JTAG bins more. If you do the command you have to 00:27:36.355 --> 00:27:40.926 keep using JTAG more before it takes effect. We have another 00:27:40.926 --> 00:27:45.898 target here if we get the demo working here, there are some 00:27:45.898 --> 00:27:51.904 other corks that we can do with that. So we can even -- we can 00:27:54.806 --> 00:28:00.746 open up. So you can also, GDB interface to this, you can open 00:28:21.266 --> 00:28:27.272 up and debug kernel in GDB, so we'll connect to JTAG, all 00:28:30.609 --> 00:28:36.615 right. It connected. We're going to halt our target. We're 00:28:51.697 --> 00:28:57.703 going to load our single file. And then we can step through 00:29:01.306 --> 00:29:07.279 instructions. Right. So every time I do a step I the target 00:29:07.279 --> 00:29:15.153 executes one instruction and GDB is showing where that is. If 00:29:15.153 --> 00:29:18.190 you have an application, if you're trying to get realtime OS 00:29:18.190 --> 00:29:21.493 running on this thing and need to figure out where it dies, 00:29:21.493 --> 00:29:23.629 this is how you connect it, this is how you can watch it, go 00:29:23.629 --> 00:29:26.999 through the instructions and see what's going on at each point in 00:29:26.999 --> 00:29:33.005 execution and do your debug, whatever you need. You need the 00:29:38.644 --> 00:29:44.650 cable back? >> Yeah. >> Here is the cable back. >> Okay. 00:29:53.592 --> 00:29:59.598 So, we can do debug, read and write memory, I'm sure you can 00:30:06.071 --> 00:30:11.843 think of fun things to do we have one example. But how do 00:30:11.843 --> 00:30:15.280 you actually use that? If you want, when Joe is talking about 00:30:15.280 --> 00:30:19.051 the ANT catalog, stuck in server and updated. So if you want to 00:30:19.051 --> 00:30:26.024 replay your JTAG commands, there's hopefully several 00:30:26.024 --> 00:30:32.998 formats for doing this. You know, this is the whole point 00:30:32.998 --> 00:30:35.634 industry stand format and there are plenty of tool that's will 00:30:35.634 --> 00:30:40.338 play back serial vector files or the version, that's binary 00:30:40.338 --> 00:30:44.609 compressed version. We were able to generate from our open 00:30:44.609 --> 00:30:48.947 source and debug we captured the commands we were issuing over 00:30:48.947 --> 00:30:52.918 JTAG in the log file went through and transformed in the 00:30:52.918 --> 00:30:56.188 serial vector format. And you can play them back on anything 00:30:56.188 --> 00:31:01.059 that plays JTAG. Pretty much anything that can play this 00:31:01.059 --> 00:31:04.062 format, which is standard format for capturing JTAG commands, 00:31:04.062 --> 00:31:08.100 this is used from everything from $10 million test equipment 00:31:08.100 --> 00:31:11.837 to $15 JTAG adapters like we have with open-source software. 00:31:11.837 --> 00:31:16.875 Whatever device you have, you can play back this capture t 00:31:16.875 --> 00:31:22.981 race and issue JTAG commands to whatever it's plugged into and 00:31:22.981 --> 00:31:29.087 whatever the commands are do them. If we want to write 00:31:29.087 --> 00:31:33.892 memory we capture, memory address, and it will go, just 00:31:33.892 --> 00:31:36.128 plug it in and it will continually write that memory 00:31:36.128 --> 00:31:39.664 address that we had setup. Joe is going to tell us about the 00:31:39.664 --> 00:31:46.471 implant that does this. >> So I am going to present to you the 00:31:46.471 --> 00:31:50.776 SOLDERPEEK. Luckily we have enough to share and were 00:31:50.776 --> 00:31:54.246 going to break boards together. [Laughter] So, SOLDERPEEK is 00:31:54.246 --> 00:32:00.185 a basically tiny board, actually like, compatible, easy to get 00:32:05.690 --> 00:32:13.532 working when doing stuff -- it's got a little 18 meg processor on 00:32:13.532 --> 00:32:19.337 it, it's got, little, UR interface serial port, which is 00:32:19.337 --> 00:32:24.976 how normally, sorry, this is based upon existing project 00:32:24.976 --> 00:32:31.249 called JTAG whisper, which turns UR access to JTAG. So what I've 00:32:31.249 --> 00:32:36.154 done, took a board and added E prompt to it. So we set it up 00:32:36.154 --> 00:32:40.458 and store this, and have this thing be stand alone and plug 00:32:40.458 --> 00:32:45.697 into system, walk away and every time it boots, wait a while and 00:32:45.697 --> 00:32:49.668 it will start playing back its XSVF file. The XSVF file 00:32:49.668 --> 00:32:53.271 will hold the contents and store in its memory. Like I said, 00:32:53.271 --> 00:32:57.576 Matt did all of the work, I was suppose to get this working, but 00:32:57.576 --> 00:33:02.647 it's not working now, it's kind of dead, in 3 days the code will 00:33:02.647 --> 00:33:10.589 be up loaded. It will all work. So, flash it, run the code that 00:33:10.589 --> 00:33:16.895 will transfer XSVF file, stores it and then next time it powers 00:33:16.895 --> 00:33:22.167 up, waits 20 seconds and dumps its pay load essentially. That 00:33:22.167 --> 00:33:28.173 brings up right to the next part of our presentation, where we 00:33:30.575 --> 00:33:36.581 need volunteers to come up and distribute boards. NSA Playset, 00:33:39.484 --> 00:33:45.490 they need hats, too, tinfoil hats. [Laughter] And, 00:34:47.319 --> 00:34:53.325 [Laughter] -- so you got the PCP's -- we'll continue with 00:35:05.570 --> 00:35:11.576 demos. Do you want to video or do it live? >> We can do it 00:35:16.081 --> 00:35:22.087 live. All right, we didn't even screw up the colors, hey, keep 00:35:30.962 --> 00:35:36.968 it down shhh -- I'm going to reboot this. So what we'll do, 00:35:45.043 --> 00:35:48.947 since the board that I have right here is having some 00:35:48.947 --> 00:35:53.785 growing pains, we'll demonstrate it with just a standard JTAG 00:35:53.785 --> 00:35:59.824 adapter hooked up to -- are you going to use Galileo. >> We 00:35:59.824 --> 00:36:04.796 have Galileo, if we have time we'll do with arm also. >> 00:36:04.796 --> 00:36:12.103 We'll play back the same JTAG chain command that we would on 00:36:12.103 --> 00:36:16.975 the SOLDERPEEK implant just doing through JTAG adapter 00:36:16.975 --> 00:36:22.981 instead of a standalone device. Stand alone device is gets TDO 00:36:26.685 --> 00:36:34.292 out properly, the data we get out makes absolutely no sense, 00:36:34.292 --> 00:36:38.730 so we need to figure that out. I need to figure that out. >> 00:36:38.730 --> 00:36:43.535 So I'm logging in here, I have a super secret password and you 00:36:43.535 --> 00:36:49.541 can see that -- all right -- so, you can see I'm just a regular 00:36:51.810 --> 00:36:55.647 user, I don't have access to things this that are owned by 00:36:55.647 --> 00:37:01.586 [static-inaudible], so I'll go over here, and we're going to 00:37:06.057 --> 00:37:12.063 launch the debugger again, and go in here, I'm going to find my 00:37:14.499 --> 00:37:20.505 command line, and, this is our sequence of commands. So what 00:37:31.583 --> 00:37:35.920 we're doing here that the bite ss of showed in memory with ACL 00:37:35.920 --> 00:37:39.591 return code for file system permission check? Were going 00:37:39.591 --> 00:37:45.597 to change those. Oh, no. It didn't work. Oh, BOO, we'll 00:37:52.904 --> 00:37:58.910 reboot and try again. Give it one more try. >> Okay. >> I 00:38:08.820 --> 00:38:14.826 know what the problem is, I didn't take a drink this time. 00:38:26.437 --> 00:38:28.439 [Laughter] Sometimes this stuff works without drinking, 00:38:28.439 --> 00:38:36.247 you don't actually need to drink -- wait? Since when? Why else do 00:38:36.247 --> 00:38:42.253 it? Right? >> Also the bars look at you funny when you bring 00:38:58.670 --> 00:39:03.942 laptops, wires and hook things up. But it's Portland so 00:39:03.942 --> 00:39:08.179 everyone is weird. Tell them it's a board game. Okay you 00:39:08.179 --> 00:39:13.484 must be HIPSTERS. [Laughter] Matt had this done and showed 00:39:13.484 --> 00:39:20.959 me 2 weeks ago. I was like Matt, you still have 2 weeks. >> 00:39:20.959 --> 00:39:26.831 We'll have to play the video. It's not working. Luckily I 00:39:26.831 --> 00:39:32.837 took a video when he did that. This worked every time I did it 00:39:39.844 --> 00:39:45.850 for the last week week. >> Okay, so, you can, we've got the 00:39:53.758 --> 00:39:57.428 same setup that we've got here with JTAG adapter plugged into 00:39:57.428 --> 00:40:05.270 laptop, plugged into Galileo. Cannot see video. I'm typing 00:40:05.270 --> 00:40:11.276 in, 12345 in case you're curious. >> Change my luggage 00:40:13.544 --> 00:40:19.550 password (Laughter). >> So you can see I don't have access to 00:40:23.421 --> 00:40:28.359 the shadow password file so I'm going over and doing the same 00:40:28.359 --> 00:40:34.365 command here that I just tried and it worked. Eventually. Now 00:40:40.438 --> 00:40:46.444 you can see that I was able to get access -- (Applause). 00:41:04.128 --> 00:41:10.134 (Applause). >> How many bytes did I write? >> 4 bytes of 00:41:12.203 --> 00:41:17.075 memory, return code that was access denied and we changed it 00:41:17.075 --> 00:41:22.814 so it never returns accession denied any more. >> And the SPF 00:41:22.814 --> 00:41:27.919 when we got it down was just a couple K? >> It was less than a 00:41:27.919 --> 00:41:34.092 K. It was a couple hundred instructions. 4 bytes, writing 00:41:34.092 --> 00:41:40.098 4 bytes of memory took, like 2 or 300 actual commands in the 00:41:42.166 --> 00:41:47.171 SPF file. First iteration when I did a DIF and generated a 00:41:47.171 --> 00:41:50.675 patch, SPF came out to 500 K. I put a little work in optimizing, 00:41:50.675 --> 00:41:53.811 it can take a while to do that. So it can take awhile and as 00:41:53.811 --> 00:41:56.714 you can see it's not 100% reliable. We can put a little 00:41:56.714 --> 00:41:59.283 more work into getting it more reliability. But, we got a 00:41:59.283 --> 00:42:01.786 demo, so. Yeah (Laughter) oh, so the, point here is that, 00:42:01.786 --> 00:42:04.856 everything you saw is working as intended. JTAG is there because 00:42:04.856 --> 00:42:07.291 you don't buy a working laptop if you can't do all of this over 00:42:07.291 --> 00:42:10.628 JTAG, you need this to build something that works in the 00:42:10.628 --> 00:42:13.965 first place, but this is not software. You can't turn off 00:42:13.965 --> 00:42:17.635 debug flags and have it be compiled out of the binary, this 00:42:17.635 --> 00:42:21.606 is going into hardware you can't take it out. We need to make 00:42:21.606 --> 00:42:24.976 sure hardware works before we sell to you but stays in 00:42:24.976 --> 00:42:28.346 hardware, this is embedded flat form. JTAG is not able to 00:42:28.346 --> 00:42:31.682 intentionally on purpose they expect people to need or want to 00:42:31.682 --> 00:42:37.688 use it, as NSA did, you can plug this on pretty much anything. 00:43:12.690 --> 00:43:16.427 Almost everything. >> As long as you have patience. >> And 00:43:16.427 --> 00:43:22.834 potentially money to spend for reverse engineering it. If 00:43:22.834 --> 00:43:27.972 you're building something, it's not just about, selling it to 00:43:27.972 --> 00:43:31.242 OEM and let OEM build it, because eventually user has to 00:43:31.242 --> 00:43:36.314 use this and I don't want somebody to picks up my phone or 00:43:36.314 --> 00:43:40.985 laptop to be able do this. You need to be able, ideally user 00:43:40.985 --> 00:43:48.860 has some say in this. Some of new things give either BIOS or 00:43:48.860 --> 00:43:52.130 route user control over whether JTAG gets turned on which 00:43:52.130 --> 00:43:55.266 functionality is enabled. Which is good thing. That means 00:43:55.266 --> 00:43:59.103 somebody can't pick up laptop, walk away, plug something 00:43:59.103 --> 00:44:04.175 simple, that's $15 -- so you can't plug a $15 JTAG adapter 00:44:04.175 --> 00:44:06.911 and get full access. We're patching memory, doesn't matter 00:44:06.911 --> 00:44:12.917 if youve got this encryption, doesnt matter what you're 00:44:16.988 --> 00:44:24.695 running, we plug this in and we get full access OIS has. 00:44:24.695 --> 00:44:28.933 Hopefully we get to the point it required user involvement to 00:44:28.933 --> 00:44:34.138 actually turn some of this on. The old assumption just don't 00:44:34.138 --> 00:44:38.042 let me walk out and plug JTAG, your system stays behind a 00:44:38.042 --> 00:44:42.813 locked door, but not everything is behind a locked door any 00:44:42.813 --> 00:44:48.819 more. That is it. (Applause) thank you. Thank you.