00:00:00.000 --> 00:00:05.906 Okay. So without further adieu, let's jump in. There are many 00:00:05.906 --> 00:00:12.379 slides and very few minutes. So here is an agenda. We'll get 00:00:12.379 --> 00:00:19.386 through it hopefully. I have a turbo version so if I go too 00:00:19.386 --> 00:00:26.927 fast, raise your hand and I'll try to slow down a bit. I have 00:00:26.927 --> 00:00:33.934 to go quick. Let's jump in and talk about android. I'm Josh. I 00:00:33.934 --> 00:00:38.839 go by JDUCK on the internet. I welcome you to say hello any 00:00:38.839 --> 00:00:46.246 time. I work for similar peer yum doing mobile defense. I have 00:00:46.246 --> 00:00:53.387 a handbook which we'll have a little event somewhere later. If 00:00:53.387 --> 00:00:57.991 you see us drinking, join us. Previous affiliations. I was 00:00:57.991 --> 00:01:01.361 hoping that doing this research would overall improve mobile 00:01:01.361 --> 00:01:05.565 security. There is years and years of people talking about 00:01:05.565 --> 00:01:10.637 these problems with android and I'm like, I have to do something 00:01:10.637 --> 00:01:15.909 about that. I decided to do what I do best which is discover and 00:01:15.909 --> 00:01:21.014 eliminate voids and exploit them to show people that they're 00:01:21.014 --> 00:01:27.321 real. They're not some BS. I'm trying to save my phone battery. 00:01:27.321 --> 00:01:34.895 There we go. So I want people to think harder on some of the 00:01:34.895 --> 00:01:40.300 security issues so they can make the improvements in their 00:01:40.300 --> 00:01:45.739 organization that they need to. To increase visibility of the 00:01:45.739 --> 00:01:51.745 code in android. There is 60 gigs of stuff. Last year I gave 00:01:51.745 --> 00:01:57.284 a talk about the droid army. I collect android devices and have 00:01:57.284 --> 00:02:03.223 them all connected now through a USB to a computer and can -- at 00:02:09.763 --> 00:02:15.769 any time across CPUs, whatever. So I want to thank the sponsors. 00:02:28.248 --> 00:02:31.418 I started this work when I worked for dock ewe lab. They 00:02:31.418 --> 00:02:35.088 allowed me to take this research on with me and see it through to 00:02:35.088 --> 00:02:38.525 the end. I wouldn't call this the end. But I want to thank 00:02:38.525 --> 00:02:41.928 Amir, is he here? Come on, you missed both talks. Man, I'll get 00:02:41.928 --> 00:02:45.098 him later. I want to thank Colin and Maxim. They're both fired, 00:02:45.098 --> 00:02:47.734 too. So what is stage fright. Androids open media library. 00:02:47.734 --> 00:02:51.171 Primarily in C plus plus. There are some points written in Java. 00:02:51.171 --> 00:02:57.077 Androids are all [indiscernible] on the device. It's meant to 00:02:57.077 --> 00:03:02.916 stand as a go between, between the download applications and 00:03:02.916 --> 00:03:09.423 other sort of high level stuff in android. And the hardware 00:03:09.423 --> 00:03:15.929 because a lot of android devices had hardware video decoders. It 00:03:15.929 --> 00:03:21.902 extracts -- which is kind of important. Brief history. 00:03:21.902 --> 00:03:26.973 Android in the 1.0 and 1.5 days had an engine called the open 00:03:26.973 --> 00:03:32.412 core which was donated to them. Later during the 2.0 development 00:03:32.412 --> 00:03:38.985 they added stage fright. But they weren't using it. They were 00:03:38.985 --> 00:03:46.159 starting to develop it. In 2.2 they made it optional to use, 00:03:46.159 --> 00:03:50.730 like in a setting. But all the devices that I had with 2.2 00:03:50.730 --> 00:03:56.736 which isn't many did that be default so I assumed they would 00:04:05.779 --> 00:04:11.051 all do that. [indiscernible] we need to instable stage 00:04:11.051 --> 00:04:17.524 frightbecause it's fast. So at 2.3GINGER bread set this as the 00:04:17.524 --> 00:04:23.396 default engine. This code was pulled into FireFox. But they 00:04:23.396 --> 00:04:29.870 decide today pull it into FireFox and ship it on all 00:04:29.870 --> 00:04:36.343 versions of FireFox except Linux around version 17. Why did look 00:04:36.343 --> 00:04:42.816 at stage fright? What was the big deal? Honestly I can't 00:04:42.816 --> 00:04:49.856 remember exactly why I started looking at it. It might be the 00:04:49.856 --> 00:04:55.162 name. When you look through, oh, Stagefright, that sounds 00:04:55.162 --> 00:05:01.535 interesting. So definitely big plus if you want to audit code 00:05:01.535 --> 00:05:08.608 to look for native code. It's much buggier than Java code. A 00:05:08.608 --> 00:05:15.649 lot of times the people that write native code are often not 00:05:15.649 --> 00:05:18.385 very good. They don't really understand what they're 00:05:18.385 --> 00:05:22.789 necessarily doing. That's cool. Especially with respect to 00:05:22.789 --> 00:05:27.794 security. So [indiscernible] people on -- and other places 00:05:27.794 --> 00:05:33.366 posting and saying my phone keeps rebooting randomly and you 00:05:33.366 --> 00:05:39.539 read down and somebody is like, you have a corrupt file on your 00:05:39.539 --> 00:05:42.809 SD card or something. So I was like, yep, that sounds really 00:05:42.809 --> 00:05:46.079 bad. It has to be bad code. I have to check that out. And 00:05:46.079 --> 00:05:53.086 there was related work published in April, where I thought that 00:05:53.086 --> 00:05:57.657 is really cool stuff, maybe I should do a talk on that stuff. 00:05:57.657 --> 00:06:03.697 So we'll talk more about some of the issues reported. It's cool 00:06:03.697 --> 00:06:09.302 that these guys -- the crap out of Stagefright on android 00:06:09.302 --> 00:06:14.374 emulators, I think. They said they have 11.5 terabytes they 00:06:14.374 --> 00:06:19.479 created that crashed Stagefright which is pretty intense. That is 00:06:19.479 --> 00:06:25.585 more data than I think anyone can go through. There are bugs 00:06:25.585 --> 00:06:31.691 and we'll talk about them later. There is this (audio blipped) on 00:06:31.691 --> 00:06:38.298 mobile devices. Pretty much what I did in part of it. So it's 00:06:38.298 --> 00:06:43.904 definitely related and they talk about some of the stuff they 00:06:43.904 --> 00:06:48.975 found in Stagefright. So related work, really old stuff is 00:06:48.975 --> 00:06:53.580 Charlie miller's talk when they talked about hacking before 00:06:53.580 --> 00:06:59.686 android was even released. He found an open media file that he 00:06:59.686 --> 00:07:05.191 reported but it was so long ago. [indiscernible] is big, it's 00:07:05.191 --> 00:07:10.297 10 --> 000 lines of code. But it's probably more than that. 00:07:10.297 --> 00:07:17.404 (muffled) there is a spot in the code where you can look at this 00:07:17.404 --> 00:07:24.044 one function and if it's going bad do this, do that. You can 00:07:24.044 --> 00:07:30.150 see which way it goes. Most of the code they supported in 00:07:30.150 --> 00:07:34.954 Stagefright is backed by common open source libraries like LIM 00:07:34.954 --> 00:07:39.025 flak or BPX or open source libraries which are projects of 00:07:39.025 --> 00:07:41.695 their own. However, there is a bunch of code that lives 00:07:41.695 --> 00:07:48.435 directly in Stagefright. That was my focus. I decided to pick 00:07:48.435 --> 00:07:54.841 MP4. I thought it was really straightforward format. But I 00:07:54.841 --> 00:08:01.948 thought it would be a good one to mess around with. The rest of 00:08:01.948 --> 00:08:06.319 this talk will primarily focus on MP4 stuff and the examples 00:08:06.319 --> 00:08:12.759 and findings. We'll talk about how it looks on a system. Where 00:08:12.759 --> 00:08:18.732 this code runs. High level. This is the new diagram they show on 00:08:18.732 --> 00:08:23.903 the website. It's cool and now they're calling on me 00:08:23.903 --> 00:08:29.042 specifically. There are many more things that run in the 00:08:29.042 --> 00:08:33.680 background. But they use a lot of inter-process communication 00:08:33.680 --> 00:08:37.817 to talk between processes. Basically media server is 00:08:37.817 --> 00:08:42.622 running as a background native service. It starts from a 00:08:42.622 --> 00:08:48.695 [indiscernible] and an android. I heard, someone told me which 00:08:48.695 --> 00:08:54.701 wasn't necessarily the case in older versions. But in android 00:08:59.239 --> 00:09:05.178 now if something is running from a nit crashes, it automatically 00:09:10.750 --> 00:09:16.756 restart PSFTP let's look at the privileges. What do you get if 00:09:23.396 --> 00:09:29.402 you pop this thing. It's interesting to find out. This is 00:09:34.974 --> 00:09:40.980 another reason why I looked at this service. I wrote a tool 00:09:45.718 --> 00:09:50.690 called PRED map to see what they were running and this one had 00:09:50.690 --> 00:09:52.692 potentially permissions violations. You can see the 00:09:52.692 --> 00:09:54.694 bottom line. The CODATEX area. Media server you would think 00:09:54.694 --> 00:09:56.696 it's been sandboxed and moved and segregated to limit risk of 00:09:56.696 --> 00:09:58.698 the code, they're actually making it very privileges I 00:09:58.698 --> 00:10:00.700 guess to do what it needs to do for the most part. For example, 00:10:00.700 --> 00:10:02.702 audio Bloop is used to lock down access to the speakers and 00:10:02.702 --> 00:10:04.704 microphone, if you have volume loop you can do anything with 00:10:04.704 --> 00:10:06.706 the input and output of audio. These are similar. I net. There 00:10:06.706 --> 00:10:08.708 is things within the Stagefright and other parts of media server 00:10:08.708 --> 00:10:10.710 that require connecting back to the internet. The biggest 00:10:10.710 --> 00:10:12.712 example being the [indiscernible] which you'll 00:10:12.712 --> 00:10:15.915 have to go out and get a license for that. And then also you can 00:10:15.915 --> 00:10:21.621 see the -- for DRM. I did this survey. I wanted to figure out, 00:10:21.621 --> 00:10:27.293 yeah, this is that slide. I have this slide and I have no idea 00:10:27.293 --> 00:10:31.364 what this number means on the left. Essential number of 00:10:31.364 --> 00:10:34.033 devices. These numbers don't make sense to me. 17 doesn't 00:10:34.033 --> 00:10:40.373 seem like a number that would jive with what I wrote here. So 00:10:40.373 --> 00:10:47.380 I will look into that later and fix it when I publish the 00:10:47.380 --> 00:10:52.218 slides. I did some [indiscernible]. Maybe it was a 00:10:52.218 --> 00:10:59.225 break down of devices. Yes. This is how many devices I looked at 00:10:59.225 --> 00:11:05.598 out of the 51 that were from Motorola or Samsung. This gives 00:11:05.598 --> 00:11:12.605 you an overview of what - looks like. The privilege, I want to 00:11:12.605 --> 00:11:20.113 look at each group and how many devices in each group. 51 on the 00:11:20.113 --> 00:11:26.586 left. These groups are on all devices. We talked about what we 00:11:26.586 --> 00:11:31.958 can do with that. It's pretty bad. Other groups. This 00:11:31.958 --> 00:11:36.863 bandwidth counting thing. I think that is uninteresting. 00:11:36.863 --> 00:11:40.133 Usually that is used to talk directly into [indiscernible]. 00:11:40.133 --> 00:11:44.304 Which Tresome is [indiscernible] to attack soldiers on android. 00:11:44.304 --> 00:11:49.842 It's more privileged than the Colonel. So the next one which 00:11:49.842 --> 00:11:56.349 is system. System is the No. 2 user on android. It owns the 00:11:56.349 --> 00:12:01.821 slash data partition. Everything is write able in slash data. And 00:12:01.821 --> 00:12:08.828 if it's not write able since he owns slash data you move it out 00:12:08.828 --> 00:12:15.301 of the way and put whatever you want in the place. System is a 00:12:15.301 --> 00:12:17.704 very high privilege. It's well thought of in the research 00:12:17.704 --> 00:12:21.007 community and android, but if you have a system, then getting 00:12:21.007 --> 00:12:27.914 -- [indiscernible] an engineering effort and not a 00:12:27.914 --> 00:12:33.086 serious effort. The next one is graphics. Graphics is used to 00:12:33.086 --> 00:12:38.658 lock down the buffer devices for android. And there have been 00:12:38.658 --> 00:12:43.696 numerous ones discovered and exploited in the -- staff. Right 00:12:43.696 --> 00:12:49.035 now it's solid but I could be proven wrong, of course. We keep 00:12:49.035 --> 00:12:53.339 going down the list. Input. If somebody gets a device, one of 00:12:53.339 --> 00:12:56.943 these 8 devices and get in through media server on that, 00:12:56.943 --> 00:13:02.281 and they can inject key strokes into your use of the device. At 00:13:02.281 --> 00:13:07.286 the bottom shell. Shell is the user that is assigned to AV 00:13:07.286 --> 00:13:12.725 shell. I have no idea why they would give that to media server 00:13:12.725 --> 00:13:18.164 at all. Blows my mind really. And the last one is radio. Radio 00:13:18.164 --> 00:13:24.170 is basically right below system. If you have radio, you can make 00:13:30.076 --> 00:13:33.746 calls, send IMS, [indiscernible] all communications with the 00:13:33.746 --> 00:13:37.850 cellular network. Take down the cellular network connection that 00:13:37.850 --> 00:13:43.322 you have. So it basically runs all the stuff that is between 00:13:43.322 --> 00:13:48.327 the cell network and the rest of android. So recap. 00:13:48.327 --> 00:13:51.531 [indiscernible] runs inside the media server. Fairly privileged. 00:13:51.531 --> 00:13:55.201 Automatically restarts whatever it crashes. It's a fairly large 00:13:55.201 --> 00:13:59.839 (muffled) provided on the groups that you're given. From remote 00:13:59.839 --> 00:14:05.778 to the kernel is probably not too difficult because of the 00:14:09.182 --> 00:14:13.352 extra [indiscernible] given to you once you're in with those 00:14:13.352 --> 00:14:17.957 privileges. So let's talk about the [indiscernible]. Basically 00:14:17.957 --> 00:14:20.526 in order to figure out what is going on with the code, I opened 00:14:20.526 --> 00:14:26.065 up a ruby. Put a breakpoint just on the open thing, okay, I'm 00:14:26.065 --> 00:14:32.438 going to play a file, so it has to open it. Then I looked back 00:14:32.438 --> 00:14:38.411 and dug around in the code. This is what a back trace looks like. 00:14:38.411 --> 00:14:43.082 I'm playing with the MP4 file and all the different functions 00:14:43.082 --> 00:14:47.320 that are in the process including paths to where they 00:14:47.320 --> 00:14:53.292 are in the code base. When we look closer we can see the - 00:14:53.292 --> 00:14:57.964 data extension. I think it's like, it's not showing here. But 00:14:57.964 --> 00:15:03.870 basically we can see at the top -- create from UI and after that 00:15:03.870 --> 00:15:09.809 it's a media extractor. We look at that and we end up with this 00:15:09.809 --> 00:15:13.446 function that moves through all the tracts that you count. When 00:15:13.446 --> 00:15:16.582 you look at that it says read meta data. You have to extract 00:15:16.582 --> 00:15:21.087 the meta data because that is where it stores that 00:15:21.087 --> 00:15:27.093 information. So you look at that and go through this chunk. Let's 00:15:29.462 --> 00:15:35.468 look at that a little bit. So the first chunk function is 00:15:38.538 --> 00:15:42.708 [indiscernible] inside Stagefright -- code. It's a 00:15:42.708 --> 00:15:48.714 recursive function. When it sees an atom, a tag length data piece 00:15:51.083 --> 00:15:58.758 of the file. That's what that is. Come in here. (audio 00:15:58.758 --> 00:16:02.161 blipped) let the guy in his green shirt and lovely wife. 00:16:02.161 --> 00:16:09.335 Those two. Yes, and the lovely wife, of course. You missed your 00:16:09.335 --> 00:16:16.008 shout out again. But now you're here. All right. Let me look at 00:16:16.008 --> 00:16:22.515 android, all versions. Git is wonderful. You see other 00:16:22.515 --> 00:16:30.523 versions are about 80 atoms and newer versions have 130. It's 00:16:30.523 --> 00:16:36.529 roughly double the amount of code. We look closer and you can 00:16:39.232 --> 00:16:46.505 see an example where the movement and track chunks are 00:16:46.505 --> 00:16:51.344 especially handling where they say [indiscernible]. The 00:16:51.344 --> 00:16:55.014 recurser is really not relevant rather than it's annoying to be 00:16:55.014 --> 00:16:59.118 bugged for codes sometimes. [indiscernible] that you're 00:16:59.118 --> 00:17:05.057 trying to tickle and find -- in. I'm thinking of all the ways to 00:17:07.226 --> 00:17:13.099 get (audio blipped) the ultimate goal looking for attack vectors 00:17:13.099 --> 00:17:19.105 is to figure out how to get my data in there. I'm in trouble 00:17:21.307 --> 00:17:27.146 now. First we try all possible ways. Unfortunately it depends 00:17:27.146 --> 00:17:33.152 on -- go ahead. You want to try? >> Sure. >> Go ahead. >> Method 00:17:35.955 --> 00:17:40.259 dolling, phone all calls into this function and ask can an 00:17:40.259 --> 00:17:46.265 attacker's data reach here. How am I doing? >> Good. Maybe I 00:17:49.101 --> 00:17:53.072 should try that more. >> You need to work on your graphics. 00:17:53.072 --> 00:17:57.643 >> If you had any idea how hard it was to do graphics in this 00:17:57.643 --> 00:18:02.048 presentation framework. >> Just put a picture of a water 00:18:02.048 --> 00:18:06.986 fountain in the background. >> Maybe everybody have to go to 00:18:06.986 --> 00:18:12.358 the bathroom. >> You go through this process until you find them 00:18:12.358 --> 00:18:16.195 all. You can't really know necessarily without looking all 00:18:16.195 --> 00:18:19.699 threw the code, all the ways it's possible. There are some 00:18:19.699 --> 00:18:22.034 problems with doing the second methodology when it's more 00:18:22.034 --> 00:18:27.306 thorough and that is all these complicated issues. There is a 00:18:27.306 --> 00:18:32.044 place inside media server in this code path, actually goes 00:18:32.044 --> 00:18:38.217 into and out of Java code like three times and runs back trace. 00:18:38.217 --> 00:18:44.890 You have to open a lot of files and have them all in the 00:18:44.890 --> 00:18:51.530 background. >> Excuse me. Do we have ... >> Let me come on the 00:18:51.530 --> 00:18:57.870 other side. >> Are we live yet? >> Awesome. How many are first 00:18:57.870 --> 00:19:04.043 timers at DEFCON? Awesome. But you all know the drill by now. 00:19:04.043 --> 00:19:09.448 What do first time speakers do? Awesome. So how is he doing by 00:19:09.448 --> 00:19:16.756 the way? Jeez. Slow down speedy. All right. Anyway, it's very -- 00:19:16.756 --> 00:19:21.827 (inaudible) like to honor him with a little tradition called 00:19:21.827 --> 00:19:29.835 shot the new. Cheers. To DEFCON. >> To DEFCON. >> As you were. >> 00:19:29.835 --> 00:19:35.841 Thank you my friends. I owe you a shot. >> You can do it right 00:19:38.411 --> 00:19:45.851 now. >> Can we do it after? Let's do it after. The other 00:19:45.851 --> 00:19:52.158 thing is instead of writing code, we mentioned C plus plus 00:19:52.158 --> 00:19:58.431 and java. Lots of times when you're trying to understand the 00:19:58.431 --> 00:20:05.704 code you have to do all this crappy stuff where you have to 00:20:05.704 --> 00:20:11.811 remember the functions and variables and all this crap and 00:20:11.811 --> 00:20:14.513 stuff. You have to be careful about [indiscernible] and 00:20:14.513 --> 00:20:17.716 lifetimes and things like that. Further on android because of 00:20:17.716 --> 00:20:22.421 the modularity and the IPC you end up having to sometimes cross 00:20:22.421 --> 00:20:25.591 boundaries that are like between processes. That can be hard to 00:20:25.591 --> 00:20:30.796 follow. But you can get through it if you keep trying. Sometimes 00:20:30.796 --> 00:20:33.065 you might have to take a break or a nap or something. That 00:20:33.065 --> 00:20:37.970 works for me. That's the best way. Go to the code if you want 00:20:37.970 --> 00:20:42.975 to know what the code does, it's in the code. The fifth vector I 00:20:42.975 --> 00:20:49.081 thought about was the video tag. I thought this is brand new. I 00:20:49.081 --> 00:20:51.150 fire up the device with the [indiscernible] attached to it. 00:20:51.150 --> 00:20:55.187 The meta beta function. The first chunk, it will break but 00:20:55.187 --> 00:21:00.126 then every other chunk even when it's recuring into more chunks 00:21:00.126 --> 00:21:05.131 will keep getting hit. That is annoying to keep saying continue 00:21:05.131 --> 00:21:10.136 all the time. Hit the breakpoint. Then I tried to - 00:21:10.136 --> 00:21:14.673 Thomas cannon back in the day talked about [indiscernible] to 00:21:14.673 --> 00:21:19.245 download files. And would load Java script through a weird 00:21:19.245 --> 00:21:23.349 content provider or something. This is actually the Screenshot 00:21:23.349 --> 00:21:29.722 other than the part on the left where the path is wrong and the 00:21:29.722 --> 00:21:36.095 URL. So as soon as you touch this link, you see this page in 00:21:36.095 --> 00:21:41.100 the middle which can be anything. It doesn't have to be 00:21:41.100 --> 00:21:47.473 what it is right now in this big white screen. It can be cat 00:21:47.473 --> 00:21:52.011 pictures or whatever. You see this downloading toast come up 00:21:52.011 --> 00:21:57.016 which disappears in one second. There is no indication that you 00:21:57.016 --> 00:22:01.353 did anything other than this downward arrow with a line at 00:22:01.353 --> 00:22:07.293 the top. If you swipe down and touch that, you can see what is 00:22:07.293 --> 00:22:12.865 on the right. The trick, the crappy scary thing is here that 00:22:12.865 --> 00:22:17.069 the variable code, the Stagefright code is treated as 00:22:17.069 --> 00:22:21.874 soon as the file is downloaded and does not require you to open 00:22:21.874 --> 00:22:25.177 the media or touch it or open it or anything like that. That is 00:22:25.177 --> 00:22:30.716 interesting. Look. I also -- can we get some kind of prompting 00:22:30.716 --> 00:22:34.854 for this. I don't want to autodownload something and 00:22:34.854 --> 00:22:39.058 expect a link to cause a download. Maybe that is not a 00:22:39.058 --> 00:22:45.531 good idea. So when I got deeper in, I took a step back and said 00:22:45.531 --> 00:22:50.569 how is this working. What I found is with this whole 00:22:50.569 --> 00:22:54.707 subsystem called the media scanner. The only thing really 00:22:54.707 --> 00:22:57.910 documented in the [indiscernible] for people to 00:22:57.910 --> 00:23:02.448 use is the media scanner connection. Really all that does 00:23:02.448 --> 00:23:08.387 is you create an object and say scan this file and that's it. 00:23:08.387 --> 00:23:13.459 The other thing is in the intent documentation. The intent class 00:23:13.459 --> 00:23:18.497 and Java stuff for android, there was a long, long, long, 00:23:18.497 --> 00:23:23.202 long, long list of intents that are supported in the system. 00:23:23.202 --> 00:23:26.171 They havethese two media mounted and media scanner scan file. 00:23:26.171 --> 00:23:29.708 They were documented as well. They are basically one line in a 00:23:29.708 --> 00:23:35.914 huge table. And then if you look closer, there is this class that 00:23:35.914 --> 00:23:39.418 is used a lot internally in the code, media scanner connection 00:23:39.418 --> 00:23:45.391 client. That one is used a lot. So I didn't want to go too much 00:23:45.391 --> 00:23:50.996 deeper. When I made the slides I went crazy deep and realized 00:23:50.996 --> 00:23:57.970 there is no way I could talk about that. So I put it at the 00:23:57.970 --> 00:24:02.541 back of the slides. We're talking about one -- the 00:24:02.541 --> 00:24:07.680 methodology and looking at the different ways to -- on the 00:24:07.680 --> 00:24:11.383 code. The media scanner and (audio blipped). Basically 00:24:11.383 --> 00:24:16.955 found, you can do through MMS. I'm showing you a thumbnail of 00:24:16.955 --> 00:24:23.028 the video. Even if it didn't show you a thumbnail I wanted to 00:24:23.028 --> 00:24:28.600 know how many seconds long the thing was, that was the trigger. 00:24:28.600 --> 00:24:34.173 (muffled) email. If you get an email with an attachment on the 00:24:34.173 --> 00:24:39.778 android it waits to say you have an attachment but it doesn't 00:24:39.778 --> 00:24:43.949 download automatically. You have to press the button. 00:24:43.949 --> 00:24:48.620 [indiscernible] To back up, there is a way inside of these 00:24:48.620 --> 00:24:54.727 APIs to tell it, it's not media scanner stuff, but a lot of 00:24:54.727 --> 00:24:59.198 these attack vectors used the download manager and that's what 00:24:59.198 --> 00:25:03.969 I talk about in the bonus lines, the download manager. It tells 00:25:03.969 --> 00:25:10.009 it not to scan the file. I saw in the code where it says don't 00:25:10.009 --> 00:25:14.446 scan the file when you download it, download it afterwards 00:25:14.446 --> 00:25:16.815 [indiscernible] scanning file. Physically adjacent, that is 00:25:16.815 --> 00:25:20.486 stuff like we're in the same room together. You're a little 00:25:20.486 --> 00:25:27.092 bit closer. You can also attack vectors if you have an SD card 00:25:27.092 --> 00:25:33.198 on your device, someone can insert an SD card on the device 00:25:33.198 --> 00:25:38.303 and compromise it. (audio blipped) the TPT mode. A whole 00:25:38.303 --> 00:25:43.375 bunch of research into this subsystem where it's not going 00:25:43.375 --> 00:25:49.481 to fit here. And so if you connect with device to your 00:25:49.481 --> 00:25:55.087 computer with this mode and transfer a media file, it will 00:25:55.087 --> 00:26:00.626 also scan it. (muffled) if you think about it anywhere that 00:26:00.626 --> 00:26:06.198 media is thumbnailed over, any way probed for meta data will 00:26:06.198 --> 00:26:12.304 trigger the Stagefright code. If you use these to talk to people 00:26:12.304 --> 00:26:18.410 you don't trust or worst, do you think anybody that you don't 00:26:18.410 --> 00:26:23.515 trust could somehow communicate with you without asking with any 00:26:23.515 --> 00:26:29.121 of these? So the scariest part is [indiscernible] by far. My 00:26:29.121 --> 00:26:34.092 research initially was doing stuff over the SD card. I 00:26:34.092 --> 00:26:37.396 discovered the media mountain intent. When you stick the SD 00:26:37.396 --> 00:26:43.335 card in, the manager says hey, there is a SD card mounted and 00:26:43.335 --> 00:26:49.341 starts the scan. I was like, wait, that can't be good. So one 00:26:54.480 --> 00:26:57.149 day I was messing around and sent myself a video. I sent it 00:26:57.149 --> 00:27:01.820 to myself with the debugger attached of course. And my 00:27:01.820 --> 00:27:08.694 screen was off, phone was locked on the table. And it hit the 00:27:08.694 --> 00:27:13.966 breakpoint. I'm like what? Are you kidding me? So before 00:27:13.966 --> 00:27:19.238 creating a notification it's like trying to get a Screenshot 00:27:19.238 --> 00:27:26.078 of this video and then it's -- at least on newer versions it 00:27:26.078 --> 00:27:31.884 will put it straight in the notification email. I don't know 00:27:31.884 --> 00:27:38.757 if I have pictures of this. Oh yeah. I need more pictures. I 00:27:38.757 --> 00:27:46.131 have some but I didn't put them in here. In theory, in theory if 00:27:46.131 --> 00:27:50.869 you explored this and did engineering work you could 00:27:50.869 --> 00:27:55.607 potentially stop the whole process of the MMS going 00:27:55.607 --> 00:28:01.346 through. You can delete it from wherever it's stored. You can 00:28:01.346 --> 00:28:06.018 stop the IM notification. And then you can -- nobody would 00:28:06.018 --> 00:28:08.186 know anything. Even if they were using the device at the time. 00:28:10.489 --> 00:28:13.292 That is a theoretically possible things that freaks me the fuck 00:28:13.292 --> 00:28:20.432 out. I don't know about you guys. I did not do that work. So 00:28:20.432 --> 00:28:27.873 how does it work? The MMS stuff works in hangouts. Proto-testing 00:28:27.873 --> 00:28:33.111 later, the new version of that. The app messenger which is kind 00:28:33.111 --> 00:28:37.683 of like the throw back of the old messaging app they removed 00:28:37.683 --> 00:28:42.120 in newer versions. Also does a lot of processing automatically. 00:28:42.120 --> 00:28:47.559 The other version does not do it. Although if somebody sends 00:28:47.559 --> 00:28:54.600 you an MMS message even if you don't know who it is, it's like 00:28:54.600 --> 00:29:00.105 hey did you see this video of you? You might be like me, and 00:29:00.105 --> 00:29:07.546 you download it. If you use hangouts or messenger, turn it 00:29:07.546 --> 00:29:12.951 off because it's nasty. It's vulnerable potentially. 00:29:12.951 --> 00:29:18.357 [indiscernible] this device here, I disabled the app. The 00:29:18.357 --> 00:29:24.363 MMS comes in in messaging in this phone. If you're looking at 00:29:26.498 --> 00:29:30.636 it, if you turn the screen sideways it redraws the activity 00:29:30.636 --> 00:29:34.973 and there is vulnerability again. You lock the screen and 00:29:34.973 --> 00:29:39.311 unlock it, vulnerability again. Any time it's on the screen, 00:29:39.311 --> 00:29:42.781 that is another trigger. [indiscernible] attack vector. I 00:29:42.781 --> 00:29:47.119 get this question a lot on Twitter. Is silent tech 00:29:47.119 --> 00:29:52.758 effective. I don't know. I don't use those things. A lot of times 00:29:52.758 --> 00:29:58.830 when a lot of people jump onto a technology it becomes a big risk 00:29:58.830 --> 00:30:04.469 in its. If you have any ideas or thoughts or testing, I would 00:30:04.469 --> 00:30:10.108 love to hear about that sort of stuff. Let's get into the bugs 00:30:10.108 --> 00:30:15.747 and I think I have ten minutes or something. Is that not right? 00:30:15.747 --> 00:30:21.687 Who has the timer? We can do this. So basic methodology was 00:30:21.687 --> 00:30:25.924 to just [indiscernible] process -- and while it's running go get 00:30:25.924 --> 00:30:31.797 some code and if it crashes go where it crashes because that 00:30:31.797 --> 00:30:38.603 has to be bad code. You do that until your brain melts and you 00:30:38.603 --> 00:30:43.475 want a nap or whatever. First round, the details, again 00:30:43.475 --> 00:30:49.314 focused on MP4. We didn't bother to create a large purpose. We 00:30:49.314 --> 00:30:56.121 just used a one media file or two. Again, see my curser, is it 00:30:56.121 --> 00:31:02.728 over there? There it is. Maybe we can play the video. That is a 00:31:02.728 --> 00:31:08.734 total waste of time but it would be funny. Not normal to use a 00:31:11.937 --> 00:31:17.943 computer screen that is 20 feet from you. So, yes, Amir, thank 00:31:22.013 --> 00:31:26.785 you for that. That was bad ass. So you can imagine it was a lot 00:31:26.785 --> 00:31:31.523 of fun hearing that sound over and over again. And when you 00:31:31.523 --> 00:31:35.527 don't hear it you're like, wonder what happened. That was 00:31:35.527 --> 00:31:40.465 for about a week where we found 6200 crashes. I went through all 00:31:40.465 --> 00:31:43.535 of these crashes and bucketed them and looked deeper into 00:31:43.535 --> 00:31:47.139 them. Unfortunately the crashes that we found were 00:31:47.139 --> 00:31:51.543 noninteresting bugs. It's checking if something that is 0 00:31:51.543 --> 00:31:56.414 and if not the guys at Stagefright decided they were 00:31:56.414 --> 00:31:59.785 going to kill themselves making you lose audio and everything 00:31:59.785 --> 00:32:05.724 else. [indiscernible] when I was looking at the code, I'm like, 00:32:08.660 --> 00:32:13.532 okay, that's lame. But let's look around, maybe just a 00:32:13.532 --> 00:32:18.637 dysfunction. Within two or three lines it was just very important 00:32:18.637 --> 00:32:22.307 vulnerabilities. I found about five and they became these two 00:32:22.307 --> 00:32:28.313 CBEs (ph.) the first one is a merger of several issues. We 00:32:41.326 --> 00:32:44.596 decided to through American fuzzy logic. There are not very 00:32:44.596 --> 00:32:48.867 many people that said they heard it. Three that used it and ten 00:32:48.867 --> 00:32:54.206 that heard of it. Fuzzy (audio blipped) was developed by the 00:32:54.206 --> 00:32:59.978 security industry for a long time. He came up with this idea 00:32:59.978 --> 00:33:05.650 of look at the way code flows and if it flows from here to 00:33:05.650 --> 00:33:13.491 here, we'll treat that as a transition and keep track of 00:33:13.491 --> 00:33:15.727 three things. And he is like if there is a new one of these 00:33:15.727 --> 00:33:19.297 three things like from here to here instead of here to there, 00:33:19.297 --> 00:33:25.203 that is new. We want more. The goal in creating this wasn't 00:33:25.203 --> 00:33:29.641 necessarily to find crashes which is going to happen when 00:33:29.641 --> 00:33:34.946 you do automated testing. It's to find new code paths with the 00:33:34.946 --> 00:33:38.049 purpose of loading [indiscernible] in a more 00:33:38.049 --> 00:33:42.487 problematic and intentional way. The traditional other way is to 00:33:42.487 --> 00:33:48.260 go down with all the files you can find and run them through 00:33:48.260 --> 00:33:53.665 this long process where you see which code does it hit. Not very 00:33:53.665 --> 00:34:01.373 much fun. (audio blipped) so I'm like echoing, yeah, yeah, yeah 00:34:01.373 --> 00:34:07.379 into the fire and ran it and it went well. We developed a 00:34:10.548 --> 00:34:16.221 harness, calling the Stagefright code. [indiscernible] server I 00:34:16.221 --> 00:34:23.295 just got, a 32 core machine. Double high fives. I guess every 00:34:23.295 --> 00:34:26.932 day or so, maybe two days I would stop the fuzzer and trash 00:34:26.932 --> 00:34:31.670 them and bucket them and look at each unique thing and try my 00:34:31.670 --> 00:34:36.741 best. Sometimes I got it on the first try but sometimes I did a 00:34:36.741 --> 00:34:40.111 more deep analysis to fix the vulnerabilities before I started 00:34:40.111 --> 00:34:45.016 the fuzzy running again. What is the point of finding the same 00:34:45.016 --> 00:34:51.723 vulnerability 800 --> 000 times? Not really fun. This is supercool. I 00:34:51.723 --> 00:34:56.027 don't think I finished it. Length of testing. We tested for 00:34:56.027 --> 00:35:02.467 2 or 3 weeks off and on. The speed was 32 executions per 00:35:02.467 --> 00:35:09.007 second per core. And we found a lot of bugs. That includes 00:35:09.007 --> 00:35:12.010 [indiscernible] references. That's a lame crash. That's 00:35:12.010 --> 00:35:18.516 nice. Get rid of the noise. That resulted in some more bugs. You 00:35:18.516 --> 00:35:25.056 can see the first -- I guess that is a little inaccurate, the 00:35:25.056 --> 00:35:31.563 first four I found in the first round and the remaining -- is 00:35:31.563 --> 00:35:38.069 that five or six? Six. The other six came up during the second 00:35:38.069 --> 00:35:43.108 round in addition to all the references. They didn't get 00:35:43.108 --> 00:35:47.012 assigned CDs. So let's look at that issue we said we will look 00:35:47.012 --> 00:35:51.116 at again. Around a year ago, that put a fix into the 00:35:51.116 --> 00:35:55.954 [indiscernible] from the guys that did the fuzzing Intel. And 00:35:55.954 --> 00:36:01.292 they said [indiscernible] these two bugs. Looking closer, 5.0 is 00:36:01.292 --> 00:36:06.665 released, that is really interesting. So here is the new 00:36:06.665 --> 00:36:13.671 code, you can see they're -- math to a 64 bit unsigned image. 00:36:13.671 --> 00:36:20.111 That looks like it would be good, right? But is it? I 00:36:20.111 --> 00:36:26.584 thought this would be good. I thought this was good. We fixed 00:36:26.584 --> 00:36:33.058 that one. That is awesome. Let's keep going. When I was 00:36:33.058 --> 00:36:37.896 [indiscernible] found this crash over and over. I thought they 00:36:37.896 --> 00:36:44.903 fixed it. When you multiply a bunch of 32 bit images together 00:36:44.903 --> 00:36:52.644 -- 64 bit images, it does all the math first in a 32 bit way 00:36:52.644 --> 00:36:56.815 and then it just goes in and assigns the result to the 64 bit 00:36:56.815 --> 00:36:59.818 imager. There is no promotion happening at all just because of 00:36:59.818 --> 00:37:07.192 the assignment. I don't think I have the fix in here. The fix 00:37:07.192 --> 00:37:11.129 was basically just casting one of them to a 64 bit imager. It 00:37:11.129 --> 00:37:13.131 could have been the 2 or the [indiscernible] any of them. -- 00:37:13.131 --> 00:37:19.137 come look at this. It did look like it was fixed. 00:37:22.807 --> 00:37:29.447 Exploitability and I'm totally going to run out of time. Let's 00:37:29.447 --> 00:37:35.487 go faster -- result in memory corruption. These have been 00:37:35.487 --> 00:37:42.760 proven lots of times. Especially in -- code given they often have 00:37:42.760 --> 00:37:48.800 virtual function pointer tables and other things going on in 00:37:48.800 --> 00:37:54.839 memory. Some -- do come into play. And diversity although 00:37:54.839 --> 00:38:00.845 it's a barrier to research, it doesn't necessarily prevent a 00:38:00.845 --> 00:38:04.749 worm (ph.) which can build support for as many things as it 00:38:04.749 --> 00:38:09.053 knows about into itself. Media cap. In the frame of 00:38:09.053 --> 00:38:14.893 exploitation. We have a nit, that means two things. On the 00:38:14.893 --> 00:38:20.732 positive side this weakness that has been in android since the 00:38:20.732 --> 00:38:24.536 beginning is rare. Whereas as apps are created they have the 00:38:24.536 --> 00:38:31.276 same - at their birth. It does -- every time it crashes the 00:38:31.276 --> 00:38:37.348 address will be completely randomized again. But on the 00:38:37.348 --> 00:38:43.421 downside because it restarts whenever it crashes you can 00:38:43.421 --> 00:38:49.794 trigger whatever over and over and over again. Although that 00:38:49.794 --> 00:38:53.198 does depend on the attack factor. You can imagine some guy 00:38:53.198 --> 00:38:55.700 that is going to download your email attachments and look at 00:38:55.700 --> 00:38:58.903 them over and over again. He is going to get fed up. Is that 00:38:58.903 --> 00:39:06.344 word possible or "prossible". That is new. Another thing, 00:39:06.344 --> 00:39:13.084 [indiscernible] in media server. I send threads that look for 00:39:13.084 --> 00:39:19.090 binder events. They are coming from outside. Means there is a 00:39:21.326 --> 00:39:26.164 little bit of lack of determinism in the layout. So 00:39:26.164 --> 00:39:33.071 apart from -- even if not randomized the -- might get in 00:39:33.071 --> 00:39:40.178 the way because of a boundary. Android 5.0 I had in mitigation 00:39:40.178 --> 00:39:47.252 that most people were not aware of. The guys that make android 00:39:47.252 --> 00:39:54.926 were probably not aware of this. The code here in the top block, 00:39:54.926 --> 00:40:00.798 it's doing any number of elements of an array. 00:40:00.798 --> 00:40:05.403 [indiscernible] they finally added a way to catch this sort 00:40:05.403 --> 00:40:11.042 of problem where -- what happens intrinsically inside the 00:40:11.042 --> 00:40:16.748 compiler. I don't have the link now, but the work these guys did 00:40:16.748 --> 00:40:20.818 is a ticket that is almost ten years old. The compiler team at 00:40:20.818 --> 00:40:24.989 android [indiscernible] maybe because it matched but they 00:40:24.989 --> 00:40:31.796 decided to do that. Let's have a break down of the big important 00:40:31.796 --> 00:40:36.000 mitigation that android applied to Stagefright. This doesn't 00:40:36.000 --> 00:40:39.737 come into effect unless you're in. It may limit you from what 00:40:39.737 --> 00:40:45.743 you can talk to (muffled) talk to the audio driver. Stack of 00:40:48.613 --> 00:40:52.550 these completely, there is not stack corruption going on. 00:40:52.550 --> 00:40:57.522 Dynamic allocation. ASR, as we said only applies, we have 00:40:57.522 --> 00:41:01.592 another ten minutes? I thought that was GTFO? Let's just keep 00:41:01.592 --> 00:41:07.598 going. You just drive me off when you're ready? >> What we're 00:41:12.170 --> 00:41:18.176 attempting to do is hold this - a little bit longer. >> I'm 00:41:23.614 --> 00:41:29.620 almost done. >> Well take some questions. >> I want to do a 00:41:33.791 --> 00:41:38.830 demo first, though. >> All right. >> NX is not a big deal. 00:41:38.830 --> 00:41:44.402 You can pass over it. Newer versions, it's still possible to 00:41:44.402 --> 00:41:49.941 by pass. It requires circle guessing or might require you to 00:41:49.941 --> 00:41:55.480 do neat tricks because it's only a 30 bit layout. Exploitability, 00:41:55.480 --> 00:42:00.018 definitely on old versions, badly on old versions. Newer 00:42:00.018 --> 00:42:06.524 versions I think it's do able and I want to spend more time 00:42:06.524 --> 00:42:13.097 with it but I don't have time because I'm speaking to you guys 00:42:13.097 --> 00:42:19.137 out of state. I think I have somewhere on this computer a 00:42:19.137 --> 00:42:25.710 window that has stuff in it. Not the cat window. Let's try this 00:42:25.710 --> 00:42:30.948 one. Can you guys read that in the back, the text? Or do I need 00:42:30.948 --> 00:42:36.954 to make it bigger. I got a thumbs up for negative 3. Make 00:42:39.090 --> 00:42:43.828 it bigger, boom, boom, boom, is that good enough? All right. 00:42:43.828 --> 00:42:50.368 Where is my mouse, it's on the wrong screen. I don't know if 00:42:50.368 --> 00:42:58.309 this is going to work. Black cat, I did not do a live demo 00:42:58.309 --> 00:43:04.582 but let's try it. We have the device right here. I'm deleting 00:43:04.582 --> 00:43:08.286 the messages I sent myself in the speaker room. I'm going to 00:43:08.286 --> 00:43:13.691 leave the screen on here and I think we'll run this exploit 00:43:13.691 --> 00:43:18.763 just like this. One point of importance is this attack right 00:43:18.763 --> 00:43:24.969 now is not going over the network. It's a violation of the 00:43:24.969 --> 00:43:28.739 end-user license agreement in terms of conditions that you can 00:43:28.739 --> 00:43:33.811 use the network. This is going over a tool chain basically that 00:43:33.811 --> 00:43:37.181 allows me to pretend like messages are coming in from the 00:43:37.181 --> 00:43:44.355 carrier network and host my own MMC server. Let's run it. This 00:43:44.355 --> 00:43:50.361 is a 2 Meg video file. It sends it down this channel. I don't 00:43:53.865 --> 00:43:59.036 know, you probably can't see this and I'm looking like an 00:43:59.036 --> 00:44:03.474 idiot over here. I didn't get any messages yet, either. That 00:44:03.474 --> 00:44:07.712 is why we don't do live demos. Because people show up to your 00:44:07.712 --> 00:44:13.718 talk and bring something like web based stations. I still 00:44:16.721 --> 00:44:18.789 haven't gotten a message yet but I see it transferring. It's 00:44:18.789 --> 00:44:24.795 tricky to show you both screens at the same time. Open what? I 00:44:33.104 --> 00:44:39.110 think I have something -- get user media. If you can't see 00:44:45.516 --> 00:44:50.054 down there. I still haven't got a message. I think we're going 00:44:50.054 --> 00:44:52.757 to go back to the video because this is retarded. I'm 00:44:52.757 --> 00:44:59.196 disappointed because this works like every time. Except for 00:44:59.196 --> 00:45:05.570 right now because of whatever reason it's prevented from 00:45:05.570 --> 00:45:09.607 working. Looks like a network issue. Let's play a video. It 00:45:09.607 --> 00:45:17.615 will be more fun and it has cool music by Archie Varteck (ph.). 00:45:17.615 --> 00:45:23.621 This is just to show you there is no indication. Thank you. So 00:45:42.006 --> 00:45:48.012 also on the screens, the device goes very slow. [indiscernible]. 00:46:00.725 --> 00:46:06.731 That's the thing about devices, they're easy to exploit and they 00:46:11.335 --> 00:46:17.341 also are full of old bugs. I don't know how to do this. You 00:46:42.833 --> 00:46:48.839 booing me off stage now? I do have a couple more slides but 00:47:10.328 --> 00:47:16.333 I'll do this. >> Do not go out the side door. Go out the 00:47:30.014 --> 00:47:32.016 back.Go out the back, not the side. >> Don't go out the side, 00:47:32.016 --> 00:47:34.018 please. >> I hope you guys get an update soon.