1 00:00:00,000 --> 00:00:06,280 All right. So hi, thanks for coming. This is weaponizing the Windows API with Railgun, 2 00:00:06,420 --> 00:00:14,740 which is an extension of Metasploit. So some of you probably have no idea who I am. I'm 3 00:00:14,740 --> 00:00:21,620 the light cosign. I am one of the core developers for the Metasploit Pro product. And before 4 00:00:21,620 --> 00:00:27,460 that I was a longtime Metasploit framework contributor and a professional penetration 5 00:00:27,460 --> 00:00:32,640 tester. Before I get started, there's just a couple 6 00:00:32,640 --> 00:00:37,060 people, and this is far from a complete list that I wanted to just give a shout out to. 7 00:00:37,160 --> 00:00:42,420 These are all the people who really helped me get to this point and mentor me, teach 8 00:00:42,420 --> 00:00:50,740 me a lot of the stuff that made me the person I am today. I've spent the past about two 9 00:00:50,740 --> 00:00:57,440 and a half years working on Metasploit as a contributor. And when I first started working 10 00:00:57,440 --> 00:01:02,820 on it, H.D. Moore said something to me that I think is a quote that needs to be kind of 11 00:01:02,820 --> 00:01:08,280 immortalized. He said that if you don't think you're a noob, then you're not trying hard 12 00:01:08,280 --> 00:01:14,460 enough. So what I'm going to try and do with this talk is just kind of show that this stuff 13 00:01:14,460 --> 00:01:20,080 can be done by anyone who has the desire to learn it, and it's not as hard as you think. 14 00:01:20,300 --> 00:01:25,120 So hopefully at the end of this you'll come away thinking Railgun is pretty cool. You'll 15 00:01:25,120 --> 00:01:27,080 want to contribute some modules back. 16 00:01:27,080 --> 00:01:32,420 And maybe next year you guys will do a talk on something cool you did with Railgun. 17 00:01:34,160 --> 00:01:41,620 So everybody knows Metasploit for its exploits and being able to get shells on a box. As 18 00:01:41,620 --> 00:01:48,820 a penetration tester, I said, well, that's great, but now what? You know, there's a 19 00:01:48,820 --> 00:01:53,620 lot more you have to do than just get a shell on the box. You have to actually achieve 20 00:01:53,620 --> 00:01:57,060 some sort of objective that is meaningful for your client or your customer. So I'm going 21 00:01:57,080 --> 00:01:57,680 to try to get you guys to do that. 22 00:01:58,080 --> 00:02:04,300 And that's where post exploitation comes in. There's a lot more that goes on in Metasploit 23 00:02:04,300 --> 00:02:10,340 now with the development of post-exploitation from gathering, from stealing credentials, 24 00:02:10,620 --> 00:02:15,040 gathering information, doing further reconnaissance on the network once you've gotten that first 25 00:02:15,040 --> 00:02:21,800 foothold. And in a very short period of time, we've come up with a lot of new possibilities 26 00:02:21,800 --> 00:02:26,980 through the advent of the post module. I don't know how well you can see that, but just 27 00:02:27,080 --> 00:02:33,420 Just in Windows post modules alone there are 105 modules currently in the Metasploit framework. 28 00:02:33,920 --> 00:02:39,520 And these do everything from screw with the wireless card to decrypting stored passwords 29 00:02:39,520 --> 00:02:43,540 to, I mean, just about anything you can possibly imagine. 30 00:02:44,240 --> 00:02:50,280 And this is all made possible on the Windows environment from our Meterpreter payload. 31 00:02:51,220 --> 00:02:57,420 For those of you who don't know what Meterpreter is, it is sort of like the default go to payload 32 00:02:57,420 --> 00:02:59,060 now for Metasploit. 33 00:02:59,660 --> 00:03:07,440 It is a COMPILED C DLL that most of our exploits inject into memory via a stager. 34 00:03:07,840 --> 00:03:12,860 So it provides an enhanced command shell, but what's really important is it provides 35 00:03:12,860 --> 00:03:18,960 a standard API that module developers can code to. 36 00:03:19,180 --> 00:03:20,260 And it provides a standard API that module developers can code to. 37 00:03:20,260 --> 00:03:28,080 provides a lot of functionality. One of the benefits of Meterpreter is that we can ‑‑ 38 00:03:28,080 --> 00:03:34,160 once we've gotten that initial shell, we can migrate it into other processes and gain system 39 00:03:34,560 --> 00:03:42,240 level access very quickly and easily. So jumping right into Railgun, Railgun is one of the 40 00:03:42,240 --> 00:03:50,520 extensions for Meterpreter. Basically, it's a part of the standard API that allows for 41 00:03:50,520 --> 00:03:56,060 arbitrary loading of DLLs on the system. As long as you know the path of the DLL that 42 00:03:56,060 --> 00:04:01,040 you're trying to load, you can just pass that information into Railgun, it will map the 43 00:04:01,040 --> 00:04:07,060 DLL into memory, and then you can actually get function pointers out of that module. 44 00:04:07,300 --> 00:04:12,060 So it's doing run‑time dynamic linking. And we're doing it on the 45 00:04:12,060 --> 00:04:12,220 floor. 46 00:04:12,240 --> 00:04:17,780 So we pass it a DLL name, then we pass it some function names, and we get to call that 47 00:04:17,780 --> 00:04:21,400 function as if it was already coded directly into Meterpreter. 48 00:04:23,040 --> 00:04:28,580 Since Windows API DLLs are always at a known location, this means the entire Windows API 49 00:04:28,580 --> 00:04:37,560 is ripe for exploitation and use for whatever nefarious purposes that we might have on that 50 00:04:37,560 --> 00:04:38,060 system. 51 00:04:43,180 --> 00:04:50,400 So Railgun is providing us a fully dynamic access to the Windows API. That's all the 52 00:04:50,400 --> 00:04:56,120 core functions that any Windows developer would want to use to do anything on that system. 53 00:04:56,580 --> 00:05:01,220 It doesn't sound that exciting at first, but when you start looking at what the possibilities 54 00:05:01,220 --> 00:05:06,100 that opens up for you are, it's very, very powerful. 55 00:05:06,920 --> 00:05:12,840 By calling these APIs from a user land process, we can actually impersonate any user on that 56 00:05:12,840 --> 00:05:13,260 system. 57 00:05:13,740 --> 00:05:19,980 And this can be very important for things like cryptographic context, where the cryptographic 58 00:05:19,980 --> 00:05:22,100 context will change from user to user. 59 00:05:22,280 --> 00:05:29,340 So if we migrate from a system process into a user process, we can then call Windows cryptographic 60 00:05:29,340 --> 00:05:34,380 APIs as if we were that user, and the operating system will just go ahead and decrypt that 61 00:05:34,380 --> 00:05:35,440 data right for us. 62 00:05:35,440 --> 00:05:39,040 And you'll see a little bit of how some of that works later when we get to some of the 63 00:05:39,040 --> 00:05:39,340 demos. 64 00:05:39,920 --> 00:05:45,780 But basically Railgun and the access to the Windows API makes anything possible once 65 00:05:45,780 --> 00:05:47,000 you get that initial shell. 66 00:05:48,940 --> 00:05:53,000 So let's talk about Railgun and its history briefly here. 67 00:05:53,720 --> 00:06:01,060 In June of 2010, a community user called Patrick HVE submitted Railgun via the mailing list. 68 00:06:01,800 --> 00:06:05,420 And it was just an extension from Interpreter.com. 69 00:06:05,420 --> 00:06:12,700 load at the time. By September, Steven fewer had added 64-bit support. And February of 70 00:06:12,700 --> 00:06:19,960 2011, Chao Mu, another user on the IRC community, took over support for Railgun and started 71 00:06:19,960 --> 00:06:25,340 adding new features and patches and things. But by fall of last year, he kind of just 72 00:06:25,340 --> 00:06:30,740 disappeared off the face of the earth again. So here's where I get into some wishful thinking. 73 00:06:30,740 --> 00:06:37,360 Starting August 2012, some of you will start contributing back to Metasploit and Railgun. 74 00:06:37,920 --> 00:06:43,880 And December 2012, the minds predict the apocalypse. Who knows? Maybe it's Railgun related. 75 00:06:46,460 --> 00:06:53,120 So how it works on the C side is that it uses a Windows API function called Load Library 76 00:06:53,520 --> 00:07:00,600 and another one called Get Proc Address. So Load Library just takes a path to a DLL and 77 00:07:00,600 --> 00:07:04,960 maps that into memory if it's not already there and returns a handle to it. From there, 78 00:07:05,040 --> 00:07:11,520 Get Proc Address takes that handle and actually takes a function name and returns you a function 79 00:07:11,520 --> 00:07:18,360 pointer that you can then use to basically alias any function out of that module. There 80 00:07:18,360 --> 00:07:23,120 are some additional utility functions, like some generic memory read and write functions. 81 00:07:23,860 --> 00:07:30,100 So as we return some of the data, we then read the return right out of memory. It can 82 00:07:30,100 --> 00:07:30,580 get a little bit more complex. It can get a little bit more complex. It can get a little 83 00:07:30,580 --> 00:07:34,120 hairy, but ‑‑ and I'll show you what some of that looks like in the demo. 84 00:07:35,140 --> 00:07:41,900 On the Ruby side, we have a bunch of libraries. They all live in the Rex library under post, 85 00:07:41,980 --> 00:07:50,080 meterpreter, extension, standard API, Railgun. So the actual code for the Ruby side of the 86 00:07:50,080 --> 00:07:56,300 API lives there, but also what's important is the definitions for these libraries and 87 00:07:56,300 --> 00:08:00,140 these functions exist there. So you can ‑‑ when you're writing a module, 88 00:08:00,140 --> 00:08:06,960 you can define the DLL and you can define your functions within your module or you can 89 00:08:06,960 --> 00:08:13,260 just go ahead and build it right into Railgun by creating these definition files. And here's 90 00:08:13,260 --> 00:08:17,420 a brief look. It doesn't ‑‑ you can't see that really well, so I'm going to actually 91 00:08:17,420 --> 00:08:24,960 show you some ‑‑ I'm flipping the wrong way. So this is what one of the definition 92 00:08:24,960 --> 00:08:30,120 files looks like. This is the definition for the advanced API 32 DLL. And this is what 93 00:08:30,140 --> 00:08:34,860 it looks like. You can see there's actually a custom structure defined here. It creates 94 00:08:34,860 --> 00:08:40,880 the DLL, defines it via the path and puts in the constants manager. And then we can 95 00:08:40,880 --> 00:08:46,880 see the function ‑‑ all the functions and it goes down quite a long way here, but 96 00:08:46,880 --> 00:08:51,280 these are all the different functions out of that DLL being defined for our API. 97 00:08:57,320 --> 00:08:58,440 Oh. Sorry. 98 00:09:01,140 --> 00:09:06,800 So the basic anatomy of the function definition is that we have a function name, 99 00:09:07,000 --> 00:09:11,340 what type of function it is, basically what type of return value it has, and then just 100 00:09:11,340 --> 00:09:16,180 pass it in an array of parameters and flip over here again so I can actually show you 101 00:09:16,180 --> 00:09:23,500 that. So this is the name of the function. Then we have our type. So this is a Boolean. 102 00:09:23,540 --> 00:09:29,540 It returns true, false. And then here's our array of our parameters. And what you have 103 00:09:29,540 --> 00:09:30,060 is this. 104 00:09:30,060 --> 00:09:37,000 The type of data that goes into that parameter. The name of it, which is only sort of important. 105 00:09:37,420 --> 00:09:42,320 And then whether it's an in, an out, or an in out parameter. For anyone who hasn't worked 106 00:09:42,320 --> 00:09:46,880 with the Windows API, what that basically means is an in parameter is one where you're 107 00:09:46,880 --> 00:09:51,000 just putting data in. An out parameter is where you're expecting to get back. And an 108 00:09:51,000 --> 00:09:55,440 in out is where, like, the function will read data in but might change that data on the 109 00:09:55,440 --> 00:09:56,080 way back out. 110 00:09:57,220 --> 00:10:00,040 And so, I mean, it's very ‑‑ you can see, once you have a function, you can see, 111 00:10:00,060 --> 00:10:04,500 once you actually know the structure, it's very simple and easy to define these functions 112 00:10:05,160 --> 00:10:06,880 and add new ones constantly. 113 00:10:14,340 --> 00:10:20,580 Railgun also knows about Windows constants. They're defined in the API constants.rb file 114 00:10:20,580 --> 00:10:27,820 in that same Railgun folder. And flip back here again. Flip back and forth off the slides. 115 00:10:27,820 --> 00:10:33,920 But it couldn't be simpler to add new ones of these either. It's just basically a call. 116 00:10:33,980 --> 00:10:40,360 You can copy paste this and just change it out for your name and value. So that way we 117 00:10:40,360 --> 00:10:44,740 don't have to constantly be looking up on MSDN, like, oh, well, what does that constant 118 00:10:44,740 --> 00:10:49,700 actually mean? Once you find it, just throw it in here and Railgun will know about it 119 00:10:49,700 --> 00:10:50,400 forever afterwards. 120 00:10:56,380 --> 00:10:56,780 So 121 00:11:26,780 --> 00:11:40,400 in the Ruby side, we pass ‑‑ for a D word parameter, we pass in a fixed num or 122 00:11:40,400 --> 00:11:46,000 big num. Or if it's one of those defined constants, we can pass in a string representation 123 00:11:46,000 --> 00:11:48,680 of that constant and it will interpret it for us. 124 00:11:51,120 --> 00:11:56,760 We have the PD word, which is a pointer to a D word. You pass it as a fixed num. And 125 00:11:56,760 --> 00:12:03,500 num in Ruby. And what you're doing is actually when you're passing it into the parameter 126 00:12:03,500 --> 00:12:10,980 for the function call, you pass in the content. And Railgun will handle the actual referencing 127 00:12:10,980 --> 00:12:15,720 for you on the back end. So you just basically pass in the data and don't worry about the 128 00:12:15,720 --> 00:12:21,000 fact that it's a pointer. And the only kind of weird thing is if it's an out parameter, 129 00:12:21,000 --> 00:12:26,940 then you just pass it a four because that's the size of a D word and so it's the size 130 00:12:26,940 --> 00:12:31,500 of a pointer. And if you need a null pointer for any reason, you can just pass it nil. 131 00:12:33,280 --> 00:12:39,040 Then we have, of course, pchars and pwchars, which is just wide characters and pointers 132 00:12:39,040 --> 00:12:43,940 to characters and wide characters. Same thing, we pass the data, so we're passing it strings. 133 00:12:45,620 --> 00:12:50,780 And again, if it's an out only parameter, then we pass it the size of the buffer that 134 00:12:50,780 --> 00:12:50,980 we want. 135 00:12:52,820 --> 00:12:57,660 And that includes the null byte. So you have to watch that. You can get, you know, you're 136 00:12:57,660 --> 00:12:59,120 off by one errors there. 137 00:13:01,060 --> 00:13:06,760 But so here's just some example that shows some of those data types in use. So you can 138 00:13:06,760 --> 00:13:12,620 see the definition on the side here. We've got a PD word, a pointer to a wide char, 139 00:13:12,900 --> 00:13:14,300 and some D words in there. 140 00:13:14,580 --> 00:13:20,860 And if you actually look down at the acquire context call on the right, you can see that 141 00:13:21,000 --> 00:13:28,240 we point in four for the out pointer to the D word. We put a null pointer for the container. 142 00:13:29,460 --> 00:13:35,560 And then we have some basically fake constants that we define up above that we pass in for 143 00:13:35,560 --> 00:13:41,060 the other parameters. So just a quick little look to demonstrate those data types being 144 00:13:41,060 --> 00:13:44,780 used. And we'll have some demo here closer to the end. 145 00:13:48,240 --> 00:13:50,980 That we have a Boolean type. It's, there are three types of Boolean types. The first is 146 00:13:50,980 --> 00:13:54,860 there's not much I can say about it. It does exactly what you think it does. So you just 147 00:13:54,860 --> 00:14:01,220 pass it a boolean, a true false in Ruby. And another example, here's the is debugger present 148 00:14:01,220 --> 00:14:11,220 Windows API call. And it returns an actual false value. Bytes and words basically do 149 00:14:11,220 --> 00:14:18,440 the exact same thing as D words, but they'll be truncated to the appropriate length by 150 00:14:18,440 --> 00:14:24,240 railgun, so it handles all of that for you. And then the last sort of catch all is the 151 00:14:24,240 --> 00:14:29,120 pointer to a blob. And this is basically any data that doesn't fit any of the other data 152 00:14:29,120 --> 00:14:39,320 types. It's a blob. And on the Ruby side we just treat it as a string. And this is important 153 00:14:39,320 --> 00:14:43,020 also because railgun doesn't really help you parse structures, so sometimes you have to 154 00:14:43,020 --> 00:14:48,420 do some kind of rejiggering there to work with some of the more complex structures. 155 00:14:48,440 --> 00:14:56,180 Some of the more advanced Windows structure types. Here's another example of a definition 156 00:14:56,180 --> 00:15:04,720 and then seeing how it's actually used with those data types. I mean, we'll go over all 157 00:15:04,720 --> 00:15:08,720 of this at the demo. I just wanted to make sure it was on the slides for anyone who didn't 158 00:15:08,720 --> 00:15:18,420 get to see the presentation. So sometimes we have to kind of face the 159 00:15:18,440 --> 00:15:19,320 question and say, what's the best way to use this? And then we kind of fake it. And 160 00:15:19,320 --> 00:15:26,000 I kind of made reference to this earlier with the D word thing. There's a lot of crazy 161 00:15:26,000 --> 00:15:29,880 data types that you can run into with the Windows API, a lot of custom structures. 162 00:15:30,940 --> 00:15:35,820 And even simple things like handles and pointers that Ruby doesn't have a concept of. So we 163 00:15:35,820 --> 00:15:48,420 kind of fake it. Anything that basically boils down to being a number you just treat as a D word. Otherwise it's a blob. If neither really works for your scenario, my recommendation is to use it as a D word. 164 00:15:48,440 --> 00:15:56,300 You can add a function call to this. If you don't know what a function call is, you can just add support for it yourself. It seems intimidating at first, but it's actually really easy to work with this stuff. 165 00:15:59,080 --> 00:16:05,300 So when you make an actual function call, you're actually returned a hash. That hash 166 00:16:05,300 --> 00:16:10,500 will always contain, at the very least, the result of a get last error call. So basically 167 00:16:10,500 --> 00:16:14,660 Railgun will make the function call for you and then it will call the Windows get last 168 00:16:14,660 --> 00:16:18,320 error function, which will tell you any error code that occurs. 169 00:16:18,420 --> 00:16:24,380 with the running of that function. And then the hash will contain any out values from 170 00:16:24,380 --> 00:16:30,660 that function call. So if anyone ‑‑ for anyone who is not familiar with get last error, 171 00:16:30,920 --> 00:16:36,260 it will return an error code of zero if everything went fine. Otherwise you will get a system 172 00:16:36,260 --> 00:16:41,240 error code and there's a nice handy MSDN page where you can look up what any of those mean. 173 00:16:41,240 --> 00:16:50,000 I recommend that everyone have that page bookmarked because it's super, super useful. I reference 174 00:16:50,000 --> 00:17:09,640 it all the time. Okay. Oh, so this is ‑‑ I'm sorry. This is just an example of some 175 00:17:09,640 --> 00:17:10,640 code using Railgun. 176 00:17:10,700 --> 00:17:11,220 Using 2DMX. I'm sorry. This is just an example of some code using Railgun using 2DMX. I'm 177 00:17:11,240 --> 00:17:18,020 sorry. This is different function calls and we acquire the cryptographic context and return 178 00:17:18,020 --> 00:17:26,160 value is then used in the next function call. So that just shows you we call the JSON challenged 179 00:17:26,160 --> 00:17:32,980 crypt require context and get the hash and make a reference to the PH provider value 180 00:17:32,980 --> 00:17:41,080 out of the return and pass that into the next function call. So some of the more 181 00:17:41,080 --> 00:17:45,120 tricky situations that you can run into, again, is the complex structures that you'll have 182 00:17:45,120 --> 00:17:49,760 to parse yourself. A lot of times you end up doing some funny things like having to 183 00:17:49,760 --> 00:17:56,180 get pointers back and then increment the pointer yourself and do another memread and do a memread 184 00:17:56,180 --> 00:18:03,900 and increment a pointer. And so you can end up with some kind of tedious work with that. 185 00:18:06,480 --> 00:18:10,420 Because you're reading everything directly out of memory, if you don't know the length 186 00:18:10,420 --> 00:18:14,600 of a string, you can run into some tricky situations with that, too. Although somebody 187 00:18:14,600 --> 00:18:18,180 was just telling me that they got around that by actually then using Railgun again 188 00:18:18,180 --> 00:18:23,280 to call size of back on the pointer. So that's something that you should probably be able 189 00:18:23,280 --> 00:18:31,120 to do. And one of the downfalls right now with Railgun is that it's slow because every 190 00:18:31,120 --> 00:18:36,960 single request and every read operation has to be sent as a packet from your client back 191 00:18:36,960 --> 00:18:40,220 to the meterpreter on the victim machine. 192 00:18:40,220 --> 00:18:46,080 And so, like, large numbers of string reads, for example, is a very slow process. So it 193 00:18:46,080 --> 00:18:50,520 seems like, you know, I'm just pulling this data structure out of memory on my victim. 194 00:18:50,620 --> 00:18:56,480 It should come back to me. But if it's got, like, a massive string in there or a bunch 195 00:18:56,480 --> 00:19:01,680 of different parameters, it has to send a new packet for each little bit that it's pulling 196 00:19:01,680 --> 00:19:05,800 back. And that can actually take some time. That was one of the things Chow Mu was working 197 00:19:05,800 --> 00:19:09,040 on fixing before he dropped off the face of the earth. 198 00:19:10,220 --> 00:19:15,260 It was doing some nice multi‑read stuff. So hopefully we can get that back on track 199 00:19:15,260 --> 00:19:20,420 in the near future. So tricks of the trade. These are just the 200 00:19:20,420 --> 00:19:27,400 things that I've found exceptionally useful for learning to do Railgun. MSDN is your 201 00:19:27,400 --> 00:19:33,240 friend. I don't know how many people do Windows API programming or spend time on MSDN, but 202 00:19:33,240 --> 00:19:38,940 it's ‑‑ it gives you all the information you need right there. It will give you function, 203 00:19:39,560 --> 00:19:46,680 definitions. It will give you examples. So use MSDN. Find examples of the code in C. 204 00:19:47,020 --> 00:19:51,900 And write it ‑‑ whatever you're trying to do, write it in C first. Because you're 205 00:19:51,900 --> 00:19:57,840 doing this weird transition from Ruby into C. And sometimes things don't behave the way 206 00:19:57,840 --> 00:20:02,740 you expect it to. So if you write it in C and kind of look at it in memory at the time, 207 00:20:03,500 --> 00:20:08,040 you can know exactly what to expect. And then when you go to do it on the Ruby side, it 208 00:20:08,040 --> 00:20:08,920 goes much faster. 209 00:20:08,940 --> 00:20:15,620 So it's kind of like Microsoft wants to help you own their systems. Because I don't know 210 00:20:15,620 --> 00:20:20,520 how well you can see that. But there's the definition of the function. It looks very 211 00:20:20,520 --> 00:20:27,220 similar to the function definitions we have in that Railgun code, right? Seriously. Right 212 00:20:27,220 --> 00:20:31,060 there they give you an example down at the bottom of the page of what that C code looks 213 00:20:31,060 --> 00:20:35,620 like. So I mean it's like they give you a walk‑through and hold your hand through 214 00:20:36,080 --> 00:20:37,020 doing all of this. 215 00:20:37,020 --> 00:20:42,500 this. They even give you great tools, the free Visual Studio. You can write your C code 216 00:20:42,960 --> 00:20:48,380 and then just look at exactly what those structures look like in memory. So there's no real mystery 217 00:20:48,380 --> 00:20:53,660 if you do it in C on a Windows box first and then just port it over to the Ruby. 218 00:20:56,180 --> 00:21:00,760 So by this point you're all saying, oh, God, this guy is going on and on and on about this 219 00:21:00,760 --> 00:21:07,760 stuff and why do I care anymore? What is Railgun useful for? So anything you can do with the 220 00:21:07,760 --> 00:21:14,680 Windows API is available and one of the reasons Railgun makes this extra special is that we're 221 00:21:14,680 --> 00:21:19,540 not compiling new extensions into that DLL, right? If we wanted to add this the traditional 222 00:21:19,540 --> 00:21:24,640 way, we would have to write new C code, hook it in, and that's more data that has to go 223 00:21:24,640 --> 00:21:29,480 down and expand the size of that payload on the victim's machine, slowing the victim 224 00:21:29,480 --> 00:21:29,860 down. 225 00:21:29,860 --> 00:21:36,680 Making it more likely that it's going to be detected. So here's some example mayhem 226 00:21:36,680 --> 00:21:44,840 that's been caused with Railgun. Smart FTP is an FTP client that stores encrypted passwords, 227 00:21:45,200 --> 00:21:52,060 but it encrypts all the passwords with the Windows cryptographic API. So using Railgun, 228 00:21:52,220 --> 00:21:57,800 we make those same exact function calls and get the victim machine to go ahead and decrypt 229 00:21:57,800 --> 00:21:58,880 the passwords for us. 230 00:21:59,000 --> 00:21:59,840 There's no pullback. 231 00:21:59,860 --> 00:22:04,660 Pulling down the encrypted password and having to crack it and use our own processor time 232 00:22:04,660 --> 00:22:11,800 for it, the victim does all the work for us. Another contributor added one that Windows 233 00:22:12,480 --> 00:22:18,440 has a credential store where it stores passwords for things like RDP and a couple other Microsoft 234 00:22:18,440 --> 00:22:22,600 specific things, and it's all exposed through the Windows API. 235 00:22:22,940 --> 00:22:29,320 So as long as you are in the context of the user who stored those passwords, you basically 236 00:22:29,320 --> 00:22:33,500 just ask the operating system to give them to you, and it will, because it trusts it. 237 00:22:33,580 --> 00:22:35,500 You're that guy. Why wouldn't it give it to you? 238 00:22:37,460 --> 00:22:43,400 There's some post modules that will actually use the wireless API. And with that, we can 239 00:22:43,400 --> 00:22:49,200 actually get any stored profile, so saved passwords for wireless networks. We can make 240 00:22:49,200 --> 00:22:54,460 the wireless card on our victim actually actively scan for new networks, disconnect from networks, 241 00:22:54,700 --> 00:22:55,960 connect to new networks. 242 00:22:56,480 --> 00:22:59,300 One that I haven't gotten around to doing, but it's called TRI, which is called TRI, 243 00:22:59,300 --> 00:23:05,200 is on my plate is actually to use the victim's wireless card to then set up a fake access 244 00:23:05,200 --> 00:23:11,020 point. So, I mean, if you think about that, you take control of a desktop, they're wired 245 00:23:11,020 --> 00:23:16,060 in and then you set up a fake wireless AP off their card, you've got basically a whole 246 00:23:16,060 --> 00:23:20,400 other network that you've set up that you can pivot into and trick people into connecting 247 00:23:20,400 --> 00:23:24,760 to. It's just some really fun things you can do. 248 00:23:26,700 --> 00:23:34,440 So, enough blathering and slides. It's time for some demos. Hopefully this will be a little 249 00:23:34,440 --> 00:23:42,420 more exciting for everybody. So I've got a ‑‑ come on ‑‑ a server 2008 VM set up here. 250 00:23:43,340 --> 00:23:49,320 We're going to just go ahead and make sure all our settings are correct. We're just going 251 00:23:49,320 --> 00:23:51,960 to pop a shell on it with the PS exec module. 252 00:23:53,160 --> 00:23:53,680 Okay. 253 00:23:55,460 --> 00:24:00,500 So we've got our meterpreter session. We're going to run the PS command to get the process 254 00:24:00,500 --> 00:24:07,660 list. And let's find explorer. Okay. So what I'm going to do is I'm going to go ahead and 255 00:24:07,660 --> 00:24:12,920 migrate meterpreter into the explorer process so that we're operating in user land so you 256 00:24:12,920 --> 00:24:20,860 can kind of see some of this stuff interactively. And it will take a little second here. It's 257 00:24:20,860 --> 00:24:23,440 basically just reinjecting itself into a new process. 258 00:24:24,300 --> 00:24:30,860 And so now we should, if we check our UID, we're running as that actual user. And we're 259 00:24:30,860 --> 00:24:35,140 going to drop into the IRB, which is basically IRB shell, which is just an interactive Ruby 260 00:24:35,140 --> 00:24:40,400 shell that we can basically write out commands as if we're writing a module, but do it in 261 00:24:40,400 --> 00:24:52,480 real time. And so we're going to just call on rail gun here. So everything is done through 262 00:24:52,480 --> 00:24:56,680 the client object that represents your connection to the victim and then we're calling the Railgun 263 00:24:56,680 --> 00:25:05,360 extension and within that user 32 is the specific DLL that the first function we're going to 264 00:25:05,360 --> 00:25:11,500 use is based out of. And we're just going to throw a quick little message box up there 265 00:25:11,500 --> 00:25:23,780 just to be the simple obvious example so pass it a null pointer. Pass it the message and 266 00:25:23,780 --> 00:25:29,460 the title of the window and then we're going to pass it a string representation of the 267 00:25:29,460 --> 00:25:34,900 MBOK constant, which just tells it that the message box is an okay button message box. 268 00:25:36,200 --> 00:25:37,360 And we're going to call that. 269 00:25:39,800 --> 00:25:40,320 And 270 00:25:40,320 --> 00:25:44,120 And there you can see our simple little message box. 271 00:25:50,420 --> 00:25:52,700 So we go ahead and say okay to that. 272 00:25:53,100 --> 00:25:54,020 That's kind of cool. 273 00:25:54,180 --> 00:25:58,360 But, you know, for a pen test, who cares if you can pop up a little message box, right? 274 00:25:58,560 --> 00:26:02,260 So we've got calculator running here in programmer mode. 275 00:26:02,420 --> 00:26:03,100 That's for you, Manils. 276 00:26:03,100 --> 00:26:11,320 And we're going to find that PID here in our ‑‑ in our ‑‑ back in our process list. 277 00:26:11,840 --> 00:26:14,820 Excuse me while I find the PID. 278 00:26:17,380 --> 00:26:18,640 There we go. 279 00:26:19,040 --> 00:26:19,600 Okay. 280 00:26:21,720 --> 00:26:22,280 400. 281 00:26:23,100 --> 00:26:23,660 Okay. 282 00:26:24,980 --> 00:26:25,900 Is that right? 283 00:26:26,180 --> 00:26:27,180 That can't be right. 284 00:26:27,860 --> 00:26:28,420 Okay. 285 00:26:28,580 --> 00:26:29,240 Yeah, it was 400. 286 00:26:29,540 --> 00:26:30,020 Okay. 287 00:26:30,080 --> 00:26:33,040 So, again, we're going to call client and then Railgun. 288 00:26:33,100 --> 00:26:35,560 And this time we're going to call the kernel 32 DLL. 289 00:26:36,200 --> 00:26:39,720 And we're going to call open process, which just open ‑‑ oops. 290 00:26:40,560 --> 00:26:41,620 If I could type. 291 00:26:42,880 --> 00:26:49,920 All this does is open up a handle to that process with a set permission. 292 00:26:50,360 --> 00:26:54,700 And, again, we're going to pass it in a constant, which Railgun already knows about. 293 00:26:55,300 --> 00:26:57,880 And it's going to be the process terminate. 294 00:26:58,860 --> 00:27:02,520 And that's just basically the privilege level that we're opening that handle with. 295 00:27:03,520 --> 00:27:08,900 False here is just basically ‑‑ has to do with handle inheritance and process manipulation. 296 00:27:09,240 --> 00:27:12,820 It's really not important for this ‑‑ this particular demo. 297 00:27:13,120 --> 00:27:14,400 And then we pass it the PID. 298 00:27:15,680 --> 00:27:18,960 And you can see here, this is the return hash I was talking about. 299 00:27:19,060 --> 00:27:21,680 We got ‑‑ we know it worked because our get last error is zero. 300 00:27:22,120 --> 00:27:25,440 And that number is actually the representation of the handle. 301 00:27:26,960 --> 00:27:32,260 So I'm just going to go shove that return value into a variable here. 302 00:27:35,060 --> 00:27:38,200 And then we're going to call a new function. 303 00:27:43,380 --> 00:27:46,380 Terminate ‑‑ terminate process. 304 00:27:50,520 --> 00:27:56,580 And for terminate process, all we do is we give it the handle and an error code or an 305 00:27:56,580 --> 00:27:57,060 exit code. 306 00:27:58,660 --> 00:28:00,700 And our calculator is gone. 307 00:28:01,340 --> 00:28:01,920 . 308 00:28:09,180 --> 00:28:14,140 So that's sort of the easy version of Railgun. 309 00:28:15,800 --> 00:28:22,260 And just kind of a quick demonstration to show you the simple and easy way you can call 310 00:28:22,260 --> 00:28:23,520 some of these predefined functions. 311 00:28:24,180 --> 00:28:26,380 What I want to show you now is the Smart FTP. 312 00:28:27,060 --> 00:28:31,940 This is one of the saved XML files that Smart FTP stores a saved connection in. 313 00:28:32,520 --> 00:28:37,140 And you can see we've got the name of the connection, some data about, you know, what 314 00:28:37,140 --> 00:28:39,360 host it was, what port, the user name. 315 00:28:39,520 --> 00:28:43,320 And here we have an encrypted password saved in that XML file. 316 00:28:45,640 --> 00:28:51,180 So what we do is in our ‑‑ and I just closed it. 317 00:28:51,280 --> 00:28:51,940 That was brilliant. 318 00:28:52,520 --> 00:28:53,000 Sorry. 319 00:28:53,220 --> 00:28:54,640 Let me pull that back up. 320 00:28:55,680 --> 00:28:57,180 Module ‑‑ Control, shift, T. 321 00:28:58,220 --> 00:29:02,500 Control, shift, T. I guess I could just ‑‑ . 322 00:29:04,680 --> 00:29:06,200 There we go. 323 00:29:08,020 --> 00:29:14,620 So in this module, we actually ‑‑ there's a lot of garbage here just for searching out 324 00:29:14,620 --> 00:29:16,920 for the XML files and parsing them. 325 00:29:17,320 --> 00:29:21,120 But what we're interested in here is the actual decryption routine. 326 00:29:21,540 --> 00:29:25,060 So we pass in that encrypted password we saw in the XML file. 327 00:29:26,060 --> 00:29:29,900 We do some packing to get it in the right format. 328 00:29:30,440 --> 00:29:31,620 And we have ‑‑. 329 00:29:32,500 --> 00:29:37,460 We define some constants here that are useful for the cryptographic functions. 330 00:29:38,000 --> 00:29:45,180 But then you can see we basically just ‑‑ we call a series of crypto API functions to 331 00:29:45,180 --> 00:29:48,160 acquire the cryptographic context, create a hash. 332 00:29:48,340 --> 00:29:53,740 That hash data is then used to derive the cryptographic key that was used to encrypt 333 00:29:53,740 --> 00:29:54,380 these passwords. 334 00:29:54,860 --> 00:29:59,540 Destroy the hash, destroy ‑‑ we decrypt the password, then destroy everything and 335 00:29:59,540 --> 00:30:01,020 do garbage collect behind us. 336 00:30:01,020 --> 00:30:21,380 So we can turn this ‑‑ into ‑‑ this ‑‑ this. 337 00:30:22,180 --> 00:30:23,140 . 338 00:30:23,140 --> 00:30:23,540 . 339 00:30:23,540 --> 00:30:24,880 . 340 00:30:24,880 --> 00:30:24,980 . 341 00:30:24,980 --> 00:30:25,140 . 342 00:30:31,020 --> 00:30:31,040 . 343 00:30:31,040 --> 00:30:33,060 So, I mean, this is a very common problem. 344 00:30:33,180 --> 00:30:37,940 You'll find a lot of these modules sitting in Metasploit framework for decrypting 345 00:30:37,940 --> 00:30:43,480 these passwords because a lot of clients think that if they use a real encryption 346 00:30:43,480 --> 00:30:45,580 algorithm, surely, it must be safe. 347 00:30:45,740 --> 00:30:51,420 But of course, they hard code ‑‑ they hard code the encryption key or the routine 348 00:30:51,420 --> 00:30:54,520 for gathering the encryption key directly into the app. 349 00:30:54,660 --> 00:30:58,860 So it's very easy to reverse engineer that back out, and they've broken sort of the 350 00:30:58,860 --> 00:31:00,120 first rule of cryptography. 351 00:31:00,120 --> 00:31:06,900 of taking that key and separating it from what you're encrypting. So by simply getting 352 00:31:06,900 --> 00:31:12,320 onto that machine and calling the same exact API calls in the correct sequence, we just 353 00:31:12,320 --> 00:31:14,840 get the operating system to do all the work for us. 354 00:31:16,680 --> 00:31:25,240 I can't actually demo this part because I don't have wireless on the VM, but just a 355 00:31:25,240 --> 00:31:32,220 quick ‑‑ another quick example. This is a module that does the wireless LAN stuff 356 00:31:32,220 --> 00:31:38,020 I was talking about. And it basically open ‑‑ uses Railgun to open a handle to the wireless 357 00:31:38,020 --> 00:31:47,320 LAN API interface and then actually pulls a list of all the saved profiles on that interface. 358 00:31:48,340 --> 00:31:53,140 And then we just basically do some pointer manipulation magic to parse through all of 359 00:31:53,140 --> 00:31:53,860 the information. 360 00:31:53,860 --> 00:31:59,960 And, again, the same thing, as long as we're in the correct user context, the context of 361 00:31:59,960 --> 00:32:05,640 the user who originally saved those passwords, the operating system just returns those passwords 362 00:32:05,640 --> 00:32:07,920 in a decrypted format for us. 363 00:32:10,040 --> 00:32:20,820 So to sort of recap, Railgun basically lets you turn the machine into a weapon against 364 00:32:20,820 --> 00:32:21,360 itself. 365 00:32:22,100 --> 00:32:22,780 Okay. 366 00:32:25,560 --> 00:32:35,360 They provide everything you need to just destroy any ‑‑ wow, sorry, I'm stuttering 367 00:32:35,360 --> 00:32:41,360 like crazy here. They provide you all the tools you need. All you have to do is basically 368 00:32:41,360 --> 00:32:49,220 redefine them so that you can call them from the Ruby side. And I'm sorry, I ran a little 369 00:32:49,220 --> 00:32:51,360 fast here. That's actually all I've got. 370 00:32:53,860 --> 00:32:55,000 Thank you.