00:00:00.000 --> 00:00:06.006 (muffled audio) these were not imagined patterns. The mind -- 00:00:20.187 --> 00:00:24.291 this was something real. Something alien in its 00:00:24.291 --> 00:00:30.297 simplicity. (muffled) were there others who observed this -- 00:00:40.340 --> 00:00:46.346 stickiness. Able to untangle this perplexity. Understood this 00:00:54.588 --> 00:01:00.527 cipher that -- was around this key. [indiscernible]. This must 00:01:12.372 --> 00:01:18.378 be some kind of ... >> Like I said. All right. 00:01:25.485 --> 00:01:31.024 ...(applause)... >> Good morning, everyone. Welcome to 00:01:31.024 --> 00:01:36.263 DEFCON 20, fucking 3. Really? That's it. In the interest of 00:01:36.263 --> 00:01:42.402 time I'm going to kick it off. That cut the presentations to 45 00:01:42.402 --> 00:01:46.707 minutes now not an hour. When he is done, I'm going to escort him 00:01:46.707 --> 00:01:49.576 out. There are no Q and A rooms. With that, have a great 00:01:49.576 --> 00:01:55.582 presentation. >> Okay. Hi, everybody. I hope you enjoyed 00:02:13.934 --> 00:02:19.940 DEFCON. Okay. A question, do you play computer games? Yeah, okay. 00:02:22.876 --> 00:02:26.546 And there is a few who play computer games, have you ever 00:02:26.546 --> 00:02:31.118 thought about getting hacked by the games you play? I am to mas 00:02:31.118 --> 00:02:36.990 and I'm going to talk about that. There is a security camera 00:02:36.990 --> 00:02:44.631 here and if you don't want you face to show up on the screen, 00:02:44.631 --> 00:02:47.634 maybe you should sit back further or hide your face when 00:02:47.634 --> 00:02:55.575 the time comes. That's sad. Myself, my name is Tamas 00:02:55.575 --> 00:02:57.577 Szakaly. I'm from Hungry and I work for a security company 00:02:57.577 --> 00:02:59.579 called PR-Audit. I formed the European championship of global 00:02:59.579 --> 00:03:01.515 [indiscernible] and I'm not sure what is happening with the 00:03:01.515 --> 00:03:03.517 slides. They are ... Changing automatically. Okay. So what am 00:03:03.517 --> 00:03:05.519 I? My favorite quote from my favorite movie summarizes this 00:03:05.519 --> 00:03:07.521 quite well. I am not a computer nerd, I prefer to be called a 00:03:07.521 --> 00:03:09.856 hacker. And I do [indiscernible] executeables, I love tinkering 00:03:09.856 --> 00:03:12.759 with copy protection schemes. I just to -- but I just have to 00:03:12.759 --> 00:03:15.228 say this, I very, very much professor Q demon, half eaten 00:03:15.228 --> 00:03:17.898 fruits and places of glass in wooden frames. With that I have 00:03:17.898 --> 00:03:20.133 to make a confession. I'm sorry, guys. Slides are changing 00:03:20.133 --> 00:03:22.169 automatically. Something I fucked up with the PowerPoint, I 00:03:22.169 --> 00:03:25.305 think. Okay. So the confession, I was for years and I am in love 00:03:25.305 --> 00:03:27.741 with the -- API. It can be so disgustingly beautiful. 00:03:27.741 --> 00:03:32.712 [indiscernible] later on. Okay. So now they are not changing, 00:03:32.712 --> 00:03:38.718 wow. Okay. Games and game modeling. Since I'm talking to a 00:03:52.532 --> 00:03:58.538 room full of -- I'm sure I don't have to tell you about the urge 00:04:49.089 --> 00:04:55.095 to make things better, enhance your own ideas. And game 00:05:07.340 --> 00:05:11.778 modeling is the same principle. You have the framework, the game 00:05:11.778 --> 00:05:17.684 and you just have to create something of it. And you also 00:05:17.684 --> 00:05:23.723 have to share it with others. This is why -- will always play 00:05:23.723 --> 00:05:30.931 a big part in gaming. You can applaud your creation and others 00:05:30.931 --> 00:05:37.003 can download and play them. Game security. One important aspect 00:05:37.003 --> 00:05:41.441 of this is player gaming. Nobody likes to play alone. Nearly all 00:05:41.441 --> 00:05:45.712 games have some sort of multiplayer fashionability. What 00:05:45.712 --> 00:05:50.450 this means from a security standpoint? It means there is a 00:05:50.450 --> 00:05:55.188 constant exchange between the clients and the server and this 00:05:55.188 --> 00:06:02.796 data can be quite complex like whole maps. Also they often used 00:06:02.796 --> 00:06:07.367 -- protocols. And you should realize this is a 00:06:07.367 --> 00:06:09.369 [indiscernible]. It is indeed worth (audio blipped) games. 00:06:09.369 --> 00:06:11.471 They have talked about zero -- in game (audio blipped). But I'm 00:06:11.471 --> 00:06:14.274 in the going to talk about those games. I'm going to talk about 00:06:14.274 --> 00:06:17.177 scripting in games. There are lots and lots of games that 00:06:17.177 --> 00:06:22.382 incorporate scripting language or existing languages. Why do 00:06:22.382 --> 00:06:27.621 they do this? They do this because it makes creating 00:06:27.621 --> 00:06:32.993 dynamic content easier. The other part of this is these 00:06:32.993 --> 00:06:36.496 scripting -- are available to modelers. Could this be really 00:06:36.496 --> 00:06:39.366 dangerous? Stop right here for a moment and think about it. You 00:06:39.366 --> 00:06:41.368 as a game creator, create a mode or map and incorporate some 00:06:41.368 --> 00:06:43.370 scripts in it. The player downloads the map or joins a 00:06:43.370 --> 00:06:45.372 server and the map gets downloaded automatically to his 00:06:45.372 --> 00:06:47.374 machine. And eventually that script you put in there will be 00:06:47.374 --> 00:06:49.376 run on his machine. Okay? So most of the game developers 00:06:49.376 --> 00:06:51.378 realize this can be a trap. So they try to do something nasty, 00:06:51.378 --> 00:06:53.380 and try to restrict functionality and implement 00:06:53.380 --> 00:06:55.382 sandboxes. But often do this wrongly, they fail. Okay. If 00:06:55.382 --> 00:06:57.384 this kind of -- are done, I'm not the first one to realize 00:06:57.384 --> 00:06:59.386 this and I'm not. There are lots and lots of references on the 00:06:59.386 --> 00:07:01.321 internet involving exploiting scripting in games. In fact, in 00:07:01.321 --> 00:07:03.323 2014 there were several exploits that got huge gaming media 00:07:03.323 --> 00:07:05.325 coverage. If this is this common, why am I talking about 00:07:05.325 --> 00:07:07.327 this? Why am I talking at DEFCON? Because these scripting 00:07:07.327 --> 00:07:09.329 -- are used to [indiscernible] but they can be used to access 00:07:09.329 --> 00:07:15.101 your computer and through your computer they can be used to 00:07:15.101 --> 00:07:20.373 access your entire home network. Like your security cameras, your 00:07:20.373 --> 00:07:23.843 smart house components and stuff like that. And nobody seems to 00:07:23.843 --> 00:07:31.418 talk about this kind of stuff. Okay. So what are some of the 00:07:31.418 --> 00:07:35.088 demons that are abusing scripting engines and games. My 00:07:35.088 --> 00:07:42.929 first [indiscernible] and the -- game. Remember when I said that 00:07:42.929 --> 00:07:45.332 most of the game developers realize that scripting can be a 00:07:45.332 --> 00:07:47.534 threat. Well Crytech isn't one of them. They seem to realize 00:07:47.534 --> 00:07:49.536 resistant since they didn't implement sandboxes (audio 00:07:49.536 --> 00:07:51.771 blipped). -- with the -- and I'm going to show you this using a 00:07:51.771 --> 00:07:53.973 crisis 2 (ph.) mode that I created. Just one moment. Okay. 00:07:53.973 --> 00:07:59.980 It's loading. And I'm sure that at least some of you have 00:10:09.876 --> 00:10:15.415 thought about hacking something by the push of a big red button. 00:10:15.415 --> 00:10:21.488 But we're going to do that now. And just put down the -- so 00:10:21.488 --> 00:10:27.460 we're here on this deserted island and we have a big red 00:10:27.460 --> 00:10:34.000 button. Wonder what it does. I'm just going to push it and yeah 00:10:34.000 --> 00:10:40.006 ... Thank you, guys. Okay. How did I do that? In CryEngine 3 00:10:48.047 --> 00:10:52.552 every object that can be used -- I'm going to -- okay. So every 00:10:52.552 --> 00:10:58.558 object has a USB attached to it and here you can see the bigger 00:11:03.229 --> 00:11:06.799 buttons and this is -- handler and you can see that it's just 00:11:06.799 --> 00:11:12.805 an order to execute and blah, blah, blah things. I can't 00:11:19.846 --> 00:11:25.852 really see ... Sorry. Okay. So that's how you can executes via 00:11:36.396 --> 00:11:41.234 a crisis 2 map on a player's machine. One thing, what was 00:11:41.234 --> 00:11:46.639 that backslash backslash hashtag thing, that is one of the 00:11:46.639 --> 00:11:52.645 reasons I love the API. Every function that use (inaudible) 00:12:06.125 --> 00:12:08.127 can accept -- if your team can accept a windows [indiscernible] 00:12:08.127 --> 00:12:11.397 control, you have the chance to load DLS or load executable 00:12:11.397 --> 00:12:14.867 files from that remote share and you don't have to write share 00:12:14.867 --> 00:12:20.707 code. You just have to use the share. And this has one nice 00:12:20.707 --> 00:12:27.046 side effect, you can steal -- responses if you can load a 00:12:27.046 --> 00:12:32.952 file. If you can get to load a file. I'm going to show you this 00:12:32.952 --> 00:12:36.589 -- CryEngine 3SDK which is much newer version of CryEngine 3 00:12:36.589 --> 00:12:42.595 than the one used in crisis 2. And I have this [indiscernible] 00:12:45.798 --> 00:12:51.804 server set up here. And this is the same button with different 00:12:57.577 --> 00:13:03.216 code. It just tries to access a file from the share. Okay. Jump 00:13:03.216 --> 00:13:09.222 into the game. And push button. Okay. Now I push button and you 00:13:17.030 --> 00:13:22.235 can see on the server that there is indeed my NTL (ph.) challenge 00:13:22.235 --> 00:13:28.241 response. It's a nice trick, I think. Okay. Moving on. But 00:13:38.418 --> 00:13:44.057 before moving on, we are at slide No. [indiscernible] and I 00:13:44.057 --> 00:13:50.063 am personally not a believer in the -- but maybe the daemon gods 00:13:53.866 --> 00:14:01.407 are. So this -- [indiscernible]. So my next game is Dota2. It 00:14:01.407 --> 00:14:09.115 uses a scripting engine but it has a sandbox. But that sandbox 00:14:09.115 --> 00:14:15.888 is leaky and it in fact has a huge leak. We can use the entire 00:14:15.888 --> 00:14:21.127 standard -- library. You can read files and write files. What 00:14:21.127 --> 00:14:24.764 this means? You can steal information, you can deploy 00:14:24.764 --> 00:14:29.469 stuff or just use the anti-stealing trick I just 00:14:29.469 --> 00:14:37.410 showed you. Or you can overwrite executeables and I'm going to 00:14:37.410 --> 00:14:42.548 show you this in a video because -- sorry -- because again, it's 00:14:42.548 --> 00:14:48.554 not working. It stopped working a few days ago. Okay. That's the 00:14:58.231 --> 00:15:04.170 video. Sorry. I can't really see that. Okay. In this video I'm 00:15:06.639 --> 00:15:13.146 going to show you a Dota2 mode where I attached a -- script to 00:15:13.146 --> 00:15:19.152 the NPCs (ph.) handler. So when the NPC is found my code will 00:15:22.855 --> 00:15:28.861 run and this code will decode a base 64 encoded executable and 00:15:32.064 --> 00:15:37.069 over-right the Dota2 main executable. The next time the 00:15:37.069 --> 00:15:43.810 gamer starts the game, it won't be the game that starts, but it 00:15:43.810 --> 00:15:49.816 will be our executable. Okay? So it's just loading the map. Takes 00:15:53.386 --> 00:15:59.392 a few seconds. I'm just ... Commands and you will see the 00:16:05.398 --> 00:16:11.404 game freezes a bit. It encodes the base 64 executable and 00:16:14.507 --> 00:16:20.379 shortly you will see that, yeah, it got overwritten. You can see 00:16:20.379 --> 00:16:27.687 the size difference there. And it will try to start the game, 00:16:27.687 --> 00:16:34.293 it will be the industry standard exploit -- tool. Thanks. I'm 00:16:34.293 --> 00:16:40.299 sorry. There's something wrong. PowerPoint. Okay. I will just do 00:16:48.941 --> 00:16:54.947 this this way. My next, surprise, surprise it's a script 00:17:02.855 --> 00:17:08.861 able game called digital combat simulator. A flight simulator. 00:17:15.401 --> 00:17:21.407 In fact this was the first game I found some script abuse in. I 00:17:23.910 --> 00:17:27.413 reported it to eagle dynamics and they fixed it and then I 00:17:27.413 --> 00:17:32.852 found another one that I am going to show you. Or rather I'm 00:17:32.852 --> 00:17:39.158 going to ask you if you can find the fault. On the screen you can 00:17:39.158 --> 00:17:45.898 see the entire sandbox implementation of DCS. Where is 00:17:45.898 --> 00:17:51.604 the leak? Where did the -- dynamics fuck up? You can win 00:17:51.604 --> 00:17:58.911 this fine bottle of Hungarian [indiscernible] if you know the 00:17:58.911 --> 00:18:04.183 answer. Nobody? Nobody speaks fluent? Then I'm just going to 00:18:04.183 --> 00:18:11.791 show you, it's on the 24th line. It's this line. They try to 00:18:11.791 --> 00:18:17.263 disable loading -- [indiscernible] it shouldn't be 00:18:17.263 --> 00:18:23.269 loading. It is nothing in itself. That was the fault. Now, 00:18:27.206 --> 00:18:32.111 if you could tell me the answer, I've prepared some back up 00:18:32.111 --> 00:18:37.316 questions. First one being the title of this talk is a quote. 00:18:37.316 --> 00:18:43.322 Who asked that question? I'm sure this is a right answer. But 00:18:47.760 --> 00:18:53.766 I was thinking about Joshua from War Games. That's embarrassing, 00:19:00.339 --> 00:19:06.345 you were right. I don't know whoever answered first, but yes, 00:19:10.750 --> 00:19:16.856 you should find me after the talk, okay? And have your 00:19:16.856 --> 00:19:23.162 [indiscernible]. I just skipped my second back up question which 00:19:23.162 --> 00:19:29.702 is what is my favorite movie. Jurassic Park that was a quote 00:19:29.702 --> 00:19:35.708 from it. -- lots of exploits start out as crashes. This one 00:19:45.818 --> 00:19:53.692 will be a different crash. I created a mission in this flight 00:19:53.692 --> 00:19:59.698 simulator where I attached a script to the plane crash. This 00:20:04.003 --> 00:20:10.009 script does one thing. It [indiscernible] from a remote 00:20:12.411 --> 00:20:18.417 share. Let's start the game. Okay. Sorry, it's loading. I 00:20:21.787 --> 00:20:27.793 couldn't load all my games because I have only 8 gigs of 00:20:32.998 --> 00:20:39.004 RAM. It's loading ... Yeah. Okay. I am going to jump into 00:20:43.676 --> 00:20:49.682 the cockpit of a ... That should be a [indiscernible] popping up. 00:21:02.995 --> 00:21:06.065 But yeah it's under the... Under everything. That was it. Sorry. 00:21:12.404 --> 00:21:15.608 I don't want to take any more time. But yes, that popped up. 00:21:15.608 --> 00:21:21.614 You should believe me. Okay. So my next is a bit different. It's 00:21:28.087 --> 00:21:34.093 different by two reasons. This one won't abuse a scripting but 00:21:37.696 --> 00:21:43.702 it will abuse a dangerous and not without feature in a game 00:21:48.340 --> 00:21:53.078 and also this time the gamer will be the bad guy. So we will 00:21:53.078 --> 00:22:00.719 attack the server. The game is ARMA sword. It's a military 00:22:00.719 --> 00:22:06.725 game. You can set up your name and logo and website and so on. 00:22:10.062 --> 00:22:14.433 Every time you join the server, this information will get 00:22:14.433 --> 00:22:19.572 displayed not just for you but for everyone on that server. And 00:22:19.572 --> 00:22:24.510 how do this work? In your profile you can set up a -- that 00:22:24.510 --> 00:22:30.683 points to an XML file and every time you join the server it will 00:22:30.683 --> 00:22:36.755 look for the XML file and parse your information from there. 00:22:36.755 --> 00:22:41.594 When I first read about this, I was like, this is got to be an 00:22:41.594 --> 00:22:44.797 [indiscernible] I'm sure of it. And it wasn't. But not to worry. 00:22:44.797 --> 00:22:50.803 It's still an SRF (ph.) and I am going to show you this. This 00:22:55.374 --> 00:22:59.445 daemon was based on real life experiences that was -- on the 00:22:59.445 --> 00:23:06.118 server. And he also had a PHP charge server on the same 00:23:06.118 --> 00:23:10.222 machine, a PHP charge server that was only accessible from 00:23:10.222 --> 00:23:16.228 the local host. This is a PHP charge server. And PHP charge is 00:23:20.065 --> 00:23:24.203 vulnerable to RCE that can be triggered by a [indiscernible]. 00:23:24.203 --> 00:23:30.209 What I'm going to do is edit my ... Oh, jeez ... My profile. And 00:23:32.411 --> 00:23:38.417 set up a URL that triggers the PHP charge exploit. So when I 00:23:47.826 --> 00:23:53.832 join the server, okay, I can't really see it, sorry. Which one 00:24:00.906 --> 00:24:06.912 is multiplayer? This one? Okay. Thanks. Sorry. Okay. So just put 00:24:15.888 --> 00:24:19.591 a bit away because I will have ... [indiscernible] since the 00:24:19.591 --> 00:24:23.028 PHP charge will trigger a [indiscernible] as soon as I 00:24:23.028 --> 00:24:26.899 join the server. It's working. It's trying to join the server. 00:24:26.899 --> 00:24:32.905 It's a bit slow since there are several games running on the 00:24:42.581 --> 00:24:48.587 same machine. And yes, we've got a connection. And this is a 00:24:50.756 --> 00:24:56.762 shell, you can see ID, name, so, yes, we have just executed code 00:24:59.198 --> 00:25:05.137 on a server. And I will... This was a [indiscernible] that we 00:25:17.216 --> 00:25:21.320 didn't see the answer to. There are games where you can -- that 00:25:21.320 --> 00:25:27.993 you can see the answer to, too. And one of these games is 00:25:27.993 --> 00:25:33.832 Garry's Mod. You may remember that I talked about Garry's Mod. 00:25:33.832 --> 00:25:39.505 It had its share of related exploits in the past and this 00:25:39.505 --> 00:25:46.612 resulted in a pretty solid sandbox. Garry did fix a lot of 00:25:46.612 --> 00:25:51.583 things. But it has also a huge API. There are lots and lots of 00:25:51.583 --> 00:25:56.955 functions and yeah, there are some dangerous functions, too, 00:25:56.955 --> 00:26:04.730 like this one. There is an HTTP function and it uses this 00:26:04.730 --> 00:26:08.867 structure. As you can see this is a Screenshot from the 00:26:08.867 --> 00:26:14.807 documentation, you can see you can control every aspect of an 00:26:14.807 --> 00:26:18.143 HTTP. You can account for the metals and the headers and so 00:26:18.143 --> 00:26:20.345 on. What this means? If you create a map or mode or server 00:26:20.345 --> 00:26:26.351 in Garry's mod. You can have a full fledged HTTP proxy to the 00:26:30.956 --> 00:26:36.962 gamer's home network. Yeah, I'm going to show you that with a 00:26:39.097 --> 00:26:46.705 Garry's mod mode I created. I have implemented three 00:26:46.705 --> 00:26:52.044 [indiscernible] commands that only superadministrators can 00:26:52.044 --> 00:26:58.050 use. One of them is ACK scam players. I -- as a 00:27:02.121 --> 00:27:05.591 superadministrator will issue this command and it will -- all 00:27:05.591 --> 00:27:10.963 player's networks at home for [indiscernible] servers. And 00:27:10.963 --> 00:27:17.436 hopefully it will find this camera here. Yes, it did. You 00:27:17.436 --> 00:27:23.442 can see it's an authorized access on that IP address. I'm 00:27:26.211 --> 00:27:30.582 just going to switch to duplicate. Sorry about that. But 00:27:30.582 --> 00:27:36.588 I can't see anything. Okay. Now my -- command is used to brute 00:27:43.161 --> 00:27:48.567 force an HTTP basic authentication server. So we 00:27:48.567 --> 00:27:54.573 just are going to put the user ID and the HTTP server's address 00:27:58.243 --> 00:28:05.984 here as parameters and we can see that it tries a few user 00:28:05.984 --> 00:28:10.522 name/password combos and it finds that the user name and 00:28:10.522 --> 00:28:16.228 password are admin admin. We have the user name and password 00:28:16.228 --> 00:28:20.933 for this camera here, now we can steal images through the game. 00:28:20.933 --> 00:28:26.939 This is what my third consult command is used for. It also 00:28:30.108 --> 00:28:36.114 requires the user ID to know who to [indiscernible]. It requires 00:28:46.291 --> 00:28:53.999 a URL. This URL can be from the HTTP server response. It could 00:28:53.999 --> 00:29:01.940 be brute force but I didn't have the time for it. So when I issue 00:29:01.940 --> 00:29:09.615 the command, it should -- okay. It's working. Okay. It's 00:29:09.615 --> 00:29:14.820 received the image and yeah, here you are on the screen 00:29:14.820 --> 00:29:20.826 inside the game. Thanks. Okay. My final daemon, you should be 00:29:30.602 --> 00:29:33.839 afraid of mice. And we're not talking about those two guys 00:29:33.839 --> 00:29:39.111 although they can be dangerous, too. I'm talking about this one. 00:29:39.111 --> 00:29:43.181 I don't know if you can see this. This is a G whatever mouse 00:29:43.181 --> 00:29:45.817 and like all Logitech it's [indiscernible] by the software. 00:29:45.817 --> 00:29:51.823 This code runs in a very, very tight sandbox. But it still can 00:29:54.192 --> 00:30:00.198 be certain -- by a guy named Corsix (ph.) and his company of 00:30:10.208 --> 00:30:16.214 heros [indiscernible]. He abused -- to achieve two tricks. The 00:30:19.718 --> 00:30:25.991 first trick is to get any -- get the memory address of any 00:30:25.991 --> 00:30:33.365 variables. The second one being able to create variables that 00:30:33.365 --> 00:30:37.469 points to arbitrary memory locations. These two tricks 00:30:37.469 --> 00:30:45.444 combined leads to arbitrary -- that leads to code execution. 00:30:45.444 --> 00:30:49.881 How did he do these two tricks? The first trick, in lieu of 00:30:49.881 --> 00:30:55.887 every variable is a T value. T value is a -- that stores the 00:31:00.158 --> 00:31:06.998 actual value in its first 8 bytes. In case of a real number, 00:31:06.998 --> 00:31:12.804 that first 8 bytes is double and in case of any other variables 00:31:12.804 --> 00:31:17.542 it's pointed to a structure. For example for a -- string it's a T 00:31:17.542 --> 00:31:24.483 string pointer. If you can get [indiscernible] to for example a 00:31:24.483 --> 00:31:31.356 string as a number, then we can get that pointer with memory 00:31:31.356 --> 00:31:39.331 address. And of course it did exactly that. It used a four 00:31:39.331 --> 00:31:47.339 loop and up code is responsible for every parameter of the for 00:31:47.339 --> 00:31:54.880 loop is a number. We know the second code just assumed they 00:31:54.880 --> 00:31:59.451 are numbers. So they get [indiscernible] numbers and 00:31:59.451 --> 00:32:05.724 that's how you get memory addresses as doubles. Okay? So 00:32:05.724 --> 00:32:10.796 the second trick, it's a bit trickier. And it's done 00:32:10.796 --> 00:32:15.333 basically in these two lines. And I'm going to go through it 00:32:15.333 --> 00:32:21.072 line by line. Okay. [indiscernible] are entities 00:32:21.072 --> 00:32:26.111 that belong to functions and they represent function 00:32:26.111 --> 00:32:30.649 parameters or variables that are declared outside of the scope of 00:32:30.649 --> 00:32:33.084 the function. So we create a stream that looks like -- a 00:32:33.084 --> 00:32:36.087 value. We have a chunk of memory that can be -- of that value. An 00:32:36.087 --> 00:32:38.323 up value that points to the memory location, this end thing 00:32:38.323 --> 00:32:40.926 here. Second line. We want the address of that memory chunk. So 00:32:40.926 --> 00:32:43.762 we get the address of the string but because the [indiscernible] 00:32:43.762 --> 00:32:49.768 string is a T string structure, we're going to need to add 24 00:32:52.504 --> 00:32:58.510 bytes to it. Because the first 24 bytes of the T string 00:33:00.512 --> 00:33:05.750 structure is just mass data. So now we get the memory -- address 00:33:05.750 --> 00:33:11.756 in PTR. So next step. We modify the byte code by hand. So that 00:33:15.093 --> 00:33:21.099 the variable magic will point to -- will be -- ...(foreign 00:33:23.201 --> 00:33:29.107 word)... representing LUA functions (ph.). We set up 00:33:29.107 --> 00:33:36.481 magic's value by concatenating the PTR string three times. So 00:33:36.481 --> 00:33:42.487 magic is a string. When it gets - as a closure, you can see on 00:33:47.559 --> 00:33:53.565 the bottom part of the slide, corrector 16 to 24 will be the 00:33:56.034 --> 00:33:58.036 closures up fast. It's an array of pointers. Since those 00:33:58.036 --> 00:33:59.971 correctors are indeed -- we set the outer functions. First up 00:33:59.971 --> 00:34:01.973 value to point to our memory address. The memory address you 00:34:01.973 --> 00:34:03.975 want to read or write. And because the first 00:34:03.975 --> 00:34:05.977 [indiscernible] value of that function is magic, we can access 00:34:05.977 --> 00:34:07.979 that memory address via magic. Okay? So how did Codex exploit 00:34:07.979 --> 00:34:09.981 this? It creates a C closure on the LUA. C closure is a LUA 00:34:09.981 --> 00:34:11.983 representation of a function pointer [indiscernible]. He then 00:34:11.983 --> 00:34:13.985 replaced this function pointer with a pointer to -- load which 00:34:13.985 --> 00:34:15.987 is also C closure function. And it's basically a wrap-around 00:34:15.987 --> 00:34:17.989 load library. So after that, when he code the core routine of 00:34:17.989 --> 00:34:19.991 the [indiscernible] as a parameter. He can load that -- 00:34:19.991 --> 00:34:21.993 [indiscernible] space of the game. What did I do differently? 00:34:21.993 --> 00:34:25.297 Keep in mind it's a 64 byte exploits and his was 32. What 00:34:25.297 --> 00:34:31.303 this means? It means that the layouts and -- packing is 00:34:34.706 --> 00:34:41.546 different. The coding conversions are different. So we 00:34:41.546 --> 00:34:47.552 can't modify function parameters as they are not -- in memory, 00:34:50.956 --> 00:34:56.962 they are not on the stack. They are passed as registers. The 00:35:01.166 --> 00:35:07.172 most important difference of this -- the most important thing 00:35:09.741 --> 00:35:15.747 of this 64 byte difference is that size of a double equals the 00:35:20.785 --> 00:35:24.389 size of a pointer. This makes this exploit a lot easier. Since 00:35:24.389 --> 00:35:26.391 you don't have to worry about the size difference by using the 00:35:26.391 --> 00:35:28.393 first trick. Okay? And I also couldn't call [indiscernible] 00:35:28.393 --> 00:35:30.395 since LL load lib is just the start when you have LUA as the 00:35:30.395 --> 00:35:32.397 start code. I have to -- functions directly. I have to 00:35:32.397 --> 00:35:34.399 find a useful native function that accepts one parameter that 00:35:34.399 --> 00:35:36.401 is a pointer. Load library is a good candidate since it accepts 00:35:36.401 --> 00:35:38.403 a string and -- execute would be, too. So we have to get load 00:35:38.403 --> 00:35:40.405 library's address. We have to replace -- with load library 8 00:35:40.405 --> 00:35:42.407 and override the [indiscernible] with the LUA8. This is because 00:35:42.407 --> 00:35:44.409 we can't modify the parameter itself, we have to modify the 00:35:44.409 --> 00:35:46.411 data that it points to. The pointer points to the LUA state 00:35:46.411 --> 00:35:48.413 so we have to over-right that. And we have to decode 00:35:48.413 --> 00:35:50.415 [indiscernible] and execute the load library. How to get the 00:35:50.415 --> 00:35:52.417 address of the [indiscernible]. It gives you back the state so 00:35:52.417 --> 00:35:54.419 that is easy. There were some -- I had to stop the garbage 00:35:54.419 --> 00:35:56.421 collector and I had to restore the UL state. And one of the 00:35:56.421 --> 00:35:58.423 questions remains how to get load library's address? The 00:35:58.423 --> 00:36:00.358 simple solution is to use the memory difference in the PD 00:36:00.358 --> 00:36:02.360 executable to calculate the load library address. There is much 00:36:02.360 --> 00:36:04.362 more generic solution, you can get and read the address of the 00:36:04.362 --> 00:36:06.364 empty header. From that you can have the import directories, you 00:36:06.364 --> 00:36:08.366 can search for -- [indiscernible] and you can have 00:36:08.366 --> 00:36:10.368 mode library's address from the import address table. All this 00:36:10.368 --> 00:36:12.370 with these two tricks. This is much much more generic and 00:36:12.370 --> 00:36:14.372 something like that can be used on other operating systems. With 00:36:14.372 --> 00:36:20.111 this approach there is a restriction, you can only 00:36:20.111 --> 00:36:26.117 overwrite 16 bytes of the LUA state. This is not really a 00:36:26.117 --> 00:36:32.123 problem since we can omit the DLL and load library will still 00:36:32.123 --> 00:36:38.329 find the DLL. If you use UNC pass, we have 9 characters for 00:36:38.329 --> 00:36:44.335 an IP address or a domain name. So it's not really a problem. 00:36:49.941 --> 00:36:55.947 Okay. I'm running out of time I think. So I'm just going to show 00:36:59.918 --> 00:37:05.857 you this -- here is the profile with the script. This is the 00:37:15.633 --> 00:37:21.639 script and it's attached to the middle mouse button. When I 00:37:33.985 --> 00:37:39.991 press the little mouse button, a cat appears. So we are at the 00:37:48.700 --> 00:37:51.469 end of my talk. One question, should we listen to Joshua and 00:37:51.469 --> 00:37:57.475 just stick to a nice game of chess? Of course. We should play 00:38:29.374 --> 00:38:35.380 computer games but we should be aware of these traps. And 00:39:18.823 --> 00:39:24.829 [indiscernible] those interlopers should pay more 00:39:39.477 --> 00:39:45.483 attention to this kind of stuff. Okay. This concludes my talk. 00:39:57.462 --> 00:40:03.468 Thank you very much for listening and have a good 00:40:10.775 --> 00:40:12.777 DEFCON.