How is everyone doing? I'm genuinely surprised. So either y'all went to bed early or you never went to bed. So thank you so much for being here. This talk is Maldaptive. Diving really, really deep into LDAP obfuscation, de-obfuscation and detection. My name is Daniel Bohannon. Everyone I know calls me Debo for short, so feel free to call me that. I'm a principal threat researcher for a startup company called Permiso Security doing cloud and identity stuff. For the last better part of a decade, I've been really focused on end point security, doing some IR and threat research at Mandiant, Microsoft. And I have a little bit of a problem with obfuscation. It's kind of an obsession of mine of taking things that look normal and making them look just absolutely crazy. And then as a defender, looking for ways to detect those things. Another thing I'm really passionate about is coffee and books and all the great conversations that happen around both of those things. Hello, everyone. So I'm Sabayita. You can call me Sabi for short. I'm originally from Albania. I recently moved to Germany, Berlin, working for Solaris as a senior cyber security engineer. I'm passionate about cyber defense. Currently I'm also working on the field, doing a little incident response, detection engineering and time and time allows threat hunting. I do have also some experience in consulting and government. Love mountains. You can see even a goat there. And enjoy moving a lot at the Great Espresso. All right. So to kick things off, we're going to do a little historical lesson on Active Directory and LDAP. And then we're going to break down kind of the components of LDAP so we know which pieces we're talking about when we get into the main piece of the talk, which is diving crazy deep into all the obfuscation. And then at the end, we'll talk more about our solution. You know, we don't like to just create problems. We want to actually have some real solutions there so that defenders can walk away equipped with something really beneficial. And then we'll do a demo and a tool release at the end. So let's get going. We are going to go back in time to the days of disco balls and DeLoreans, talking about the 1980s. The Directory Access Protocol, or the DAP, was a directory service kind of at that time. LDAP is the lightweight version. That's the L in LDAP. Between 93 and 97, you have three different versions of LDAP come onto the scene. In 1998, the Open LDAP Project released Open LDAP. And then what's important for this presentation is in the year 2000, Microsoft released Active Directory, in which they kind of ensured compliance with LDAP. So it's important to remember there's a server and client side component here. So Active Directory, we chose that because it's the most popular, most widely used application service, or directory service application in use. And so we wanted to make sure all the rules of obfuscation that we were discovering and building would work against an Active Directory server. So that's the server side component. You have clients that will issue LDAP queries, or LDAP, what are called search filters. And LDAP is literally the protocol that allows that exchange of information between the client side and the server side. On the offensive side, LDAP, or AD in general, is quite a popular topic. And you look at open source tooling in the last decade, you have things like PowerView from the folks at SpectreOps, BloodHound, SharpHound, SoapHound, any kind of hound, right? Looking for really quick ways to get information from an offensive perspective, but also for defensive perspectives. With BloodHound and PingCastle, looking for ways to give defenders quick visibility into attack paths so that they can make better choices and increase the complexity for an attacker just to come in and get a really short path to DA or whatever else they want. So as defenders, we should then ask, okay, if attackers are using this, what are our data sources for defending? And so this is actually kind of a point of frustration for us. When we started this research, even until today, there's not that many options for production-ready telemetry gathering for LDAP search filters. What we use in our lab environment was Silk ETW by Ruben Boonen. And actually one of the modules that were released with Mount Adaptive is a telemetry module to allow you to install these things, configure them, so you can have locally that client-side visibility. And then on the server side, there are options like kind of like debug mode options, but those are not generally recommended to turn on in production. So if you want this visibility in production, the best case right now is get Microsoft Windows Defender. CrowdStrike has some stuff I've heard as well, but in terms of like, if you want to just trust the detections they have, cool. If you want to have all the data so you can validate, then maybe explore your options a little bit. So another thing to keep in mind is there are big differences between client-side and server-side logs when it comes to LDAP. For all the hackers in the room, you're going to love client-side logs because it's basically like WYSIWYG. Like any obfuscation we're going to talk about, you put that in, that's exactly what it looks like in those client-side logs. Awesome for obfuscation evasion. With an important caveat, it depends how you're issuing that query. So a lot of the mechanisms, like the ADDZ accelerator in PowerShell will use the WLDAP32.DLL to route that request. If that's the case, then the data will show up in an ETW stream for the LDAP provider and you can scoop it out. However, some folks have noticed there are many other ways to talk to an Active Directory server. So SOAP Hound is an example from Falcon Force where they said, hey, let's just make SOAP requests directly to the domain controller and avoid any kind of client-side logging. So because of this, it's still a valuable data source, but it's important to look at the server-side logs as well. There is significant normalization that occurs in server-side logs. So a lot of the obfuscation we'll talk about is normalized, but there are still some interesting tricks that do persist. And yeah, that's all I'll say about that right now. So over the next 40-ish minutes, we're going to be doing an absolute speed run through all of the obfuscations that we've enumerated and built out for this research. This is something we've spent over 2,000 hours of R&D on. For the record, that's too much R&D. I don't recommend it to anybody. But here we are, so we're really happy to get this out there and then let our minds think about something else. And as I mentioned earlier, we're going to be doing a demo and tool release for MAL Adaptive. And the name comes from MAL Adaptive because typically people would think of LDAP queries as like a pretty simple, rigid kind of a language. So how flexible can it really be? And we hope to convince you pretty quickly that it can be pretty flexible. So with that, let's look at the LDAP overview so we know which pieces of an LDAP search request we're talking about for each obfuscation technique. So we're going to... let's dive deep into the anatomy of an LDAP search request. We'll be looking at RFC 4511. There are many components to an LDAP search request, but we are going to be focused on the four main ones, which is the base object, where in the active directory structure to start the search, the scope that says how far to let the search run, the filter, which is the logic of what to look for in the directory structure, and the attribute selection, which are the properties that we want to bring back. As defenders, most people focus on the filter for detecting malicious LDAP queries. So for this reason, it's also going to be our primary obfuscation focus. We don't want to overlook also the base object and attribute selection. So they are going to be our secondary and tertiary obfuscation focus. As filter is the main one, let's see what makes up a filter. So well, it's made up of tokens. There are five required tokens that we have group start and group end, the hold in the middle, the attribute and the value for it, and the comparison operator. So here, for example, we are looking, I'm looking for myself, basically. There are also two optional tokens, which is boolean operator and extensible match filter. Debo is going to talk about these in the upcoming slides. But just so you know, these are bitwise values. They have different meanings based on the attributes, and Microsoft documents all of these per attribute. So different numbers mean actually different things to different attributes. In this one, basically, we're looking for objects that are not disabled, let's say. Most people actually do not write simple filters like this. They do try to combine multiple filters, and they do that with a boolean operator to create a filter list. So it's not going to look actually as a pretty tree just like this one, but it's a single row, usually. So it's going to be composed of two filters, which together they make up a filter list, and the whole string is actually called a search filter for an LDAP search request. Uh-oh. Sorry. No, we don't don't need help with PowerPoint transitions. Moving on. Hold on. It looks like you could use some help with crowd work. Hilarious. Oh, Clippy. I have trivia and jokes. I don't know. I could use that on a Sunday morning. How about y'all? What do you call the biggest LDAP search request in history? Any takers? It's pronounced ten and a half megabytes. Because that's the limit for a search request. Now, Clippy actually comes armed with sources. But just know that that's a lot of data. And keep in mind, LDAP is not just for querying information. It's also for updating records. But for the purpose of recon, I encourage anybody in this room to issue something even close to ten and a half megs and see how much shows up in your logs. All right. Thanks, Sabi. So now that we had a good idea of the different components of LDAP that we're going to be looking at, let's actually do the fun stuff of obfuscation. For all the defenders in the room, it's going to get dark and bleak before it gets bright again. But we promise there is a light at the end of the tunnel. So as Sabi mentioned, the filter is going to be the primary obfuscation focus because it really is kind of the primary defensive detection focus today. And we're going to spend most of our time on the filter. And then a lot of the techniques that work on the filter will then be applied to the base object and attribute selection as well. There's a lot of things that we discovered that are not documented. Some of it was sheer luck. Some of it was brute forcing. Some of it was the fact that when you build an obfuscation framework, you're kind of defining the boundaries of a language and it's going to break out sometimes and teach you things that still work. And so we'll try to mention things that are undocumented and then also put this undocumented icon at the top. So we're going to start by looking at these five tokens and looking at obfuscation that can be applied to each, beginning with the attribute token. So let's see how what we can do to obfuscate the attribute. We can actually do casing. It is case sensitive, so we can play with it. We can use object, OID object identifier. OID object identifier, Microsoft defines it as a dotted string of numbers, which is actually quite true because you can also add this OID prefix at the beginning of it and it's still going to work, which is also case sensitive. Another thing that is really fascinating and undocumented is that we can add prefixes of zeros to each octet on this part and it executes just fine. It will also show just like this also on client side logs. Another thing we can do for attribute obfuscation is ambiguous name resolution. So the same applies as above. So we can use insensitive casing and OID notation even for the ANR. But what is exactly ANR? So in case you know some name, but you don't know in which property it actually is, you can search and what it would actually do depending on the version of active directory, it will logically transform this single term into this query. So basically everything is ended in a wildcard, except for some attributes that do not support this. And in case your search actually contains a space just like us, we're looking for domain admins, then it's going to be added another this one. So these four ones because it will treat it as a first name, last name, last name, first name. Some nice obfuscation tricks. So we can use ANR, for example, if we're trying to search for curb TGT. And we can also use which is the second example, only the some parts of it. And it's going to be an explicit wildcard. So we'll still even on the second example, we're still going to have the same results. And the third example, which is very nice, we actually discovered that if you add an implicit wildcard, after that, everything you add is going to be ignored. So you can play with it, but you're still going to be to get the result of ANR. And return the curb TGT. And just as this also going to be handled from our detection framework. If you don't want to do all the crazy stuff with a wildcard, and just be explicit, you can actually just add an equal sign, which is document the which is the documented way to get the information. As a recap for attribute obfuscation, we can do casing, object identify notation, and ambiguous name resolution. Ah, Clippy again. Do you know where else ambiguous name resolution exists? We don't know Clippy. Where? Microsoft, what is more ambiguous than resolving to rename your products every six months? Am I right? I did not know Clippy was allowed to make Microsoft burns. I don't know if that was cleared. Thanks, Clippy. So one token down. We've talked about attributes. Next, we're gonna look at the comparison operator. Most of the time, this is an equals sign. When it comes to Active Directory's implementation of LDAP, you also have the approximately equal to because casing doesn't matter. But it does prevent you from using the wildcard and hex characters that we'll be talking a lot more about later. But we're really going to focus on the range operator. So greater than equal to less than equal to. So here's an example a lot of red teamers would be familiar with service principal name equal star means give us the objects that have an SPN, any value, I don't care, but it must be defined. Well, technically, we could rewrite this with a string operator and say, hey, make sure it's present, it has a value that is greater than or equal to the alphabetical sorting of a string that begins with equals, or the exclamation point, or is less than ZZZ. So there are other ways logically that you can accomplish this equivalence, this presence filter. One really important note, if you think about the printable range of ASCII characters, this is the proper ordering that we all know and love and have agreed upon as a standard as an industry. We do not know why, but there is an abnormal range or sorting for strings in Active Directory casing doesn't matter. So we get rid of those. But you have all of the digits and alpha characters at the end, you have this very specific grouping of special characters, and then all the other characters fall right into the middle. This took us probably five days to find because it only occurred this bug only occurred like one out of 1000 iterations. But this is the ordering. So our obfuscation framework handles that, but just know it's kind of weird. Another thing we can do is use the range filters for precise values. So SAM account type equals this number ending with 368. This is another bitwise value. But let's say that detections were looking at this. Well, you could also instead of saying ends with 368, say greater than equals to 7, less than equal to 9, and then specifically exclude the 7 and 9. So logically, you're left with an 8. If you're like me and are more visual person, I like to think of it as a timeline. And so greater than equal to 7, less than equal to 9, and then let's just pop off the 7 and 9. So you're left with the 8. There are a lot of kind of flavors or recipes we built into the obfuscation module, showing a couple of them here. One of my favorites is actually using ranges for exclusions. In this last example, where you can say give me the presence filter, but then exclude everything outward and inclusive of the numbers 7 and 9. So you're left with 8. So again, those are all random options in the obfuscation filter, the obfuscation module. This works for numbers. It also works for strings with a caveat that suffixes are a little tricky. But yeah, it is still quite effective for those things. So in review for the second token type of comparison operator, we have approximately equal to, we have the logical equivalence for the presence filter, and then we can use the range operators to do some really fun stuff for precise values, whether they're strings or numbers. And defenders should be pretty familiar with some of these we just looked at because it's actually part of the Sharp Hound project. So that same account type, service principal name. So again, these are pretty relevant examples, and you can see that if a detection was looking for this, it would probably get smoked by what we just showed you. So the third token type is the Boolean operator. Mostly we think of ands and ors, but when it comes to LDAP, the not is where things get really crazy really fast. So let's take a really practical example. Let's say you're looking for country equals Albania. You want to have all those objects that come out of Active Directory. One thing you can do is just throw a bunch of Boolean operators inside of it, and logically it doesn't matter if you and and or one thing, it's still going to be that same one thing. Additionally, you can also put in double negation. Again, logically this is still going to give you country equals Albania, the same number of objects. Additionally, if you wanted to do a Boolean operator, you can technically slide it right inside of the filter itself. So in this case, if we're looking for location equals Kukic, which is a city inside of Albania, you can see that bottom example, that Boolean is sitting directly inside of the group start, group end filters or tokens. In our parser that we wrote for this research, we handle this similarly, but do call out the distinction because it is extremely important for certain kinds of detections, as well as obfuscation and deobfuscation scenarios. Most of the time, though, you're dealing with a slightly more complex filter like this. So this is saying, I want to know when the country is Albania, and either the location is Kukic or Tirana, two cities. It's important to know that the Boolean operator has kind of a scope of influence. So in this case, there are two Booleans, and you can see the boxes around the filters that they affect. If we added in a third set, there are now three groups. And so as we're parsing it, we basically create a stack of Boolean operators to know exactly how many Booleans are affecting the filter that we're looking at. One really, really fun feature is the not Boolean operator. So let's slide that in there. The not only affects the first filter or the first Boolean operator that it modifies. So we can see location equals Kukic is modified by that not, but the filter just below it is completely, it doesn't modify it at all. So this is another one that we have to track, as well as a lot of crazy things like negation, traversal, because you can have lots of layers in between, and you have to track the Booles all the way. Lots of fun. Honestly, a lot of headaches. But yeah, it's built into the parser, so we don't have to think about that anymore. And we'll see that in the demos towards the end. My personal favorite obfuscation technique with Boolean operators is logical inversion. So for any math nerds in the house, this is known as DeMorgan's law, but basically not A or B is the same as not A and not B with the inverse sitting below. So what you can do is take any LDAP search filter, choose a spot and negate it. In this case, we're going to choose the whole filter. And now everything else kind of to the right of that is going to be in scope for obfuscation. So step number two is identifying within that in scope section, all the ands and ors and inverting them. And then the third step is locating all the filters and inverting them from a negation perspective. So none of these filters are negated. So we're going to add that not and those are now negated. Now, this is logically the same as what we started with. Again, this is a lot of headaches if you're parsing this manually. And so in the parser, we basically have a concept of what's the logical inclusion? Is this included, true or false? What's the logical Boolean? Is it and or? And we also maintain a stack of all those Boolean operator tokens for your convenience. So interview for the third token type of Boolean operator, we have the additive nature, double negation, and then DeMorgan's laws for the Boolean operator inversion. Oh, goodness. Okay. What is my least favorite LDAP token type? I'm assuming Boolean operator, but let's see what happens here. Yep, Boolean operator, because I'm afraid of getting tied up in knots. Oh, that's cringe, Clippy. Clippy's losing steam fast. Yeah, get that out of the way. Okay. All right, the fourth token type extensible match filter. So Sabi mentioned this before. This is for attributes that have bitwise values. It's an integer number, but it actually represents a base two add-ins for all the bitwise flags based on which attribute that it is. So it is, there are four values that are supported by the by active directories LDAP implementation, we're going to focus on the first two, because they're the most interesting in terms of obfuscation. And that's the and and the or. For me, I remember the or because it ends with dot 804. So 804 is or 803 is not or. All right, so here's an example. User account control, and you can see in the red is the extensible match filter. In this case, it's an 803, so that's an and, and it's the number 515, which is the base two add-ins 1, 2, and 512. So one of the things we can do is what we've called bitwise breakout. So we can break that 515 out into 1 and 514. Again, as long as we have the proper grouping of add-ins, we can do this. 514 is actually 2 and 512. So we can break that out even further. So from a detection perspective, we can spread our logic across many different filters, which is really, really complicated. But it's also fun. If you started with an or, the same trick applies. Just make sure that the Boolean operator you add is an or instead of an and and that it matches the extensible match filter. This is a pretty trivial example, but a lot of real world examples can get pretty crazy. Like this is a git domain user from PowerView. Massive number. You can imagine all the random groupings and regroupings of base two add-ins to produce the same value in your overall search filter. So another thing we can do is if you have a filter that is a precise value. So this is looking for the exact ones and zero set to equal this number. What you can do is use this little formula. You can add the extensible match filter of and for all the one bits. You can add the or extensible match filter for all the zero bits and negate it and then and both of those filters together. What's really cool about this is now we have extensible match filters and we can use the first breakout type to break those into smaller and smaller random groupings of those base two add-ins. So we're not going to take this further, but this could explode into 10, 15, 20 different filters all slammed together. So interview for the fourth token type of extensible match filter, we have the bitwise breakout with and and or and then also the precise breakout, which kind of combines the second one with the first one. Thanks, Thibaut. Let's look at what we can do to obfuscate a little the value. We are still in the filter section. So excluding a couple of attribute types, just like seeing here, it is still casing doesn't matter. So it's case sensitive. And we can also do prepended zeros to anything that are bitwise digits or numbers. And we got some undocumented feature regarding timestamps is that we originally noticed that sometimes milliseconds were present, but it didn't actually seem to matter. If you change the millisecond values or remove them, it turns out you can add actually add literally anything as long as you have a capital Z in it. So and technically, it is going to be treated still as a correct timestamp in the results. And it doesn't need to be only capital Z, it can also be it's hex encoding representation, which leads us to the next point, which is hex encoding for value obfuscation. And it's our favorite thing to do to be honest, the hex encoding itself, it exists to be able to to escape certain special characters, which Microsoft has detailed here very well. But you can also escape any printable characters that you want to as well. So you can swap these with the hex representations, and it's still going to be to give you the same results. And it's going to show just like this on the client side logs. Again, our parser, our parser parses codes decodes all the values. So it's all being handled. One undocumented thing is that Microsoft says that the hex representation should be followed by two characters representative SK hex character. But that's actually not true for the first 16 characters, you can drop the leading zero and it's still going to work. Wildcards, we mentioned a little bit even on the wildcards. So for example, instead of looking for the curb TGT, you can also just look for RBG and see what you get. These actually for wildcards, we are not the only ones who have been looking for evasion purposes. So even the researcher Hope Walker, these are two very well great posts blog posts recent, it's a researcher at specter ops, and she outlines using wildcards for evasion purposes. As a recap, for value, we can do casing, we can do prepended zeros, timestamps, hex encoding, and wildcards. The good news is that's all you can do with obfuscation. Nah, I'm lying, you guys, we got much more. So until now, we actually were looking for top and obfuscation. Let's see outside of it a little. And for example, for filter wide obfuscation, you can actually add group start and group end, as long as as much as you want, as long as you stay until the depth of 99. You can also add white space all over, and it is significant. And it can be new line, tab, etc. Garbage filters, again, need here actually you need to be careful if you're looking for if you're actually using logical or or logical end, because in case you're looking for logical end, you need to make sure the properties exist. But you can go crazy with ours. And lastly, is filter filter reordering. So until now, we only handled the filter. Let's see what we can do with base object. As a reminder, the base object is where in the active directory. So structure, we want to see we want to start the search, there are some good detection opportunities that we feel aren't discussed as much. And for example, like some offensive tools, just like certify, they have a very benign common and super search, super common search filter. So in this case is the base object, and it's looking for public key services, we are going to focus from a syntax perspective on a simple, really simple object like this. All the tricks we've seen until now, okay, for example, they still work, which is the casing, we can play, you can do also the hex encoding for the value portion, you can use the ID notation of the attributes, and also supports the ID prefix as well as your prefix. And white space, it actually can be added at the end, as well as between the slashes of the LDAP prefix. Something interesting is that it's true for the base object, but not for the value in the filter is that as long as hex is not present, you can actually encapsulate it with double quotes, and it will show up this way in client side logs, but it's not going to look like this on server side logs. Lastly, is the attribute selection. Basically, it's which attributes properties do you want to be returned in the results. And here also, casing doesn't matter, you can substitute just like previously, you can also use object identifier notation, also supports adding OID prefix and prepended zeros, add white space only after the attributes that are on the OID syntax. Not sure why, but yeah, a lot of trial and error, to be honest. We have the option also to add duplicate attributes, and garbage attributes, literally anything you want. And the person who's going to answer about this is no one else than Clippy. Hey, Daniel, what do you call this character? Asterix, wildcard or splat? I think this is an ages question. But all three are true. But there's a lot of space down there. So let's see what Clippy has to say. F, all the above. So two more important things here is from an input perspective and the attribute selection. If the only value defined is a wildcard, it will return all the properties, even just the same as if you don't define any attribute selection. What's fascinating is that in the server side logs, that wildcard is going to literally be printed as the string square brackets, all A-L-L, all lowercase. Now, if you'll notice, E is that if you have a list of attributes, and any one of those is a wildcard, then it will, the server side logs will translate that wildcard into this other string all with list. If you are, and you should be, if you are parsing these attribute selection values, you need to know that this weird string is prepended to the first attribute. So you have to do a really specific split and translation that we that we do in the logging module. But just know there's some weirdness that goes on there. Thanks, Clippy. All right, now that is actually the end of the obfuscation portion. So we've talked about the search filter, we've talked about the base object, the attribute selection. So for all the defenders in the room, what now? So from a solution perspective, we're going to focus on three steps. One is parsing, two is enriching, and then three is the actual detection itself. So from a parsing perspective, when we started this research, there was no parser for LDAP search filters. And so we naively said, let's just build a parser. How hard could it be? To be honest, that was over half of the research, but it was one of the most interesting and fulfilling parts of this. And so we wrote a C sharp state machine parser to firstly do tokenization. So that means when you have a string come in, that's the entire search filter, let's break it into tokens. So we know which ones are attributes, values, comparison operator, etc. Next, you want to organize those tokens into a representation that allows you to understand the structure of nested Boolean operators and filters and filter lists and all those sorts of things. And then you can move on to actual enrichment, which is step number two. So here's an example of using all the conversion modules within Mount Adaptive to start with a string, break it into tokens, and then every step of the way, we try to decode and enrich however much we can. So as Sabi mentioned, when there are hex values, we'll automatically decode them for you. But we leave the original syntax as well. One distinction between... so in our parsing, we do tokenization, and then we basically create a parse tree or a syntax tree, which is almost an abstract syntax tree, but we drop the abstract part because abstract says, let's drop things that don't need to be there, like insignificant white space. Well, by definition, obfuscation doesn't need to be there. So we actually want to keep all those insignificant things so we can recreate the input from that parse tree. And then after we break this into tokens and do those enrichments, we'll then group them into filters and branches and a tree structure to do certain kinds of obfuscation and detections that require that kind of tree grouping functionality as we go through and parse it. And then the final step is actually detect. So we try to make it as simple as possible. We wrapped all this inside of a single function called find evil. So you can pipe any number of search filters you want into find evil. And for each of those filters, it will parse it, do all the enrichment we just talked about. It will run it through all our complete detection rule set, which we are releasing with maladaptive. So 65 rules and counting. And then for each of those detections, the rule carries with it a dynamic score or weight, if you will, as well as an explanation. So it'll give you an example of what kind of thing it's looking for. And then it will actually show you the specific part of your search filter that flagged on that rule, as well as in the name, you can see. It'll actually pull out specific values. So it should be really colorfully obvious, as you'll see in the demo, of exactly why this thing was flagged for this rule. And if you look at the bottom, as I said, we spent over half the time just building this parser. We wrote and rewrote every piece of this parser two to three times to make it as fast as we possibly could. And in this example, we're parsing this search filter 100,000 times, doing full parsing, full detections, and it's clocking in at just under 4.4 seconds. And that's on a moderately spec laptop. Because we know that the number, the volume of search filters in production environments is massive. And so we wanted this to be really usable right out of the box. Oh, and shout out to Olaf Hartung at Falconforce. He was really instrumental in taking all these rules for us and running them multiple times across his entire client data set, since we don't have that data set, and then giving us feedback and stats on, hey, which rules need to be tuned a little bit. So, Olaf, if you're watching, thanks so much, buddy. We really appreciate it. So instead of talking more about the solution, let's go into the last section and actually just show a demo. If you haven't picked up on it by now, we really like to have fun. When you spend 2,000 hours on something, you have to trick yourself into being motivated, so we added colors however we can. This is our ASCII art, and it's actually a fully functioning LDAP query that will return any object that has a name property. Clippy seems to like it as well. I can't tell if he's hanging out or trying to eat the terminal or what's going on. So in the first example, this is that Albania, Cucos, Tirana filter example with a little bit of obfuscation. So if we tokenize it, we can see it breaks out which things are attributes, values, et cetera. If we do the enriched tokens, we can now see it says, hey, this is a defined attribute, and it translates to the letter L. And we have these other context objects as well. So if we look at the context object, remember this is things like the Boolean operator. We group all these things into filters so that we can write detection logic against the entire filter. So we can easily access the string values, but then we have a dictionary and list of the full token objects. So all the metadata nested from tokenization we can find in the filter. And then if we look at the context object for the Boolean operator, we'll see this is a logically inclusive filter. This is tracking that full stack of Boolean operators that you still have direct access to. And then every single value goes through the full value parsing. So any hex characters are parsed. At any time, you can look for the raw content or the decoded content. Pipe that into Find Evil, and we can see these are the individual rules that matched for this particular search filter. This is just showing a couple properties. In the next demos, you'll see a little better view of the entirety of the rules. Let's do another parsing example, this time using the bitwise value. So remember all the bitwise breakout where like 515 can be 1, 2, 5, 12? Well, here's a rule that flag and says, hey, if user account control attribute has the flag 128 set to true, then flag this alert. I won't go into the details of why that's an interesting detection, but what we want to show you is when we parse this value, we automatically know this is a bitwise attribute, and we parse the value to get those base two add-ins, either in a dictionary format or a list format. So you can immediately write detections for combinations of true and false. Now keep in mind, this is per filter, so that breakout stuff does complicate it a bit, but you can at least extract the flags and aggregate it back together for your final detections across the entirety of the search filter. The last parsing example is looking for some actually kind of crazy stuff. So decoding hex characters in this first example, that's easy sauce. So this is trusted domain, easy detection. But when it's things like wildcards, they're actually missing characters, so we can't precisely say what the person was looking for. But in our detection module, you have the ability to define strings of interest, like curbtgt, domain admins, domain controllers, and the parser and the detection rules will go through and actually expand the wildcards and say, hey, does this wildcarded string match any of your sensitive terms? And that also handles the two ANR scenarios that Sabi mentioned earlier, with the implicit wildcard or the explicit wildcard. So yeah, those are some really fun detections that go beyond just pure deobfuscation, but really kind of logically looking at some suspicious strings of interest. And finally, we've put all this together into a colorful interactive menu to make it fun to explore. We can test our input, the LDAP search filter, and we can explore the obfuscation menus for all the techniques we covered in this presentations. Wildcards are also supported. We can add obfuscation layer by layer, and we can also remove it. And if you're lazy, you can use all wildcards to randomly apply all the options. Let's test again. The search filter still works. Detection module is built in and findevils shows a full summary of detections, scores, explanations, and more colors. Lastly, if you don't like interactive menus, we have full CLI support. So the interactive menu lets you randomly choose ingredients, and you can copy out the receipt for non interactive user. All the pictures for pretty printing and detection summaries are also available via CLI. Thank you. It's always awkward in blue teamer talks. Was that a shell? Do we clap or not? Our apologies for not including a dramatic pause. Hopefully that was fun for everyone. We're almost done here. We just want to reiterate that Sabi and I are both defenders, and from the very beginning of this research, we knew that we had not seen people talking about this, and to be honest, attackers didn't really need this help. So why hand them a fully loaded machine gun when defenders still often don't even have the telemetry in the first place? So from the very beginning, we weren't strong armed. We decided that we wanted to release this in a unique kind of two-stage approach. So today what we've released is everything we've talked about, minus the obfuscation module. We're releasing a corpus of 1,337 benign obfuscated examples, so you only have to run our code to look at examples of obfuscated search filters. For anyone who's really ambitious, you have the full parser, and the deobfuscation modules look suspiciously like the obfuscation ones. So if you want to do a little bit, go for it. But just keep in mind, we spent over 1,000 hours on the obfuscation module, so there is a heck of a lot of craziness that we put in there. Our goal, pending a CFP response, is hopefully by the end of this year, to do a part two of this presentation to focus really deeply on all the differences in client and server-side logging, a lot of the weird scenarios we had to build into the parser to support all of this, and then at that point, releasing the obfuscation module. So yeah, just want to make that really clear. That's clear on the GitHub, which will be on the last slide as well. But again, as defenders, we wanted to try to be as creative as possible and help defenders not be completely throwing tomatoes at us up on the stage. And we made this very clear in the CFP process. Big red text, no surprises. So we're really happy that there was support in us doing that kind of a release. So the final takeaways, LDAP is still widely used by attackers. It's very valuable. And in our opinion, defensively, it's still kind of immature in terms of detection. It seems to be a lot of kind of string-based detections. And even looking at blog posts of people doing LDAP hunting, there just aren't as many of them as I would like to see, that we would like to see. And then lastly, we released maladaptive to help try to bring awareness to what can happen, to show that we shouldn't just be doing string-based detections, and we're providing the parser in all of our detection modules so that hopefully you can, right out of the gate, start using it in your environment if you already have a mechanism to get all of those search filters. Our unofficial takeaway is we wanted to leave you with something a little different. And so we wanted to leave you with our, each of our favorite Albanian proverb. So I'm going to go first. I'm not a native speaker, so forgive my pronunciation. But mine is rofsah malet, which literally means live long like a mountain. It's kind of a blessing of well-being. I like to think of it in this scenario as we just climbed a crazy mountain together. I'm a little out of breath, personally. But in this industry, we have to help each other out. We have to recognize the shoulders that we stand on. And so when you see someone else struggling up the mountain, trying to understand what you're learning, help them up, get them to the top, and then they'll be able to see the next mountain they're going to climb and the person they're going to bring along with them. And my favorite expression, and I think the audience would agree with me here, Debo, is tlutom jomokapsa letras, which it means, please no more paperclips. It was fun while it lasted. All right. And with that, we just want to say thank you so much for your time. Thank you, DEF CON and to all the organizers. We had such a great time putting this research together, and we're really happy to be here. Here's all of our contact information. Here's the link to Mount Adaptive. Please reach out, and we'll be up here for questions. But thank you again for your time. Any brave souls for questions? Questions or criticisms, everything is welcome. One right here, yeah. So the question is, what was our process for finding all the undocumented stuff? Well, sometimes luck, sometimes... I think the best answer that we can give is, people ask us, why do you make obfuscation frameworks? It's kind of a little twisted, but it's really a way of kind of working backwards and defining a grammar. Because it's all a language, right? What's linguistically, syntactically allowed in a language? Whether that's PowerShell or LDAP or anything else. So our understanding is, let's say, actually, when Sabi wrote the hex encoding function, to take values and do hex encoding, we wrote that function, we plugged it into our test harness, and one out of every 500 examples would fail. It wouldn't return the same results we expected. And we eventually realized that's because hex values, or hex characters in the value, is not allowed when the extensible match filter is defined, right? So that is now an incompatibility that no one said anywhere, but our tool helped us find because it found an example that broke what we'd expected to see. So that's how we found a lot of these examples. And then just some tricks you kind of learn along the way, like, hey, pre-pinning zeros, that seems like something that someone might have thought to ignore, because it's insignificant, but it still shows up in logs, therefore, it's meaningful to us. And so some of those tricks, you just kind of pick up along the way and keep carrying forward. But yeah, great question. Thank you. Yeah. Yeah, good question. So the question was, in our research, against the obfuscation techniques we found, how effective is Windows Defender or other tools like that? We don't have access to those tools. So actually don't know. In general, I'd say, you know, I've spent the last decade doing real-time detections, actually spending some time at Microsoft in Defender telemetry, looking at how we detect processes and stuff like that on the endpoint. So what I would say that a lot of red teamers criticize blue teamers for is why do you make static kind of rigid detections? Sometimes it's out of ignorance, sometimes more likely it's out of performance. So I mean, there are millions and millions and millions of search filters flying around doing crazy regexes to try to find it to try to find these bizarre scenarios probably is going to bring down performance overall. So from a product's perspective, that's I think why a lot of decisions are made, but we don't have any direct insight into Defender or anyone else on how they're stacking up against this. If anyone from Microsoft or anyone else wants to reach out, we'd be more than happy to share more of the research in detail and help if there's anything that we can do to protect the community in that regard. Great question. Thank you. Any last questions? Yes. The question was, did we have trouble with all the colors for formatting? Trouble to who? The answer is yes. Yeah. So in terms of we actually did, we split our programming actually partially. We use PowerShell core. So we did a lot of it in Windows, a lot of it on Mac, a little bit in Linux just to test compatibility. But yeah, in terms of color differences, we actually stuck with the original colors, the original 16. We experimented with the dark colors for things like distinguished name values. Those are the darkened version of all the RDNs to represent the overall tokens. But that darkness shows up better on Windows. On Mac, it actually doesn't quite show up as much. But yeah, so that was a factor we had to kind of play around with. But yeah, I like the color question. I've never gotten that before. So thank you. All right. I think with this, we're at time. We'll be around front if anyone else wants to talk or ask questions. But again, thank you everyone for coming to the talk. Have a good one. . .