00:00:00.067 --> 00:00:04.638 My name is Sean Pierce, this is abusing native shims for post 00:00:04.638 --> 00:00:10.644 exploitation. Good morning, there is more people here than I 00:00:12.779 --> 00:00:17.050 thought there would be. I'm going to assume everyone is hung 00:00:17.050 --> 00:00:23.056 over. So about me. I'm Sean, I have a CISSP and other certs. 00:00:27.461 --> 00:00:33.467 That is my Twitter handle. GitHub and STB dot tools and 00:00:35.469 --> 00:00:43.310 sites that I can control. Just as a disclaimer. I'm not a 00:00:43.310 --> 00:00:50.584 pentester, not a developer, not an iSIGHT representative. Why am 00:00:50.584 --> 00:00:56.590 I using their slides? They look really nice. To that point I 00:01:01.628 --> 00:01:05.766 just want to say that I love who I work for and there is just a 00:01:05.766 --> 00:01:11.972 bunch of great people there and really smart. And I cannot say 00:01:11.972 --> 00:01:15.909 enough good things about them. If you want to know more about 00:01:15.909 --> 00:01:21.848 them, that is their website. Why am I here? When I was 21 my dad 00:01:21.848 --> 00:01:26.153 took me to Las Vegas and we were at the Rio buffet and he said 00:01:26.153 --> 00:01:29.489 what do you want to do today. And I saw someone walk by with a 00:01:29.489 --> 00:01:36.463 BlackHat bag. I said is this going on now, he said no, but 00:01:36.463 --> 00:01:44.137 DEFCON is. So I snuck in. A lot of T-shirts and I met cool 00:01:44.137 --> 00:01:49.176 people and it encouraged me to get into this field. My dad 00:01:49.176 --> 00:01:55.182 passed away a few years ago, and I think he would be really proud 00:01:57.317 --> 00:02:01.521 that I'm giving this talk here today with y'all. He really is 00:02:01.521 --> 00:02:07.527 the reason why I'm here. Getting onto the talk. A bit of history 00:02:09.596 --> 00:02:12.866 behind application compatibility. It's funny and 00:02:12.866 --> 00:02:16.403 there's a reason why I think Microsoft has such a dominant 00:02:16.403 --> 00:02:20.841 place in the market. They go to so much effort to keep with 00:02:20.841 --> 00:02:24.644 application compatibility. An enormous amount of effort that 00:02:24.644 --> 00:02:31.518 you can't imagine. Just a simple case study, the original SIM 00:02:31.518 --> 00:02:38.091 city that ran on Windows 3.9 or whatever had a free 00:02:38.091 --> 00:02:42.929 [indiscernible] up to use bug. Free some memory. A free 00:02:42.929 --> 00:02:48.001 function. It says I'm done with this memory and still continue 00:02:48.001 --> 00:02:50.537 to use it. That is terrible. But lucky for it the old operating 00:02:50.537 --> 00:02:57.844 system didn't really use a lot of memory. Didn't have a lot of 00:02:57.844 --> 00:03:02.249 concurrent processes running and didn't take it back all that 00:03:02.249 --> 00:03:05.318 much. And in the new operating system, Windows 95 the operating 00:03:05.318 --> 00:03:07.320 manager was way more efficient and it would want memory all the 00:03:07.320 --> 00:03:13.326 time. This program would crash frequently. If you're a user and 00:03:17.330 --> 00:03:20.801 you install your old favorite game on a new operating system 00:03:20.801 --> 00:03:23.370 and it crashes all the time, you're going to blame the new 00:03:23.370 --> 00:03:29.476 operating system. Microsoft couldn't have this. The -- Def 00:03:29.476 --> 00:03:35.482 team drove down in his audio blipped and filled up with every 00:03:38.618 --> 00:03:40.620 -- he could buy and said everyone take at least three 00:03:40.620 --> 00:03:46.626 games and it has to work on Windows 95. Has to. They would 00:03:52.232 --> 00:03:56.503 hard code things into the operating system to watch for 00:03:56.503 --> 00:04:00.874 certain crappy code that was written by random people all 00:04:00.874 --> 00:04:03.877 over the world. And they would account for that in the 00:04:03.877 --> 00:04:10.050 operating system. Which is kind of terrible. It was what they 00:04:10.050 --> 00:04:14.087 needed to do to maintain such application compatibility. And 00:04:14.087 --> 00:04:16.289 there are other case stories and I encourage you to read the old 00:04:16.289 --> 00:04:19.593 new thing, the Windows developers and testers (audio 00:04:19.593 --> 00:04:25.065 blipped) put it into a book. And some stories are funny. One 00:04:25.065 --> 00:04:29.803 where the graphics card manufacturer wrote the driver 00:04:29.803 --> 00:04:33.039 and in the driver specifications, it says do you 00:04:33.039 --> 00:04:39.045 support this, return bull lean, true or source. And the 00:04:41.748 --> 00:04:47.020 manufacturer returned true for everything which is terrible. 00:04:47.020 --> 00:04:49.523 Because that is how the operating system determined if 00:04:49.523 --> 00:04:53.493 it should do something in hardware or software. Microsoft 00:04:53.493 --> 00:04:58.832 called them up and was like, hey, WTF, and they were like we 00:04:58.832 --> 00:05:03.303 don't care. Honestly we don't care. Even if we did, we would 00:05:03.303 --> 00:05:07.641 have no way to push out a patch. And even if we wanted to do 00:05:07.641 --> 00:05:10.110 that, that (audio blipped) we don't support that anymore and 00:05:10.110 --> 00:05:13.079 don't have the source code for it anymore. Which is apparently 00:05:13.079 --> 00:05:15.749 a common problem. Microsoft built their own database of what 00:05:15.749 --> 00:05:17.751 graphic card supported once and they hooked that function and 00:05:17.751 --> 00:05:19.753 did it all themselves. Microsoft goes to great lengths to make 00:05:19.753 --> 00:05:21.755 sure this still works. Not just for third-party bad code or dumb 00:05:21.755 --> 00:05:23.757 programmers, it's also for os bugs. Certain programmers leaned 00:05:23.757 --> 00:05:25.759 on certain features in the operating system such as this 00:05:25.759 --> 00:05:27.761 case study of synchronous buffer commit. When you call a right 00:05:27.761 --> 00:05:29.763 function and you think you're writing data to a disk, you're 00:05:29.763 --> 00:05:31.765 putting it to the buffer and the operating system will write 00:05:31.765 --> 00:05:33.767 things efficiently to the hard drive in batches or whatever. If 00:05:33.767 --> 00:05:35.769 you have a database program that is not good, because you have to 00:05:35.769 --> 00:05:37.771 guarantee that your file is in a certain state. Now, Windows had 00:05:37.771 --> 00:05:39.773 this function where it says right everything to this. Flush 00:05:39.773 --> 00:05:42.976 the buffer. Great. So they can guarantee it worked and 00:05:42.976 --> 00:05:49.783 developers loved this because it was efficient. (audio blipped) 00:05:49.783 --> 00:05:55.789 impact. And then they moved to like a newer version of the 00:05:58.859 --> 00:06:04.898 operating system, Windows 95 and they noticed the database 00:06:04.898 --> 00:06:10.170 program was going really, really slow. Turned out Microsoft never 00:06:10.170 --> 00:06:16.176 implemented that function. It doesn't do anything. When they 00:06:19.012 --> 00:06:25.018 thought they were flushing something to disk, it wasn't at 00:06:28.822 --> 00:06:34.828 all. Which is terrible. So what was Microsoft do with these 00:06:36.963 --> 00:06:42.969 programs that are running super-slow? They knock out the 00:06:58.351 --> 00:07:00.287 function again. Which is hill hilarious. This line where the 00:07:00.287 --> 00:07:06.293 operating system pretends or lies about something frequently 00:07:11.698 --> 00:07:17.370 happens between versions of Windows. Like Windows 7, that's 00:07:17.370 --> 00:07:22.575 the major version of 7. There are so many programs that had 00:07:22.575 --> 00:07:26.846 bugs and how it determined what version something was, they just 00:07:26.846 --> 00:07:31.551 called it Windows 6.1. Like that's the function call, what 00:07:31.551 --> 00:07:35.855 it returns is Windows 6.1 instead of 7. But they run on 00:07:35.855 --> 00:07:43.363 this fine but fail to run on Window's 7. They have a lot of 00:07:43.363 --> 00:07:49.069 lying when it comes to 64 bit or 32 bit apps running on 64 bit 00:07:49.069 --> 00:07:55.008 machines and I'll have examples in a bit. A while ago Microsoft 00:07:55.008 --> 00:07:59.579 tried to stop hard coding values into the operating system and 00:07:59.579 --> 00:08:03.316 started to bundle a bunch of stuff together. There are a few 00:08:03.316 --> 00:08:07.120 basic vocabulary words. A mode and shim. So a fix is one of 00:08:07.120 --> 00:08:09.155 these little things. This is if you right click on a program and 00:08:09.155 --> 00:08:11.157 go to properties and compatibility tab. Here you can 00:08:11.157 --> 00:08:13.159 say run as administrator or have a certain display setting. It 00:08:13.159 --> 00:08:15.161 does one little thing. A mode is a bunch of fixes bundled 00:08:15.161 --> 00:08:19.399 together. If you say compatibility mode here, then 00:08:19.399 --> 00:08:23.203 you say I wanted Windows XP, SP3 or this or that and you get a 00:08:32.379 --> 00:08:38.385 bunch of fixes that are already put together. And configurations 00:08:44.924 --> 00:08:52.766 are bundled together in what they call a shim database file 00:08:52.766 --> 00:08:57.804 or SDB file. What actually happens when a process is being 00:08:57.804 --> 00:09:01.674 shimmed? Some parent process will call a function like create 00:09:01.674 --> 00:09:05.578 process or execute, shell execute or something like that. 00:09:05.578 --> 00:09:10.183 And when it gets down the lower level API calls, the operating 00:09:10.183 --> 00:09:14.287 system and (inaudible) checks the registry to see if this 00:09:14.287 --> 00:09:17.657 process should be shimmed and sends an undocumented 00:09:17.657 --> 00:09:21.327 compatible, app come pat, maybe one underscore, and it will 00:09:21.327 --> 00:09:27.333 specify what it needs to do. The child process does a similar 00:09:30.303 --> 00:09:32.806 checking to make sure it shouldn't shim as well. So it 00:09:32.806 --> 00:09:38.812 typically works in that a table, a data structure in memory 00:09:42.348 --> 00:09:47.253 called the import address table holds all the addresses for the 00:09:47.253 --> 00:09:51.291 operating system function calls that that program is going to 00:09:51.291 --> 00:09:57.697 use. This is cool because -- including this route kit 00:09:57.697 --> 00:10:03.069 framework, compatibility framework, will use -- to hook 00:10:03.069 --> 00:10:07.373 in whatever it wants to manipulate. When I say "shim" 00:10:07.373 --> 00:10:10.577 I'm talking about the code that sits in between the import 00:10:10.577 --> 00:10:15.248 address table and the rest of Windows API. And they made great 00:10:15.248 --> 00:10:18.852 hooking libraries and told no one about it. If you dynamically 00:10:18.852 --> 00:10:20.920 load something, it hooks that too. The address label from one 00:10:20.920 --> 00:10:22.922 of the DLLs it does that too (audio blipped). Use for shims 00:10:22.922 --> 00:10:24.924 -- just for third party -- (audio blipped) a fix-it patch. 00:10:24.924 --> 00:10:26.926 If you are seeing exploit against your enterprise and you 00:10:26.926 --> 00:10:28.928 tell Microsoft and they're like okay, okay, we'll patch it come 00:10:28.928 --> 00:10:30.930 Tuesday. Patch Tuesday and a month, I can't wait for that, 00:10:30.930 --> 00:10:32.932 they give you a fix it. If you crack that open you'll see it's 00:10:32.932 --> 00:10:34.934 just a shim database file, SDB file with certain configurations 00:10:34.934 --> 00:10:36.936 and usually there is some patching information. A lot of 00:10:36.936 --> 00:10:38.938 times it's not a super-elegant fix but worse comes to worst, it 00:10:38.938 --> 00:10:40.940 will cause a memory leak or crash the process before it 00:10:40.940 --> 00:10:42.942 becomes exploited. EMIT, the enhanced -- experience tool kit 00:10:42.942 --> 00:10:44.944 uses shimming as well to get a process and either like up its 00:10:44.944 --> 00:10:46.946 security by saying you must enforce ALR or must enforce DLP 00:10:46.946 --> 00:10:48.948 ..(audio blipped)..like that. I want to introduce to you the 00:10:48.948 --> 00:10:50.950 tool that Microsoft released that lets us make our own shims. 00:10:50.950 --> 00:10:52.952 Called the application compatibility administrator. I 00:10:52.952 --> 00:10:54.954 want to show you a cool undocumented trick. The text is 00:10:54.954 --> 00:10:56.956 little small. You need to be an administrator to install the 00:10:56.956 --> 00:10:58.958 shim and I'll tell you why in a minute. Here I created a fix. I 00:10:58.958 --> 00:11:00.894 specified PuTTY dot EXE as the program I want to shim. Here is 00:11:00.894 --> 00:11:02.896 a file on disk. I'll tell you why in a minute it wanted the 00:11:02.896 --> 00:11:04.898 file. You'll see here that there's a BUN of fixes that 00:11:04.898 --> 00:11:06.900 Microsoft has already made, I'm sorry, modes. And they ..(audio 00:11:06.900 --> 00:11:08.902 blipped).. and that's cool of them. They provide 300 some odd 00:11:08.902 --> 00:11:10.904 fixes. Some of them API TRACER, API logger, read bios, reroute 00:11:10.904 --> 00:11:14.574 registry keys, reroute file pass. Fun stuff. If you go to 00:11:14.574 --> 00:11:18.912 where that program is and you open up a command line and then 00:11:18.912 --> 00:11:22.282 you run the app come pat or the application compatibility 00:11:22.282 --> 00:11:25.952 administrator from the command line with the option of slash X, 00:11:25.952 --> 00:11:29.956 everything will look normal and you go through the same sort of 00:11:29.956 --> 00:11:31.958 thing. And I specify that PuTTY should be my target program. Now 00:11:31.958 --> 00:11:38.331 you'll notice instead of like the 300 some odd fixes we now 00:11:38.331 --> 00:11:41.768 have 808. A lot of them are very specific, specific to a program. 00:11:41.768 --> 00:11:44.771 So you see adobe acro bat or Norton antivirus. It's fun to 00:11:44.771 --> 00:11:46.773 see how Microsoft was manipulating those particular 00:11:46.773 --> 00:11:48.775 processes. Now I just specified ..(audio blipped).. fixes called 00:11:48.775 --> 00:11:52.145 ELL. And as you can imagine it allows us to inject any 00:11:52.145 --> 00:11:55.648 arbitrary DLL into any process we choose and it runs with that 00:11:55.648 --> 00:11:58.585 process' rights. Here I'm specifying a DLL that I stored 00:11:58.585 --> 00:12:01.754 in the root directory. Now earlier I chose PuTTY. Say I 00:12:01.754 --> 00:12:04.123 want this executable. And ..(audio blipped).. why. Because 00:12:04.123 --> 00:12:07.927 it went and analyzed that file and said here is a check some. 00:12:07.927 --> 00:12:12.265 Here is a bunch of stuff I can trigger off of, compile time and 00:12:12.265 --> 00:12:15.635 all that. I can use that to trigger and execute my shim but 00:12:15.635 --> 00:12:20.807 I removed all those and said I just want to trigger off the 00:12:20.807 --> 00:12:25.578 name, PuTTY dot EXE. I have to save a shim database file 00:12:25.578 --> 00:12:28.214 beforehand. I specified the file name and I'm saving it to disk. 00:12:28.214 --> 00:12:34.220 I'm going to use a program called SBDINT. It's found on 00:13:36.049 --> 00:13:40.053 every Windows computer out there. Installing on the command 00:13:40.053 --> 00:13:44.057 line here. SBDINST. ..(audio blipped).. it will say installed 00:13:44.057 --> 00:13:48.494 successfully. >> Hang on a second. >> And then it's 00:13:48.494 --> 00:13:53.399 installed. Now every time I execute PuTTY -- >> Okay. >> 00:13:53.399 --> 00:13:59.172 Wait. >> Here is my DLL. >> Jesus I've never met a more 00:13:59.172 --> 00:14:05.344 grabby speaker in my life. >> I always run out of time in my 00:14:05.344 --> 00:14:11.117 practice talks. >> We have Mike on stage. He is a new attendee. 00:14:11.117 --> 00:14:16.456 He is representing all of you new attendees. How is he doing? 00:14:16.456 --> 00:14:21.794 I have one question for the crowd. What the fuck are you 00:14:21.794 --> 00:14:27.366 doing here at 10 a.m. on Sunday? You must be some kind of god or 00:14:27.366 --> 00:14:30.002 something. First time attendee, DEFCON. Thank you for coming. >> 00:14:30.002 --> 00:14:32.505 Anyways. >> Let's talk about PuTTY now. >> Also I really like 00:14:32.505 --> 00:14:35.441 more of a conversation, so if someone has more of a question, 00:14:35.441 --> 00:14:37.744 feel free to yell out. I do have to roll pretty fast on this. 00:14:37.744 --> 00:14:39.746 Okay. Everyone good on that. Just made a shim and installed 00:14:39.746 --> 00:14:42.682 it with Microsoft's tool. This is the public version of the 00:14:42.682 --> 00:14:44.984 tool. They have a private version that shows more 00:14:44.984 --> 00:14:46.986 information and gives more capability on a lot of things. 00:14:46.986 --> 00:14:49.122 I'll show you those things in a minute. One of the major ones is 00:14:49.122 --> 00:14:51.124 hot patching. This public tool has no awareness of hot 00:14:51.124 --> 00:14:53.126 patching. But in shim database files you can specify that 00:14:53.126 --> 00:14:55.128 something be hot patched. And that is powerful. So I said you 00:14:55.128 --> 00:14:57.130 need to be administrator and you only need to be administrator to 00:14:57.130 --> 00:14:59.132 write to two registry keys and that's all SBDINST did. I copied 00:14:59.132 --> 00:15:01.067 the SBD file on the desktop and dropped it into a Windows 00:15:01.067 --> 00:15:03.069 folder. I made two entries. The first specifies there is a 00:15:03.069 --> 00:15:05.071 program that doesn't need to be shimmed. And the second one this 00:15:05.071 --> 00:15:07.073 is a GUI that points to this one. It specifies exactly the 00:15:07.073 --> 00:15:09.909 path on disk of my shim database file. The SDB file. And I've 00:15:09.909 --> 00:15:14.447 played with this and it's funny because you can specify go in 00:15:14.447 --> 00:15:19.652 there and change to a UNC path so you have the shim database 00:15:19.652 --> 00:15:23.656 loaded over the network instead which is hilarious. Those are 00:15:23.656 --> 00:15:27.627 registry keys that I was referring to. The current hyphae 00:15:27.627 --> 00:15:32.031 local machine, that is why you need admin privileges. But if 00:15:32.031 --> 00:15:36.035 you ..(audio blipped).. you don't need to be admin. Those 00:15:36.035 --> 00:15:41.240 are the de-felts. It will drop the copy SDB file into. If you 00:15:41.240 --> 00:15:45.211 use standard installer found on all the Window's machines and 00:15:45.211 --> 00:15:49.215 install something it will had the fix to the add/remove 00:15:49.215 --> 00:15:53.619 program's menu. You can click and say uninstall and it will 00:15:53.619 --> 00:15:58.024 pop it out. Bad guys have used this, install it, and 00:15:58.024 --> 00:16:01.928 immediately uninstall it because they don't want it shows up. 00:16:01.928 --> 00:16:06.732 That is weird because all it does is add those registry keys. 00:16:06.732 --> 00:16:11.938 If they added the keys, they wouldn't have it show up. I have 00:16:11.938 --> 00:16:15.908 never seen a ..(audio blipped).. manually install a shim. There 00:16:15.908 --> 00:16:21.514 is a simple rule that I put up there. It keys off the magic 00:16:21.514 --> 00:16:27.453 value. So what can we do with this. We can do targeted 00:16:27.453 --> 00:16:31.691 persistence. If PuTTY is run every single [indiscernible] 00:16:31.691 --> 00:16:36.829 there is some stuff I can grab. Whatever, I'll show a demo in a 00:16:36.829 --> 00:16:40.900 second. There is this registry key that malware has used. If 00:16:40.900 --> 00:16:45.671 you have a program name in it and then you have the stream, 00:16:45.671 --> 00:16:49.342 debunker, it will execute your debuger instead of this program. 00:16:49.342 --> 00:16:54.146 So we have a similar type of per SYS stance mechanism but shims 00:16:54.146 --> 00:16:58.551 are way more powerful. We can do API logging and terminate any 00:16:58.551 --> 00:17:03.289 program that we want. There is a terminate fix, I don't know why 00:17:03.289 --> 00:17:07.326 it's a fix. There is crazy things you can do. You're in the 00:17:07.326 --> 00:17:11.364 process space and can capture credentials. You can snoop 00:17:11.364 --> 00:17:13.566 network traffic Trojanize any ..(audio blipped). -- there was 00:17:13.566 --> 00:17:16.269 one interested in SKATA systems. They drop a shim database file 00:17:16.269 --> 00:17:18.938 that keys off the SKATA software running. If the software never 00:17:18.938 --> 00:17:21.874 ran they wouldn't care. If it did run it would grab this 00:17:21.874 --> 00:17:24.076 information and execute the malicious code and send back 00:17:24.076 --> 00:17:27.246 config stuff. We can force DLL loaded. I can force an old one 00:17:27.246 --> 00:17:30.449 to load instead of a new one. I can introduce a 10 year-old 00:17:30.449 --> 00:17:33.352 vulnerability into a system. -- I'm going to show an example of 00:17:33.352 --> 00:17:36.289 that. I could have done in the past UAC bypassing. But just 00:17:36.289 --> 00:17:39.225 patched. I was like, oh. Just before my talk. Since I'm a 00:17:39.225 --> 00:17:41.694 malware guy I'm into mall ware obfuscation. Processes need to 00:17:41.694 --> 00:17:44.363 elevate privileges to do things like direct access to the hard 00:17:44.363 --> 00:17:47.466 drive or write to the registry or ..(audio blipped).. is the 00:17:47.466 --> 00:17:49.669 one that is usually targeted. And -- Microsoft quietly added 00:17:49.669 --> 00:17:55.675 this feature and didn't document anywhere. The manifest file, the 00:18:02.481 --> 00:18:08.487 manifest part of the binary called autoelevate and if that 00:18:13.492 --> 00:18:19.498 was ..(audio blipped).. then that program when it launched 00:18:23.369 --> 00:18:29.375 would automatically elevate to system level authority. Which is 00:18:33.279 --> 00:18:39.285 hilarious. They didn't think it was a big deal because you have 00:18:46.459 --> 00:18:52.465 to be signed by Microsoft for that to work. With shims there 00:18:59.672 --> 00:19:05.611 is a fix called redirect EXE, you see that program running? 00:19:08.347 --> 00:19:15.955 Run this one instead. Just because. And run it with the 00:19:15.955 --> 00:19:19.859 same privileges. So the common tactic would be to install a 00:19:19.859 --> 00:19:25.865 shim and you have your malware on disk or UNC path and say I 00:19:33.973 --> 00:19:39.979 want to run sound volume. But wait a second redirect EXE run 00:19:42.214 --> 00:19:50.156 this instead and my malware has the system level privileges that 00:19:50.156 --> 00:19:56.162 sound volume did. That's fun. Here is a sample of the dry dex 00:19:59.498 --> 00:20:06.172 malware using it. It runs SDBINST. And it uses this 00:20:06.172 --> 00:20:10.209 redirect EXE fix for its malware. ..(audio blipped).. 00:20:10.209 --> 00:20:16.215 installed with high privileges. A number of malware families 00:20:18.584 --> 00:20:21.387 have used this. More recent in the past year it's become more 00:20:21.387 --> 00:20:23.389 widely used. I think after the Microsoft fix, it won't be used 00:20:23.389 --> 00:20:25.391 as much. The Microsoft patch was an optional patch. And didn't 00:20:25.391 --> 00:20:27.393 install by default, FYI. Depending on your settings. 00:20:27.393 --> 00:20:29.395 Black energy, roaming tiger, search protect was infected with 00:20:29.395 --> 00:20:31.397 it when I began doing my research. Just potentially 00:20:31.397 --> 00:20:33.399 unwanted program. It's not that big a deal. [indiscernible] 00:20:33.399 --> 00:20:35.401 update, spelled weird. Dry dex. There are a few other malware 00:20:35.401 --> 00:20:37.403 families. Black energy, particularly the second 00:20:37.403 --> 00:20:39.405 variation is interesting because it's been around for a while. 00:20:39.405 --> 00:20:41.407 Used for cyber crime and then picked up for use by ..(audio 00:20:41.407 --> 00:20:43.409 blipped).. Way more sophisticated with 64 bit plug 00:20:43.409 --> 00:20:45.411 ins and used shimming for ADP bypass. They used another fix 00:20:45.411 --> 00:20:47.413 called disable NX show UI. It disables the NX bit. You can 00:20:47.413 --> 00:20:49.415 execute stuff on the stack. That was funny. The second espionage 00:20:49.415 --> 00:20:51.417 group to do something with it was called roaming tiger. An 00:20:51.417 --> 00:20:53.419 ton, I want to butcher his last name. Outed last year by my 00:20:53.419 --> 00:20:55.421 company. Sand worm. This group was outed by ESEP at zero 00:20:55.421 --> 00:20:57.423 knights last year as well. Here we can see, may not be easy to 00:20:57.423 --> 00:20:59.425 see, but we're using John Ericson, his STB explorer to 00:20:59.425 --> 00:21:01.360 analyze the file they dropped. They say I don't want any of the 00:21:01.360 --> 00:21:03.362 Microsoft predefined fixes although there are plenty, I 00:21:03.362 --> 00:21:05.364 want my own fix. Which you can do. So their fix applies to 00:21:05.364 --> 00:21:07.366 explore [indiscernible] and all you need to do to make a custom 00:21:07.366 --> 00:21:09.368 fix is make a DLL that supports two functions and a shim that 00:21:09.368 --> 00:21:11.370 says use this DLL. That's where the fix is. Pretty simple to do. 00:21:11.370 --> 00:21:13.372 So I'd like to show some examples of how a pentester 00:21:13.372 --> 00:21:15.374 might use this or malware might use this in the future. There is 00:21:15.374 --> 00:21:17.376 anti-analysis examples I'll get to. I like the idea of old to 00:21:17.376 --> 00:21:19.378 new. You take an old crappy piece of malware and when it 00:21:19.378 --> 00:21:21.380 runs on a system that you compromised, you can specify, 00:21:21.380 --> 00:21:23.382 change this at run time. This IP address is this IP address, this 00:21:23.382 --> 00:21:25.384 is ex-flowing to this location. If a responder came across a 00:21:25.384 --> 00:21:27.386 computer and finds that this malware is running and you can 00:21:27.386 --> 00:21:29.388 make a simple thing and he dumps it or gets it off a disk or runs 00:21:29.388 --> 00:21:31.390 it in a sandbox and says it's doing something simple, speaking 00:21:31.390 --> 00:21:33.392 out to this IP address or whatever, search for a domain 00:21:33.392 --> 00:21:35.394 name or whatever, we don't see it. It was hard-coded. Little 00:21:35.394 --> 00:21:37.396 did he know it was changing dynamically at run time. And 00:21:37.396 --> 00:21:39.398 instant responders should be aware that SDB files can do 00:21:39.398 --> 00:21:41.400 things like that at run time. PuTTY ..(audio blipped).. with 00:21:41.400 --> 00:21:43.402 an inject DLL fix. Where is my mouse? There it is. We can 00:21:43.402 --> 00:21:45.404 inject an arbitrary DLL. There is a cool program out there 00:21:45.404 --> 00:21:47.406 called PuTTY writer. Adrian Fortuna. I'm sorry if I 00:21:47.406 --> 00:21:49.408 butchered your name. It's cool. It's a DLL that when injected 00:21:49.408 --> 00:21:51.410 into PuTTY will hook the input and output networking and will 00:21:51.410 --> 00:21:53.412 use a connect back to send you that information. So all you 00:21:53.412 --> 00:21:55.414 have to do -- I just ran PuTTY on the left to show you it's 00:21:55.414 --> 00:21:57.416 PuTTY. On the right is a Linux machine and I started net cat 00:21:57.416 --> 00:21:59.418 listener. Here I'll go through the same deal where I make a fix 00:21:59.418 --> 00:22:01.353 and apply it to PuTTY. And I specify PuTTY writer and that 00:22:01.353 --> 00:22:07.359 ..(audio blipped).. no matter where you execute PuTTY from. If 00:22:07.359 --> 00:22:13.365 you're executing on this machine, it will inject PuTTY 00:22:19.405 --> 00:22:24.043 writer and connects back to my shell and shows everything that 00:22:24.043 --> 00:22:30.049 user is doing. Which is awesome. You can also configure PuTTY to 00:22:33.385 --> 00:22:39.391 execute a command upon connection. So if I were doing 00:22:42.995 --> 00:22:49.001 malicious things I would specify the command of put this key into 00:22:54.506 --> 00:23:00.446 your authorized key files in the dot SSH folder so I can ..(audio 00:23:06.952 --> 00:23:12.958 blipped).. drop something. There I'm specifying I don't want any 00:23:17.062 --> 00:23:23.302 of those things if PuTTY came out with a new function. They 00:23:23.302 --> 00:23:29.308 can change the send and receive functions. I don't have a whole 00:23:33.145 --> 00:23:39.151 lot of time. So there I am installing the shim from the 00:23:42.988 --> 00:23:48.994 command line and then deleting the file. Here I'm running PuTTY 00:23:51.997 --> 00:23:57.736 and PuTTY writer was automatically injected and 00:23:57.736 --> 00:24:03.676 connects back to my net cat listener on the right. And here 00:24:07.513 --> 00:24:13.519 I am legitimately using PuTTY. And I can see all the see 00:24:17.356 --> 00:24:23.362 strokes coming across, including the user name and password which 00:24:25.564 --> 00:24:31.570 happens in two seconds. The SSH service is being super-slow. 00:24:33.772 --> 00:24:39.778 There you have it. I can watch everything they're doing. Inject 00:24:42.781 --> 00:24:49.688 a command in there. Fun stuff. Thank you. The second example 00:24:49.688 --> 00:24:51.991 I'm going to show you here is when I'm going to use the 00:24:51.991 --> 00:24:57.997 correct file path fix to redirect a path. Over on the 00:25:58.757 --> 00:26:03.495 right there is a network share that I opened up. 00:26:03.495 --> 00:26:07.499 Controller/catch is the share name. Here I'm making a shim 00:26:07.499 --> 00:26:11.470 specifying FireFox. I encourage all of you to check this out and 00:26:11.470 --> 00:26:17.476 look at every single one of these fixes documented and 00:26:35.160 --> 00:26:41.166 otherwise. There is a lot of fun to be had with these things. 00:27:25.677 --> 00:27:27.679 With the correct file path fix, with the correct file path fix, 00:27:27.679 --> 00:27:31.350 it would fix some program that was hard-coded to C:/settings to 00:27:31.350 --> 00:27:36.588 C:/users. A lot of programs made that mistake. That's terrible. 00:27:36.588 --> 00:27:42.828 But they did that. They had lots and lots of ..(audio blipped).. 00:27:42.828 --> 00:27:50.135 and that kind of thing. With that I'm say don't do that. I do 00:27:50.135 --> 00:27:56.375 that here, I found the FireFox profile and give it a semi-colon 00:27:56.375 --> 00:28:02.548 and then the new path. I remove all the parameters, all the 00:28:02.548 --> 00:28:08.820 filters it can trigger off of. Fast forward this a little bit. 00:28:08.820 --> 00:28:14.026 I'm saving the file and installing it. Deleting that. If 00:28:14.026 --> 00:28:18.530 original SDB file. And FireFox. Here on the right it's 00:28:18.530 --> 00:28:23.101 redirecting all its stuff across my network share. There is key 3 00:28:23.101 --> 00:28:26.705 dot DB which is where the passwords are stored. There was 00:28:26.705 --> 00:28:29.641 no prompting from Mozilla or FireFox. Another example. I 00:28:29.641 --> 00:28:32.277 mentioned subverting system integrity. That's a big thing 00:28:32.277 --> 00:28:36.214 for me. I prefer stealth and misdirect to war games and red 00:28:36.214 --> 00:28:39.184 teaming and all that stuff. Here I'm demonstrating autoruns. 00:28:39.184 --> 00:28:43.589 Awesome fantastic tool, it will show you tons and tons of places 00:28:43.589 --> 00:28:46.058 where malware will really enjoy planting some code because that 00:28:46.058 --> 00:28:48.994 is how it can get ..(audio blipped).. when a user logs in 00:28:48.994 --> 00:28:51.930 or a machine boots up. I have several versions. I'm going to 00:28:51.930 --> 00:28:54.399 rewind this a bit. I just downloaded and compiled Dexter 00:28:54.399 --> 00:28:57.603 which is a POS malware. It's right there on the dex top. We 00:28:57.603 --> 00:28:59.972 can see with autoruns it's detecting that registry key, it 00:28:59.972 --> 00:29:02.674 has something really suspicious in it. You can right click and 00:29:02.674 --> 00:29:05.877 go to value and it will pull up regedit and show the exact 00:29:05.877 --> 00:29:09.314 registry key that it found that was so weird. Here I made a shim 00:29:09.314 --> 00:29:15.320 which is awesome if I don't say so myself. And here I'm 00:29:18.890 --> 00:29:24.896 redirecting file -- the registry keys. So that when it looked 00:29:29.434 --> 00:29:35.440 ..(audio blipped).. particularly common one. It redirects it to 00:30:10.242 --> 00:30:14.579 an empty registry keys. So all these versions will not detect 00:30:14.579 --> 00:30:20.585 my malware anymore. It shows some other tools in there like 00:30:33.765 --> 00:30:39.771 processes -- prop dump and I added an EXE fix. When someone 00:31:23.782 --> 00:31:29.788 tries to execute those, it will fail. No way around that. You 00:31:37.162 --> 00:31:43.168 can just change the name of the process or the file and it won't 00:31:45.937 --> 00:31:51.943 be shimmed anymore. So that's hilarious. I can shim autoruns. 00:32:03.088 --> 00:32:09.094 And even better, I've also added a shim for regedit. The registry 00:32:23.775 --> 00:32:29.781 editor built into Microsoft will not detect my malware anymore. 00:32:40.992 --> 00:32:46.998 It will not see the malware key. The latest version of autoruns 00:33:01.446 --> 00:33:04.549 does something different and my default registry redirect shim 00:33:04.549 --> 00:33:08.320 doesn't work on it. So it will show up for the latest version 00:33:08.320 --> 00:33:12.357 but none of the prior versions. Here -- let me back up just a 00:33:12.357 --> 00:33:15.961 little bit -- here this showed up in the latest version, 13.4 00:33:15.961 --> 00:33:20.899 and I said go to this registry key and it's not there for 00:33:20.899 --> 00:33:24.903 regedit which is hilarious. Okay. So moving onto the malware 00:33:24.903 --> 00:33:30.909 which is my favorite thing. I broke it down into three 00:33:57.802 --> 00:34:03.742 categories. Benign executeables which is PuTTY where you use 00:34:10.682 --> 00:34:17.322 fixes to make it malicious like load library redirect. Do hot 00:34:17.322 --> 00:34:23.328 patching where we could hot patch, overwrite the OEP, the 00:35:08.707 --> 00:35:10.909 original entry point for the executable if you don't know, 00:35:10.909 --> 00:35:13.111 and we could make our own rock chain and use native code there 00:35:13.111 --> 00:35:15.113 to build out some malicious stuff. That is tedious. So the 00:35:15.113 --> 00:35:17.115 next category is I would say dependently malicious software. 00:35:17.115 --> 00:35:19.117 Malicious executable. There can be a kill switch in the program 00:35:19.117 --> 00:35:21.119 that without a shim installed on the system, it wouldn't be able 00:35:21.119 --> 00:35:23.121 to get around. Like an ignore exception fix or you can hot 00:35:23.121 --> 00:35:25.123 patch all the jump instructions of the program and redirect the 00:35:25.123 --> 00:35:27.125 program flow at run time to do your malicious deeds. Tons and 00:35:27.125 --> 00:35:29.394 tons of ways to do this. There is just an infinite number of 00:35:29.394 --> 00:35:31.396 ways you can make something bad or from bad to worse. The last 00:35:31.396 --> 00:35:33.398 category was obfuscated. I have some shell code up there that I 00:35:33.398 --> 00:35:35.400 -- [indiscernible] and pull that out. I'm sorry if you can't see. 00:35:35.400 --> 00:35:37.402 I just got some shell code. And here I have some assembly that 00:35:37.402 --> 00:35:39.404 was label, label. And that processed ..(audio blipped).. 00:35:39.404 --> 00:35:41.406 instruction which is an infinite loop and it jumps to itself over 00:35:41.406 --> 00:35:43.408 and over. If you execute this program it will just stop there 00:35:43.408 --> 00:35:45.410 and jump to itself over and over again. No way around that. There 00:35:45.410 --> 00:35:47.412 is a shim here that I made with SDB explorer that creates a 00:35:47.412 --> 00:35:49.414 patch that knocks out the EBFE instruction. When malware is 00:35:49.414 --> 00:35:51.416 running on the intended victim system, it will be malicious and 00:35:51.416 --> 00:35:56.855 call the shell code. If not the IRR guy that dropped it in a 00:35:56.855 --> 00:36:02.794 sandbox, nothing is happening. This is how I make and install 00:36:12.370 --> 00:36:18.376 that B file. I use John Eric sons slash C and have that 00:36:29.054 --> 00:36:35.060 config file. That is the output of the program. Output dot SDB 00:36:44.436 --> 00:36:50.442 and install it. You can use John Ericsons explorer to install an 00:36:59.851 --> 00:37:05.790 SDB file stealthily. Here is something else. I have -- mess 00:37:13.898 --> 00:37:19.904 with this code because I shortened it to make it easier. 00:37:28.780 --> 00:37:31.683 I have some shell code, malicious shell code. I have the 00:37:31.683 --> 00:37:35.286 shell code key. I made it the same length. I do simple 00:37:35.286 --> 00:37:40.358 obfuscation. It tries to execute the result. Why not use a single 00:37:40.358 --> 00:37:45.330 byte key. I can make a shim that patches over this key with a 00:37:45.330 --> 00:37:47.332 value that I choose. I can decrypt this to anything I want. 00:37:47.332 --> 00:37:50.502 I can make it benign and maliciously, say I want these 00:37:50.502 --> 00:37:53.371 bytes now to be exploit code or something else. I can do that 00:37:53.371 --> 00:37:59.377 quite easily. I think that's quite exciting because when you 00:39:30.235 --> 00:39:32.804 have this kind of hacker type stub in the shim, you don't have 00:39:32.804 --> 00:39:35.406 -- on file or in the malware and you don't have it in the shim 00:39:35.406 --> 00:39:37.442 but it will only be produced dynamically on the target system 00:39:37.442 --> 00:39:40.812 if you so choose. So for those of you who want persistence, 00:39:40.812 --> 00:39:46.284 here is the config for patching explorer dot EXE for Windows 7, 00:39:46.284 --> 00:39:52.190 64 bit, X86 and Windows 8. So, sorry, I have to run through 00:39:52.190 --> 00:39:57.195 this fast. Current prevention for this. I made a number of 00:39:57.195 --> 00:40:01.733 good tools. You can disable shimming through -- Windows uses 00:40:01.733 --> 00:40:06.070 this stuff internally. When you go into compatibility mode it's 00:40:06.070 --> 00:40:08.072 using a shim. If there is a program named install dot EXE 00:40:08.072 --> 00:40:10.074 it's elevated through shimming. This is important. If you have 00:40:10.074 --> 00:40:12.076 -- it's automatically elevated in Windows. You can remove the 00:40:12.076 --> 00:40:14.078 shim engine, the thing that is doing the patching. That is not 00:40:14.078 --> 00:40:16.080 recommended because other things use it like IMIT. You can 00:40:16.080 --> 00:40:18.082 resolve the SDB installer. That is a good start unless you're 00:40:18.082 --> 00:40:20.084 applying fix it patches to things. The bad guys can use the 00:40:20.084 --> 00:40:22.086 manual install method. And you can always allow no 00:40:22.086 --> 00:40:24.088 administrative access to that box but that is probably never 00:40:24.088 --> 00:40:26.090 going to happen. The current tools out there, I talked about 00:40:26.090 --> 00:40:28.092 most of them, the public application compatibility tool 00:40:28.092 --> 00:40:30.094 kit and manager and the installer SDB is on every 00:40:30.094 --> 00:40:32.096 Window's computer. [indiscernible] database values 00:40:32.096 --> 00:40:34.098 and all the documented. Shims dot EXE is made by a guy named 00:40:34.098 --> 00:40:36.100 David Tomets or something like that. I told him I was giving 00:40:36.100 --> 00:40:38.102 this talk. He is like that is cool. I said can I demo your 00:40:38.102 --> 00:40:40.104 tool. I said can you send me a trial version. He is like, no, 00:40:40.104 --> 00:40:42.106 you to pay for it. Or you can just let me demo it for 00:40:42.106 --> 00:40:44.108 Screenshots and he's like no, you have to pay for that. A 00:40:44.108 --> 00:40:46.110 parser, since shims are checked all the time because ..(audio 00:40:46.110 --> 00:40:48.112 blipped).. execution all the time, they had to cache that 00:40:48.112 --> 00:40:50.114 information. It's a great place for forensic value that a 00:40:50.114 --> 00:40:52.116 program was executed. None of these programs, nothing out 00:40:52.116 --> 00:40:54.118 there helps defend or prevent malicious shims. I made a number 00:40:54.118 --> 00:40:56.120 of tools and break them into three categories. One is for 00:40:56.120 --> 00:40:58.122 detection. You can scan a file for -- you can scan something so 00:40:58.122 --> 00:41:00.058 you can determine if it will be shimmed or not. It will tell 00:41:00.058 --> 00:41:02.060 you, yes, this would have been shimmed and the thing that would 00:41:02.060 --> 00:41:04.062 have been applied to it. There is a shim process scanner which 00:41:04.062 --> 00:41:06.064 scans every process in the os. I've only tried it for Windows 00:41:06.064 --> 00:41:08.066 7, 64 bit. But it seems to work. It does that through checking 00:41:08.066 --> 00:41:10.068 the DLLs that are loaded into the process and see if they're 00:41:10.068 --> 00:41:12.070 the shimming DLLs and it checks the registry and it checks the 00:41:12.070 --> 00:41:14.072 PED flags. Undocumented flags in the process of the environmental 00:41:14.072 --> 00:41:16.074 block structure. And then I made really basic script to check for 00:41:16.074 --> 00:41:18.076 -- to see if the DLLs are in any of the processing spaces. Shim 00:41:18.076 --> 00:41:20.078 guard, I made this for the purpose of preventing shim from 00:41:20.078 --> 00:41:22.080 being installed but it's hard to do because I would have to mess 00:41:22.080 --> 00:41:24.082 with the permissions and when something tried to install it 00:41:24.082 --> 00:41:26.084 would notify me and that got too complicated. I made a PowerShell 00:41:26.084 --> 00:41:28.086 script to alert as well. I made two plug ins. One for volatility 00:41:28.086 --> 00:41:30.088 and one for autopsy. Autopsy is cool. You can load the imager 00:41:30.088 --> 00:41:32.090 and whatever else. You can search for things on it. And in 00:41:32.090 --> 00:41:34.092 the future I'll start doing more stuff with it. And I white 00:41:34.092 --> 00:41:36.094 listed a bunch of hashes for known STP files. And volatility 00:41:36.094 --> 00:41:38.096 is the open-source live memory forensic's framework and I made 00:41:38.096 --> 00:41:40.098 a [indiscernible] for that and made it search for SDB files. I 00:41:40.098 --> 00:41:42.100 give Microsoft a lot of crap but they did an enormous amount of 00:41:42.100 --> 00:41:44.102 work. I love how the quotes say nothing is available to bypass 00:41:44.102 --> 00:41:46.104 except for the redirect EXE or the load library. No harmful 00:41:46.104 --> 00:41:48.106 code can be injected into the process except for the inject 00:41:48.106 --> 00:41:50.108 DLL fix or custom fixes. You're not opening any additional 00:41:50.108 --> 00:41:52.110 security vulnerabilities. You cannot use shims except for the 00:41:52.110 --> 00:41:54.112 disable, or hardened fix or disable defender fix or disable 00:41:54.112 --> 00:41:56.114 SR or DNX bit fix. There's a few others out there. I just want to 00:41:56.114 --> 00:41:58.116 note some prior work. Sorry for the guy that was trying to take 00:41:58.116 --> 00:42:00.051 a picture of that. I'll post it online. This is a great reverse 00:42:00.051 --> 00:42:02.120 engineer. He started a blog called secrets the application 00:42:02.120 --> 00:42:04.188 compatibility database and he didn't finish it. He stopped 00:42:04.188 --> 00:42:06.491 half way through. I found these guys, they blogged about 00:42:06.491 --> 00:42:09.727 something a while back. I wish I found this sooner. Mark was one 00:42:09.727 --> 00:42:12.196 of the first ones to talk about this in a security context. And 00:42:12.196 --> 00:42:18.202 John talked about this last year at BlackHat Asia. Particularly 00:42:23.875 --> 00:42:29.881 patching the shim engine stuff. Special thanks to my peeps, 00:42:36.287 --> 00:42:42.293 John, Greg, Wyatt, and Patrick. I made a lot of my own string 00:42:52.403 --> 00:42:58.409 handling functions and Patrick said it made him want to stab 00:43:05.983 --> 00:43:11.989 out his eyes and that was good insight for me. Other resources 00:43:14.525 --> 00:43:22.266 for this stuff. Shims blog. And I just want to say I apologize. 00:43:22.266 --> 00:43:27.038 I'm sorry the application compatibility, I'm adding more 00:43:27.038 --> 00:43:34.879 load to this crap because I know so many people hate it and it's 00:43:34.879 --> 00:43:40.885 a pain to so many people. I don't think we have time for 00:43:50.628 --> 00:43:56.634 questions. Out in the hall I can. So I'll talk to you, I'm a 00:44:31.702 --> 00:44:37.708 little hungry so I might try to get food while people are 00:44:46.851 --> 00:44:52.857 talking to me. There is my GitHub and there is my Twitter 00:47:18.536 --> 00:47:24.542 and my email. You can email me. That's it.