Hi, I'm Ben Feinstein. I'm with the SecureWorks Counter Threat Unit. I'm going to be giving you a talk today about Snort plugin development. And just to start off a little basics. So what am I going to talk about today? I'm going to go over the v2 Snort architecture at a higher level and cover some of the internals. And I'm going to go over the process of Snort plugin development and cover two areas of that. And one area is dynamic rules. The other area is dynamic preprocessors. I'm going to go over some of the relevant Snort APIs, give you some code examples, point out a few areas that can be confusing and that can hold you up in development, give you a few tips on how to succeed. And I'm also going to be discussing two new plugins or two new dynamic preprocessors that are GPLed. They're available on the SecureWorks website. There'll be a URL later in the present presentation. The first preprocessor deals with ActiveX controls, essentially a virtual kill bit. And the other preprocessor deals with SSH Diffie-Hellman Key Exchange that is affected by the Debian OpenSSL random number generator bug. So some basics. I don't need to review for some of the guys in the front row here from SourceFire, but Snort is an open source IDS and IPS that was originally created by Marty Kuhn. He released it back in 1998 and it was commercialized later by SourceFire Inc. There's an inline mode that's available. The inline mode is essentially IPS. Typically it's going to use a Linux bridge plus net filter. And you have IPQ and NFQ interfaces to queue the packets in and out of kernel space and user space through Snort and let Snort make verdicts on how to take action on those packets and streams. Some of you that follow Snort are aware that V3 is now making its way through beta. This is a long time in coming and we're real excited to see that code base getting released. I am not going to be discussing V3 today. I'm not going to be talking about the V3 architecture. Marty will do much more justice to that and you can catch a talk from Marty at some other conferences and he will talk all about the V3 architecture. It's some really cool stuff they've done there. It's quite modularized. It's built to be extended. You have the Snort rules and the rules matching engine. So the SF engine is a dynamic plug-in. So actually the core rule matching engine is pluggable. You also have dynamic detection plug-ins that can implement or extend the rules language. So you can add new keywords and new constructs to the syntax of the rules language by building shared objects and dynamic plug-ins that will add to the detection capabilities of Snort. They also have output plug-ins. So output plug-in example is the Unified or the Unified 2 outputs. That's a highly efficient binary alert and log stream. You have your classic syslog output. And there's some other output plug-ins as well that are less commonly used. And you've got your classic two types of preprocessors here. You've got detection preprocessors. What those essentially do is they look at traffic and they will generate alerts. And in an in-line scenario, they will generate alerts. In an in-line scenario, they may drop traffic or send resets. Then you have normalization preprocessors. What these are there for is to decode and normalize traffic before it's presented to other plug-ins and to other end of the Snort rules matching language or engine rather. So for instance, HTTP inspect is a preprocessor that does some normalization of HTTP requests. And then other rules and preprocessors can then inspect the decoded traffic there. So can you continue on with talking about the architecture? A dynamic preprocessor is basically a shared object. You can define a packet processing callback, a C function, that Snort is going to queue or send packets through. You have the ability to do preprocessor local storage. And you also have the ability, using the stream API, to do stream local storage. You define callbacks to deallocate your stream local storage when Snort decides to free that session object. It'll call your cleanup method, and you can gracefully free your memory that you've allocated. Now dynamic rules are relatively new in the Snort code base. You could think of a dynamic rule as essentially writing a Snort rule in C. I may be wrong, but I think around 2.8.01, there was an ability to register a C callback added to the dynamic rules APIs. So before that C callback was added, there was defined. It seemed to me like the only reason to do dynamic rules was to obfuscate what your rule's doing, to kind of hide maybe the exploit or the vulnerability that could be determined from the rule. 2.6.1.5 was the version I'm hearing from SourceFire. So basically some commercial Snort rule sets out there use these dynamic rules for some of their rules. However, it's relatively straightforward to a reverse engineer these files in something like IDA Pro. So it does raise the bar in terms of obfuscating the content of your rules, but it's not going to prevent a more skilled adversary from figuring out what's in there. So a few other internals to cover is the alerting versus logging. It's pretty simple. Logs are going to contain the packet capture data in addition to the alert summary. Alerts are just simply the summaries. Unified2 is an interesting addition in that it's an extensible output format, or it's designed to be extensible. My understanding of it is that you can encode additional data, for instance, from your preprocessor using length value encodings into that Unified2 stream. So it's great if your preprocessor wants to log some additional data. You ought to use Unified2. Some examples, I believe the SourceFire codebase is moving to try to use this Unified2 to gather the preprocessor statistics and performance statistics, and also things like port scan alerts. So what do you need to get started developing Snort plugins? Or to step back a moment, why do you want to develop Snort plugins? Well, Snort is quite mature. It's a common part of IT security environments all over the world. So instead of chasing around the new hotness of the day, the new security technology, sometimes it makes sense to extend the capabilities of your existing control. So you've already got widely deployed. So Snort is going to give you some great features. It's going to reassemble the streams for you. It's going to put stuff back in order. It gives you a nice, mature alerting and logging framework. So it's really a nice environment to start developing this kind of technology instead of just creating a whole new separate program or module to do all these things. So one great resource is the Snort developers mailing list. The SourceFire developers are great. They're on there. All the time. They're typically very responsive. And just my advice would be, you know, do your homework before you mail the list. You're going to get a much better experience. And you're going to save everybody time and aggravation. So there is some issues with documentation around building dynamic preprocessors. There's some example code in the Snort code base. There's a few older materials online from around the 2.6 time frame. But the APIs have changed some. Some things have changed. So the documentation is a little bit out of date. And I'm hoping that from this talk and from the source code that we're publishing, other plug-in developers can kind of get a better sense of how to build these things. So like I said, there's some basic examples in there in the Snort code base of the dynamic rules and the dynamic preprocessors. So how are you going to get started developing? Use the source. It's there. Start looking at existing plug-ins. How are they working? How are they working? How are they doing their work? How do they do what they do? The DNS plug-in is a good start. It's relatively small. The HTTP inspect plug-in is much more full-featured. There's a lot more code in it. And there's some other interesting plug-ins that you can look at how they're doing things and kind of figure out how you should use the APIs. I personally approach development by writing small blocks of code and unit testing them and doing incremental development like that. So I think that's a great way to approach it. And also, when you're working on a project, when you get stuck, if you're really stuck and you can't get past it, go to the Snort developers list, post the problem you're having, and typically someone out there will have encountered this problem and have an answer for you. So my Snort development environment basically is the Snort 2.8.x source tarball, whatever the latest stable release is, running CentOS 5 box with GCC 4.1 and glibc 2.5. Now, CentOS, or Red Hat Enterprise 5, is a little bit different. It's a little bit more complex, but you can see that we have packages, slightly older versions of Autocomp and Automake. So to get your environment working and in sync with the SourceFire development environment, you're going to have to build Autocomp 2.6.1 and Automake 1.10 from scratch, put that in your path, and use those tools, unless you want to screw around with Automate and Autocomp yourself and deal with that mess. So to jump into the dynamic rules, these are probably the simplest ways you can extend Snort using the C language. key header file that you ought to look at. It's the SFSnortPluginAPI header. What it does is it defines C structure equivalents to all the rule syntax structures. We're talking flow, content, PCRE, those kind of structures. Basically, in C code, I can create a struct that defines the same properties as I would in the rules language. Inside your dynamic rule file or C file that can contain multiple rules, you have this array of pointers to rules called rules. The framework pretty much handles the rest. You point Snort to the dynamic rule shared object you've built, and you have dummy rules that have to be present. It will load them into the engine. The Snort makefile pretty much takes care of most of it for you. It creates the shared objects using lib tool, and they'll be dynamically loaded at Snort in runtime. How do you get Snort to load your runtime? There's a few command line and configuration options you should be aware of. In the Snort config command line, you've got dynamic detection live and dynamic detection live dir. The first one of these is you just point it to your shared object file. It's going to load it up. The second, you're going to give it a directory to any number of shared objects that are dynamic rules, and it will load those up. Snort has this new command line option called dump dynamic rules. All these dynamic rules require stubbed or dummy rules to be in the rules files, meta rules. This will actually dump all that information out for you in a nice format. You can throw it into a rules file. Below I've got an example of just real basic hello world rule. It's using this new keyword called metadata, colon, engine shared. You link it up with your SID, which in this case is 2,000,001, and you've got a generator ID of three. Three is the generator ID that's assigned to dynamic rules. So that's just very basic stubbed out meta rule that you'd see spit out by Snort. As I said, you've got different C structs for all the rules options. A rule option is simply a union of all the different types of structures there. A rule structure itself is simply a null terminated array of rule options. You also have a rule pointer to a rule header struct. You have rule header to the header structure. There is a type of header have some rule references, which would be, like, pointers to a CVE, pointers to some web reference, for instance. The API also exposes functions to match on these different rule constructs for content, flow, flow bits, and such. So you can actually create a rule option for a content match, call the content match function in the API, and get back rule match or rule no match. It also offers some basic functions to register and to dump the dummy rules out. So what I got up here is just a very simple content info structure. This comes from the example dynamic rules that's in the snort source tarball. All this is is looking for the content of net bus. You tell it what buffers to look in. Typically, you're going to use the normalized buffers, but you could use raw buffers. And these two null objects and the zero counters down there, when you register the rule with snort, it goes and creates the boy or more structures, sets those pointers, and, of course, it fast pattern matcher and you basically will initialize that structure for you. You need to do that before you can call the content match with this structure. And then here you just wrap that. If you want to create a rule option, you simply wrap the content info and this option type content macro. macro. There you go. You can pass that rule option in and have that null terminated array of rule options in your rule structure. Then below is just the API call you're going to make to attempt a content match using a pointer to your content structure. That void pointer, that's just a casted to void star. It's a SF snort packet, which is the standard structure that you're going to get passed in your callback function. PCRE matching, same thing here. You give it some PCRE flags. You give it what buffers you want to match against, and then you wrap it in a pound to find option type PCRE object. There's your PCRE match function. You've initialized your PCRE structure. You have a packet pointer. You can go call that. It's going to return rule match or rule no match, and you would know whether your PCRE is matching in that content or not. Same thing with flow. Establish. Establish to client to server. Wrap it in an object. You've got a function call to check if the flow is matched. Here's how you create this rule structure for a dynamic rule file. You have two other C files that are going to find this rule struct. You have a null terminated array of pointers to rules, and then basically the engine itself is going to call register rules on that array, which will then internally fix up the Ahoro Corsic, the pointers, all that stuff. Add it to the engine. On to the C processing callback that we mentioned. This is really the most powerful part of dynamic rules. You're going to be able to just define a C function and say to the engine that when you've matched all these elements of my rule, also I want you to call this C function, pass the packet to it, and the C function will return a rule match or rule no match. You can do this to create much more sophisticated matching algorithms than you could ever do in a rule. Here's just a very simple MyDynamicRule.c. Include a couple header files. Define my callback function. In my rule structure, I have a pointer to it, and the snort engine is going to take care of the rest. Here's a little code snippet from an example rule detection function. Now, I failed to say at the beginning of this talk, I've got two of these lovely DC404 T-shirts available here. I'm going to give one of these T-shirts to whoever can answer this question on here, and one of the T-shirts to the best question at the end of the presentation. I don't know if I'll let the Source Fire guys answer this question, but what does this little C snippet do? This callback. You get a packet structure, I cast it to a sf snort packet, and I have this if statement. I'm going to match on the if. Who out there for a lovely DC404 T-shirt, t-shirt can tell me what this does. This is going to match if the IP ID is odd. I'm simply taking it mod two. Very simple stuff. But this is an example of something you couldn't do in the Snort Rules language. There's no operator to say take IP ID and take it modular something and compare it. But you can define a four- or five-line C function that will do the exact same thing. So maybe the two best questions will get t-shirts. Another key header file you want to look at is the dynamicpreprocessor.h. The key structure to be aware of is this dynamic preprocessor data. Almost everything you're doing with the APIs is going to be off of pointers to this DPD object. It's typically named underscore DPD. You've got callbacks for initialization. You've got callbacks for initialization. Exit, restart of your preprocessor. You've got callbacks to, or you've got function pointers to internal logging functions. You've got ability to interact with the stream APIs, the search APIs. You have alerting functions. And also you have the ability to do Snort inline functions like packet drop. And all this is available through that dynamic preprocessor data structure that is available to your preprocessor. And right here, here's a little code snippet from my ActiveX preprocessor. All you do is you define the setup function. And I'm registering a preprocessor called ActiveX. I'm giving it a pointer to, I'm pointing it to my initialization function. Initialization function takes the command line arguments for your preprocessor named ActiveX. It's going to call the add preproc function on the dynamic preprocessor data structure. And it's going to basically say what priority do I want. You have transport, application, and a few others. And also pp ActiveX is going to be a unique number that I've defined in another header file. That uniquely applies. It identifies the ID of that preprocessor. And then you've got process ActiveX, which is where the real work of the module happens. It gets passed a pointer to sf snort packet. You get a context pointer. And then after you've done all your work, you see that alert add call. That's basically calling the snort alert mechanism to say, hey, my preprocessor wants to generate an alert. In another header file, I've defined a signature ID and a string that goes along with that signature. ActiveX event kilbit str. I basically call that alert add and it shoves it right into the snort alert queue. So when you're in the preprocessor you can also use some of the dynamic rules functionality. Using the rule match function, register1 rule is a curious callback. It was a little confusing for me. You register one rule, you give it a pointer to your rule. And then there's a, you know, you have to there's this flag called don't register rule. At first, I scratched my head and said, okay, register one rule, but don't register a rule. All the don't register rule does is it doesn't add it into the tree of nodes there. You still have to call this function to initialize all the pointers in your structures there. It sets up the ahocorsic and the internal pointers, but this was a confusing point to me. When you're using rule structures inside your preprocessor, you need to register them, but not register them. These plug-ins I'm talking about, you can download them from secureworks.com slash research slash tools. There's a link to the snort plug-ins there. I'm releasing them, released this Wednesday morning under the GPL. We can't support these. We can't give any warranty for these plug-ins. Use them at your own risk. Your mileage may vary, but we do appreciate feedback so we can help improve these things and bug reports. Also, if you want to extend these plug-ins, you have no obligation to, but we'd love to feed the code back to us upstream so we can get those fixes in there. The first plug-in that we're releasing is just a simple ActiveX detection dynamic preprocessor. What it does is it inspects web traffic for some JavaScript or scripting that's going to instantiate a vulnerable ActiveX control. When I say vulnerable, it's basically based on public vulnerability disclosures about ActiveX controls. In the preprocessor configuration, I point the preprocessor to a local database file of ActiveX controls listed by class ID and optionally method and property. The database is in XML format. I'm sorry, but it seemed easy at the time to parse. It basically just looks at the traffic, the responses coming off the web servers, looks for ActiveX instantiation, looks for the class ID and a PCRE. Basically, if you define methods and properties in the database, it'll also look for, is that scripting using those vulnerable methods or properties? It can be evaded, like most things in security. JavaScript is a great way to obfuscate attacks. I'm not going to un-XOR your JavaScript and determine that there's an ActiveX control in there. However, today, a lot of attackers that are attacking these ActiveX controls, they're just using plain class IDs. They're not really being that sophisticated. Also, you could probably evade this with some HTTP encodings, using gzip or deflate. In the future, I want to add some snort inline support to this so that when it detects the plugin getting instantiated, it could actually drop the packet or potentially send a reset back. Also I want to extend this some more to leverage all the work that HEP Inspect is doing there. And another idea is to leverage the unified2 output plugin to write out some more details about the ActiveX control that we've triggered on. I took a shortcut implementing this, and I used the match rule function. It was very convenient. It's probably not the most efficient way to do this, in terms of space and time, but it was most efficient for me to implement. The code right now is performing a naive linear search of class IDs. Basically, my point is, the plan is to take the high performance, I think it's tri-based data structures that HEP Inspect is using, and leverage those. It's using snorts flowmatch to make sure that it's a response coming back from the server, and it does some content matching and some PCRE matching behind the scenes to detect that. I'm going to give you a quick live demo here of the ActiveX detection preprocessor in action. I've got a shell here. I've got a VM running. It's ids.example.com. Right here, you can see I'm pointing snort at my shared object files. It's in my working directory where I've been building the code, building the source. DynamicPresetProcessorFile, point it to the ActiveX. Point it to the SSH plugin we'll see later. You see down below I'm including a little configuration for this ActiveX control. Here's basically the configuration for that ActiveX preprocessor. You just tell it what ports you want to look on. You point it to a local XML database file. On initialization, it reads in the file, allocates pattern matching structures, and starts looking at HTTP response. The response is coming back in. Let's start up snort. Up here, you can see where my ActiveX plugin is echoing back parts of its configuration on startup. It tells you what kill bits. This is pretty verbose right here, but it's telling you what kill bits it's looking for, what properties it's looking for, and what ports it's going to look at. Snort's running. It's got that ActiveX plugin loaded. I'm going to start up a real basic HTTP server here. I'm going to start up a real basic HTTP server here. All right. Here's a normal web server. It's doing nice, red, blinking text. Hello, DC-404. You can see back here we got a get request. We sent a 200 back. Then, if we go over here, we'll do the request again just to show that there's no alerts being generated. Snort's not generating alerts. Back here, we're tailing the snort alert file, and we're getting this nice, blinking text back. Let's stop this web server. Let's run the evil web server. Now, let's go make a request there. In the background, you'll see we're going to be tailing the log. You've been pwned. There's your alert. Bad ActiveX control detected. If we look at this source code on this page, you'll see we're instantiating an ActiveX object by class ID, and we're calling the IE start method, which is bad juju, and overflowing it with four Ks of As. That's what it alerted on. You see the alert in the background there. It worked. All right. The next plug-in is a little more interesting. Basically, I'm going to do a quick background on the Debian OpenSSL random number generator. Please go see Luciano Bello and Maximiliano Bertaccini's talk tomorrow afternoon. Luciano and his colleague discovered this vulnerability in the Debian OpenSSL random number generator. I personally think it's one of the coolest vulns of 08, and I believe the Pony Awards agreed. The effect is that keys generated that were using this bad code since around September 2006 can be predicted. There's no real entropy in this random number generator other than your process ID. That bad code eventually made its way from unstable Debian to testing Debian to stable Debian, and it made its way into Debian Etch. It also made its way into Ubuntu. That code never got caught until recently and leaked its way all into these other branches of Debian. These are a couple of humorous cartoons that HD Moore threw up on his site when this vuln came out. You've got your Dilbert talking about a random number generator here. You've got XKCD doing a similar kind of thing. Guaranteed. It's by random dice roll, right? It's four. I'm going to probably breeze through this so I don't steal the thunder from Luciano, but this is bad. The Debian vuln was bad. HD Moore jumped on this thing so quick. Within hours or a day or something, he had brute-forced the weak keys, generated them, posted them to his Metasploit page. He hit this really quick, and I was impressed. You've been mitigating this vulnerability, right? You scan your assets for bad SSH and SSL servers using the backlisted keys, right? Nessus can do this for you. You scammed all your home dirs for the bad keys, right? There's a new tool called SSH VulnKey that'll do this for you. You look through all your home dirs. You look through all your Windows protected storage, browser profiles for blacklisted SSL certs, right? What about connections to external servers you don't control or your organization does not control? That are still using an unpatched Debian open SSL, okay? It still is going to impact your security. Our preprocessor, it's basically a detection preprocessor at this point. What it does is it looks at the Diffie-Hellman key exchange between the two SSH peers, and it attempts to brute-force the random values that are generated if one or both of the parties was using this bad Debian open SSL random number generator. So it's got a detective capability right now. In the near future, I hope to release code that's going to take this to the next step and be a normalization preprocessor that's going to decode the whole stream. But it's not ready yet at this time. So this will be able to detect users connecting to external servers that are using the bad SSL and connections coming in from the outside that have a bad unpatched Debian SSL. So, like I said, the goal, in the near future, is to have this actually decode both sides of the session. Right now, I calculate the shared secret, the Diffie-Hellman shared secret. I squirrel away some other data about the session into the session object or session storage. And then I generate alerts saying the client's vulnerable, the server's vulnerable. The cool thing about normalizing it is then all the other snort preprocessors and rules could then inspect on the unencrypted content. And unencrypted sessions could be logged out to PCAP or Unified. Um... I'm not a lawyer. I don't know the crypto export laws. But this may be crypto-analytic software, which may have some more controls on it. So I've got to give props to the people that really came up with this stuff. I mentioned Bello and Bertaccini. And they're speaking tomorrow afternoon. This fellow, Alexander Klink, who's at Synops GmbH over in Germany, he had posted a proof-of-concept Perl script to Full Disclosure. And I have a link to the actual script right there. And basically it's a Perl proof-of-concept that's using GNU multiple precision libraries to attempt to brute force the Debian... Excuse me. Brute force the SSH DiffHelm and Key Exchange. So these other two gentlemen here... Luciano just pointed me to their work today. I haven't had a chance to review it. But they... I believe they're doing some work on Debian, SSLVone, and SSH. But potentially related to the host keys and identity keys. Not necessarily Diffie-Helm and Key Exchange. And Luciano and his colleague have posted some patches to Wireshark that's going to break the perfect forward secrecy of TLS and SSL. And there's a link to a post on the Wireshark Bugzilla. I think you can find their code up there. And they'll probably cover this in their talk tomorrow. So I'm going to give some background on how Diffie-Helm and Key Exchange really works. It's a really elegant algorithm. And it's a way for two parties to agree on a shared key. A shared secret without ever having to have pre-knowledge or do a pre-key exchange. So the server is going to generate two numbers. A generator G and P, which is the modulus. And that's wrong, actually. It's not 1024. It's just a really long prime number. The client is going to generate a random number. Let's say X. It's going to take that number, take G to the X power, modulo P. That gives them a number E. So it's a function of G, X, and P. The server, likewise, generates a random number Y. It'll take this random number Y, raise G to the Yth power, and take it modulo P. And get another value F. So the server exchanges F with the client. The client exchanges E with the server. So all the security of this relies on the fact that it's too computationally expensive, or it's computationally infeasible, to brute force the discrete logarithm and solve for X and Y. Now, K, the shared secret K, is defined as a function of F, X, and P, and E, Y, and P. So in that sense, both parties can calculate their shared secret K, but no eavesdropper, unless you knew the X and Y value, they could never figure out what K is. The weakness here is that the X and Y random numbers, if you're using this bad Debian OpenSSL, they're not random. There's about 32,768 possibilities that you're going to get, and it's all dependent on the process ID. So I want to emphasize, this is not about SSH host keys. It's not about SSH identity keys. This is all about the Diffie-Hellman key exchange where they generate their shared secret, which builds all the values, initialization vectors, for the triple DES or AES encryption that follows. So down below, this is how they do it for a triple DES encryption on an SSH session. You got K. Both parties get K. No one else does. You take a hash, and typically it's SHA-1, and you concatenate V sub C, which is the initial version string the client sends, V sub S, which is the initial version string the server sends, I sub C, I sub S, which is their hello strings, K sub S, which is the public key signature of the server, E, F, and the shared secret K. Concatenate all that together, take a SHA-1 hash of it. That gives you hash H. H is the initial session ID. Or, excuse me, H is the session ID for the duration. If you have H and you have K, you can calculate the initialization vector from client to server. You can calculate the initialization vector for triple DES from server to client. And also, you can calculate the keys. These are the triple DES keys. And actually, those are literal A, B, C, and D. If you read the RFC, that's how they define those functions. Given K and everything else is in clear text over the wire, I can calculate the IVs, the keys, the hashes, everything I need to decrypt this SSH session. So, when does this occur? When do you have a problem here? Well, if you have an OpenSSH client or server that is linked or have been statically compiled against the vulnerable Debian OpenSSL. I believe OpenSSH actually calls the randbytes function that was found to be the problem. The X or Y values that are generated by the server and client are completely predictable based on the PID of the OpenSSH process. This is bad. I can quickly brute force through actually 32,000 possibilities if I needed to search the entire key space and solve that discrete log, and then I have the shared secret K. With X or Y, like I said, you've got the shared secret K. All bets are off. I can do your triple DES decryption. I can look inside that supposedly secure SSH session. So, some interesting implications here. Tunneled clear text passwords. Remember how people say tunneled clear text passwords are bad? Well, this shows why they're bad. If I can break the triple DES encryption, I've got your username and password in the clear. If you're using RSA or DSA public key auth, I can't do that, right? Even if I crack the DiffHelm and key exchange, I still can't break your authentication when you're using the public key stuff. But, yeah, I can harvest, clear text passwords all day long if you're using this bad Debian open SSL. You can grab files or any other data in the session that's being transferred, and observers can relatively easily tell if one or both of the servers is vulnerable and then proceed to decrypt the stream. So let's do a little live demo here of this stuff. . So right at start, I took... Let's look at the Hello World PCAP example in Wireshark here. So this is a basic, SSH session that the client is using the bad open SSL random number generator. You can see the key exchange... Let me scroll this over here. You can see the key exchange init, where it's in the packet capture, it's saying all the algorithms and such it uses. Server key exchange init. We have to grab these strings in clear text with a wire because they go into those hash functions. Here's the gex init. Here's the... key exchange reply. And these two messages are key here, the init and the reply. The init, the client sending its E value to the server, and the reply, the server sending its F value back to the client. Then you see this new keys message. They send the new keys message, and that means everything afterwards goes into encryption. And you see this stuff is all encrypted afterwards. So let's run an extended version of Alexander Klink's... Check that weak SSH keys script. So initialization is a little bit slow. It's got to load 32,768 multiple precision integers into memory, which it's doing right now. And it's not really... Private key is probably a misnomer, but these are the random values that would be generated by the OpenSSL PRNG when OpenSSH is calling it. So it's loading up all these things. There's a local file that's got all these hex value multiple precision ints, and it's reading from that local file. And by the way, it's not cracking now. It's simply loading the keys. Okay. Now it's cracking. Now it's brute forcing. Done. All right? It just told me that the client is vulnerable, the server is not. If you go back through my verbose output... I got... G. The generator G. I've got the prime number. Those are all in clear text. Nothing special about that. I got G to the X and G to the Y. And, uh... This should read G to the Y, but it's one function that just prints it out. And the cool stuff here is that K. I brute force the discrete log. I calculated the shared secret K. With K, I calculated the hash, which is the initial session ID. K sub S is the public key fingerprint of the server. IVC is the initialization vector from client to server. IVS, initialization vector the other way. And then E, C, and ES are actually the triple desk encryption keys for that session. So let's do this and snort now. ... I'm just gonna load that Hello World PCAP file we just processed through there. Before we hit that off, let's start tailing the snort log here. Alright. No alerts in there. Let's load up snort. You see SSHKEXDH. We'll come back to that in the log. So it's now about to load the PCAP file and start processing the PCAP file through the preprocessor. And boom, it's done. You go up. Okay. Generated one alert. Generated one alert. Log one packet. And here you can see the SSH ... key exchange DiffHellman group key exchange config. That's just the configuration stuff. And it points it to a local file that has all those random numbers in it. Let's go flip back over to our alert file. Boom. My preprocessor just generated an alert. It brute forced the DiffHellman key exchange and it just told you that that client is vulnerable. That client is using a bad Debian OpenSSL. Alright. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... seeing what's going on with that. It looks to be a major, major enhancement to Snort. It's all basically got Lua scripting language, hardware optimized packet acquisition that can be put in hardware. And the Snort 2.8 plugin content matching engine is simply a plugin into V3. 2.8.3, I think, is a release candidate now. It's no longer a beta. Some cool stuff was added to HTTP Inspect. They're breaking up parts of the request and the response into new buffers that you can match on, very web 2.0 of them. So to wrap it all up, I chose Snort because it's such a powerful framework. It gives me stream reassembly. It puts the packets back in order. It gives me a stream API where I can do stream local storage. It gives me a high efficiency logging and alerting output plugins. So why reinvent the wheel? I just write some Snort plugins and let the big brains at SourceFire handle the rest. So hopefully, with this talk, you can take away enough to start writing your own plugins if you've got a little bit of background in the C language. Look at the source code for existing plugins. Ask questions on the developers list. Ask me questions. Email me. And Snort V2, I'm not sure how much more it's evolving. I'm not sure where the resources are going in the V3 or V2. But I'm still seeing release after release. They're adding new things into the APIs. So if it doesn't support something you're trying to do, ask. They might do it for you. So to wrap up, I want to thank Dark Tangent, all the folks that made DEF CON happen again this year, and the goons. And also, I want to give a shout out to my local Atlanta DEF CON group, DC404. We've got a lot of speakers out here this year, Dr. Chaos, Carrick, Dave Maynor, Scott Moulton, Adam Bregner. And our own goon decode is somewhere around here. So if you have any questions, you can email me. I'm going to be heading over to the Q&A room in a few minutes after this wraps up. And this code is available on the SecureWorks website, secureworks.com slash research slash tools. There should be a link towards the bottom of the page. And we appreciate any feedback. Thank you.