1 00:00:00,500 --> 00:00:04,840 Hi, I'm Ben Feinstein. I'm with the SecureWorks Counter Threat Unit. I'm going to be giving 2 00:00:04,840 --> 00:00:10,280 you a talk today about Snort plugin development. And just to start off a little basics. 3 00:00:16,980 --> 00:00:21,200 So what am I going to talk about today? I'm going to go over the v2 Snort architecture 4 00:00:21,200 --> 00:00:27,080 at a higher level and cover some of the internals. And I'm going to go over the process of Snort 5 00:00:27,080 --> 00:00:33,120 plugin development and cover two areas of that. And one area is dynamic rules. The other 6 00:00:33,120 --> 00:00:39,360 area is dynamic preprocessors. I'm going to go over some of the relevant Snort APIs, give 7 00:00:39,360 --> 00:00:44,840 you some code examples, point out a few areas that can be confusing and that can hold you 8 00:00:44,840 --> 00:00:47,720 up in development, give you a few tips on how to succeed. 9 00:00:48,420 --> 00:00:52,960 And I'm also going to be discussing two new plugins or two new dynamic preprocessors that 10 00:00:52,960 --> 00:00:57,020 are GPLed. They're available on the SecureWorks website. There'll be a URL later in the present 11 00:00:57,020 --> 00:00:59,900 presentation. The first preprocessor deals with ActiveX 12 00:00:59,900 --> 00:01:06,900 controls, essentially a virtual kill bit. And the other preprocessor deals with SSH Diffie-Hellman 13 00:01:06,900 --> 00:01:12,000 Key Exchange that is affected by the Debian OpenSSL random number generator bug. 14 00:01:13,900 --> 00:01:18,580 So some basics. I don't need to review for some of the guys in the front row here from 15 00:01:18,580 --> 00:01:25,560 SourceFire, but Snort is an open source IDS and IPS that was originally created by Marty 16 00:01:27,020 --> 00:01:35,840 Kuhn. He released it back in 1998 and it was commercialized later by SourceFire Inc. 17 00:01:36,500 --> 00:01:41,300 There's an inline mode that's available. The inline mode is essentially IPS. Typically 18 00:01:41,300 --> 00:01:46,860 it's going to use a Linux bridge plus net filter. And you have IPQ and NFQ interfaces 19 00:01:46,860 --> 00:01:51,420 to queue the packets in and out of kernel space and user space through Snort and let 20 00:01:51,420 --> 00:01:55,480 Snort make verdicts on how to take action on those packets and streams. 21 00:01:56,780 --> 00:02:01,960 Some of you that follow Snort are aware that V3 is now making its way through beta. 22 00:02:02,180 --> 00:02:06,640 This is a long time in coming and we're real excited to see that code base getting released. 23 00:02:07,200 --> 00:02:11,940 I am not going to be discussing V3 today. I'm not going to be talking about the V3 architecture. 24 00:02:12,780 --> 00:02:16,500 Marty will do much more justice to that and you can catch a talk from Marty at some other 25 00:02:16,500 --> 00:02:20,600 conferences and he will talk all about the V3 architecture. It's some really cool stuff 26 00:02:20,600 --> 00:02:21,180 they've done there. 27 00:02:25,480 --> 00:02:28,360 It's quite modularized. It's built to be extended. 28 00:02:29,020 --> 00:02:31,680 You have the Snort rules and the rules matching engine. 29 00:02:32,200 --> 00:02:38,320 So the SF engine is a dynamic plug-in. So actually the core rule matching engine 30 00:02:38,320 --> 00:02:42,900 is pluggable. You also have dynamic detection plug-ins that 31 00:02:42,900 --> 00:02:47,860 can implement or extend the rules language. So you can add new keywords and new constructs 32 00:02:47,860 --> 00:02:52,760 to the syntax of the rules language by building shared objects and dynamic plug-ins that will 33 00:02:52,760 --> 00:02:57,140 add to the detection capabilities of Snort. They also have output plug-ins. 34 00:02:57,560 --> 00:03:01,100 So output plug-in example is the Unified or the Unified 2 outputs. 35 00:03:01,380 --> 00:03:04,540 That's a highly efficient binary alert and log stream. 36 00:03:05,040 --> 00:03:09,620 You have your classic syslog output. And there's some other output plug-ins as 37 00:03:09,620 --> 00:03:14,660 well that are less commonly used. And you've got your classic two types of 38 00:03:14,660 --> 00:03:17,280 preprocessors here. You've got detection preprocessors. 39 00:03:17,600 --> 00:03:20,860 What those essentially do is they look at traffic and they will generate alerts. 40 00:03:21,120 --> 00:03:22,740 And in an in-line scenario, they will generate alerts. 41 00:03:22,740 --> 00:03:25,480 In an in-line scenario, they may drop traffic or send resets. 42 00:03:25,800 --> 00:03:30,680 Then you have normalization preprocessors. What these are there for is to decode and 43 00:03:30,680 --> 00:03:35,160 normalize traffic before it's presented to other plug-ins and to other end of the Snort 44 00:03:35,160 --> 00:03:41,400 rules matching language or engine rather. So for instance, HTTP inspect is a preprocessor 45 00:03:41,680 --> 00:03:47,280 that does some normalization of HTTP requests. And then other rules and preprocessors can 46 00:03:47,280 --> 00:03:52,440 then inspect the decoded traffic there. So can you continue on with talking about 47 00:03:52,440 --> 00:03:56,700 the architecture? A dynamic preprocessor is basically a shared 48 00:03:56,700 --> 00:04:00,260 object. You can define a packet processing callback, 49 00:04:00,340 --> 00:04:04,500 a C function, that Snort is going to queue or send packets through. 50 00:04:05,300 --> 00:04:07,980 You have the ability to do preprocessor local storage. 51 00:04:08,380 --> 00:04:13,140 And you also have the ability, using the stream API, to do stream local storage. 52 00:04:13,660 --> 00:04:21,440 You define callbacks to deallocate your stream local storage when Snort decides to free that 53 00:04:21,440 --> 00:04:24,520 session object. It'll call your cleanup method, and you can 54 00:04:24,520 --> 00:04:26,920 gracefully free your memory that you've allocated. 55 00:04:27,520 --> 00:04:31,660 Now dynamic rules are relatively new in the Snort code base. 56 00:04:31,940 --> 00:04:36,300 You could think of a dynamic rule as essentially writing a Snort rule in C. 57 00:04:37,660 --> 00:04:45,080 I may be wrong, but I think around 2.8.01, there was an ability to register a C callback 58 00:04:45,080 --> 00:04:51,420 added to the dynamic rules APIs. So before that C callback was added, there 59 00:04:51,440 --> 00:04:55,520 was defined. It seemed to me like the only reason to do 60 00:04:55,520 --> 00:05:02,620 dynamic rules was to obfuscate what your rule's doing, to kind of hide maybe the exploit or 61 00:05:02,620 --> 00:05:04,960 the vulnerability that could be determined from the rule. 62 00:05:06,500 --> 00:05:10,560 2.6.1.5 was the version I'm hearing from SourceFire. 63 00:05:11,800 --> 00:05:17,060 So basically some commercial Snort rule sets out there use these dynamic rules for some 64 00:05:17,060 --> 00:05:21,280 of their rules. However, it's relatively straightforward to a 65 00:05:21,440 --> 00:05:23,880 reverse engineer these files in something like IDA Pro. 66 00:05:24,340 --> 00:05:30,440 So it does raise the bar in terms of obfuscating the content of your rules, but it's not going 67 00:05:30,440 --> 00:05:35,200 to prevent a more skilled adversary from figuring out what's in there. 68 00:05:36,740 --> 00:05:41,720 So a few other internals to cover is the alerting versus logging. 69 00:05:42,900 --> 00:05:45,940 It's pretty simple. Logs are going to contain the packet capture 70 00:05:45,940 --> 00:05:50,020 data in addition to the alert summary. Alerts are just simply the summaries. 71 00:05:52,080 --> 00:05:57,280 Unified2 is an interesting addition in that it's an extensible output format, or it's designed 72 00:05:57,280 --> 00:06:00,660 to be extensible. My understanding of it is that you can encode 73 00:06:00,660 --> 00:06:04,980 additional data, for instance, from your preprocessor using length value encodings 74 00:06:04,980 --> 00:06:11,520 into that Unified2 stream. So it's great if your preprocessor wants to 75 00:06:11,520 --> 00:06:14,220 log some additional data. You ought to use Unified2. 76 00:06:14,500 --> 00:06:19,740 Some examples, I believe the SourceFire codebase is moving to try to use this Unified2 to gather 77 00:06:19,740 --> 00:06:24,260 the preprocessor statistics and performance statistics, and also things like port scan 78 00:06:24,260 --> 00:06:30,920 alerts. So what do you need to get started developing 79 00:06:30,920 --> 00:06:34,100 Snort plugins? Or to step back a moment, why do you want 80 00:06:34,100 --> 00:06:37,340 to develop Snort plugins? Well, Snort is quite mature. 81 00:06:37,640 --> 00:06:41,120 It's a common part of IT security environments all over the world. 82 00:06:41,540 --> 00:06:46,820 So instead of chasing around the new hotness of the day, the new security technology, sometimes 83 00:06:46,820 --> 00:06:49,640 it makes sense to extend the capabilities of your existing control. 84 00:06:49,740 --> 00:06:54,840 So you've already got widely deployed. So Snort is going to give you some great features. 85 00:06:54,960 --> 00:06:57,540 It's going to reassemble the streams for you. It's going to put stuff back in order. 86 00:06:57,800 --> 00:07:00,800 It gives you a nice, mature alerting and logging framework. 87 00:07:01,280 --> 00:07:05,260 So it's really a nice environment to start developing this kind of technology instead 88 00:07:05,260 --> 00:07:10,320 of just creating a whole new separate program or module to do all these things. 89 00:07:11,160 --> 00:07:15,460 So one great resource is the Snort developers mailing list. 90 00:07:16,780 --> 00:07:19,100 The SourceFire developers are great. They're on there. 91 00:07:19,100 --> 00:07:21,860 All the time. They're typically very responsive. 92 00:07:22,840 --> 00:07:26,640 And just my advice would be, you know, do your homework before you mail the list. 93 00:07:26,780 --> 00:07:30,140 You're going to get a much better experience. And you're going to save everybody time and 94 00:07:30,140 --> 00:07:36,000 aggravation. So there is some issues with documentation 95 00:07:36,000 --> 00:07:40,640 around building dynamic preprocessors. There's some example code in the Snort code 96 00:07:40,640 --> 00:07:44,420 base. There's a few older materials online from 97 00:07:44,420 --> 00:07:48,100 around the 2.6 time frame. But the APIs have changed some. 98 00:07:48,100 --> 00:07:51,220 Some things have changed. So the documentation is a little bit out 99 00:07:51,220 --> 00:07:54,980 of date. And I'm hoping that from this talk and from 100 00:07:55,340 --> 00:08:00,380 the source code that we're publishing, other plug-in developers can kind of get a better 101 00:08:00,380 --> 00:08:04,180 sense of how to build these things. So like I said, there's some basic examples 102 00:08:04,180 --> 00:08:08,400 in there in the Snort code base of the dynamic rules and the dynamic preprocessors. 103 00:08:09,900 --> 00:08:14,480 So how are you going to get started developing? Use the source. It's there. 104 00:08:15,300 --> 00:08:18,080 Start looking at existing plug-ins. How are they working? How are they working? How are 105 00:08:18,080 --> 00:08:19,360 they doing their work? How do they do what they do? 106 00:08:20,440 --> 00:08:23,620 The DNS plug-in is a good start. It's relatively small. 107 00:08:24,160 --> 00:08:29,060 The HTTP inspect plug-in is much more full-featured. There's a lot more code in it. 108 00:08:29,640 --> 00:08:33,060 And there's some other interesting plug-ins that you can look at how they're doing things 109 00:08:33,060 --> 00:08:35,420 and kind of figure out how you should use the APIs. 110 00:08:37,220 --> 00:08:41,760 I personally approach development by writing small blocks of code and unit testing them 111 00:08:41,760 --> 00:08:46,600 and doing incremental development like that. So I think that's a great way to approach 112 00:08:46,600 --> 00:08:48,060 it. And also, when you're working on a project, 113 00:08:48,060 --> 00:08:51,080 when you get stuck, if you're really stuck and you can't get past it, go to the Snort 114 00:08:51,080 --> 00:08:56,380 developers list, post the problem you're having, and typically someone out there will have 115 00:08:56,380 --> 00:08:58,740 encountered this problem and have an answer for you. 116 00:09:00,140 --> 00:09:06,940 So my Snort development environment basically is the Snort 2.8.x source tarball, whatever 117 00:09:06,940 --> 00:09:13,640 the latest stable release is, running CentOS 5 box with GCC 4.1 and glibc 2.5. 118 00:09:14,380 --> 00:09:18,040 Now, CentOS, or Red Hat Enterprise 5, is a little bit different. It's a little bit more 119 00:09:18,040 --> 00:09:21,500 complex, but you can see that we have packages, slightly older versions of Autocomp and Automake. 120 00:09:21,700 --> 00:09:26,240 So to get your environment working and in sync with the SourceFire development environment, 121 00:09:26,520 --> 00:09:31,660 you're going to have to build Autocomp 2.6.1 and Automake 1.10 from scratch, put that 122 00:09:31,660 --> 00:09:35,880 in your path, and use those tools, unless you want to screw around with Automate and 123 00:09:35,880 --> 00:09:37,820 Autocomp yourself and deal with that mess. 124 00:09:39,940 --> 00:09:44,380 So to jump into the dynamic rules, these are probably the simplest ways you can extend 125 00:09:44,380 --> 00:09:46,160 Snort using the C language. 126 00:09:48,040 --> 00:09:51,980 key header file that you ought to look at. It's the SFSnortPluginAPI header. 127 00:09:52,300 --> 00:09:58,380 What it does is it defines C structure equivalents to all the rule syntax structures. We're talking 128 00:09:58,380 --> 00:10:05,540 flow, content, PCRE, those kind of structures. Basically, in C code, I can create a struct 129 00:10:05,540 --> 00:10:08,600 that defines the same properties as I would in the rules language. 130 00:10:09,620 --> 00:10:14,840 Inside your dynamic rule file or C file that can contain multiple rules, you have this 131 00:10:14,840 --> 00:10:20,300 array of pointers to rules called rules. The framework pretty much handles the rest. 132 00:10:21,040 --> 00:10:27,320 You point Snort to the dynamic rule shared object you've built, and you have dummy rules 133 00:10:27,320 --> 00:10:29,680 that have to be present. It will load them into the engine. 134 00:10:31,420 --> 00:10:36,620 The Snort makefile pretty much takes care of most of it for you. It creates the shared 135 00:10:36,620 --> 00:10:43,380 objects using lib tool, and they'll be dynamically loaded at Snort in runtime. How do you get 136 00:10:43,380 --> 00:10:44,820 Snort to load your runtime? 137 00:10:46,560 --> 00:10:51,500 There's a few command line and configuration options you should be aware of. In the Snort 138 00:10:51,500 --> 00:10:58,320 config command line, you've got dynamic detection live and dynamic detection live dir. The first 139 00:10:58,320 --> 00:11:01,080 one of these is you just point it to your shared object file. It's going to load it 140 00:11:01,080 --> 00:11:04,360 up. The second, you're going to give it a directory to any number of shared objects 141 00:11:04,360 --> 00:11:07,100 that are dynamic rules, and it will load those up. 142 00:11:08,820 --> 00:11:14,540 Snort has this new command line option called dump dynamic rules. All these dynamic rules 143 00:11:14,540 --> 00:11:20,540 require stubbed or dummy rules to be in the rules files, meta rules. This will actually 144 00:11:20,540 --> 00:11:24,080 dump all that information out for you in a nice format. You can throw it into a rules 145 00:11:24,080 --> 00:11:24,280 file. 146 00:11:24,900 --> 00:11:30,560 Below I've got an example of just real basic hello world rule. It's using this new keyword 147 00:11:30,560 --> 00:11:36,840 called metadata, colon, engine shared. You link it up with your SID, which in this case 148 00:11:36,840 --> 00:11:42,900 is 2,000,001, and you've got a generator ID of three. Three is the generator ID that's 149 00:11:42,900 --> 00:11:44,180 assigned to dynamic rules. 150 00:11:45,020 --> 00:11:50,240 So that's just very basic stubbed out meta rule that you'd see spit out by Snort. 151 00:11:52,300 --> 00:11:59,240 As I said, you've got different C structs for all the rules options. A rule option is 152 00:11:59,240 --> 00:12:06,580 simply a union of all the different types of structures there. A rule structure itself 153 00:12:07,100 --> 00:12:12,420 is simply a null terminated array of rule options. You also have a rule pointer to a 154 00:12:12,420 --> 00:12:14,520 rule header struct. You have rule header to the header structure. There is a type of header 155 00:12:14,520 --> 00:12:19,700 have some rule references, which would be, like, pointers to a CVE, pointers to some 156 00:12:19,700 --> 00:12:25,840 web reference, for instance. The API also exposes functions to match on 157 00:12:25,840 --> 00:12:29,740 these different rule constructs for content, flow, flow bits, and such. 158 00:12:30,420 --> 00:12:35,960 So you can actually create a rule option for a content match, call the content match function 159 00:12:35,960 --> 00:12:39,020 in the API, and get back rule match or rule no match. 160 00:12:40,500 --> 00:12:45,540 It also offers some basic functions to register and to dump the dummy rules out. 161 00:12:46,940 --> 00:12:50,500 So what I got up here is just a very simple content info structure. 162 00:12:51,000 --> 00:12:56,620 This comes from the example dynamic rules that's in the snort source tarball. 163 00:12:57,440 --> 00:12:59,800 All this is is looking for the content of net bus. 164 00:13:00,780 --> 00:13:04,000 You tell it what buffers to look in. Typically, you're going to use the normalized 165 00:13:04,000 --> 00:13:09,000 buffers, but you could use raw buffers. And these two null objects and the zero 166 00:13:09,000 --> 00:13:13,820 counters down there, when you register the rule with snort, it goes and creates the boy 167 00:13:13,820 --> 00:13:23,020 or more structures, sets those pointers, and, of course, it fast pattern matcher and you 168 00:13:23,020 --> 00:13:24,900 basically will initialize that structure for you. 169 00:13:24,980 --> 00:13:28,040 You need to do that before you can call the content match with this structure. 170 00:13:29,420 --> 00:13:33,340 And then here you just wrap that. If you want to create a rule option, you 171 00:13:33,340 --> 00:13:37,860 simply wrap the content info and this option type content macro. 172 00:13:37,860 --> 00:13:41,400 macro. There you go. You can pass that rule option 173 00:13:41,400 --> 00:13:45,300 in and have that null terminated array of rule options in your rule structure. 174 00:13:46,040 --> 00:13:50,540 Then below is just the API call you're going to make to attempt a content match using a 175 00:13:50,540 --> 00:13:56,320 pointer to your content structure. That void pointer, that's just a casted to 176 00:13:56,320 --> 00:14:00,340 void star. It's a SF snort packet, which is the standard 177 00:14:00,340 --> 00:14:02,620 structure that you're going to get passed in your callback function. 178 00:14:05,300 --> 00:14:09,580 PCRE matching, same thing here. You give it some PCRE flags. 179 00:14:09,880 --> 00:14:14,940 You give it what buffers you want to match against, and then you wrap it in a pound to 180 00:14:14,940 --> 00:14:19,560 find option type PCRE object. There's your PCRE match function. 181 00:14:20,100 --> 00:14:23,120 You've initialized your PCRE structure. You have a packet pointer. 182 00:14:23,480 --> 00:14:26,040 You can go call that. It's going to return rule match or rule no 183 00:14:26,040 --> 00:14:29,400 match, and you would know whether your PCRE is matching in that content or not. 184 00:14:30,240 --> 00:14:32,600 Same thing with flow. Establish. 185 00:14:32,600 --> 00:14:34,680 Establish to client to server. Wrap it in an object. 186 00:14:34,980 --> 00:14:37,960 You've got a function call to check if the flow is matched. 187 00:14:39,360 --> 00:14:42,900 Here's how you create this rule structure for a dynamic rule file. 188 00:14:43,500 --> 00:14:46,340 You have two other C files that are going to find this rule struct. 189 00:14:46,660 --> 00:14:51,340 You have a null terminated array of pointers to rules, and then basically the engine itself 190 00:14:51,340 --> 00:14:59,060 is going to call register rules on that array, which will then internally fix up the Ahoro 191 00:14:59,060 --> 00:15:01,140 Corsic, the pointers, all that stuff. 192 00:15:02,960 --> 00:15:12,400 Add it to the engine. On to the C processing callback that we mentioned. 193 00:15:12,660 --> 00:15:15,040 This is really the most powerful part of dynamic rules. 194 00:15:15,580 --> 00:15:19,860 You're going to be able to just define a C function and say to the engine that when 195 00:15:19,860 --> 00:15:24,580 you've matched all these elements of my rule, also I want you to call this C function, 196 00:15:24,720 --> 00:15:28,260 pass the packet to it, and the C function will return a rule match or rule no match. 197 00:15:28,260 --> 00:15:33,720 You can do this to create much more sophisticated matching algorithms than you could ever do 198 00:15:33,720 --> 00:15:38,440 in a rule. Here's just a very simple MyDynamicRule.c. 199 00:15:38,820 --> 00:15:43,100 Include a couple header files. Define my callback function. 200 00:15:43,660 --> 00:15:48,520 In my rule structure, I have a pointer to it, and the snort engine is going to take 201 00:15:48,520 --> 00:15:53,060 care of the rest. Here's a little code snippet from an example 202 00:15:53,060 --> 00:15:58,180 rule detection function. Now, I failed to say at the beginning of this talk, I've got two 203 00:15:58,260 --> 00:16:04,080 of these lovely DC404 T-shirts available here. I'm going to give one of these T-shirts to 204 00:16:04,080 --> 00:16:07,840 whoever can answer this question on here, and one of the T-shirts to the best question 205 00:16:07,840 --> 00:16:12,780 at the end of the presentation. I don't know if I'll let the Source Fire guys 206 00:16:12,780 --> 00:16:17,360 answer this question, but what does this little C snippet do? This callback. 207 00:16:17,540 --> 00:16:22,860 You get a packet structure, I cast it to a sf snort packet, and I have this if statement. 208 00:16:23,180 --> 00:16:28,240 I'm going to match on the if. Who out there for a lovely DC404 T-shirt, 209 00:16:28,240 --> 00:16:39,560 t-shirt can tell me what this does. This is going to match if the IP ID is odd. 210 00:16:40,600 --> 00:16:44,080 I'm simply taking it mod two. Very simple stuff. 211 00:16:44,300 --> 00:16:46,880 But this is an example of something you couldn't do in the Snort Rules language. 212 00:16:47,260 --> 00:16:51,620 There's no operator to say take IP ID and take it modular something and compare it. 213 00:16:51,620 --> 00:16:56,720 But you can define a four- or five-line C function that will do the exact same thing. 214 00:16:57,860 --> 00:17:04,820 So maybe the two best questions will get t-shirts. Another key header file you want to look at 215 00:17:04,820 --> 00:17:09,660 is the dynamicpreprocessor.h. The key structure to be aware of is this dynamic 216 00:17:09,660 --> 00:17:13,980 preprocessor data. Almost everything you're doing with the APIs 217 00:17:13,980 --> 00:17:18,480 is going to be off of pointers to this DPD object. It's typically named underscore DPD. 218 00:17:19,500 --> 00:17:21,600 You've got callbacks for initialization. You've got callbacks for initialization. 219 00:17:21,600 --> 00:17:26,500 Exit, restart of your preprocessor. You've got callbacks to, or you've got function 220 00:17:26,500 --> 00:17:30,900 pointers to internal logging functions. You've got ability to interact with the stream 221 00:17:30,900 --> 00:17:34,160 APIs, the search APIs. You have alerting functions. 222 00:17:34,500 --> 00:17:37,420 And also you have the ability to do Snort inline functions like packet drop. 223 00:17:37,860 --> 00:17:41,960 And all this is available through that dynamic preprocessor data structure that is available 224 00:17:41,960 --> 00:17:46,740 to your preprocessor. And right here, here's a little code snippet 225 00:17:46,740 --> 00:17:50,340 from my ActiveX preprocessor. All you do is you define the setup function. 226 00:17:50,340 --> 00:17:55,720 And I'm registering a preprocessor called ActiveX. I'm giving it a pointer to, I'm 227 00:17:55,720 --> 00:17:59,860 pointing it to my initialization function. Initialization function takes the command 228 00:17:59,860 --> 00:18:02,220 line arguments for your preprocessor named ActiveX. 229 00:18:02,600 --> 00:18:08,220 It's going to call the add preproc function on the dynamic preprocessor data structure. 230 00:18:08,540 --> 00:18:11,120 And it's going to basically say what priority do I want. 231 00:18:11,320 --> 00:18:13,920 You have transport, application, and a few others. 232 00:18:14,220 --> 00:18:19,320 And also pp ActiveX is going to be a unique number that I've defined in another header 233 00:18:19,320 --> 00:18:20,320 file. That uniquely applies. 234 00:18:20,340 --> 00:18:25,740 It identifies the ID of that preprocessor. And then you've got process ActiveX, which 235 00:18:25,740 --> 00:18:30,280 is where the real work of the module happens. It gets passed a pointer to sf snort packet. 236 00:18:30,500 --> 00:18:33,620 You get a context pointer. And then after you've done all your work, 237 00:18:33,680 --> 00:18:38,180 you see that alert add call. That's basically calling the snort alert mechanism 238 00:18:38,180 --> 00:18:40,780 to say, hey, my preprocessor wants to generate an alert. 239 00:18:41,320 --> 00:18:46,600 In another header file, I've defined a signature ID and a string that goes along with that 240 00:18:46,600 --> 00:18:49,180 signature. ActiveX event kilbit str. 241 00:18:50,720 --> 00:18:55,540 I basically call that alert add and it shoves it right into the snort alert queue. 242 00:19:01,280 --> 00:19:05,640 So when you're in the preprocessor you can also use some of the dynamic rules functionality. 243 00:19:08,100 --> 00:19:14,580 Using the rule match function, register1 rule is a curious callback. 244 00:19:14,800 --> 00:19:18,700 It was a little confusing for me. You register one rule, you give it a pointer 245 00:19:18,700 --> 00:19:20,320 to your rule. And then there's a, you know, you have to 246 00:19:20,320 --> 00:19:26,060 there's this flag called don't register rule. At first, I scratched my head and said, okay, 247 00:19:26,140 --> 00:19:30,780 register one rule, but don't register a rule. All the don't register rule does is it doesn't 248 00:19:30,780 --> 00:19:37,120 add it into the tree of nodes there. You still have to call this function to initialize 249 00:19:37,120 --> 00:19:43,320 all the pointers in your structures there. It sets up the ahocorsic and the internal 250 00:19:43,320 --> 00:19:49,940 pointers, but this was a confusing point to me. When you're using rule structures inside 251 00:19:49,940 --> 00:19:53,140 your preprocessor, you need to register them, but not register them. 252 00:19:55,400 --> 00:20:00,400 These plug-ins I'm talking about, you can download them from secureworks.com slash research 253 00:20:00,400 --> 00:20:07,000 slash tools. There's a link to the snort plug-ins there. I'm releasing them, released this Wednesday 254 00:20:07,000 --> 00:20:12,260 morning under the GPL. We can't support these. We can't give any warranty for these plug-ins. 255 00:20:13,080 --> 00:20:18,080 Use them at your own risk. Your mileage may vary, but we do appreciate feedback so we 256 00:20:18,080 --> 00:20:19,680 can help improve these things and bug reports. 257 00:20:20,820 --> 00:20:26,620 Also, if you want to extend these plug-ins, you have no obligation to, but we'd love 258 00:20:26,620 --> 00:20:30,960 to feed the code back to us upstream so we can get those fixes in there. 259 00:20:32,620 --> 00:20:38,920 The first plug-in that we're releasing is just a simple ActiveX detection dynamic preprocessor. 260 00:20:39,640 --> 00:20:44,940 What it does is it inspects web traffic for some JavaScript or scripting that's going 261 00:20:44,940 --> 00:20:49,520 to instantiate a vulnerable ActiveX control. When I say vulnerable, it's basically based 262 00:20:49,680 --> 00:20:52,620 on public vulnerability disclosures about ActiveX controls. 263 00:20:53,360 --> 00:20:57,860 In the preprocessor configuration, I point the preprocessor to a local database file 264 00:20:58,080 --> 00:21:01,820 of ActiveX controls listed by class ID and optionally method and property. 265 00:21:02,660 --> 00:21:10,460 The database is in XML format. I'm sorry, but it seemed easy at the time to parse. 266 00:21:11,600 --> 00:21:15,960 It basically just looks at the traffic, the responses coming off the web servers, looks 267 00:21:15,960 --> 00:21:19,020 for ActiveX instantiation, looks for the class ID and a PCRE. 268 00:21:19,640 --> 00:21:25,360 Basically, if you define methods and properties in the database, it'll also look for, is that 269 00:21:25,360 --> 00:21:28,800 scripting using those vulnerable methods or properties? 270 00:21:30,440 --> 00:21:36,280 It can be evaded, like most things in security. JavaScript is a great way to obfuscate attacks. 271 00:21:36,660 --> 00:21:43,380 I'm not going to un-XOR your JavaScript and determine that there's an ActiveX control 272 00:21:43,380 --> 00:21:47,620 in there. However, today, a lot of attackers that are 273 00:21:47,620 --> 00:21:51,500 attacking these ActiveX controls, they're just using plain class IDs. 274 00:21:51,700 --> 00:21:55,500 They're not really being that sophisticated. Also, you could probably evade this with some 275 00:21:55,500 --> 00:22:03,080 HTTP encodings, using gzip or deflate. In the future, I want to add some snort inline 276 00:22:03,080 --> 00:22:06,980 support to this so that when it detects the plugin getting instantiated, it could actually 277 00:22:06,980 --> 00:22:09,120 drop the packet or potentially send a reset back. 278 00:22:10,760 --> 00:22:16,080 Also I want to extend this some more to leverage all the work that HEP Inspect is doing there. 279 00:22:17,620 --> 00:22:22,020 And another idea is to leverage the unified2 output plugin to write out some more details 280 00:22:22,020 --> 00:22:23,920 about the ActiveX control that we've triggered on. 281 00:22:26,500 --> 00:22:31,940 I took a shortcut implementing this, and I used the match rule function. It was very 282 00:22:31,940 --> 00:22:35,900 convenient. It's probably not the most efficient way to do this, in terms of space and time, 283 00:22:36,480 --> 00:22:38,140 but it was most efficient for me to implement. 284 00:22:39,620 --> 00:22:47,600 The code right now is performing a naive linear search of class IDs. Basically, my point is, 285 00:22:47,620 --> 00:22:51,320 the plan is to take the high performance, I think it's tri-based data structures that 286 00:22:51,320 --> 00:22:57,120 HEP Inspect is using, and leverage those. It's using snorts flowmatch to make sure that 287 00:22:57,120 --> 00:23:00,560 it's a response coming back from the server, and it does some content matching and some 288 00:23:00,560 --> 00:23:02,800 PCRE matching behind the scenes to detect that. 289 00:23:03,860 --> 00:23:09,340 I'm going to give you a quick live demo here of the ActiveX detection preprocessor in action. 290 00:23:22,820 --> 00:23:27,040 I've got a shell here. I've got a VM running. It's ids.example.com. 291 00:23:29,640 --> 00:23:40,500 Right here, you can see I'm pointing snort at my shared object files. It's in my working 292 00:23:40,500 --> 00:23:45,640 directory where I've been building the code, building the source. DynamicPresetProcessorFile, 293 00:23:45,800 --> 00:23:46,880 point it to the ActiveX. 294 00:23:47,620 --> 00:23:49,520 Point it to the SSH plugin we'll see later. 295 00:23:50,380 --> 00:23:54,640 You see down below I'm including a little configuration for this ActiveX control. 296 00:24:02,220 --> 00:24:07,200 Here's basically the configuration for that ActiveX preprocessor. You just tell it what 297 00:24:07,200 --> 00:24:11,620 ports you want to look on. You point it to a local XML database file. On initialization, 298 00:24:11,720 --> 00:24:17,600 it reads in the file, allocates pattern matching structures, and starts looking at HTTP response. 299 00:24:17,620 --> 00:24:18,500 The response is coming back in. 300 00:24:20,940 --> 00:24:22,020 Let's start up snort. 301 00:24:40,720 --> 00:24:47,140 Up here, you can see where my ActiveX plugin is echoing back parts of its configuration 302 00:24:47,140 --> 00:24:47,800 on startup. 303 00:24:48,040 --> 00:24:52,160 It tells you what kill bits. This is pretty verbose right here, but it's telling you what 304 00:24:52,160 --> 00:24:56,100 kill bits it's looking for, what properties it's looking for, and what ports it's going 305 00:24:56,100 --> 00:24:56,500 to look at. 306 00:24:58,340 --> 00:25:00,440 Snort's running. It's got that ActiveX plugin loaded. 307 00:25:10,440 --> 00:25:15,600 I'm going to start up a real basic HTTP server here. 308 00:25:16,700 --> 00:25:17,120 I'm going to start up a real basic HTTP server here. 309 00:25:32,380 --> 00:25:39,760 All right. Here's a normal web server. It's doing nice, red, blinking text. Hello, DC-404. 310 00:25:40,540 --> 00:25:43,800 You can see back here we got a get request. We sent a 200 back. 311 00:25:43,800 --> 00:25:59,180 Then, if we go over here, we'll do the request again just to show that there's no alerts 312 00:25:59,180 --> 00:26:03,200 being generated. Snort's not generating alerts. 313 00:26:03,440 --> 00:26:07,620 Back here, we're tailing the snort alert file, and we're getting this nice, blinking 314 00:26:07,620 --> 00:26:08,160 text back. 315 00:26:11,820 --> 00:26:13,560 Let's stop this web server. 316 00:26:14,620 --> 00:26:16,060 Let's run the evil web server. 317 00:26:18,140 --> 00:26:19,640 Now, let's go make a request there. 318 00:26:21,840 --> 00:26:26,340 In the background, you'll see we're going to be tailing the log. 319 00:26:31,400 --> 00:26:35,160 You've been pwned. There's your alert. Bad ActiveX control detected. 320 00:26:35,720 --> 00:26:43,780 If we look at this source code on this page, you'll see we're instantiating an ActiveX 321 00:26:43,800 --> 00:26:50,800 object by class ID, and we're calling the IE start method, which is bad juju, and overflowing 322 00:26:51,620 --> 00:26:52,520 it with four Ks of As. 323 00:26:53,920 --> 00:26:55,560 That's what it alerted on. 324 00:26:56,160 --> 00:26:57,760 You see the alert in the background there. 325 00:26:58,080 --> 00:26:58,800 It worked. 326 00:27:19,140 --> 00:27:19,980 All right. 327 00:27:21,100 --> 00:27:23,720 The next plug-in is a little more interesting. 328 00:27:24,380 --> 00:27:28,520 Basically, I'm going to do a quick background on the Debian OpenSSL random number generator. 329 00:27:28,920 --> 00:27:34,740 Please go see Luciano Bello and Maximiliano Bertaccini's talk tomorrow afternoon. 330 00:27:35,920 --> 00:27:43,080 Luciano and his colleague discovered this vulnerability in the Debian OpenSSL random 331 00:27:43,080 --> 00:27:43,560 number generator. 332 00:27:43,960 --> 00:27:47,840 I personally think it's one of the coolest vulns of 08, and I believe the Pony Awards agreed. 333 00:27:49,240 --> 00:27:58,580 The effect is that keys generated that were using this bad code since around September 2006 can be predicted. 334 00:27:58,800 --> 00:28:02,540 There's no real entropy in this random number generator other than your process ID. 335 00:28:03,520 --> 00:28:10,020 That bad code eventually made its way from unstable Debian to testing Debian to stable Debian, 336 00:28:10,200 --> 00:28:11,820 and it made its way into Debian Etch. 337 00:28:11,820 --> 00:28:14,340 It also made its way into Ubuntu. 338 00:28:15,500 --> 00:28:21,020 That code never got caught until recently and leaked its way all into these other branches of Debian. 339 00:28:22,820 --> 00:28:29,340 These are a couple of humorous cartoons that HD Moore threw up on his site when this vuln came out. 340 00:28:29,640 --> 00:28:33,220 You've got your Dilbert talking about a random number generator here. 341 00:28:35,700 --> 00:28:40,980 You've got XKCD doing a similar kind of thing. 342 00:28:42,180 --> 00:28:42,640 Guaranteed. 343 00:28:42,680 --> 00:28:44,120 It's by random dice roll, right? 344 00:28:44,260 --> 00:28:44,520 It's four. 345 00:28:47,040 --> 00:28:52,520 I'm going to probably breeze through this so I don't steal the thunder from Luciano, but this is bad. 346 00:28:52,880 --> 00:28:54,000 The Debian vuln was bad. 347 00:28:54,880 --> 00:28:57,180 HD Moore jumped on this thing so quick. 348 00:28:57,540 --> 00:29:05,040 Within hours or a day or something, he had brute-forced the weak keys, generated them, posted them to his Metasploit page. 349 00:29:07,480 --> 00:29:09,520 He hit this really quick, and I was impressed. 350 00:29:13,060 --> 00:29:14,840 You've been mitigating this vulnerability, right? 351 00:29:14,980 --> 00:29:19,880 You scan your assets for bad SSH and SSL servers using the backlisted keys, right? 352 00:29:20,260 --> 00:29:21,480 Nessus can do this for you. 353 00:29:22,500 --> 00:29:25,440 You scammed all your home dirs for the bad keys, right? 354 00:29:25,660 --> 00:29:28,380 There's a new tool called SSH VulnKey that'll do this for you. 355 00:29:28,860 --> 00:29:30,680 You look through all your home dirs. 356 00:29:30,680 --> 00:29:35,620 You look through all your Windows protected storage, browser profiles for blacklisted SSL certs, right? 357 00:29:37,260 --> 00:29:41,660 What about connections to external servers you don't control or your organization does not control? 358 00:29:41,660 --> 00:29:46,240 That are still using an unpatched Debian open SSL, okay? 359 00:29:46,880 --> 00:29:48,920 It still is going to impact your security. 360 00:29:51,420 --> 00:29:55,640 Our preprocessor, it's basically a detection preprocessor at this point. 361 00:29:55,840 --> 00:30:00,480 What it does is it looks at the Diffie-Hellman key exchange between the two SSH peers, 362 00:30:01,220 --> 00:30:06,340 and it attempts to brute-force the random values that are generated 363 00:30:06,340 --> 00:30:11,300 if one or both of the parties was using this bad Debian open SSL random number generator. 364 00:30:11,800 --> 00:30:14,060 So it's got a detective capability right now. 365 00:30:14,680 --> 00:30:18,280 In the near future, I hope to release code that's going to take this to the next step 366 00:30:18,280 --> 00:30:21,500 and be a normalization preprocessor that's going to decode the whole stream. 367 00:30:21,920 --> 00:30:24,400 But it's not ready yet at this time. 368 00:30:26,360 --> 00:30:31,520 So this will be able to detect users connecting to external servers that are using the bad SSL 369 00:30:31,520 --> 00:30:37,460 and connections coming in from the outside that have a bad unpatched Debian SSL. 370 00:30:39,600 --> 00:30:41,260 So, like I said, the goal, 371 00:30:41,660 --> 00:30:45,820 in the near future, is to have this actually decode both sides of the session. 372 00:30:46,120 --> 00:30:49,100 Right now, I calculate the shared secret, the Diffie-Hellman shared secret. 373 00:30:49,300 --> 00:30:53,780 I squirrel away some other data about the session into the session object or session storage. 374 00:30:54,080 --> 00:30:57,520 And then I generate alerts saying the client's vulnerable, the server's vulnerable. 375 00:30:59,480 --> 00:31:03,860 The cool thing about normalizing it is then all the other snort preprocessors and rules 376 00:31:03,860 --> 00:31:05,720 could then inspect on the unencrypted content. 377 00:31:06,540 --> 00:31:09,480 And unencrypted sessions could be logged out to PCAP or Unified. 378 00:31:10,180 --> 00:31:10,660 Um... 379 00:31:11,660 --> 00:31:12,500 I'm not a lawyer. 380 00:31:12,600 --> 00:31:13,860 I don't know the crypto export laws. 381 00:31:14,060 --> 00:31:17,120 But this may be crypto-analytic software, 382 00:31:17,420 --> 00:31:20,120 which may have some more controls on it. 383 00:31:21,180 --> 00:31:26,300 So I've got to give props to the people that really came up with this stuff. 384 00:31:26,580 --> 00:31:28,620 I mentioned Bello and Bertaccini. 385 00:31:29,240 --> 00:31:30,780 And they're speaking tomorrow afternoon. 386 00:31:31,140 --> 00:31:35,420 This fellow, Alexander Klink, who's at Synops GmbH over in Germany, 387 00:31:35,640 --> 00:31:39,720 he had posted a proof-of-concept Perl script to Full Disclosure. 388 00:31:39,720 --> 00:31:42,420 And I have a link to the actual script right there. 389 00:31:42,980 --> 00:31:47,240 And basically it's a Perl proof-of-concept that's using GNU multiple precision libraries 390 00:31:47,960 --> 00:31:50,880 to attempt to brute force the Debian... 391 00:31:50,880 --> 00:31:51,380 Excuse me. 392 00:31:51,460 --> 00:31:53,120 Brute force the SSH DiffHelm and Key Exchange. 393 00:31:53,680 --> 00:31:55,680 So these other two gentlemen here... 394 00:31:56,200 --> 00:31:58,100 Luciano just pointed me to their work today. 395 00:31:58,200 --> 00:31:59,400 I haven't had a chance to review it. 396 00:31:59,780 --> 00:32:00,460 But they... 397 00:32:00,460 --> 00:32:04,180 I believe they're doing some work on Debian, SSLVone, and SSH. 398 00:32:04,420 --> 00:32:08,040 But potentially related to the host keys and identity keys. 399 00:32:08,180 --> 00:32:09,680 Not necessarily Diffie-Helm and Key Exchange. 400 00:32:09,680 --> 00:32:16,620 And Luciano and his colleague have posted some patches to Wireshark 401 00:32:16,620 --> 00:32:20,160 that's going to break the perfect forward secrecy of TLS and SSL. 402 00:32:20,440 --> 00:32:24,440 And there's a link to a post on the Wireshark Bugzilla. 403 00:32:24,620 --> 00:32:26,040 I think you can find their code up there. 404 00:32:26,240 --> 00:32:28,060 And they'll probably cover this in their talk tomorrow. 405 00:32:29,560 --> 00:32:33,520 So I'm going to give some background on how Diffie-Helm and Key Exchange really works. 406 00:32:34,140 --> 00:32:37,000 It's a really elegant algorithm. 407 00:32:37,360 --> 00:32:39,660 And it's a way for two parties to agree on a shared key. 408 00:32:39,680 --> 00:32:43,960 A shared secret without ever having to have pre-knowledge or do a pre-key exchange. 409 00:32:44,900 --> 00:32:48,400 So the server is going to generate two numbers. 410 00:32:48,520 --> 00:32:51,440 A generator G and P, which is the modulus. 411 00:32:51,800 --> 00:32:52,960 And that's wrong, actually. 412 00:32:53,020 --> 00:32:53,720 It's not 1024. 413 00:32:54,060 --> 00:32:55,280 It's just a really long prime number. 414 00:32:57,500 --> 00:32:59,860 The client is going to generate a random number. 415 00:32:59,940 --> 00:33:00,520 Let's say X. 416 00:33:01,300 --> 00:33:05,280 It's going to take that number, take G to the X power, modulo P. 417 00:33:05,960 --> 00:33:07,120 That gives them a number E. 418 00:33:07,120 --> 00:33:09,180 So it's a function of G, X, and P. 419 00:33:09,440 --> 00:33:12,140 The server, likewise, generates a random number Y. 420 00:33:13,020 --> 00:33:18,560 It'll take this random number Y, raise G to the Yth power, and take it modulo P. 421 00:33:18,740 --> 00:33:19,920 And get another value F. 422 00:33:20,440 --> 00:33:23,320 So the server exchanges F with the client. 423 00:33:23,440 --> 00:33:25,740 The client exchanges E with the server. 424 00:33:26,440 --> 00:33:32,520 So all the security of this relies on the fact that it's too computationally expensive, 425 00:33:32,740 --> 00:33:34,040 or it's computationally infeasible, 426 00:33:34,040 --> 00:33:38,540 to brute force the discrete logarithm and solve for X and Y. 427 00:33:39,640 --> 00:33:46,340 Now, K, the shared secret K, is defined as a function of F, X, and P, and E, Y, and P. 428 00:33:47,560 --> 00:33:51,260 So in that sense, both parties can calculate their shared secret K, 429 00:33:51,420 --> 00:33:54,800 but no eavesdropper, unless you knew the X and Y value, 430 00:33:54,980 --> 00:33:56,520 they could never figure out what K is. 431 00:33:57,200 --> 00:34:00,140 The weakness here is that the X and Y random numbers, 432 00:34:00,260 --> 00:34:03,500 if you're using this bad Debian OpenSSL, they're not random. 433 00:34:03,500 --> 00:34:07,120 There's about 32,768 possibilities that you're going to get, 434 00:34:07,220 --> 00:34:08,600 and it's all dependent on the process ID. 435 00:34:09,320 --> 00:34:13,740 So I want to emphasize, this is not about SSH host keys. 436 00:34:13,920 --> 00:34:15,620 It's not about SSH identity keys. 437 00:34:16,060 --> 00:34:19,780 This is all about the Diffie-Hellman key exchange where they generate their shared secret, 438 00:34:19,980 --> 00:34:23,620 which builds all the values, initialization vectors, 439 00:34:23,820 --> 00:34:25,820 for the triple DES or AES encryption that follows. 440 00:34:26,340 --> 00:34:31,200 So down below, this is how they do it for a triple DES encryption on an SSH session. 441 00:34:31,900 --> 00:34:32,760 You got K. 442 00:34:32,920 --> 00:34:33,480 Both parties get K. 443 00:34:33,500 --> 00:34:34,680 No one else does. 444 00:34:35,060 --> 00:34:37,120 You take a hash, and typically it's SHA-1, 445 00:34:37,720 --> 00:34:42,040 and you concatenate V sub C, which is the initial version string the client sends, 446 00:34:42,260 --> 00:34:44,660 V sub S, which is the initial version string the server sends, 447 00:34:45,420 --> 00:34:48,440 I sub C, I sub S, which is their hello strings, 448 00:34:49,620 --> 00:34:53,700 K sub S, which is the public key signature of the server, 449 00:34:54,180 --> 00:34:56,300 E, F, and the shared secret K. 450 00:34:56,680 --> 00:34:59,020 Concatenate all that together, take a SHA-1 hash of it. 451 00:34:59,120 --> 00:35:00,020 That gives you hash H. 452 00:35:01,460 --> 00:35:03,320 H is the initial session ID. 453 00:35:03,320 --> 00:35:07,200 Or, excuse me, H is the session ID for the duration. 454 00:35:08,340 --> 00:35:10,080 If you have H and you have K, 455 00:35:11,020 --> 00:35:14,100 you can calculate the initialization vector from client to server. 456 00:35:14,440 --> 00:35:18,860 You can calculate the initialization vector for triple DES from server to client. 457 00:35:19,340 --> 00:35:21,240 And also, you can calculate the keys. 458 00:35:21,440 --> 00:35:22,420 These are the triple DES keys. 459 00:35:23,860 --> 00:35:26,520 And actually, those are literal A, B, C, and D. 460 00:35:26,640 --> 00:35:29,100 If you read the RFC, that's how they define those functions. 461 00:35:30,800 --> 00:35:34,540 Given K and everything else is in clear text over the wire, 462 00:35:34,860 --> 00:35:37,740 I can calculate the IVs, the keys, the hashes, 463 00:35:37,840 --> 00:35:40,100 everything I need to decrypt this SSH session. 464 00:35:41,800 --> 00:35:43,460 So, when does this occur? 465 00:35:43,620 --> 00:35:44,560 When do you have a problem here? 466 00:35:45,040 --> 00:35:48,700 Well, if you have an OpenSSH client or server that is linked 467 00:35:48,700 --> 00:35:52,800 or have been statically compiled against the vulnerable Debian OpenSSL. 468 00:35:52,980 --> 00:35:56,080 I believe OpenSSH actually calls the randbytes function 469 00:35:56,080 --> 00:35:57,680 that was found to be the problem. 470 00:35:59,100 --> 00:36:01,560 The X or Y values that are generated by the server and client 471 00:36:01,560 --> 00:36:05,080 are completely predictable based on the PID of the OpenSSH process. 472 00:36:05,700 --> 00:36:06,340 This is bad. 473 00:36:06,880 --> 00:36:10,920 I can quickly brute force through actually 32,000 possibilities 474 00:36:11,500 --> 00:36:13,400 if I needed to search the entire key space 475 00:36:14,020 --> 00:36:15,360 and solve that discrete log, 476 00:36:15,600 --> 00:36:17,280 and then I have the shared secret K. 477 00:36:18,440 --> 00:36:20,640 With X or Y, like I said, you've got the shared secret K. 478 00:36:20,840 --> 00:36:21,820 All bets are off. 479 00:36:22,040 --> 00:36:23,780 I can do your triple DES decryption. 480 00:36:24,000 --> 00:36:26,820 I can look inside that supposedly secure SSH session. 481 00:36:28,340 --> 00:36:30,960 So, some interesting implications here. 482 00:36:31,280 --> 00:36:32,640 Tunneled clear text passwords. 483 00:36:34,500 --> 00:36:37,000 Remember how people say tunneled clear text passwords are bad? 484 00:36:37,420 --> 00:36:38,860 Well, this shows why they're bad. 485 00:36:39,420 --> 00:36:41,160 If I can break the triple DES encryption, 486 00:36:41,540 --> 00:36:43,140 I've got your username and password in the clear. 487 00:36:43,440 --> 00:36:46,280 If you're using RSA or DSA public key auth, 488 00:36:46,460 --> 00:36:48,320 I can't do that, right? 489 00:36:48,400 --> 00:36:50,560 Even if I crack the DiffHelm and key exchange, 490 00:36:50,820 --> 00:36:52,140 I still can't break your authentication 491 00:36:52,660 --> 00:36:54,420 when you're using the public key stuff. 492 00:36:55,180 --> 00:36:56,600 But, yeah, I can harvest, 493 00:36:56,820 --> 00:36:58,680 clear text passwords all day long 494 00:36:58,680 --> 00:37:01,160 if you're using this bad Debian open SSL. 495 00:37:02,740 --> 00:37:05,560 You can grab files or any other data in the session 496 00:37:05,560 --> 00:37:07,320 that's being transferred, 497 00:37:08,500 --> 00:37:11,280 and observers can relatively easily tell 498 00:37:11,800 --> 00:37:14,200 if one or both of the servers is vulnerable 499 00:37:14,200 --> 00:37:16,100 and then proceed to decrypt the stream. 500 00:37:17,240 --> 00:37:21,080 So let's do a little live demo here of this stuff. 501 00:37:44,920 --> 00:37:45,480 . 502 00:37:46,480 --> 00:37:48,500 So right at start, I took... 503 00:37:49,400 --> 00:37:51,980 Let's look at the Hello World PCAP example 504 00:37:51,980 --> 00:37:53,100 in Wireshark here. 505 00:37:53,860 --> 00:37:56,220 So this is a basic, 506 00:37:57,180 --> 00:37:59,840 SSH session that the client is using 507 00:37:59,840 --> 00:38:02,180 the bad open SSL random number generator. 508 00:38:05,040 --> 00:38:06,880 You can see the key exchange... 509 00:38:06,880 --> 00:38:08,640 Let me scroll this over here. 510 00:38:09,660 --> 00:38:11,200 You can see the key exchange init, 511 00:38:11,860 --> 00:38:13,560 where it's in the packet capture, 512 00:38:13,680 --> 00:38:15,400 it's saying all the algorithms and such it uses. 513 00:38:15,800 --> 00:38:16,840 Server key exchange init. 514 00:38:17,020 --> 00:38:19,240 We have to grab these strings in clear text with a wire 515 00:38:19,240 --> 00:38:20,580 because they go into those hash functions. 516 00:38:21,420 --> 00:38:22,420 Here's the gex init. 517 00:38:23,880 --> 00:38:24,540 Here's the... 518 00:38:25,680 --> 00:38:26,840 key exchange reply. 519 00:38:27,260 --> 00:38:29,040 And these two messages are key here, 520 00:38:29,160 --> 00:38:30,760 the init and the reply. 521 00:38:31,100 --> 00:38:34,020 The init, the client sending its E value to the server, 522 00:38:34,120 --> 00:38:36,160 and the reply, the server sending its F value 523 00:38:36,160 --> 00:38:36,920 back to the client. 524 00:38:37,220 --> 00:38:38,760 Then you see this new keys message. 525 00:38:39,300 --> 00:38:40,640 They send the new keys message, 526 00:38:40,720 --> 00:38:42,100 and that means everything afterwards 527 00:38:42,100 --> 00:38:42,940 goes into encryption. 528 00:38:43,460 --> 00:38:45,680 And you see this stuff is all encrypted afterwards. 529 00:38:48,060 --> 00:38:51,000 So let's run an extended version 530 00:38:51,000 --> 00:38:52,920 of Alexander Klink's... 531 00:38:54,380 --> 00:38:57,320 Check that weak SSH keys script. 532 00:39:02,620 --> 00:39:04,500 So initialization is a little bit slow. 533 00:39:04,640 --> 00:39:08,620 It's got to load 32,768 multiple precision integers 534 00:39:08,620 --> 00:39:11,240 into memory, which it's doing right now. 535 00:39:12,180 --> 00:39:13,460 And it's not really... 536 00:39:13,460 --> 00:39:15,580 Private key is probably a misnomer, 537 00:39:15,700 --> 00:39:17,520 but these are the random values 538 00:39:17,520 --> 00:39:21,080 that would be generated by the OpenSSL PRNG 539 00:39:21,080 --> 00:39:22,700 when OpenSSH is calling it. 540 00:39:23,240 --> 00:39:24,900 So it's loading up all these things. 541 00:39:25,040 --> 00:39:26,580 There's a local file that's got all these 542 00:39:27,080 --> 00:39:28,940 hex value multiple precision ints, 543 00:39:29,580 --> 00:39:31,120 and it's reading from that local file. 544 00:39:33,860 --> 00:39:35,420 And by the way, it's not cracking now. 545 00:39:35,500 --> 00:39:36,400 It's simply loading the keys. 546 00:39:36,600 --> 00:39:38,540 Okay. Now it's cracking. 547 00:39:38,760 --> 00:39:40,260 Now it's brute forcing. Done. 548 00:39:41,220 --> 00:39:41,800 All right? 549 00:39:42,240 --> 00:39:44,820 It just told me that the client is vulnerable, 550 00:39:45,260 --> 00:39:46,340 the server is not. 551 00:39:46,860 --> 00:39:49,300 If you go back through my verbose output... 552 00:39:51,600 --> 00:39:52,340 I got... 553 00:39:52,920 --> 00:39:53,240 G. 554 00:39:54,520 --> 00:39:55,600 The generator G. 555 00:39:56,720 --> 00:39:58,740 I've got the prime number. 556 00:39:59,440 --> 00:40:00,640 Those are all in clear text. 557 00:40:00,780 --> 00:40:01,700 Nothing special about that. 558 00:40:02,100 --> 00:40:03,680 I got G to the X and G to the Y. 559 00:40:05,060 --> 00:40:05,920 And, uh... 560 00:40:07,400 --> 00:40:08,800 This should read G to the Y, 561 00:40:08,920 --> 00:40:10,900 but it's one function that just prints it out. 562 00:40:13,680 --> 00:40:14,880 And the cool stuff here 563 00:40:15,320 --> 00:40:16,540 is that K. 564 00:40:17,100 --> 00:40:18,620 I brute force the discrete log. 565 00:40:18,740 --> 00:40:20,400 I calculated the shared secret K. 566 00:40:21,080 --> 00:40:22,660 With K, I calculated the hash, 567 00:40:22,920 --> 00:40:24,120 which is the initial session ID. 568 00:40:24,620 --> 00:40:26,560 K sub S is the public key 569 00:40:26,560 --> 00:40:28,160 fingerprint of the server. 570 00:40:28,720 --> 00:40:30,580 IVC is the initialization vector 571 00:40:30,580 --> 00:40:31,820 from client to server. 572 00:40:31,960 --> 00:40:34,240 IVS, initialization vector the other way. 573 00:40:34,580 --> 00:40:36,580 And then E, C, and ES are actually 574 00:40:36,580 --> 00:40:38,160 the triple desk encryption keys 575 00:40:38,160 --> 00:40:39,380 for that session. 576 00:40:41,640 --> 00:40:42,620 So let's do this 577 00:40:42,620 --> 00:40:43,360 and snort now. 578 00:40:59,200 --> 00:40:59,600 ... 579 00:41:17,160 --> 00:41:18,880 I'm just gonna load that Hello World 580 00:41:18,880 --> 00:41:20,440 PCAP file we just processed through there. 581 00:41:21,100 --> 00:41:22,760 Before we hit that off, let's start 582 00:41:22,920 --> 00:41:24,900 tailing the snort log here. 583 00:41:31,000 --> 00:41:32,460 Alright. No alerts in there. 584 00:41:33,960 --> 00:41:35,060 Let's load up snort. 585 00:41:35,340 --> 00:41:36,920 You see SSHKEXDH. 586 00:41:38,340 --> 00:41:39,340 We'll come back to that 587 00:41:39,340 --> 00:41:39,920 in the log. 588 00:41:43,080 --> 00:41:44,960 So it's now about to load 589 00:41:44,960 --> 00:41:47,140 the PCAP file and start processing 590 00:41:47,140 --> 00:41:48,700 the PCAP file through the preprocessor. 591 00:41:49,280 --> 00:41:50,280 And boom, it's done. 592 00:41:51,140 --> 00:41:52,360 You go up. Okay. 593 00:41:54,600 --> 00:41:55,560 Generated one alert. 594 00:41:56,280 --> 00:41:57,160 Generated one alert. 595 00:41:57,220 --> 00:41:57,800 Log one packet. 596 00:42:02,880 --> 00:42:04,980 And here you can see the SSH 597 00:42:04,980 --> 00:42:05,240 ... 598 00:42:07,720 --> 00:42:08,560 key exchange 599 00:42:08,560 --> 00:42:10,660 DiffHellman group key exchange config. 600 00:42:10,840 --> 00:42:12,620 That's just the configuration stuff. 601 00:42:12,940 --> 00:42:14,500 And it points it to a local file 602 00:42:14,500 --> 00:42:15,880 that has all those random numbers in it. 603 00:42:16,380 --> 00:42:18,080 Let's go flip back over to our alert 604 00:42:18,680 --> 00:42:19,780 file. Boom. 605 00:42:20,280 --> 00:42:22,180 My preprocessor just generated an alert. 606 00:42:22,920 --> 00:42:24,660 It brute forced the DiffHellman key exchange 607 00:42:24,660 --> 00:42:26,260 and it just told you that that client 608 00:42:26,680 --> 00:42:29,000 is vulnerable. That client is using 609 00:42:29,000 --> 00:42:30,400 a bad Debian OpenSSL. 610 00:42:31,420 --> 00:42:32,020 Alright. 611 00:42:34,160 --> 00:42:34,760 ... 612 00:42:34,760 --> 00:42:35,380 ... 613 00:42:39,660 --> 00:42:40,260 ... 614 00:42:41,040 --> 00:42:41,640 ... 615 00:42:49,880 --> 00:43:11,200 ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 616 00:43:11,200 --> 00:43:15,780 seeing what's going on with that. It looks to be a major, major enhancement 617 00:43:15,780 --> 00:43:19,120 to Snort. It's all basically got Lua scripting language, 618 00:43:19,380 --> 00:43:23,960 hardware optimized packet acquisition that can be put in hardware. 619 00:43:24,480 --> 00:43:28,820 And the Snort 2.8 plugin content matching engine is simply a plugin into V3. 620 00:43:29,620 --> 00:43:33,560 2.8.3, I think, is a release candidate now. It's no longer a beta. 621 00:43:34,120 --> 00:43:38,440 Some cool stuff was added to HTTP Inspect. They're breaking up parts of the request 622 00:43:38,440 --> 00:43:42,500 and the response into new buffers that you can match on, very web 2.0 of them. 623 00:43:45,540 --> 00:43:49,380 So to wrap it all up, I chose Snort because it's such a powerful framework. 624 00:43:49,620 --> 00:43:52,300 It gives me stream reassembly. It puts the packets back in order. 625 00:43:52,520 --> 00:43:55,680 It gives me a stream API where I can do stream local storage. 626 00:43:56,320 --> 00:44:01,340 It gives me a high efficiency logging and alerting output plugins. 627 00:44:01,800 --> 00:44:06,240 So why reinvent the wheel? I just write some Snort plugins and let the 628 00:44:06,240 --> 00:44:08,160 big brains at SourceFire handle the rest. 629 00:44:09,520 --> 00:44:14,240 So hopefully, with this talk, you can take away enough to start writing your own plugins 630 00:44:14,660 --> 00:44:16,480 if you've got a little bit of background in the C language. 631 00:44:17,520 --> 00:44:21,440 Look at the source code for existing plugins. Ask questions on the developers list. 632 00:44:21,760 --> 00:44:23,240 Ask me questions. Email me. 633 00:44:24,380 --> 00:44:27,940 And Snort V2, I'm not sure how much more it's evolving. 634 00:44:28,140 --> 00:44:31,500 I'm not sure where the resources are going in the V3 or V2. 635 00:44:31,720 --> 00:44:37,040 But I'm still seeing release after release. They're adding new things into the APIs. 636 00:44:37,040 --> 00:44:40,840 So if it doesn't support something you're trying to do, ask. 637 00:44:41,620 --> 00:44:42,780 They might do it for you. 638 00:44:43,820 --> 00:44:48,920 So to wrap up, I want to thank Dark Tangent, all the folks that made DEF CON happen again 639 00:44:48,920 --> 00:44:52,840 this year, and the goons. And also, I want to give a shout out to 640 00:44:52,840 --> 00:44:57,480 my local Atlanta DEF CON group, DC404. We've got a lot of speakers out here this 641 00:44:57,480 --> 00:45:01,580 year, Dr. Chaos, Carrick, Dave Maynor, Scott Moulton, Adam Bregner. 642 00:45:02,820 --> 00:45:06,160 And our own goon decode is somewhere around here. 643 00:45:06,640 --> 00:45:09,120 So if you have any questions, you can email me. 644 00:45:09,220 --> 00:45:13,420 I'm going to be heading over to the Q&A room in a few minutes after this wraps up. 645 00:45:13,860 --> 00:45:19,520 And this code is available on the SecureWorks website, secureworks.com slash research slash 646 00:45:19,520 --> 00:45:21,520 tools. There should be a link towards the bottom 647 00:45:21,520 --> 00:45:24,220 of the page. And we appreciate any feedback. 648 00:45:24,460 --> 00:45:25,060 Thank you.