1 00:00:00,000 --> 00:00:02,660 So, this is Hacking .NET Applications at Runtime. 2 00:00:02,760 --> 00:00:05,220 I'm John McCoy, and this is Daniel DeFries. 3 00:00:06,980 --> 00:00:10,620 So, going after .NET at Runtime is using reflection 4 00:00:10,620 --> 00:00:14,660 to activate the functionality inside of a .NET program. 5 00:00:14,960 --> 00:00:17,920 This is legitimate inside of the .NET framework. 6 00:00:18,100 --> 00:00:19,260 It's functionality inherent. 7 00:00:19,720 --> 00:00:22,240 This is part of a runtime language. 8 00:00:22,700 --> 00:00:25,300 If you go to something like Java 9 00:00:25,300 --> 00:00:29,140 or other intermediate languages 10 00:00:29,140 --> 00:00:32,860 that have CLR, you'll find this basic same functionality. 11 00:00:34,620 --> 00:00:38,440 This allows us to reflectively look at objects 12 00:00:38,440 --> 00:00:40,320 and edit them at runtime, 13 00:00:40,560 --> 00:00:42,260 and we're going to exploit this 14 00:00:42,260 --> 00:00:45,040 to make a .NET application malleable 15 00:00:45,040 --> 00:00:48,600 to not only change the value and state of it, 16 00:00:48,660 --> 00:00:50,700 but to literally change the logic flow. 17 00:00:51,040 --> 00:00:52,780 We're not going to be attacking code. 18 00:00:53,000 --> 00:00:54,840 We're going to be attacking the runtime itself. 19 00:00:56,980 --> 00:00:58,760 So, this presentation, 20 00:00:59,140 --> 00:01:02,120 we'll be covering accessing running .NET programs, 21 00:01:02,660 --> 00:01:04,060 attacking the runtime structure, 22 00:01:04,320 --> 00:01:06,780 the weak points to go after when you attack a program, 23 00:01:07,020 --> 00:01:09,420 and some tools that we're going to be releasing. 24 00:01:10,840 --> 00:01:13,640 So, the tools that you'll be getting is .NET Exploit. 25 00:01:13,820 --> 00:01:15,820 This is a framework and payload system 26 00:01:16,640 --> 00:01:18,080 with a management area, 27 00:01:18,240 --> 00:01:22,480 as well as the standard deliver, package, or payloads. 28 00:01:22,680 --> 00:01:24,480 So, it's easy to reuse, 29 00:01:24,600 --> 00:01:27,800 and hopefully people want to develop for it. 30 00:01:29,820 --> 00:01:33,220 Metasploit payload that'll work with the delivery system 31 00:01:33,220 --> 00:01:35,360 that will be arbitrary. 32 00:01:36,620 --> 00:01:39,740 And this will be a standard Metasploit delivered 33 00:01:39,740 --> 00:01:41,320 to SQL Server Management Studio. 34 00:01:42,580 --> 00:01:44,840 And we'll demo that towards the end. 35 00:01:44,900 --> 00:01:45,540 Hopefully you'll like it. 36 00:01:46,020 --> 00:01:49,520 And we also found some really nice extras 37 00:01:49,520 --> 00:01:50,860 when we were doing this research. 38 00:01:51,560 --> 00:01:54,820 We're going to be leveraging an old Visual Studio's exploit, 39 00:01:55,420 --> 00:01:58,440 as well as showing some decompilation that'll get 40 00:01:58,440 --> 00:02:00,600 around some of the protection that you might run up against 41 00:02:00,600 --> 00:02:02,560 when you're trying to decompile .NET applications. 42 00:02:03,800 --> 00:02:05,180 So, the runtime attack. 43 00:02:06,260 --> 00:02:09,040 It's going to go after the process space itself. 44 00:02:10,020 --> 00:02:11,360 This is your application. 45 00:02:12,600 --> 00:02:15,580 You can put more than one application in a process space. 46 00:02:16,840 --> 00:02:19,960 We're going to modify the runtime objects of a process 47 00:02:19,960 --> 00:02:21,500 to carry out this attack. 48 00:02:21,860 --> 00:02:24,940 We're going to be editing the underlying structure 49 00:02:24,940 --> 00:02:25,940 of an application. 50 00:02:27,080 --> 00:02:28,320 The structure itself, 51 00:02:28,320 --> 00:02:29,360 not the code base. 52 00:02:30,520 --> 00:02:32,580 This will allow us to compromise the GUI, 53 00:02:33,180 --> 00:02:36,080 instantiate new features, access the code base, 54 00:02:36,380 --> 00:02:39,420 subvert logic, and evaluate the object structure. 55 00:02:40,540 --> 00:02:43,160 Evaluating the object structure is more for reconnaissance. 56 00:02:43,380 --> 00:02:45,480 When you get into someone else's application, 57 00:02:46,120 --> 00:02:48,920 assuming you do or don't have access to their source code, 58 00:02:49,040 --> 00:02:51,680 you want to go around and figure out how those objects 59 00:02:51,680 --> 00:02:52,280 lay in memory. 60 00:02:52,440 --> 00:02:54,680 What instance of an object do you want to attack? 61 00:02:56,180 --> 00:02:58,300 This is also used in a lot of other projects. 62 00:02:58,320 --> 00:03:00,260 This is also useful when you're attacking a program live. 63 00:03:00,520 --> 00:03:03,200 So, if you're not making an out-of-the-box attack, 64 00:03:03,500 --> 00:03:05,540 you want to attack it on the fly. 65 00:03:05,840 --> 00:03:07,020 This is also useful. 66 00:03:08,380 --> 00:03:10,240 So, what is it and what is it not? 67 00:03:10,700 --> 00:03:12,400 This is a memory-only attack. 68 00:03:12,660 --> 00:03:14,260 We're not going at it on disk. 69 00:03:15,840 --> 00:03:17,360 This is deployment independent. 70 00:03:18,160 --> 00:03:21,640 That means that whatever way that you are able to make it 71 00:03:21,640 --> 00:03:24,620 into your target's runtime, this attack will be carried out the same. 72 00:03:24,820 --> 00:03:28,300 We have a few demonstration ways of getting into your target's application. 73 00:03:30,140 --> 00:03:31,060 And stability. 74 00:03:31,380 --> 00:03:32,980 We're not playing games with the heap. 75 00:03:33,060 --> 00:03:34,020 We're not messing with pointers. 76 00:03:34,200 --> 00:03:35,480 We're inside of the .NET framework. 77 00:03:35,820 --> 00:03:39,300 So, we have the stability that .NET comes with. 78 00:03:39,440 --> 00:03:43,280 You don't have to worry about accidentally changing one thing 79 00:03:43,280 --> 00:03:44,880 that changes everything else in the program. 80 00:03:46,060 --> 00:03:47,720 And this is language agnostic. 81 00:03:47,960 --> 00:03:50,660 When you're attacking a .NET program at runtime, it's IL. 82 00:03:50,860 --> 00:03:53,580 So, you don't have to care about what language it was coded in, 83 00:03:54,090 --> 00:03:57,080 as well as you should be going up against protected programs, 84 00:03:57,080 --> 00:03:59,500 which will have obstification. 85 00:03:59,900 --> 00:04:03,460 So, you shouldn't be able to convert it back into a language anyway. 86 00:04:03,600 --> 00:04:04,340 So, it doesn't matter. 87 00:04:05,700 --> 00:04:06,960 So, this is what we're attacking. 88 00:04:07,300 --> 00:04:08,340 A .NET process. 89 00:04:09,540 --> 00:04:12,060 You have app domains, assemblies, modules, classes. 90 00:04:12,280 --> 00:04:13,300 This is kind of the structure. 91 00:04:14,280 --> 00:04:16,720 At the end, we have our instances. 92 00:04:16,900 --> 00:04:18,020 And this is what we're going after. 93 00:04:19,820 --> 00:04:22,400 So, this is a classical view of a .NET process. 94 00:04:22,980 --> 00:04:25,560 You have a process where you have your GUIs and your instances. 95 00:04:25,560 --> 00:04:28,720 Inside of that, you have app domains, assemblies, 96 00:04:29,280 --> 00:04:31,840 and eventually you have your classes and values and functions. 97 00:04:32,080 --> 00:04:32,920 And this is our target. 98 00:04:33,120 --> 00:04:35,640 We're going to be going after instances at runtime. 99 00:04:35,920 --> 00:04:37,900 We really don't care what class it came from. 100 00:04:38,400 --> 00:04:40,720 We will be utilizing what class it came from, 101 00:04:40,840 --> 00:04:44,400 but the structure of the application doesn't matter. 102 00:04:44,480 --> 00:04:45,740 The structure of the objects matters. 103 00:04:47,460 --> 00:04:49,960 And this is what a program kind of looks like at runtime. 104 00:04:50,360 --> 00:04:53,960 You'll be going up against a lot of objects spinning around in memory. 105 00:04:53,960 --> 00:04:59,060 We have logical sections like the GUI and the core functionality. 106 00:04:59,580 --> 00:05:03,520 These objects are interrelated by pointers behind the scenes, 107 00:05:03,680 --> 00:05:05,360 but basically value references. 108 00:05:05,900 --> 00:05:07,220 And we have a button. 109 00:05:07,300 --> 00:05:10,680 It's interconnected by an event to a specific object. 110 00:05:10,940 --> 00:05:12,980 And this is our target. 111 00:05:13,320 --> 00:05:15,840 To go after the runtime, to go after the instances, 112 00:05:16,000 --> 00:05:17,900 to go after the events and remold all this. 113 00:05:18,280 --> 00:05:21,580 And this will allow us to change the underlying structure of a .NET application. 114 00:05:23,960 --> 00:05:26,320 So the specific task behind this attack, 115 00:05:26,520 --> 00:05:28,740 going to connect into your target application, 116 00:05:29,140 --> 00:05:33,740 find objects and hunt for the references to the specific object you want to attack. 117 00:05:33,960 --> 00:05:38,400 Like if you're going after a timer or a SQL connection or a TCP connection, 118 00:05:38,620 --> 00:05:40,940 you have to hunt down your references in order to attack it. 119 00:05:41,740 --> 00:05:43,240 Going to move between objects. 120 00:05:43,640 --> 00:05:46,540 Depending on your connection method, you might need to hunt objects. 121 00:05:46,780 --> 00:05:49,260 Other connection methods will give you references for free. 122 00:05:50,040 --> 00:05:51,680 And finally we're going to change objects. 123 00:05:52,280 --> 00:05:53,180 Using reflection, 124 00:05:53,180 --> 00:05:55,380 we'll look at the meta structure of an object, 125 00:05:55,580 --> 00:05:58,000 use its signature and edit it at runtime. 126 00:05:59,300 --> 00:06:01,800 Okay, so down to the meat of it, 127 00:06:01,880 --> 00:06:03,340 how do you get into your target application? 128 00:06:04,060 --> 00:06:05,940 So you connect into your target's runtime. 129 00:06:06,160 --> 00:06:08,500 You inject into it and spin up some .NET. 130 00:06:09,240 --> 00:06:13,340 There's some projects we'll be demoing for this 131 00:06:13,340 --> 00:06:15,660 and is the favored method for injecting, 132 00:06:15,660 --> 00:06:17,600 or for connecting to your target application. 133 00:06:18,000 --> 00:06:19,900 This is what we're going in with Metasploit. 134 00:06:20,000 --> 00:06:21,580 This is how you attack them on your system. 135 00:06:22,060 --> 00:06:24,460 Also, you can exploit the target's code base, 136 00:06:24,620 --> 00:06:28,100 or the problems inside of the application. 137 00:06:28,660 --> 00:06:32,940 We're going to be demoing Visual Studios and exploiting that. 138 00:06:33,700 --> 00:06:35,740 Both of these get you into a target application, 139 00:06:36,020 --> 00:06:37,660 not necessarily where you want to go, 140 00:06:37,760 --> 00:06:38,480 but it gets you inside. 141 00:06:39,840 --> 00:06:42,120 There's infecting the target's code base on disk. 142 00:06:42,340 --> 00:06:43,640 This is an old hack. 143 00:06:43,820 --> 00:06:45,660 You find your entrance, 144 00:06:45,860 --> 00:06:48,420 you add yourself into a no-op or something, 145 00:06:48,480 --> 00:06:49,000 and you're in. 146 00:06:49,280 --> 00:06:50,200 That's kind of been done. 147 00:06:50,740 --> 00:06:52,020 This is on disk, 148 00:06:52,240 --> 00:06:54,580 so you're going to leave some forensics evidence behind, 149 00:06:54,800 --> 00:06:57,340 as where with injecting your code into memory, 150 00:06:57,460 --> 00:06:59,620 you're not going to be worrying about leaving something on disk 151 00:06:59,620 --> 00:07:00,680 that can be recovered later. 152 00:07:02,420 --> 00:07:04,300 And finally, there's attacking the framework, 153 00:07:04,500 --> 00:07:06,360 where you infect the framework itself. 154 00:07:06,660 --> 00:07:08,980 This was presented last DEF CON, 155 00:07:09,140 --> 00:07:12,020 and has a little bit of research behind it, 156 00:07:12,060 --> 00:07:12,800 and it's pretty strong. 157 00:07:12,960 --> 00:07:14,280 When you infect the framework, 158 00:07:14,440 --> 00:07:16,940 you don't have to worry about the target application 159 00:07:16,940 --> 00:07:18,660 seeing your code running inside of it. 160 00:07:18,660 --> 00:07:22,320 You can access core things like toString, 161 00:07:22,380 --> 00:07:24,060 and when someone uses it, you attack them. 162 00:07:24,460 --> 00:07:27,160 So you can basically have an entrance into any application 163 00:07:27,160 --> 00:07:28,800 that uses the framework, 164 00:07:28,940 --> 00:07:30,280 which is all the .NET applications. 165 00:07:33,980 --> 00:07:36,860 So, demoing how to connect into a target application. 166 00:07:37,600 --> 00:07:39,160 We'll bring up Mandiant's highlighter. 167 00:07:41,360 --> 00:07:44,280 Going to be injecting a 64-bit payload in there. 168 00:07:44,880 --> 00:07:46,700 If it's a 32-bit application, 169 00:07:46,960 --> 00:07:48,200 you inject the 32-bit, 170 00:07:49,860 --> 00:07:51,580 so we inject in, 171 00:07:51,720 --> 00:07:54,020 and this spins up a payload that says, 172 00:07:54,120 --> 00:07:55,640 what do you want to load in? 173 00:07:56,980 --> 00:07:59,880 We'll select hack buttons. 174 00:08:00,920 --> 00:08:02,920 A nice little demo that goes in, 175 00:08:02,960 --> 00:08:04,640 and it adds objects to the form itself. 176 00:08:05,460 --> 00:08:08,660 And it's pretty easy to go in and edit forms, 177 00:08:08,720 --> 00:08:11,680 since they're made to be fairly receptive to new objects. 178 00:08:13,200 --> 00:08:15,820 And we can click these buttons, 179 00:08:15,980 --> 00:08:17,480 and they go through and add events, 180 00:08:18,200 --> 00:08:19,880 programmatically to everything it finds on the form. 181 00:08:20,260 --> 00:08:22,240 In this case, it adds a right-click event 182 00:08:22,240 --> 00:08:23,220 to everything on here. 183 00:08:23,520 --> 00:08:24,540 When you right-click, 184 00:08:24,740 --> 00:08:26,000 it brings up an editing menu. 185 00:08:26,980 --> 00:08:30,140 And so you can edit pretty much anything 186 00:08:30,140 --> 00:08:31,280 as you normally would. 187 00:08:31,500 --> 00:08:33,340 This is pretty much the same concept 188 00:08:33,340 --> 00:08:35,760 as what Visual Studios does 189 00:08:35,760 --> 00:08:37,200 when you're editing it offline. 190 00:08:38,360 --> 00:08:41,400 And you can dig into pretty much any part of this 191 00:08:41,400 --> 00:08:42,460 and edit it however you want. 192 00:08:42,600 --> 00:08:44,140 And of course, you can do this programmatically 193 00:08:44,140 --> 00:08:45,760 to reskin any application. 194 00:08:48,200 --> 00:08:49,400 And there's some other ones. 195 00:08:49,540 --> 00:08:51,340 Like, you can make them draggable and all that. 196 00:08:54,160 --> 00:08:55,140 Make them poppable. 197 00:08:55,240 --> 00:08:57,680 But this is just a demonstration of the injection. 198 00:08:57,980 --> 00:08:59,080 So that's injecting. 199 00:08:59,980 --> 00:09:01,360 Demonstrating the exploitation. 200 00:09:06,960 --> 00:09:09,860 As a quick exploit for Visual Studios, 201 00:09:10,080 --> 00:09:12,000 there's a way to run arbitrary code 202 00:09:12,000 --> 00:09:14,720 inside of Visual Studios when you open a project. 203 00:09:15,440 --> 00:09:16,880 So we opened a project, 204 00:09:16,880 --> 00:09:18,980 and now there's arbitrary code running. 205 00:09:20,520 --> 00:09:21,780 So we'll again say, 206 00:09:21,880 --> 00:09:23,620 hey, what payload do we want to load into this? 207 00:09:24,540 --> 00:09:26,620 And we'll load the lead. 208 00:09:27,420 --> 00:09:29,720 So this just programmatically goes through 209 00:09:29,720 --> 00:09:30,940 and changes everything into lead. 210 00:09:31,220 --> 00:09:31,920 Ha ha. 211 00:09:32,080 --> 00:09:35,720 So this is actually .NET form. 212 00:09:35,900 --> 00:09:36,480 It's live. 213 00:09:36,700 --> 00:09:37,780 It's actual objects. 214 00:09:38,020 --> 00:09:39,120 And we're going to lead it. 215 00:09:40,680 --> 00:09:43,100 Part of this system is a communication console 216 00:09:43,100 --> 00:09:44,360 with all of the payloads. 217 00:09:44,720 --> 00:09:45,780 So you can... 218 00:09:45,780 --> 00:09:47,120 We have our delivery system. 219 00:09:47,240 --> 00:09:47,860 We have our lead. 220 00:09:48,500 --> 00:09:51,220 What application it's in, the PID, the user. 221 00:09:51,700 --> 00:09:54,140 And this will hopefully be extracted 222 00:09:54,140 --> 00:09:56,080 to run over the network. 223 00:09:56,300 --> 00:09:59,200 So you can arbitrarily communicate with payloads 224 00:09:59,200 --> 00:10:00,680 that have been deployed on someone else's system. 225 00:10:01,440 --> 00:10:03,920 So we'll go ahead and lead Visual Studios. 226 00:10:05,660 --> 00:10:07,780 We'll also bring up a data connection. 227 00:10:08,980 --> 00:10:10,440 So we lead it. 228 00:10:10,620 --> 00:10:11,660 It comes through. 229 00:10:11,720 --> 00:10:13,760 It iterates through every object that it finds 230 00:10:13,760 --> 00:10:15,260 that's of a control type, 231 00:10:15,260 --> 00:10:16,700 and changes its text to lead. 232 00:10:18,260 --> 00:10:20,880 And this actually happens in code. 233 00:10:23,220 --> 00:10:27,640 So the plus side of this is it's completely programmatic, 234 00:10:27,720 --> 00:10:29,600 and we don't have to worry about disturbing 235 00:10:29,600 --> 00:10:31,240 the underlying structure of the program. 236 00:10:33,820 --> 00:10:36,520 And also, FYI, if you save this, 237 00:10:36,600 --> 00:10:38,620 it actually saves a lead into your code base. 238 00:10:41,300 --> 00:10:43,000 And that's exploiting that. 239 00:10:46,780 --> 00:10:49,160 So that's the general connection types. 240 00:10:49,340 --> 00:10:50,800 There's also infecting the framework, 241 00:10:51,080 --> 00:10:52,960 which I'm not going to be demoing, 242 00:10:53,060 --> 00:10:54,300 but there's some code base 243 00:10:54,300 --> 00:10:55,640 that we're going to be releasing to do that. 244 00:10:56,020 --> 00:10:58,140 Like I said, it's pretty strong and pretty effective. 245 00:10:59,380 --> 00:11:02,000 So this is the overall structure 246 00:11:02,000 --> 00:11:05,280 of the application, or the system. 247 00:11:05,460 --> 00:11:06,680 You have your payloads. 248 00:11:06,680 --> 00:11:10,220 They get packaged into a safe wrapper 249 00:11:10,220 --> 00:11:12,760 that gets injected into your target application, 250 00:11:13,080 --> 00:11:14,600 so you don't have to worry about threading 251 00:11:14,600 --> 00:11:16,820 or any other hiccups when you're running 252 00:11:16,820 --> 00:11:18,180 inside of another application. 253 00:11:18,440 --> 00:11:20,680 And you have your injection into your target application. 254 00:11:23,560 --> 00:11:25,820 So this is the basics for how we're getting in. 255 00:11:26,300 --> 00:11:28,020 We inject into our target application. 256 00:11:28,400 --> 00:11:29,800 We spin up some C++. 257 00:11:30,020 --> 00:11:32,720 This unpacks itself in memory and spins up C Sharp. 258 00:11:33,120 --> 00:11:34,500 This can either be your hack 259 00:11:34,500 --> 00:11:36,080 or your payload delivery system. 260 00:11:36,500 --> 00:11:41,520 At this point, it loads up our arbitrary payloads, 261 00:11:41,520 --> 00:11:43,580 and they attack the target application. 262 00:11:47,980 --> 00:11:50,640 So this is the basic idea of what you're up against 263 00:11:50,640 --> 00:11:52,240 when you inject into a target application. 264 00:11:53,260 --> 00:11:55,080 You basically end up in nowhere. 265 00:11:55,320 --> 00:11:56,680 You have no references, 266 00:11:56,700 --> 00:11:59,480 and you have no way of getting to your target application. 267 00:12:00,360 --> 00:12:02,400 You can hope to get some statics 268 00:12:02,400 --> 00:12:05,260 or some entrances, APIs, or some object reference, 269 00:12:05,560 --> 00:12:07,960 but on a whole, you're pretty much in the middle of nowhere. 270 00:12:09,540 --> 00:12:11,380 So how do you get from the middle of nowhere 271 00:12:11,380 --> 00:12:12,380 to your target application? 272 00:12:12,900 --> 00:12:14,200 There's nothing stopping you, 273 00:12:14,200 --> 00:12:15,720 but there's also no doors to use. 274 00:12:16,900 --> 00:12:19,680 So the favored method that we're going after 275 00:12:19,960 --> 00:12:21,800 is accessing the GUI 276 00:12:21,800 --> 00:12:24,300 to turn that around into an object. 277 00:12:25,000 --> 00:12:29,420 You say, Windows, give me a handle to the window, 278 00:12:29,980 --> 00:12:32,920 and then you ask .NET to turn that handle into an object. 279 00:12:33,460 --> 00:12:36,400 Once you have the Windows form that you want 280 00:12:36,400 --> 00:12:37,720 inside of your target application, 281 00:12:38,080 --> 00:12:40,900 you can iterate inside of that through all of the controls, 282 00:12:41,100 --> 00:12:42,480 access all of the events, 283 00:12:42,480 --> 00:12:45,700 the events being function pointers to your target objects. 284 00:12:46,660 --> 00:12:48,120 And once you've done this, 285 00:12:48,260 --> 00:12:51,140 you can iterate through the object structure 286 00:12:51,140 --> 00:12:53,800 using each object to gain more references 287 00:12:54,360 --> 00:12:56,300 until you've either reached your target object 288 00:12:56,300 --> 00:13:00,900 or you have exhausted the entire object structure. 289 00:13:02,640 --> 00:13:05,900 And that's how you get around into the object structure. 290 00:13:06,180 --> 00:13:08,780 At this point, once you have all of the references, 291 00:13:08,980 --> 00:13:11,460 it's pretty simple to implement your changes 292 00:13:11,460 --> 00:13:12,520 to your target application. 293 00:13:15,740 --> 00:13:18,880 So as a quick demo for mixing the GUI, 294 00:13:20,580 --> 00:13:28,840 we'll spin up RedGate's memory profiler. 295 00:13:30,360 --> 00:13:31,680 We'll inject into it. 296 00:13:32,400 --> 00:13:34,320 And the nice thing about this is 297 00:13:34,320 --> 00:13:37,460 basically any .NET application is susceptible. 298 00:13:38,360 --> 00:13:39,380 Once you're in, 299 00:13:39,520 --> 00:13:41,360 there's nothing that can really stop you. 300 00:13:41,460 --> 00:13:44,200 There are a little bit of tricks that can be played inside, 301 00:13:44,500 --> 00:13:45,640 but I'll get to that later. 302 00:13:47,080 --> 00:13:48,900 So we're inside of our target application. 303 00:13:51,980 --> 00:13:53,660 We'll load up our hack buttons again, 304 00:13:53,800 --> 00:13:55,880 and we have a payload inside of our target. 305 00:14:00,360 --> 00:14:03,880 Utilizing our communication paradigm, 306 00:14:06,000 --> 00:14:11,400 we can say we want to load another payload in there. 307 00:14:12,100 --> 00:14:15,510 And so instead of picking from one of the payloads, 308 00:14:16,040 --> 00:14:18,860 we'll actually load another .NET application into it. 309 00:14:22,380 --> 00:14:25,660 And this is .NET Reactor, a code protection system, 310 00:14:25,880 --> 00:14:28,480 itself being protected by a good number of 311 00:14:28,480 --> 00:14:30,320 obstification, shells, 312 00:14:30,500 --> 00:14:33,140 everything that this protection system could throw 313 00:14:33,140 --> 00:14:34,660 at protecting other .NET applications. 314 00:14:35,320 --> 00:14:37,720 So we're injecting one application into another, 315 00:14:37,900 --> 00:14:38,680 and at this point, 316 00:14:38,700 --> 00:14:40,400 they're essentially becoming one application. 317 00:14:40,400 --> 00:14:42,260 They're in the same app domain. 318 00:14:42,800 --> 00:14:44,360 They're not sharing logic flow, 319 00:14:44,540 --> 00:14:46,080 but they are one application now. 320 00:14:46,940 --> 00:14:48,240 And so now we can say, 321 00:14:48,320 --> 00:14:49,580 add yourself to that form, 322 00:14:49,760 --> 00:14:52,360 since these are all one application now. 323 00:14:52,780 --> 00:14:54,700 ANSI Memory Profiler and Reflector. 324 00:14:55,720 --> 00:14:58,880 And again, we can go through and lead everything, 325 00:14:59,000 --> 00:14:59,380 all that, 326 00:14:59,480 --> 00:15:01,640 and it leads everything that it finds 327 00:15:01,640 --> 00:15:02,960 in this object structure, 328 00:15:03,120 --> 00:15:05,440 and this one leads everything in that object structure, 329 00:15:05,560 --> 00:15:07,000 which is why they're separate. 330 00:15:07,620 --> 00:15:08,660 But at this point, 331 00:15:08,680 --> 00:15:09,940 we can do things like, 332 00:15:09,940 --> 00:15:12,400 pop controls on and off. 333 00:15:13,180 --> 00:15:15,900 But we can also pop controls on and off 334 00:15:15,900 --> 00:15:17,140 of multiple applications. 335 00:15:18,280 --> 00:15:20,000 So we've now popped a button. 336 00:15:23,780 --> 00:15:25,540 And at this point, 337 00:15:25,580 --> 00:15:28,760 this button over here is still part of this logic flow. 338 00:15:31,140 --> 00:15:31,740 And, 339 00:15:35,580 --> 00:15:37,940 its functionality here is maintained. 340 00:15:38,060 --> 00:15:39,140 We haven't broken it. 341 00:15:39,940 --> 00:15:40,960 When we put it over here, 342 00:15:41,080 --> 00:15:42,840 we kept all of the same links. 343 00:15:42,980 --> 00:15:44,080 So when this is clicked, 344 00:15:44,220 --> 00:15:45,620 it activates the same functionality. 345 00:15:47,000 --> 00:15:50,520 This is allowing us to intermix the GUIs 346 00:15:50,520 --> 00:15:53,140 and the core functionality of independent applications. 347 00:15:55,180 --> 00:15:58,620 Also notice that the style of this window 348 00:15:58,620 --> 00:16:01,160 matches the application we put it into 349 00:16:01,160 --> 00:16:02,600 and not its actual parent. 350 00:16:03,200 --> 00:16:05,780 This is due to where threads come from, 351 00:16:05,860 --> 00:16:08,340 determines their style. 352 00:16:09,940 --> 00:16:12,500 And there's some fun games that you can play with this. 353 00:16:14,180 --> 00:16:16,680 So now that we can intermix GUIs, 354 00:16:16,800 --> 00:16:17,860 we can intermix logic. 355 00:16:18,040 --> 00:16:19,880 We can basically remold applications 356 00:16:19,880 --> 00:16:22,200 into new Frankenstein apps 357 00:16:22,720 --> 00:16:23,800 or mashups, 358 00:16:23,880 --> 00:16:24,760 whatever you want to call it. 359 00:16:26,220 --> 00:16:31,040 And this allows us to do more complex things 360 00:16:31,040 --> 00:16:32,500 when we get into other applications. 361 00:16:32,740 --> 00:16:34,460 We can bring tools with us 362 00:16:34,460 --> 00:16:36,180 that are other applications. 363 00:16:40,100 --> 00:16:40,660 And... 364 00:16:42,980 --> 00:16:46,060 And so that's being able to play with the GUI. 365 00:16:50,940 --> 00:16:53,220 So this is basically what we can attack. 366 00:16:53,940 --> 00:16:55,560 When we actually go after 367 00:16:56,300 --> 00:16:58,400 fundamentally changing a target application, 368 00:16:58,720 --> 00:17:02,020 we'll go after the events that are inside of the application. 369 00:17:02,660 --> 00:17:03,900 We'll go to a button 370 00:17:03,900 --> 00:17:07,140 and wrap the function that it goes to. 371 00:17:07,880 --> 00:17:08,440 So, 372 00:17:08,440 --> 00:17:10,180 the games that I like to play 373 00:17:10,180 --> 00:17:12,240 is find this object that it goes to, 374 00:17:12,360 --> 00:17:13,320 wrap it, 375 00:17:13,400 --> 00:17:14,340 derive from it, 376 00:17:14,460 --> 00:17:14,900 inherit, 377 00:17:15,160 --> 00:17:17,620 and intercept all of the functionality 378 00:17:17,620 --> 00:17:18,740 that they would be calling, 379 00:17:18,900 --> 00:17:21,100 and then put it back in place of its original. 380 00:17:21,520 --> 00:17:23,100 This allows you to 381 00:17:24,080 --> 00:17:25,240 intercept the event, 382 00:17:25,420 --> 00:17:27,300 arbitrarily do new functionality, 383 00:17:27,620 --> 00:17:28,900 and not have to worry about 384 00:17:29,440 --> 00:17:32,300 whether you're going to match the signature or anything else 385 00:17:32,300 --> 00:17:34,840 because you're basically the original object structure. 386 00:17:36,740 --> 00:17:37,260 Um... 387 00:17:37,860 --> 00:17:41,540 Also, this doesn't change the underlying object's code, 388 00:17:41,640 --> 00:17:43,540 so you don't have to worry about someone detecting 389 00:17:43,540 --> 00:17:46,520 that you're making changes to your target's code base 390 00:17:46,520 --> 00:17:49,060 because this is just a wrapper 391 00:17:49,060 --> 00:17:51,780 in another module that's being loaded into it. 392 00:17:53,660 --> 00:17:54,220 So, 393 00:17:55,400 --> 00:17:58,460 something fun that we've whipped up for you 394 00:17:58,460 --> 00:18:00,640 is an SQL modification. 395 00:18:02,980 --> 00:18:05,640 So we spin up SQL Server Management Studio. 396 00:18:07,860 --> 00:18:09,600 And inject into it. 397 00:18:10,340 --> 00:18:12,000 SQL Server Management Studio 398 00:18:12,000 --> 00:18:13,760 is a 32-bit application. 399 00:18:14,120 --> 00:18:16,420 A lot of the .NET apps you'll be going up against 400 00:18:16,420 --> 00:18:17,440 will be in MSIL 401 00:18:17,440 --> 00:18:19,240 and targeted generically. 402 00:18:19,540 --> 00:18:22,180 But this is targeted at 32-bit, 403 00:18:22,200 --> 00:18:24,340 so you have to use a 32-bit injection system. 404 00:18:27,860 --> 00:18:29,480 So, for the payload for this, 405 00:18:29,620 --> 00:18:31,620 we're going to be using a targeted attack. 406 00:18:31,780 --> 00:18:33,800 These are pretty much just generic attacks 407 00:18:33,800 --> 00:18:36,760 that can be deployed against any .NET application arbitrarily. 408 00:18:37,260 --> 00:18:39,700 This is more for R&D and showing you, 409 00:18:39,720 --> 00:18:41,940 in code, how to do these things. 410 00:18:42,660 --> 00:18:43,220 Um... 411 00:18:43,220 --> 00:18:44,480 The SQL attacks. 412 00:18:45,420 --> 00:18:45,980 Um... 413 00:18:45,980 --> 00:18:47,880 We'll start out with SQL Defender. 414 00:18:48,600 --> 00:18:49,700 It's loaded in. 415 00:18:49,800 --> 00:18:51,220 It goes after this form. 416 00:18:51,380 --> 00:18:52,720 Adds a star to it to say, 417 00:18:52,760 --> 00:18:53,720 yeah, we're online. 418 00:18:54,600 --> 00:18:56,780 And so now what this does 419 00:18:56,780 --> 00:18:59,180 is it adds a whole new security model 420 00:18:59,180 --> 00:19:00,140 to the login process 421 00:19:00,140 --> 00:19:02,160 to defeat brute forcing. 422 00:19:03,060 --> 00:19:05,800 What we've basically done is subverted that event 423 00:19:05,800 --> 00:19:06,780 for the connect button, 424 00:19:06,940 --> 00:19:08,200 as in the previous slide. 425 00:19:08,360 --> 00:19:10,240 And now that we own this connect button, 426 00:19:10,500 --> 00:19:11,700 when you click this, 427 00:19:11,860 --> 00:19:13,420 it now has your username and password. 428 00:19:14,120 --> 00:19:16,860 And so what this is is... 429 00:19:20,040 --> 00:19:22,420 When you type in a username and password 430 00:19:22,420 --> 00:19:24,540 defined in the protection mechanism, 431 00:19:24,800 --> 00:19:26,500 it opens up an admin console. 432 00:19:26,720 --> 00:19:29,080 This lets you choose how many failed attempts you'll allow 433 00:19:29,080 --> 00:19:31,460 before you lock out the login process. 434 00:19:33,040 --> 00:19:34,780 You can change your username and password 435 00:19:34,780 --> 00:19:35,940 to get to this admin panel. 436 00:19:36,700 --> 00:19:39,960 Also, if someone does get locked out 437 00:19:39,960 --> 00:19:41,780 and they keep brute forcing into your server, 438 00:19:41,960 --> 00:19:43,080 if they finally do get in, 439 00:19:43,700 --> 00:19:45,140 it'll, instead of logging them in, 440 00:19:45,380 --> 00:19:47,440 it'll change your password to a 40-character random. 441 00:19:49,560 --> 00:19:52,060 And this is also where you come and say, 442 00:19:52,200 --> 00:19:53,480 oh, I don't want to be locked out anymore. 443 00:19:53,700 --> 00:19:54,700 Let me in. Let me try again. 444 00:19:55,500 --> 00:19:57,440 As well as some Twitter keys that say, 445 00:19:57,540 --> 00:19:59,560 hey, if someone is trying to hack my system, 446 00:19:59,980 --> 00:20:01,400 what account should I notify? 447 00:20:02,060 --> 00:20:04,760 So if someone breaks into your physical account, 448 00:20:04,780 --> 00:20:08,440 and decides that they're going to try and brute force overnight, 449 00:20:08,720 --> 00:20:10,720 this will add an extra layer of protection. 450 00:20:11,040 --> 00:20:13,700 This is just a demonstration of adding third-party patches 451 00:20:13,700 --> 00:20:15,340 to a .NET application. 452 00:20:16,560 --> 00:20:19,840 The basic premise of this is you can pretty easily 453 00:20:19,840 --> 00:20:22,980 add third-party solutions to existing applications 454 00:20:22,980 --> 00:20:24,940 without having to worry about compromising 455 00:20:24,940 --> 00:20:26,240 the overall structure of the program. 456 00:20:26,380 --> 00:20:28,260 You don't have to worry about some pointer 457 00:20:28,260 --> 00:20:29,640 when you're connecting to a database 458 00:20:29,640 --> 00:20:31,500 because we're affecting this one object. 459 00:20:31,500 --> 00:20:37,380 And these modifications are done in just a few lines. 460 00:20:37,740 --> 00:20:40,100 Instead of being hundreds and hundreds of lines, 461 00:20:40,420 --> 00:20:44,500 these most of the time are in between 50 and 100 lines. 462 00:20:44,720 --> 00:20:46,580 You're dealing with high-level .NET 463 00:20:46,580 --> 00:20:50,600 instead of walking lines. 464 00:20:52,380 --> 00:20:55,580 Another targeted attack that whipped up 465 00:20:55,580 --> 00:20:58,040 is going after ANSI memory profiler again. 466 00:20:59,120 --> 00:21:00,780 So this one, 467 00:21:01,680 --> 00:21:05,620 is loading up a payload that'll go after the trialware. 468 00:21:07,180 --> 00:21:09,520 The trialware on ANSI memory profiler 469 00:21:09,520 --> 00:21:12,260 pretty much works off of this one window. 470 00:21:12,440 --> 00:21:15,740 As most good programmers do a whole bunch of logic 471 00:21:15,740 --> 00:21:18,120 and then return a value, that's all this window does. 472 00:21:18,680 --> 00:21:21,440 If you've activated or you're still in your trial period, 473 00:21:21,600 --> 00:21:23,980 this window says, okay, everything's fine, go on. 474 00:21:24,540 --> 00:21:25,760 And that's all this does. 475 00:21:25,920 --> 00:21:27,900 It says, everything's fine, go on. 476 00:21:28,320 --> 00:21:29,320 And the nice... 477 00:21:31,500 --> 00:21:31,820 Thank you. 478 00:21:37,440 --> 00:21:40,500 The nice thing about this is it's implemented in two lines. 479 00:21:40,940 --> 00:21:44,860 The code is literally dialogue result okay, close window. 480 00:21:53,260 --> 00:21:55,480 So reflection is the main tool we're using. 481 00:21:55,680 --> 00:21:58,120 You can do a whole bunch of things like, hey, object, 482 00:21:58,320 --> 00:21:59,900 what's your events, what's your functions, 483 00:21:59,900 --> 00:22:01,480 what's your method, so on and so forth. 484 00:22:01,940 --> 00:22:03,880 You can get constructors and all of that. 485 00:22:05,220 --> 00:22:08,000 So if you're a coder, this is the most interesting part. 486 00:22:08,160 --> 00:22:10,260 And if you're not, here's a nice graphic for you. 487 00:22:12,360 --> 00:22:13,800 So when you come into reflection, 488 00:22:14,100 --> 00:22:16,160 you're gonna have an object. 489 00:22:16,300 --> 00:22:17,560 You say, get type for object. 490 00:22:17,740 --> 00:22:18,560 That'll get you a type. 491 00:22:18,660 --> 00:22:21,800 You say, hey, type, what kind of methods do you have? 492 00:22:22,120 --> 00:22:25,840 This will return you a method info object. 493 00:22:26,100 --> 00:22:28,740 You can then utilize this to activate that method info. 494 00:22:28,740 --> 00:22:30,540 You pass in a couple of parameters, 495 00:22:30,700 --> 00:22:31,740 and you activate the method. 496 00:22:32,400 --> 00:22:36,220 You can ask for values and properties, 497 00:22:36,440 --> 00:22:38,980 properties being the getter and setter that wraps a value. 498 00:22:39,620 --> 00:22:43,340 And at runtime, getters and setters turn into functions. 499 00:22:44,700 --> 00:22:46,260 You can go around and get events. 500 00:22:46,480 --> 00:22:48,560 Events are a really nice part to attack, 501 00:22:48,720 --> 00:22:50,920 so I've spent a little bit of time focusing on that. 502 00:22:51,900 --> 00:22:54,160 Also, you can get constructors for your objects. 503 00:22:54,520 --> 00:22:57,040 You can basically dig around in an application 504 00:22:57,040 --> 00:22:58,720 and grab anything that you want. 505 00:22:58,720 --> 00:23:02,160 You can grab the inherited types, 506 00:23:02,400 --> 00:23:04,300 you can grab interfaces, 507 00:23:05,800 --> 00:23:09,020 and basically think of it as developing at runtime. 508 00:23:10,500 --> 00:23:12,840 So here's a little bit of code for hacking an event. 509 00:23:13,120 --> 00:23:17,460 Events are normally completely secured against outside tampering, 510 00:23:17,600 --> 00:23:21,260 so you can be confident that if you've set something to your event 511 00:23:21,260 --> 00:23:23,160 that no one outside of you can change that. 512 00:23:23,540 --> 00:23:24,780 This gets around that. 513 00:23:25,880 --> 00:23:28,700 Basically, you say, give me a flag that says, 514 00:23:28,700 --> 00:23:30,060 instance nonpublic, 515 00:23:30,280 --> 00:23:32,000 and then you ask for the events. 516 00:23:32,380 --> 00:23:34,520 So this function takes in, say, a button, 517 00:23:34,640 --> 00:23:38,600 and you say, hey, get me the field of events in string, 518 00:23:38,780 --> 00:23:41,780 so you're actually using proper names at runtime. 519 00:23:42,460 --> 00:23:44,820 And you say, get me the instance nonpublic. 520 00:23:45,360 --> 00:23:46,760 And so it does. 521 00:23:46,900 --> 00:23:48,900 It just returns a private instance variable. 522 00:23:49,200 --> 00:23:50,620 You can say static, private, 523 00:23:50,820 --> 00:23:52,540 anything you want will be returned. 524 00:23:53,600 --> 00:23:56,700 So simply take your events object that you now have 525 00:23:56,700 --> 00:23:58,020 that you got off of the button, 526 00:23:58,020 --> 00:24:01,780 and you say, hey, get me your head off of your events. 527 00:24:02,100 --> 00:24:03,720 And again, it returns it. 528 00:24:04,220 --> 00:24:07,460 And then finally, it's a linked list inside of an event, 529 00:24:07,600 --> 00:24:09,040 and you say, get me your handler, 530 00:24:09,580 --> 00:24:12,980 and again, instance nonpublic, which is private, 531 00:24:13,480 --> 00:24:15,080 and it returns that value, 532 00:24:15,200 --> 00:24:16,840 and then you say, set value on that. 533 00:24:17,460 --> 00:24:20,180 And you set the event to null. 534 00:24:20,520 --> 00:24:23,180 And that's all you have to do to access someone else's event 535 00:24:23,180 --> 00:24:23,820 and wipe it out. 536 00:24:23,880 --> 00:24:25,980 This is basically the same premise that you would use 537 00:24:25,980 --> 00:24:27,340 to reconnect the connect button, 538 00:24:27,340 --> 00:24:28,720 or anything else, 539 00:24:29,160 --> 00:24:30,200 or text boxes, 540 00:24:30,200 --> 00:24:31,240 or pretty much anything. 541 00:24:31,740 --> 00:24:33,760 Once you can control someone's values, 542 00:24:33,860 --> 00:24:34,960 you control everything. 543 00:24:36,780 --> 00:24:38,820 So the basic premise of this attack 544 00:24:39,080 --> 00:24:41,160 is you inject into your target application, 545 00:24:41,560 --> 00:24:43,260 you drive deep into it, 546 00:24:43,300 --> 00:24:45,400 you gain access to the target objects. 547 00:24:46,200 --> 00:24:47,400 Once you've done this, 548 00:24:47,560 --> 00:24:49,460 you can access the objects. 549 00:24:49,660 --> 00:24:50,920 You access a button, 550 00:24:51,080 --> 00:24:52,980 you rip out the events out of the button, 551 00:24:53,080 --> 00:24:53,960 and you change them, 552 00:24:54,120 --> 00:24:55,600 and then you pwn the application. 553 00:24:55,600 --> 00:24:56,780 And it's done. 554 00:24:57,640 --> 00:25:00,180 You're not worried about editing anything else 555 00:25:00,180 --> 00:25:01,400 outside of the object structure. 556 00:25:01,840 --> 00:25:03,800 At this point, you don't care about 557 00:25:03,800 --> 00:25:05,480 what the code is underlying this, 558 00:25:05,620 --> 00:25:07,780 so no matter what kind of protection mechanisms 559 00:25:08,140 --> 00:25:10,020 they may have implemented on the code, 560 00:25:10,040 --> 00:25:11,380 at memory, they're all objects, 561 00:25:12,000 --> 00:25:13,700 and they're free to be messed with. 562 00:25:15,860 --> 00:25:17,460 This is what it used to look like 563 00:25:17,460 --> 00:25:19,240 when you would go after an application. 564 00:25:19,540 --> 00:25:21,300 You might spin up IDA and step through it 565 00:25:21,300 --> 00:25:23,320 and try and change values this way. 566 00:25:24,200 --> 00:25:25,580 This is what .NET brings. 567 00:25:25,600 --> 00:25:27,620 A lot faster development time. 568 00:25:27,780 --> 00:25:29,380 Instead of hundreds of hours 569 00:25:29,380 --> 00:25:30,880 and looking through thousands of lines, 570 00:25:31,060 --> 00:25:32,420 you're talking about 15 minutes 571 00:25:32,420 --> 00:25:33,580 and looking at 50 lines. 572 00:25:35,400 --> 00:25:38,660 Most protection mechanisms can be broken down 573 00:25:38,660 --> 00:25:40,700 to attacking one function or one value, 574 00:25:42,100 --> 00:25:44,980 and with the .NET attack, 575 00:25:45,260 --> 00:25:47,340 you can basically iterate through the object structure 576 00:25:47,340 --> 00:25:48,500 and find what you want 577 00:25:48,500 --> 00:25:50,320 in a matter of minutes or seconds, hopefully, 578 00:25:50,440 --> 00:25:51,900 with a little bit of practice. 579 00:25:54,720 --> 00:25:57,360 So, as a quick public service announcement, 580 00:25:58,660 --> 00:26:02,140 we found a really old Visual Studios hack 581 00:26:02,140 --> 00:26:04,060 that's been around since 2006. 582 00:26:04,600 --> 00:26:06,320 Microsoft thinks this is a feature 583 00:26:06,320 --> 00:26:08,080 that it runs arbitrary code on your system. 584 00:26:11,020 --> 00:26:13,140 So basically, all you have to do 585 00:26:13,140 --> 00:26:17,120 to make an infected project is... 586 00:26:19,260 --> 00:26:21,000 Let's see, let's spin up... 587 00:26:22,380 --> 00:26:23,160 This one. 588 00:26:23,800 --> 00:26:26,960 So all you have to do to make an infected project 589 00:26:26,960 --> 00:26:29,400 for any version of Visual Studios, 590 00:26:29,720 --> 00:26:31,300 this is a feature that's core 591 00:26:31,300 --> 00:26:33,360 to the functionality of Visual Studios. 592 00:26:34,080 --> 00:26:35,440 They say it's not a threat 593 00:26:35,440 --> 00:26:37,120 because it requires multiple clicks. 594 00:26:41,500 --> 00:26:44,340 So this loads arbitrarily 595 00:26:45,460 --> 00:26:46,980 whatever code you want. 596 00:26:47,420 --> 00:26:49,040 They say it's a couple of clicks 597 00:26:49,040 --> 00:26:50,780 because when you load it up 598 00:26:50,780 --> 00:26:52,380 on a system that you didn't develop it in, 599 00:26:52,500 --> 00:26:53,980 it either comes up with this 600 00:26:53,980 --> 00:26:55,500 or, hey, you didn't develop this code. 601 00:26:55,840 --> 00:26:57,240 So you come into the application, 602 00:26:57,540 --> 00:26:59,500 you look at the about box, and that's it. 603 00:27:00,520 --> 00:27:04,540 So this happens because this image box is infected, 604 00:27:05,280 --> 00:27:09,280 and it's the constructor of the image box. 605 00:27:09,460 --> 00:27:11,780 All you have to do is put whatever arbitrary code 606 00:27:11,780 --> 00:27:14,700 you want inside of there, and that's it. 607 00:27:14,760 --> 00:27:16,380 It executes when they look at it. 608 00:27:18,400 --> 00:27:21,940 So the added scary thing is 609 00:27:21,940 --> 00:27:24,680 maybe you can make a scanner that would go through 610 00:27:24,680 --> 00:27:26,120 and look for the code base, 611 00:27:26,240 --> 00:27:27,900 and you could look at it before you open it. 612 00:27:29,520 --> 00:27:32,220 It turns out that if you don't rebuild, 613 00:27:32,460 --> 00:27:34,740 that whatever code was left in there, 614 00:27:34,820 --> 00:27:36,520 so we'll go to that same constructor, 615 00:27:37,060 --> 00:27:38,300 it's completely empty. 616 00:27:40,160 --> 00:27:42,280 Look at the about box, and it's still there. 617 00:27:43,820 --> 00:27:45,720 So regardless of what the code says 618 00:27:45,720 --> 00:27:48,060 until you rebuild, it'll be utilizing old objects 619 00:27:48,060 --> 00:27:48,880 that could be infected. 620 00:27:49,680 --> 00:27:53,780 And this is core to the functionality, apparently. 621 00:27:54,020 --> 00:27:56,100 Microsoft has no plans in taking it out. 622 00:27:56,900 --> 00:27:59,540 So I decided that I would whip up 623 00:27:59,540 --> 00:28:01,080 a nice little infected app 624 00:28:01,600 --> 00:28:04,840 that instead of showing the user something pleasant, 625 00:28:05,500 --> 00:28:07,900 it would Twitter out the computer name 626 00:28:08,540 --> 00:28:09,780 and the IP address. 627 00:28:11,020 --> 00:28:13,660 So when people download and run this application, 628 00:28:15,640 --> 00:28:17,380 it decides to Twitter out. 629 00:28:17,660 --> 00:28:20,860 And so I'll be putting out an application 630 00:28:20,860 --> 00:28:22,540 that says in the EULA, 631 00:28:22,600 --> 00:28:24,180 hey, when you use this, I'm going to Twitter. 632 00:28:26,040 --> 00:28:28,020 And hopefully Microsoft will get the message 633 00:28:28,020 --> 00:28:29,800 that this is not some feature. 634 00:28:30,160 --> 00:28:32,000 If you have arbitrary code execution 635 00:28:32,000 --> 00:28:33,460 on a programmer's machine, 636 00:28:33,700 --> 00:28:37,560 you can basically pwn whatever company they might work for. 637 00:28:37,800 --> 00:28:40,960 You can do something that specifically messes 638 00:28:40,960 --> 00:28:41,880 with the development cycle. 639 00:28:42,000 --> 00:28:43,320 You can go after the SVN 640 00:28:43,320 --> 00:28:44,880 that it has access to. 641 00:28:45,940 --> 00:28:47,480 Developers often run as admin. 642 00:28:47,700 --> 00:28:50,140 So you can leverage that into something 643 00:28:50,140 --> 00:28:51,560 pretty powerful and scary. 644 00:28:55,100 --> 00:28:58,240 So some of the other fun ones that we also have 645 00:28:58,240 --> 00:28:59,980 is data piggybacking. 646 00:29:00,580 --> 00:29:03,240 The basic premise of this is the same as the other ones. 647 00:29:03,300 --> 00:29:04,940 Once you're inside of another target application, 648 00:29:05,900 --> 00:29:08,660 you can send whatever you want. 649 00:29:12,200 --> 00:29:14,320 So SQL Server Management Studio. 650 00:29:14,640 --> 00:29:16,280 So you make it into someone else's machine 651 00:29:16,280 --> 00:29:17,160 through some exploit. 652 00:29:17,460 --> 00:29:20,780 And you're unable to get back out to the net, 653 00:29:20,880 --> 00:29:23,760 but SQL Server has a valid communication portal. 654 00:29:24,920 --> 00:29:26,760 And you leverage its credentials 655 00:29:26,760 --> 00:29:29,040 to get you back out to the net. 656 00:29:29,460 --> 00:29:30,940 So we inject into it. 657 00:29:32,220 --> 00:29:34,360 We select data piggybacking. 658 00:29:37,480 --> 00:29:42,100 And again, this management console allows us 659 00:29:42,100 --> 00:29:43,600 to talk directly to that payload. 660 00:29:44,000 --> 00:29:46,680 We can send emails, Twitters, UDPs. 661 00:29:47,240 --> 00:29:50,860 And so we can send a Twitter of whatever we want. 662 00:29:53,700 --> 00:29:57,400 And it, inside of the object structure, 663 00:29:57,640 --> 00:30:00,660 leverages the credentials of SQL Server Management Studio 664 00:30:00,660 --> 00:30:01,620 to send Twitters. 665 00:30:03,660 --> 00:30:05,940 Or UDP packets or email. 666 00:30:06,140 --> 00:30:08,600 This is just a nice data exfiltration tool. 667 00:30:08,800 --> 00:30:10,560 So once you're inside of your target, 668 00:30:10,700 --> 00:30:13,100 you can migrate around until you find an application 669 00:30:13,100 --> 00:30:14,440 that does have rights to get out. 670 00:30:17,680 --> 00:30:20,340 And so here's a Metasploit payload that we developed. 671 00:30:23,620 --> 00:30:24,280 All right. 672 00:30:24,520 --> 00:30:26,820 So I'm not much of a .NET programmer, 673 00:30:27,400 --> 00:30:30,160 but I do like Metasploit quite a bit. 674 00:30:30,160 --> 00:30:33,340 And I like getting Metasploit integrated 675 00:30:33,340 --> 00:30:35,220 with as much stuff as possible. 676 00:30:35,440 --> 00:30:37,480 So we thought it would be really cool 677 00:30:37,480 --> 00:30:42,000 if you could go from one machine to another remote machine 678 00:30:42,000 --> 00:30:44,680 using any arbitrary exploit that you had 679 00:30:44,680 --> 00:30:45,780 that you could get from Metasploit 680 00:30:45,780 --> 00:30:46,700 any way you can find in. 681 00:30:46,920 --> 00:30:50,380 And then do in-memory remote .NET code injection 682 00:30:50,380 --> 00:30:52,220 to the remote machine through that. 683 00:30:52,820 --> 00:30:54,580 So we set out to do that. 684 00:30:54,800 --> 00:30:57,600 So what we wrote was essentially just a C++ shim 685 00:30:57,600 --> 00:30:59,500 that right now it's a Meterpreter extension, 686 00:30:59,500 --> 00:31:00,760 but you can do it. 687 00:31:00,800 --> 00:31:01,740 It's just a DLL, 688 00:31:01,880 --> 00:31:05,480 so you can just use the IRB load library call to load it up. 689 00:31:05,560 --> 00:31:07,200 You don't actually have to write your own Meterpreter extension 690 00:31:07,200 --> 00:31:07,960 if you don't want to. 691 00:31:09,420 --> 00:31:11,340 And that will spin up .NET 692 00:31:11,340 --> 00:31:14,460 from within whatever process that you've migrated to. 693 00:31:14,680 --> 00:31:17,680 So now you can execute arbitrary C Sharp if you feel like it, 694 00:31:17,720 --> 00:31:19,340 and you don't have to write your payloads in C++ 695 00:31:19,340 --> 00:31:21,540 if you're attacking a C Sharp application. 696 00:31:22,040 --> 00:31:24,120 So we just have a VM over here 697 00:31:24,120 --> 00:31:26,140 that's got SQL Server Management Studio running on it. 698 00:31:26,860 --> 00:31:29,280 And I should get a remote desktop to that. 699 00:31:41,160 --> 00:31:43,140 And so we've got a Meterpreter shell. 700 00:31:43,260 --> 00:31:44,640 I just put something vulnerable on it. 701 00:31:44,900 --> 00:31:48,140 And then if you look at the process list 702 00:31:48,140 --> 00:31:52,340 and find SQL Server Management Studio SMS, 703 00:31:52,700 --> 00:31:53,340 it's 3088. 704 00:31:53,640 --> 00:31:56,560 So if we just migrate to 3088, 705 00:32:05,400 --> 00:32:07,500 that's just the boilerplate Meterpreter extension 706 00:32:07,500 --> 00:32:08,220 that they wrote. 707 00:32:08,440 --> 00:32:09,740 And then I just wrote this command alive 708 00:32:09,740 --> 00:32:11,480 that spins up .NET 709 00:32:11,480 --> 00:32:13,160 and then whatever payload that you have. 710 00:32:13,380 --> 00:32:16,120 So you can write anything that has some C Sharp in it 711 00:32:16,120 --> 00:32:16,720 and a void main, 712 00:32:17,000 --> 00:32:18,920 and this will just execute it for you 713 00:32:18,920 --> 00:32:20,140 inside that C Sharp application. 714 00:32:20,460 --> 00:32:21,720 So the thing you saw before 715 00:32:21,720 --> 00:32:23,480 that attacks SQL Server Management Studio 716 00:32:23,480 --> 00:32:24,400 that tweeted your password, 717 00:32:24,680 --> 00:32:27,480 if we look at the login here, 718 00:32:27,740 --> 00:32:28,760 oh, it would have worked. 719 00:32:29,500 --> 00:32:30,280 If this was open. 720 00:32:30,400 --> 00:32:30,440 There. 721 00:32:30,560 --> 00:32:31,880 So let's try it again. 722 00:32:32,860 --> 00:32:33,500 Is it there? 723 00:32:34,060 --> 00:32:34,460 Yeah. 724 00:32:34,560 --> 00:32:35,460 So there's the asterisk 725 00:32:35,460 --> 00:32:36,380 on SQL Server Management Studio. 726 00:32:36,640 --> 00:32:38,160 So now you don't have to do any of the work 727 00:32:38,160 --> 00:32:40,100 of figuring out how to get .NET running 728 00:32:40,100 --> 00:32:42,560 within a C Sharp process or anything like that. 729 00:32:42,740 --> 00:32:43,720 It's all there for you 730 00:32:43,720 --> 00:32:45,700 and you can just deliver Metasploit payloads 731 00:32:45,700 --> 00:32:46,360 in .NET now, 732 00:32:46,500 --> 00:32:47,540 which I thought was kind of cool. 733 00:32:47,680 --> 00:32:48,600 And it never touches disk 734 00:32:48,600 --> 00:32:50,780 because the Metasploit people 735 00:32:50,780 --> 00:32:53,140 did all that great stuff with DLL injection 736 00:32:53,140 --> 00:32:56,120 and that's essentially underlying how this works 737 00:32:56,120 --> 00:32:58,160 as you DLL inject into some process 738 00:32:58,160 --> 00:33:00,620 and they're doing all the fancy reflective DLL injection stuff 739 00:33:00,620 --> 00:33:01,760 and then we leverage that 740 00:33:01,760 --> 00:33:03,280 and spin up .NET inside 741 00:33:03,280 --> 00:33:05,100 and it's pretty cool, I think. 742 00:33:15,400 --> 00:33:16,860 And so like he said, 743 00:33:16,960 --> 00:33:18,900 of course you can use any of these payloads 744 00:33:19,400 --> 00:33:21,340 and deploy them across the network 745 00:33:21,340 --> 00:33:22,820 or make your own void main. 746 00:33:29,020 --> 00:33:31,420 So now that you've successfully pwned, 747 00:33:32,360 --> 00:33:34,400 you can pretty much do anything you want. 748 00:33:34,520 --> 00:33:36,360 Anything in .NET can now be done. 749 00:33:36,600 --> 00:33:41,280 You can do anything from access the system's Windows API 750 00:33:41,280 --> 00:33:42,760 to write to disk, 751 00:33:43,420 --> 00:33:45,880 leverage any of the credentials of your target application 752 00:33:45,880 --> 00:33:48,660 or migrate around to your target application 753 00:33:48,660 --> 00:33:50,420 until you find the credentials you want. 754 00:33:52,260 --> 00:33:54,240 Some of the non-evil uses of this 755 00:33:54,240 --> 00:33:55,540 are also quite applicable. 756 00:33:55,940 --> 00:33:57,980 If you want to write third party patches, 757 00:33:57,980 --> 00:33:58,880 for your application, 758 00:33:59,100 --> 00:34:02,260 and you want to do it with a short development time, 759 00:34:02,380 --> 00:34:02,920 this is great. 760 00:34:03,280 --> 00:34:05,880 You can edit the GUI, you can edit the logic 761 00:34:05,880 --> 00:34:09,740 and then you wrap your application with a loader 762 00:34:09,740 --> 00:34:11,220 that injects it every time it loads. 763 00:34:12,260 --> 00:34:14,440 Also there's defensive payloads 764 00:34:14,440 --> 00:34:16,320 like the SQL one that'll stop brute forcing. 765 00:34:16,540 --> 00:34:18,880 So you can write independent protection systems 766 00:34:18,880 --> 00:34:20,700 that'll work for you 767 00:34:20,700 --> 00:34:22,440 that no one else maybe knows about 768 00:34:22,440 --> 00:34:24,900 or you have one set of developers 769 00:34:24,900 --> 00:34:27,220 developing something to be injected 770 00:34:27,220 --> 00:34:29,040 and you can hold this back 771 00:34:29,040 --> 00:34:30,280 from your main development cycle. 772 00:34:31,440 --> 00:34:32,640 There's also bug hunting. 773 00:34:33,040 --> 00:34:35,020 You can inject into your target application 774 00:34:35,020 --> 00:34:37,140 and of course bug hunt. 775 00:34:37,220 --> 00:34:39,600 You can find the exact values of anything 776 00:34:40,220 --> 00:34:42,820 and get deep inside of it 777 00:34:42,820 --> 00:34:43,780 and find out the state. 778 00:34:43,980 --> 00:34:45,380 You can find out the connection 779 00:34:48,040 --> 00:34:51,920 and there's also flexible programs that can be built. 780 00:34:52,400 --> 00:34:55,720 This is nice because now you basically have an API 781 00:34:55,720 --> 00:34:57,200 that can work with any application 782 00:34:57,220 --> 00:35:01,260 instead of worrying about 783 00:35:01,260 --> 00:35:02,940 how do you connect to a target application. 784 00:35:03,240 --> 00:35:04,840 You reach straight down inside of it 785 00:35:04,840 --> 00:35:07,260 and access any part of it you wish. 786 00:35:08,060 --> 00:35:09,580 This is specifically nice 787 00:35:09,580 --> 00:35:13,220 when you're maybe trying to figure out 788 00:35:13,220 --> 00:35:14,220 how an API works. 789 00:35:14,420 --> 00:35:15,640 You can reach inside of it 790 00:35:15,640 --> 00:35:17,660 and literally dig around inside of it 791 00:35:17,660 --> 00:35:18,920 until you understand it 792 00:35:18,920 --> 00:35:21,240 or even remold it to add a new API. 793 00:35:23,900 --> 00:35:26,300 So the things that can slow this attack. 794 00:35:26,660 --> 00:35:27,200 So the things that can slow this attack. 795 00:35:27,220 --> 00:35:28,640 There's a little bit of framework security 796 00:35:28,640 --> 00:35:30,360 but that's not any concern. 797 00:35:31,180 --> 00:35:32,900 Some people say they're trying to make 798 00:35:32,900 --> 00:35:33,880 defensive countermeasures 799 00:35:33,880 --> 00:35:37,140 but of course you can attack their countermeasures 800 00:35:37,140 --> 00:35:40,220 or since this is basically loaded 801 00:35:40,220 --> 00:35:42,680 at a specific instance in time 802 00:35:43,140 --> 00:35:45,680 you can wait until all of your authentication is done 803 00:35:45,680 --> 00:35:47,160 and the defensive countermeasures 804 00:35:47,160 --> 00:35:48,140 have all spun down 805 00:35:48,140 --> 00:35:50,360 and then inject into the application 806 00:35:50,360 --> 00:35:52,180 and get your work done 807 00:35:52,180 --> 00:35:53,860 and possibly unload from memory. 808 00:35:54,320 --> 00:35:56,260 A lot of the hacks that you can do 809 00:35:57,220 --> 00:35:57,740 is basically rewiring. 810 00:35:57,940 --> 00:35:59,740 You don't actually have to add code to your target 811 00:35:59,740 --> 00:36:01,600 so you can get in, rewire your target 812 00:36:01,600 --> 00:36:02,800 and then get out. 813 00:36:03,140 --> 00:36:05,460 And so you won't be resident in memory anymore. 814 00:36:07,260 --> 00:36:09,520 Also, bad programming design 815 00:36:09,520 --> 00:36:10,840 can make this really hard. 816 00:36:11,480 --> 00:36:13,240 When you find a program that has 817 00:36:13,240 --> 00:36:15,000 vestigial buttons and classes 818 00:36:15,000 --> 00:36:16,820 all over the place for no apparent reason 819 00:36:16,820 --> 00:36:17,860 you can get pretty lost. 820 00:36:19,720 --> 00:36:22,320 And other bizarre development cycles. 821 00:36:22,720 --> 00:36:22,880 And other bizarre development cycles. 822 00:36:22,880 --> 00:36:24,660 But as a whole, most programmers 823 00:36:24,660 --> 00:36:25,900 have a pretty clean design 824 00:36:27,220 --> 00:36:28,040 and high-end apps 825 00:36:28,040 --> 00:36:30,740 so you can get around pretty logically. 826 00:36:31,540 --> 00:36:33,400 And I'm hoping that 827 00:36:33,400 --> 00:36:35,280 a development cycle will spin up 828 00:36:35,280 --> 00:36:37,160 and we'll be developing a better way 829 00:36:37,160 --> 00:36:38,860 to walk around the objects 830 00:36:40,380 --> 00:36:42,140 and attack them that way. 831 00:36:42,980 --> 00:36:43,540 and attack them that way. 832 00:36:43,540 --> 00:36:44,000 Was there one more? 833 00:36:44,840 --> 00:36:46,960 Oh, okay. So how do I get paid from this? 834 00:36:48,400 --> 00:36:49,800 We're going to make these hacks 835 00:36:49,800 --> 00:36:51,540 and give them away for free. 836 00:36:51,640 --> 00:36:53,320 So this is all going out for free 837 00:36:53,320 --> 00:36:55,080 under the Creative Commons 838 00:36:55,080 --> 00:36:56,400 non-commercial. 839 00:36:57,220 --> 00:36:59,080 So it's all going to be out there to play with. 840 00:36:59,600 --> 00:37:01,220 We get paid, hopefully, 841 00:37:01,320 --> 00:37:02,920 to build countermeasures against this. 842 00:37:03,480 --> 00:37:04,040 Yeah. 843 00:37:09,160 --> 00:37:15,800 Basically, we get paid 844 00:37:15,800 --> 00:37:16,980 by building countermeasures 845 00:37:16,980 --> 00:37:18,020 so if a company 846 00:37:19,540 --> 00:37:21,300 would like to get this 847 00:37:21,300 --> 00:37:23,400 they would be able to hire us 848 00:37:23,400 --> 00:37:24,600 as contractors 849 00:37:24,600 --> 00:37:26,860 to come in and protect their system 850 00:37:27,220 --> 00:37:28,960 from this or add additional protection. 851 00:37:42,940 --> 00:37:45,040 So some of the people 852 00:37:45,040 --> 00:37:46,300 that really helped with this 853 00:37:46,300 --> 00:37:48,800 on Coding the Wheel, James Devlin, 854 00:37:49,020 --> 00:37:51,000 Soren Sorban, they did some nice research. 855 00:37:51,000 --> 00:37:54,080 And Erez Metelaza, 856 00:37:55,160 --> 00:37:57,460 he did the attacking the framework. 857 00:37:57,740 --> 00:37:58,800 Some really nice stuff. 858 00:37:59,900 --> 00:38:02,220 Thanks to some of my good friends 859 00:38:02,220 --> 00:38:03,140 that added to this. 860 00:38:03,820 --> 00:38:05,540 And check out the book 861 00:38:05,540 --> 00:38:07,120 Managed Code Root Kits. 862 00:38:07,520 --> 00:38:10,060 This is coming out in a couple of months 863 00:38:10,060 --> 00:38:11,100 and definitely something 864 00:38:11,100 --> 00:38:12,400 if you want to attack the framework. 865 00:38:14,700 --> 00:38:16,180 And as I said, 866 00:38:16,220 --> 00:38:17,200 this is all going out 867 00:38:17,200 --> 00:38:18,860 under the public use license. 868 00:38:23,920 --> 00:38:25,920 And there will be Q&A 869 00:38:25,920 --> 00:38:26,860 over in 1.06. 870 00:38:30,080 --> 00:38:32,700 And some of the additional payloads 871 00:38:32,700 --> 00:38:33,580 if you want to watch, 872 00:38:33,820 --> 00:38:34,960 we can run over them. 873 00:38:38,100 --> 00:38:38,500 Okay. 874 00:38:38,740 --> 00:38:39,960 We want to show Twitter real quick. 875 00:38:40,460 --> 00:38:41,280 One last thing 876 00:38:41,280 --> 00:38:42,140 in case you didn't believe 877 00:38:42,140 --> 00:38:43,480 that it was actually doing it. 878 00:38:45,400 --> 00:38:45,800 Okay. 879 00:38:48,440 --> 00:38:48,840 So, 880 00:38:53,460 --> 00:38:55,860 when you log into your SQL server 881 00:38:55,860 --> 00:38:56,600 every time now, 882 00:38:57,160 --> 00:38:58,620 it shows you your 883 00:38:58,620 --> 00:39:00,400 SA password and black hat. 884 00:39:09,560 --> 00:39:11,700 So, we have a couple of extra minutes. 885 00:39:11,860 --> 00:39:12,160 So, 886 00:39:13,760 --> 00:39:15,620 I'm going to just spin up 887 00:39:15,620 --> 00:39:16,340 some injection 888 00:39:16,340 --> 00:39:18,580 and do a couple of fun demos 889 00:39:18,840 --> 00:39:19,680 that I've really enjoyed. 890 00:39:20,440 --> 00:39:22,560 So, we can basically at this point 891 00:39:22,560 --> 00:39:24,220 intermix applications, of course. 892 00:39:25,740 --> 00:39:27,020 And injecting 893 00:39:27,020 --> 00:39:28,580 into our target application 894 00:39:28,580 --> 00:39:29,720 allows us to 895 00:39:31,900 --> 00:39:33,060 edit the GUI 896 00:39:33,060 --> 00:39:34,840 and add 897 00:39:34,840 --> 00:39:36,680 some intermingling features. 898 00:39:41,420 --> 00:39:42,880 So, when we get 899 00:39:42,880 --> 00:39:44,100 into the target application, 900 00:39:45,060 --> 00:39:46,040 we can 901 00:39:47,740 --> 00:39:48,380 ask 902 00:39:48,840 --> 00:39:49,760 the code object 903 00:39:49,760 --> 00:39:51,220 the code behind it. 904 00:39:51,400 --> 00:39:53,200 So, when you're inside of it, 905 00:39:53,380 --> 00:39:55,040 you say, hey, what's your code? 906 00:39:55,620 --> 00:39:57,120 And it divulges its code. 907 00:39:57,520 --> 00:39:59,140 So, you can jump around to objects 908 00:39:59,140 --> 00:40:00,760 and say, hey, what are you running? 909 00:40:01,200 --> 00:40:02,780 And instead of hunting through 910 00:40:02,780 --> 00:40:03,520 the object structure, 911 00:40:04,060 --> 00:40:05,260 you're right there in code. 912 00:40:08,540 --> 00:40:08,980 Also, 913 00:40:10,580 --> 00:40:11,460 going after 914 00:40:11,460 --> 00:40:12,720 SQL Server, 915 00:40:18,960 --> 00:40:20,460 we'll inject into that. 916 00:40:36,060 --> 00:40:37,760 And spin up 917 00:40:37,760 --> 00:40:40,400 the communication 918 00:40:40,400 --> 00:40:40,980 console. 919 00:40:43,440 --> 00:40:44,800 Pretty much the same 920 00:40:44,800 --> 00:40:45,120 hacks. 921 00:40:48,000 --> 00:40:48,720 Leading 922 00:40:49,360 --> 00:40:51,340 I guess I lost a couple of payloads. 923 00:40:51,580 --> 00:40:52,820 Okay, well, thank you very much 924 00:40:52,820 --> 00:40:53,700 for coming to my talk. 925 00:40:53,780 --> 00:40:54,440 Hope you enjoyed it.