00:00:00.000 --> 00:00:06.039 Good afternoon everybody. How are we doing? [ applause & 00:00:06.039 --> 00:00:09.276 cheers ]. >> All right. Let's learn some stuff about 00:00:09.276 --> 00:00:15.382 Powershell. In my day job I'm a simple country lawyer but I open 00:00:15.382 --> 00:00:21.388 up the computer now and then. I remember when I first saw 00:00:24.024 --> 00:00:31.198 Powershell I thought this is neat. This is my directory 00:00:31.198 --> 00:00:38.805 listing. This is awesome. What's my ip address. It doesn't do 00:00:38.805 --> 00:00:43.310 anything. And then I hate Powershell. Done with this. So 00:00:43.310 --> 00:00:47.848 long those lines I like to use the power from Powershell and 00:00:47.848 --> 00:00:53.387 I'm doing demos on my own systems but it can be 00:00:53.387 --> 00:00:59.393 frustrating. Rich is going to show us what he has done. Let's 00:01:01.595 --> 00:01:07.601 give him a big hand [ applause ] >> All right. Thanks for coming. 00:01:11.405 --> 00:01:17.411 A lot bigger crowd than I realize. My name is Rich Kelley. 00:01:19.813 --> 00:01:26.820 First talk first time at Defcon. Background on myself. Come 00:01:26.820 --> 00:01:30.324 officer officer. Network engineering software 00:01:30.324 --> 00:01:36.630 development, end up in security mostly for government. Most 00:01:36.630 --> 00:01:43.570 recently branched out cofounded a company out of Virginia. In my 00:01:43.570 --> 00:01:49.576 spare time I will release some utilities. All right. So why 00:01:55.916 --> 00:02:00.187 should you care? If you are here you probably know this. The 00:02:00.187 --> 00:02:03.457 first point is that Powershell is here to stay. It's going to 00:02:03.457 --> 00:02:11.064 be on windows in the foreseeable future. If you are not using it, 00:02:11.064 --> 00:02:14.668 you are really just cheating yourself. It's resource that's 00:02:14.668 --> 00:02:18.839 there and don't have to put on disk usually. I recommend taking 00:02:18.839 --> 00:02:24.778 a look at Powershell. Offensive community is focusing on that. 00:02:24.778 --> 00:02:30.217 From the defense side I get the feeling that a lot of defender 00:02:30.217 --> 00:02:34.321 don't realize how powerful it has. The function within 00:02:34.321 --> 00:02:40.327 Powershell, completely unnecessary. The more we bring 00:02:43.664 --> 00:02:50.671 up the more we can secure things. I was struck by most 00:02:50.671 --> 00:02:55.909 mortem analysis, incident attacker will use Powershell. 00:02:55.909 --> 00:03:01.848 Research topic that might be a good area for focusing. Okay. So 00:03:06.286 --> 00:03:09.423 what is the Powershell weaponization problem? I guess 00:03:09.423 --> 00:03:13.627 to put it simply how to get your Powershell running on your 00:03:13.627 --> 00:03:20.100 machine and get your results back. It may not be obvious but 00:03:20.100 --> 00:03:25.405 up until few months ago I was actually not really that easy to 00:03:25.405 --> 00:03:28.241 work Powershell into your work flow. There's number of script 00:03:28.241 --> 00:03:32.612 and tools came out but they are still vague understanding of how 00:03:32.612 --> 00:03:37.117 you would use it on an engagements. So when I started 00:03:37.117 --> 00:03:42.022 this project I was trying to make it easy for myself and 00:03:42.022 --> 00:03:49.329 number of people convinced me to put in a talk so here I am. So 00:03:49.329 --> 00:03:52.532 has this problem been solved? Yes. The couple of months we've 00:03:52.532 --> 00:03:54.835 had interesting and great tools came out to utilize Powershell. 00:03:54.835 --> 00:04:00.774 Excuses are getting less and less. When I started this and 00:04:06.079 --> 00:04:12.052 drove me down this path is there's this fuzzy area you gain 00:04:12.052 --> 00:04:17.624 access, use Powershell and good to go. And that's where I 00:04:17.624 --> 00:04:23.163 started to fill in the gaps. There's bunch of solutions, a 00:04:23.163 --> 00:04:28.668 few days I'll talk about quickly and everybody should check out 00:04:28.668 --> 00:04:35.208 as well. All right. Briefly I want to go over other ways to 00:04:35.208 --> 00:04:40.747 use Powershell, weaponize it. If you have ipo access you can 00:04:40.747 --> 00:04:45.018 bring up the Powershell. If you bypass the execution policy, 00:04:45.018 --> 00:04:50.423 input your script. Copy/paste your Powershell. It's there free 00:04:50.423 --> 00:04:58.098 to use. You are probably use the line on top there which is refer 00:04:58.098 --> 00:05:04.471 to the demo, where you are using the web client to reach out and 00:05:04.471 --> 00:05:09.543 download and staged on some web server. The next way is if you 00:05:09.543 --> 00:05:12.746 have command shell, probably where you used it. You can't 00:05:12.746 --> 00:05:18.685 just drop in Powershell console like you would normally. The 00:05:18.685 --> 00:05:23.590 nature of the Powershell and way it works makes it difficult to 00:05:23.590 --> 00:05:29.062 get around that payload. There's number of utilities that will 00:05:29.062 --> 00:05:32.532 help you with that. Command argument. Powershell execute and 00:05:32.532 --> 00:05:37.137 go ahead and execute that return some results. That's probably 00:05:37.137 --> 00:05:44.010 how most of you use Powershell on most of your tests. If you 00:05:44.010 --> 00:05:49.816 have this shell you can use modules that make things not 00:05:49.816 --> 00:05:54.588 easy. You can use execute Powershell module. It's been 00:05:54.588 --> 00:05:59.793 around. And you can stage your script on your local attack 00:05:59.793 --> 00:06:05.999 machine, takes care some of the heavy lifting for you. Through 00:06:05.999 --> 00:06:11.571 the interpreter section to execute. I have had few issues 00:06:11.571 --> 00:06:18.111 with it. Occasionally opens up a lot of Powershell incidents. It 00:06:18.111 --> 00:06:24.985 was flaky a couple of times. Most recently April or may, 00:06:24.985 --> 00:06:29.956 Powershell payloads. If it was around when I started it, I may 00:06:29.956 --> 00:06:35.962 not have gone down the path. It has some nice features. You do 00:06:38.598 --> 00:06:45.905 get an interactive console. And pass it extreme of file path 00:06:45.905 --> 00:06:51.578 where your local scripts are. Once it runs it will load up 00:06:51.578 --> 00:06:54.848 scripts for you. It's nice you can use right now. There's cobra 00:06:54.848 --> 00:07:00.787 strike. If you have that, I think this is probably the first 00:07:03.223 --> 00:07:06.326 really clean solution to the Powershell weaponization problem 00:07:06.326 --> 00:07:12.399 that I saw. In this case if you have beacon on a machine and I'm 00:07:12.399 --> 00:07:15.902 a big fan of that, import and local script and does the hard 00:07:15.902 --> 00:07:19.439 work for you. Your function is available there. So if you have 00:07:19.439 --> 00:07:22.275 cobra strike, this is really easy. Some other options. 00:07:22.275 --> 00:07:29.349 Powershell remoting. You have to have enabled. Once it is you can 00:07:29.349 --> 00:07:34.054 use Powershell to invoke, whether it's administrator or 00:07:34.054 --> 00:07:41.728 once you get on the machine it's a nice feature and you don't 00:07:41.728 --> 00:07:48.768 have to install anything. Wmi there's going to be a talk on 00:07:48.768 --> 00:07:55.842 that tomorrow. And I recommend you go to that. And empire this 00:07:55.842 --> 00:08:03.416 is the tool I was eluding to. Just couple of days ago, it's 00:08:03.416 --> 00:08:08.722 kind of a game changer post exploitation agent implemented 00:08:08.722 --> 00:08:15.795 in Powershell. It has a really nice fame work to build modules 00:08:15.795 --> 00:08:21.801 for that. I recommend you go to their website and take a look at 00:08:24.037 --> 00:08:27.907 that. Okay. So I'm always hard on my client to give 00:08:27.907 --> 00:08:31.644 requirements. On myself I want fully interactive Powershell as 00:08:31.644 --> 00:08:37.650 the native Powershell executable. And I want 00:08:40.553 --> 00:08:43.289 capability to seamlessly import. You don't want to stage them. I 00:08:43.289 --> 00:08:45.892 just want to import modules give it to path and be done with it. 00:08:45.892 --> 00:08:51.898 Last December sometimes and work on and off and proved more 00:08:59.339 --> 00:09:04.644 challenging than I thought. All right. I'm going to attempt a 00:09:04.644 --> 00:09:10.650 live demo here and see how this works out. Okay. Harness is the 00:09:25.065 --> 00:09:31.070 actual payload. It's interactive remote, c sharp. So Microsoft 00:09:35.308 --> 00:09:39.612 has got a lot of functions that you can use to build out your 00:09:39.612 --> 00:09:44.317 custom host. So if you want to big into the library you can do 00:09:44.317 --> 00:09:48.087 that. The documentation on it was limited and that's why I 00:09:48.087 --> 00:09:55.028 struggled quite a bit at the beginning. I bundle everything 00:09:55.028 --> 00:09:57.697 in the python fame framework. You can integrate the payload 00:09:57.697 --> 00:10:02.202 in. It's got the usual command. In this case there's not a whole 00:10:02.202 --> 00:10:08.208 lot of modules. It's not the focus of the handler. I have a 00:10:11.377 --> 00:10:17.383 number of payloads here. Mostly just 86 and 64-bits. Executable 00:10:20.286 --> 00:10:26.292 and drl to inject into the memory and I will show yaw that. 00:10:32.132 --> 00:10:37.237 So if you want to use payload, very similar meta display here. 00:10:37.237 --> 00:10:43.243 So in practice you probably wouldn't use the dropper. You 00:11:03.396 --> 00:11:08.268 try to avoid touching disk when you are on mission. You run it 00:11:08.268 --> 00:11:14.674 like that and executable and it's up to you how you would get 00:11:14.674 --> 00:11:19.312 it to your target. In this case I've already dropped it on the 00:11:19.312 --> 00:11:24.484 target. And see if we can get a call back. I want to show you is 00:11:24.484 --> 00:11:26.786 you don't need a special handler. In this case, see if we 00:11:26.786 --> 00:11:32.792 can use net cat. We give a nice call back. So you don't need 00:11:36.095 --> 00:11:42.535 special features. This is running unmanaged payload. One 00:11:42.535 --> 00:11:48.541 of the things I also that you don't get in interactive 00:11:51.644 --> 00:11:54.514 payloads is you notice in Powershell you get the multiline 00:11:54.514 --> 00:12:00.453 inputs. So I want the feature in there. Hallmark of having 00:12:11.764 --> 00:12:17.770 Powershell. You can do stuff like this now. What is doing in 00:12:23.309 --> 00:12:26.746 the background is every time you send something it's doing the 00:12:26.746 --> 00:12:29.382 check. And once it says it's clean it goes ahead and executes 00:12:29.382 --> 00:12:34.687 it. You can just print out. This allows you to build function on 00:12:34.687 --> 00:12:40.693 a fly. The buffer can't keep up with each other. Eventually I 00:12:47.800 --> 00:12:55.241 would like to have that problem solved as well. So that was 00:12:55.241 --> 00:12:59.178 getting kind of close to my first objective. It's not 00:12:59.178 --> 00:13:04.450 completely implemented yet. But I'm working through some of the 00:13:04.450 --> 00:13:11.691 bugs. The next thing if you use handler built in to the 00:13:11.691 --> 00:13:17.697 framework here you get a little bit more functionality. You load 00:13:21.000 --> 00:13:27.006 the handler here. Running on ad. Once again it will execute it. 00:13:30.176 --> 00:13:36.182 And we get a call back here. So. We can interact here. Using the 00:13:39.419 --> 00:13:42.588 server and client together you can import modules across the 00:13:42.588 --> 00:13:47.894 wires. So in this case built in some custom command. The 00:13:47.894 --> 00:13:53.900 difference is the module...and I'll try it send it through 00:13:58.071 --> 00:14:04.010 wire. It's through the same channel you are currently using. 00:14:12.885 --> 00:14:18.891 In this case once you in the memory there you can see the 00:14:23.896 --> 00:14:28.868 function from power up available. See if we can 00:14:28.868 --> 00:14:32.405 do...invoke all checks. What I have noticed so that it does 00:14:32.405 --> 00:14:36.309 consume a lot of memory. There you go. The next thing I want to 00:14:36.309 --> 00:14:42.315 show is reflected payload. I want to show you a video. I 00:14:55.027 --> 00:14:59.999 apologize if it's too small. So in this case you are going to 00:14:59.999 --> 00:15:05.938 run your handled like you normally would. Load up the 00:15:11.944 --> 00:15:15.715 reflected dol, from the reflective pet project. You 00:15:15.715 --> 00:15:18.551 should get out those as well. And reflected drl are built off 00:15:18.551 --> 00:15:24.557 the students here. Without those projects I could not implement 00:15:26.826 --> 00:15:32.832 this myself. So now you create the payload. I've staged an 00:15:37.236 --> 00:15:40.940 interpreter call back here and running the system. And you can 00:15:40.940 --> 00:15:45.411 use the reflect drl module and -- memory directly into l sec 00:15:45.411 --> 00:15:52.118 here. Okay. So it inject into l saas this payload is getting 00:15:52.118 --> 00:15:58.124 more to ramp up but eventually you get a call back here into 00:16:05.932 --> 00:16:11.938 your system. Any time now. There you go. You get a call back and 00:16:20.913 --> 00:16:26.919 you can interact with the session. You can do indoor min 00:16:32.658 --> 00:16:38.664 nigh cats. Before you can import your modules all the way across 00:16:45.504 --> 00:16:51.510 the wire. Any special function require handler there's a symbol 00:16:56.182 --> 00:17:07.860 in front of it. Differentiate the commands. In this case I'll 00:17:07.860 --> 00:17:13.866 import minicats. And just to prove that it's loaded into the 00:17:17.737 --> 00:17:20.840 memory you can take a look at what the current process i.d. 00:17:20.840 --> 00:17:26.846 is. Running in l saas. This is very similar to the capability 00:17:37.890 --> 00:17:43.896 like things like empire out it's hard to detect in the future as 00:17:49.936 --> 00:17:57.944 well. So invoke minicats. There we go. You get your results back 00:17:57.944 --> 00:18:03.883 just normally would. Minicats for your passwords. Okay. So 00:18:09.021 --> 00:18:14.593 under the hood the payload is compiled net 4.0 I think you can 00:18:14.593 --> 00:18:19.966 down to 3.5 if you needed to. It does need system assemble where 00:18:19.966 --> 00:18:24.070 all the internal management come from to built out your 00:18:24.070 --> 00:18:28.407 Powershell host. I've tested a number of systems. As far as the 00:18:28.407 --> 00:18:34.413 server concern it's a separate project. You can build your own. 00:18:38.985 --> 00:18:44.991 The listener is a sync io it allows you to run asynchronous 00:18:50.129 --> 00:18:55.468 processes, but tasks in the thread. That's kind of a pet 00:18:55.468 --> 00:19:01.407 project you can implement. You can easily do that. Why python? 00:19:07.613 --> 00:19:12.218 It's for the learning experience. It helped me to 00:19:12.218 --> 00:19:16.122 actually fill in some gaps that I had. And I have a lot of 00:19:16.122 --> 00:19:19.358 appreciations now that it does behind the seen. No critique 00:19:19.358 --> 00:19:25.364 there. It's also my performance. Payload is compatible. As far as 00:19:36.575 --> 00:19:39.011 the defense I haven't done too much work in this. You can 00:19:39.011 --> 00:19:42.014 actually probably stop attacks in-system automation and trigger 00:19:42.014 --> 00:19:45.284 any malicious use and see if it's loaded and tell whether 00:19:45.284 --> 00:19:51.190 something is there that shouldn't be. And also new 00:19:51.190 --> 00:19:57.196 features in Powershell 5.0 has nice log in features. The talk 00:20:02.201 --> 00:20:08.207 earlier today he went through a lot of great defense techniques. 00:20:13.212 --> 00:20:17.249 Okay. That's all I have. Big thanks to all these people. 00:20:17.249 --> 00:20:21.187 Wouldn't be possible. Thanks for the encouragement. Here's all my 00:20:21.187 --> 00:20:27.193 contacts if you have questions. Thank you [ applause ]