[00:05.500 --> 00:12.700] How is everyone doing? I'm genuinely surprised. So either [00:12.700 --> 00:15.120] y'all went to bed early or you never went to bed. So thank you [00:15.120 --> 00:18.540] so much for being here. This talk is Maldaptive. Diving [00:18.540 --> 00:22.680] really, really deep into LDAP obfuscation, de-obfuscation and [00:22.680 --> 00:26.580] detection. My name is Daniel Bohannon. Everyone I know calls [00:26.580 --> 00:29.620] me Debo for short, so feel free to call me that. I'm a principal [00:29.620 --> 00:32.480] threat researcher for a startup company called Permiso Security [00:32.480 --> 00:35.940] doing cloud and identity stuff. For the last better part of a [00:35.940 --> 00:39.320] decade, I've been really focused on end point security, doing [00:39.320 --> 00:42.620] some IR and threat research at Mandiant, Microsoft. And I have [00:42.620 --> 00:46.100] a little bit of a problem with obfuscation. It's kind of an [00:46.100 --> 00:48.640] obsession of mine of taking things that look normal and [00:48.640 --> 00:52.540] making them look just absolutely crazy. And then as a defender, [00:52.540 --> 00:55.460] looking for ways to detect those things. Another thing I'm really [00:55.460 --> 00:57.040] passionate about is coffee and books and all the great [00:57.040 --> 00:59.480] conversations that happen around both of those things. [01:00.780 --> 01:06.140] Hello, everyone. So I'm Sabayita. You can call me Sabi for [01:06.140 --> 01:10.320] short. I'm originally from Albania. I recently moved to [01:10.320 --> 01:14.380] Germany, Berlin, working for Solaris as a senior cyber [01:14.380 --> 01:18.580] security engineer. I'm passionate about cyber defense. [01:18.580 --> 01:23.200] Currently I'm also working on the field, doing a little [01:23.200 --> 01:26.340] incident response, detection engineering and time and time [01:26.340 --> 01:30.360] allows threat hunting. I do have also some experience in [01:30.360 --> 01:34.700] consulting and government. Love mountains. You can see even a [01:34.700 --> 01:41.140] goat there. And enjoy moving a lot at the Great Espresso. [01:41.140 --> 01:43.820] All right. So to kick things off, we're going to do a little [01:43.820 --> 01:46.520] historical lesson on Active Directory and LDAP. And then [01:46.520 --> 01:49.100] we're going to break down kind of the components of LDAP so we [01:49.100 --> 01:51.400] know which pieces we're talking about when we get into the main [01:51.400 --> 01:54.120] piece of the talk, which is diving crazy deep into all the [01:54.120 --> 01:56.780] obfuscation. And then at the end, we'll talk more about our [01:56.780 --> 01:59.540] solution. You know, we don't like to just create problems. We [01:59.540 --> 02:01.320] want to actually have some real solutions there so that [02:01.320 --> 02:03.940] defenders can walk away equipped with something really [02:03.940 --> 02:08.440] beneficial. And then we'll do a demo and a tool release at the [02:08.440 --> 02:12.880] end. So let's get going. We are going to go back in time to the [02:12.880 --> 02:15.300] days of disco balls and DeLoreans, talking about the [02:15.300 --> 02:20.120] 1980s. The Directory Access Protocol, or the DAP, was a [02:20.120 --> 02:22.800] directory service kind of at that time. LDAP is the [02:22.800 --> 02:27.300] lightweight version. That's the L in LDAP. Between 93 and 97, you [02:27.300 --> 02:30.200] have three different versions of LDAP come onto the scene. In [02:30.200 --> 02:34.260] 1998, the Open LDAP Project released Open LDAP. And then [02:34.260 --> 02:36.000] what's important for this presentation is in the year [02:36.000 --> 02:40.120] 2000, Microsoft released Active Directory, in which they kind of [02:40.120 --> 02:43.700] ensured compliance with LDAP. So it's important to remember [02:43.700 --> 02:47.240] there's a server and client side component here. So Active [02:47.240 --> 02:49.940] Directory, we chose that because it's the most popular, most [02:49.940 --> 02:53.480] widely used application service, or directory service [02:53.480 --> 02:56.220] application in use. And so we wanted to make sure all the [02:56.220 --> 02:59.020] rules of obfuscation that we were discovering and building [02:59.020 --> 03:03.020] would work against an Active Directory server. So that's the [03:03.020 --> 03:05.760] server side component. You have clients that will issue LDAP [03:05.760 --> 03:09.740] queries, or LDAP, what are called search filters. And LDAP [03:09.740 --> 03:11.840] is literally the protocol that allows that exchange of [03:11.840 --> 03:15.920] information between the client side and the server side. On the [03:15.920 --> 03:20.680] offensive side, LDAP, or AD in general, is quite a popular [03:20.680 --> 03:23.160] topic. And you look at open source tooling in the last [03:23.160 --> 03:25.980] decade, you have things like PowerView from the folks at [03:25.980 --> 03:29.160] SpectreOps, BloodHound, SharpHound, SoapHound, any kind [03:29.160 --> 03:31.600] of hound, right? Looking for really quick ways to get [03:31.600 --> 03:34.540] information from an offensive perspective, but also for [03:34.540 --> 03:37.560] defensive perspectives. With BloodHound and PingCastle, [03:37.560 --> 03:40.480] looking for ways to give defenders quick visibility into [03:40.480 --> 03:44.840] attack paths so that they can make better choices and [03:45.620 --> 03:50.440] increase the complexity for an attacker just to come in and get [03:50.520 --> 03:53.920] a really short path to DA or whatever else they want. So as [03:53.920 --> 03:56.360] defenders, we should then ask, okay, if attackers are using [03:56.360 --> 04:00.280] this, what are our data sources for defending? And so this is [04:00.280 --> 04:03.040] actually kind of a point of frustration for us. When we [04:03.040 --> 04:05.740] started this research, even until today, there's not that [04:05.740 --> 04:08.160] many options for production-ready telemetry [04:08.160 --> 04:11.660] gathering for LDAP search filters. What we use in our lab [04:11.660 --> 04:15.460] environment was Silk ETW by Ruben Boonen. And actually one [04:15.460 --> 04:18.440] of the modules that were released with Mount Adaptive is [04:18.560 --> 04:20.880] a telemetry module to allow you to install these things, [04:20.880 --> 04:23.040] configure them, so you can have locally that client-side [04:23.040 --> 04:25.920] visibility. And then on the server side, there are options [04:25.920 --> 04:28.380] like kind of like debug mode options, but those are not [04:28.380 --> 04:31.320] generally recommended to turn on in production. So if you want [04:31.320 --> 04:34.800] this visibility in production, the best case right now is get [04:34.800 --> 04:38.300] Microsoft Windows Defender. CrowdStrike has some stuff I've [04:38.300 --> 04:40.800] heard as well, but in terms of like, if you want to just trust [04:40.800 --> 04:44.040] the detections they have, cool. If you want to have all the data [04:44.040 --> 04:47.300] so you can validate, then maybe explore your options a little [04:47.300 --> 04:51.220] bit. So another thing to keep in mind is there are big [04:51.220 --> 04:53.800] differences between client-side and server-side logs when it [04:53.800 --> 04:57.500] comes to LDAP. For all the hackers in the room, you're [04:57.500 --> 04:59.980] going to love client-side logs because it's basically like [05:00.420 --> 05:03.800] WYSIWYG. Like any obfuscation we're going to talk about, you [05:03.800 --> 05:05.800] put that in, that's exactly what it looks like in those [05:05.800 --> 05:09.500] client-side logs. Awesome for obfuscation evasion. With an [05:09.500 --> 05:13.620] important caveat, it depends how you're issuing that query. So a [05:13.620 --> 05:18.460] lot of the mechanisms, like the ADDZ accelerator in PowerShell [05:18.460 --> 05:23.020] will use the WLDAP32.DLL to route that request. If that's [05:23.020 --> 05:26.500] the case, then the data will show up in an ETW stream for the [05:26.500 --> 05:31.060] LDAP provider and you can scoop it out. However, some folks have [05:31.060 --> 05:33.300] noticed there are many other ways to talk to an Active [05:33.300 --> 05:37.140] Directory server. So SOAP Hound is an example from Falcon Force [05:37.140 --> 05:39.480] where they said, hey, let's just make SOAP requests directly to [05:39.480 --> 05:42.420] the domain controller and avoid any kind of client-side logging. [05:42.680 --> 05:46.680] So because of this, it's still a valuable data source, but it's [05:46.680 --> 05:49.940] important to look at the server-side logs as well. There [05:49.940 --> 05:54.040] is significant normalization that occurs in server-side logs. [05:54.040 --> 05:57.260] So a lot of the obfuscation we'll talk about is normalized, [05:57.260 --> 05:59.100] but there are still some interesting tricks that do [05:59.100 --> 06:03.100] persist. And yeah, that's all I'll say about that right now. [06:03.920 --> 06:07.500] So over the next 40-ish minutes, we're going to be doing an [06:07.500 --> 06:10.880] absolute speed run through all of the obfuscations that we've [06:10.880 --> 06:15.280] enumerated and built out for this research. This is something [06:15.280 --> 06:19.480] we've spent over 2,000 hours of R&D on. For the record, that's [06:19.480 --> 06:22.840] too much R&D. I don't recommend it to anybody. But here we are, [06:22.840 --> 06:26.380] so we're really happy to get this out there and then let our [06:26.380 --> 06:29.440] minds think about something else. And as I mentioned earlier, [06:29.440 --> 06:31.340] we're going to be doing a demo and tool release for MAL [06:31.340 --> 06:34.260] Adaptive. And the name comes from MAL Adaptive because [06:34.260 --> 06:36.680] typically people would think of LDAP queries as like a pretty [06:36.680 --> 06:40.560] simple, rigid kind of a language. So how flexible can it really [06:40.560 --> 06:43.800] be? And we hope to convince you pretty quickly that it can be [06:43.800 --> 06:47.320] pretty flexible. So with that, let's look at the LDAP overview [06:47.320 --> 06:49.840] so we know which pieces of an LDAP search request we're [06:49.840 --> 06:52.460] talking about for each obfuscation technique. [06:54.320 --> 07:00.100] So we're going to... let's dive deep into the anatomy of an LDAP [07:00.100 --> 07:04.640] search request. We'll be looking at RFC 4511. There are many [07:04.640 --> 07:08.380] components to an LDAP search request, but we are going to be [07:08.380 --> 07:14.200] focused on the four main ones, which is the base object, where [07:14.200 --> 07:17.820] in the active directory structure to start the search, [07:17.820 --> 07:22.320] the scope that says how far to let the search run, the filter, [07:22.320 --> 07:25.580] which is the logic of what to look for in the directory [07:25.580 --> 07:29.020] structure, and the attribute selection, which are the [07:29.020 --> 07:34.260] properties that we want to bring back. As defenders, most [07:34.260 --> 07:37.940] people focus on the filter for detecting malicious LDAP [07:38.700 --> 07:42.800] queries. So for this reason, it's also going to be our [07:42.800 --> 07:48.700] primary obfuscation focus. We don't want to overlook also the [07:48.700 --> 07:52.180] base object and attribute selection. So they are going to [07:52.180 --> 07:57.240] be our secondary and tertiary obfuscation focus. As filter is [07:57.240 --> 08:03.000] the main one, let's see what makes up a filter. So well, it's [08:03.000 --> 08:06.420] made up of tokens. There are five required tokens that we [08:06.920 --> 08:10.760] have group start and group end, the hold in the middle, the [08:10.760 --> 08:15.740] attribute and the value for it, and the comparison operator. So [08:15.740 --> 08:18.040] here, for example, we are looking, I'm looking for [08:18.040 --> 08:24.220] myself, basically. There are also two optional tokens, which [08:24.220 --> 08:28.860] is boolean operator and extensible match filter. Debo is [08:28.860 --> 08:32.860] going to talk about these in the upcoming slides. But just so [08:32.860 --> 08:35.660] you know, these are bitwise values. They have different [08:35.660 --> 08:38.380] meanings based on the attributes, and Microsoft [08:38.380 --> 08:42.380] documents all of these per attribute. So different numbers [08:42.380 --> 08:49.080] mean actually different things to different attributes. In this [08:49.080 --> 08:51.980] one, basically, we're looking for objects that are not [08:51.980 --> 08:56.380] disabled, let's say. Most people actually do not write simple [08:56.380 --> 09:00.500] filters like this. They do try to combine multiple filters, and [09:00.500 --> 09:04.740] they do that with a boolean operator to create a filter [09:04.740 --> 09:12.590] list. So it's not going to look actually as a pretty tree just [09:12.590 --> 09:17.450] like this one, but it's a single row, usually. So it's going to [09:17.450 --> 09:20.790] be composed of two filters, which together they make up a [09:20.790 --> 09:24.490] filter list, and the whole string is actually called a [09:24.490 --> 09:30.010] search filter for an LDAP search request. Uh-oh. [09:30.010 --> 09:32.870] Sorry. No, we don't don't need help with PowerPoint [09:32.870 --> 09:35.090] transitions. Moving on. [09:37.870 --> 09:41.250] Hold on. It looks like you could use some help with crowd [09:41.250 --> 09:46.790] work. Hilarious. Oh, Clippy. I have trivia and jokes. I don't [09:46.790 --> 09:48.890] know. I could use that on a Sunday morning. How about y'all? [09:49.990 --> 09:53.430] What do you call the biggest LDAP search request in history? [09:54.050 --> 09:59.630] Any takers? It's pronounced ten and a half megabytes. Because [09:59.630 --> 10:03.290] that's the limit for a search request. Now, Clippy actually [10:03.290 --> 10:07.130] comes armed with sources. But just know that that's a lot of [10:07.130 --> 10:09.610] data. And keep in mind, LDAP is not just for querying [10:09.610 --> 10:12.050] information. It's also for updating records. But for the [10:12.050 --> 10:15.450] purpose of recon, I encourage anybody in this room to issue [10:15.450 --> 10:18.930] something even close to ten and a half megs and see how much [10:18.930 --> 10:23.470] shows up in your logs. All right. Thanks, Sabi. So now that [10:23.470 --> 10:25.730] we had a good idea of the different components of LDAP [10:25.730 --> 10:28.350] that we're going to be looking at, let's actually do the fun [10:28.350 --> 10:32.150] stuff of obfuscation. For all the defenders in the room, it's [10:32.150 --> 10:35.250] going to get dark and bleak before it gets bright again. But [10:35.250 --> 10:38.910] we promise there is a light at the end of the tunnel. So as [10:38.910 --> 10:40.870] Sabi mentioned, the filter is going to be the primary [10:40.870 --> 10:43.950] obfuscation focus because it really is kind of the primary [10:43.950 --> 10:47.450] defensive detection focus today. And we're going to spend most of [10:47.450 --> 10:50.030] our time on the filter. And then a lot of the techniques that [10:50.030 --> 10:52.950] work on the filter will then be applied to the base object and [10:52.950 --> 10:57.390] attribute selection as well. There's a lot of things that we [10:57.390 --> 11:00.710] discovered that are not documented. Some of it was sheer [11:00.710 --> 11:03.170] luck. Some of it was brute forcing. Some of it was the fact [11:03.170 --> 11:04.970] that when you build an obfuscation framework, you're [11:04.970 --> 11:07.250] kind of defining the boundaries of a language and it's going to [11:07.250 --> 11:10.550] break out sometimes and teach you things that still work. And [11:10.550 --> 11:14.150] so we'll try to mention things that are undocumented and then [11:14.150 --> 11:17.710] also put this undocumented icon at the top. So we're going to [11:17.710 --> 11:20.750] start by looking at these five tokens and looking at [11:20.750 --> 11:23.350] obfuscation that can be applied to each, beginning with the [11:23.350 --> 11:31.390] attribute token. So let's see how what we can do to obfuscate [11:31.390 --> 11:34.710] the attribute. We can actually do casing. It is case [11:34.710 --> 11:40.490] sensitive, so we can play with it. We can use object, OID [11:40.490 --> 11:45.570] object identifier. OID object identifier, Microsoft defines it [11:45.570 --> 11:48.930] as a dotted string of numbers, which is actually quite true [11:48.930 --> 11:52.910] because you can also add this OID prefix at the beginning of [11:52.910 --> 11:55.830] it and it's still going to work, which is also case [11:55.830 --> 12:00.110] sensitive. Another thing that is really fascinating and [12:00.110 --> 12:04.390] undocumented is that we can add prefixes of zeros to each [12:04.390 --> 12:09.090] octet on this part and it executes just fine. It will also [12:09.090 --> 12:13.330] show just like this also on client side logs. Another thing [12:13.330 --> 12:16.950] we can do for attribute obfuscation is ambiguous name [12:16.950 --> 12:22.050] resolution. So the same applies as above. So we can use [12:22.050 --> 12:27.070] insensitive casing and OID notation even for the ANR. But [12:27.070 --> 12:31.310] what is exactly ANR? So in case you know some name, but you [12:31.310 --> 12:36.350] don't know in which property it actually is, you can search and [12:36.350 --> 12:38.970] what it would actually do depending on the version of [12:38.970 --> 12:42.550] active directory, it will logically transform this single [12:42.550 --> 12:47.990] term into this query. So basically everything is ended in [12:48.110 --> 12:51.670] a wildcard, except for some attributes that do not support [12:51.670 --> 12:56.490] this. And in case your search actually contains a space just [12:56.490 --> 13:01.210] like us, we're looking for domain admins, then it's going [13:01.210 --> 13:05.970] to be added another this one. So these four ones because it will [13:05.970 --> 13:09.490] treat it as a first name, last name, last name, first name. [13:10.350 --> 13:14.250] Some nice obfuscation tricks. So we can use ANR, for example, [13:14.250 --> 13:18.550] if we're trying to search for curb TGT. And we can also use [13:18.550 --> 13:22.350] which is the second example, only the some parts of it. And [13:22.350 --> 13:26.490] it's going to be an explicit wildcard. So we'll still even on [13:26.490 --> 13:30.710] the second example, we're still going to have the same results. [13:30.710 --> 13:33.810] And the third example, which is very nice, we actually [13:33.810 --> 13:38.590] discovered that if you add an implicit wildcard, after that, [13:38.590 --> 13:44.210] everything you add is going to be ignored. So you can play with [13:44.210 --> 13:48.530] it, but you're still going to be to get the result of ANR. [13:48.550 --> 13:54.970] And return the curb TGT. And just as this also going to be [13:54.970 --> 13:58.850] handled from our detection framework. If you don't want to [13:58.850 --> 14:03.570] do all the crazy stuff with a wildcard, and just be explicit, [14:03.570 --> 14:06.990] you can actually just add an equal sign, which is document [14:06.990 --> 14:12.430] the which is the documented way to get the information. As a [14:12.430 --> 14:16.390] recap for attribute obfuscation, we can do casing, object [14:16.390 --> 14:21.990] identify notation, and ambiguous name resolution. Ah, Clippy [14:21.990 --> 14:25.370] again. Do you know where else ambiguous name resolution [14:25.370 --> 14:30.610] exists? We don't know Clippy. Where? Microsoft, what is more [14:30.610 --> 14:34.170] ambiguous than resolving to rename your products every six [14:34.170 --> 14:35.730] months? Am I right? [14:37.050 --> 14:40.050] I did not know Clippy was allowed to make Microsoft burns. [14:40.050 --> 14:43.910] I don't know if that was cleared. Thanks, Clippy. So one [14:43.910 --> 14:46.490] token down. We've talked about attributes. Next, we're gonna [14:46.490 --> 14:49.210] look at the comparison operator. Most of the time, this is an [14:49.210 --> 14:51.950] equals sign. When it comes to Active Directory's [14:51.950 --> 14:55.310] implementation of LDAP, you also have the approximately equal to [14:55.770 --> 14:59.610] because casing doesn't matter. But it does prevent you from [14:59.610 --> 15:02.210] using the wildcard and hex characters that we'll be talking [15:02.430 --> 15:04.810] a lot more about later. But we're really going to focus on [15:04.810 --> 15:07.690] the range operator. So greater than equal to less than equal [15:07.690 --> 15:10.410] to. So here's an example a lot of red teamers would be familiar [15:10.410 --> 15:13.330] with service principal name equal star means give us the [15:13.330 --> 15:16.110] objects that have an SPN, any value, I don't care, but it must [15:16.110 --> 15:19.850] be defined. Well, technically, we could rewrite this with a [15:19.850 --> 15:23.110] string operator and say, hey, make sure it's present, it has a [15:23.110 --> 15:25.270] value that is greater than or equal to the alphabetical [15:25.270 --> 15:28.810] sorting of a string that begins with equals, or the exclamation [15:28.810 --> 15:32.450] point, or is less than ZZZ. So there are other ways logically [15:32.450 --> 15:35.590] that you can accomplish this equivalence, this presence [15:35.590 --> 15:39.590] filter. One really important note, if you think about the [15:39.590 --> 15:42.050] printable range of ASCII characters, this is the proper [15:42.050 --> 15:45.230] ordering that we all know and love and have agreed upon as a [15:45.230 --> 15:48.830] standard as an industry. We do not know why, but there is an [15:49.590 --> 15:52.790] abnormal range or sorting for strings in Active Directory [15:52.790 --> 15:54.850] casing doesn't matter. So we get rid of those. But you have all [15:54.850 --> 15:57.150] of the digits and alpha characters at the end, you have [15:57.150 --> 16:00.050] this very specific grouping of special characters, and then all [16:00.050 --> 16:02.990] the other characters fall right into the middle. This took us [16:02.990 --> 16:05.590] probably five days to find because it only occurred this [16:05.590 --> 16:08.970] bug only occurred like one out of 1000 iterations. But this is [16:09.610 --> 16:12.450] the ordering. So our obfuscation framework handles that, but [16:12.450 --> 16:16.770] just know it's kind of weird. Another thing we can do is use [16:16.770 --> 16:19.310] the range filters for precise values. So SAM account type [16:19.310 --> 16:22.710] equals this number ending with 368. This is another bitwise [16:22.710 --> 16:25.470] value. But let's say that detections were looking at this. [16:25.470 --> 16:28.430] Well, you could also instead of saying ends with 368, say [16:28.430 --> 16:32.150] greater than equals to 7, less than equal to 9, and then [16:32.150 --> 16:35.070] specifically exclude the 7 and 9. So logically, you're left with [16:35.070 --> 16:38.770] an 8. If you're like me and are more visual person, I like to [16:38.770 --> 16:42.230] think of it as a timeline. And so greater than equal to 7, less [16:42.230 --> 16:45.570] than equal to 9, and then let's just pop off the 7 and 9. So [16:45.570 --> 16:49.350] you're left with the 8. There are a lot of kind of flavors or [16:49.350 --> 16:52.950] recipes we built into the obfuscation module, showing a [16:52.950 --> 16:55.570] couple of them here. One of my favorites is actually using [16:55.570 --> 16:58.910] ranges for exclusions. In this last example, where you can say [16:58.910 --> 17:02.230] give me the presence filter, but then exclude everything outward [17:02.230 --> 17:05.550] and inclusive of the numbers 7 and 9. So you're left with 8. So [17:05.550 --> 17:07.410] again, those are all random options in the obfuscation [17:07.410 --> 17:10.850] filter, the obfuscation module. This works for numbers. It also [17:10.850 --> 17:13.490] works for strings with a caveat that suffixes are a little [17:13.490 --> 17:18.430] tricky. But yeah, it is still quite effective for those [17:18.430 --> 17:20.670] things. So in review for the second token type of comparison [17:20.670 --> 17:23.830] operator, we have approximately equal to, we have the logical [17:23.830 --> 17:26.030] equivalence for the presence filter, and then we can use the [17:26.030 --> 17:28.670] range operators to do some really fun stuff for precise [17:28.670 --> 17:31.530] values, whether they're strings or numbers. And defenders should [17:31.530 --> 17:34.010] be pretty familiar with some of these we just looked at because [17:34.010 --> 17:38.430] it's actually part of the Sharp Hound project. So that same [17:38.430 --> 17:41.310] account type, service principal name. So again, these are pretty [17:41.310 --> 17:44.010] relevant examples, and you can see that if a detection was [17:44.010 --> 17:46.330] looking for this, it would probably get smoked by what we [17:46.330 --> 17:50.210] just showed you. So the third token type is the Boolean [17:50.210 --> 17:53.050] operator. Mostly we think of ands and ors, but when it comes to [17:53.050 --> 17:57.530] LDAP, the not is where things get really crazy really fast. So [17:57.530 --> 17:59.570] let's take a really practical example. Let's say you're [17:59.570 --> 18:01.830] looking for country equals Albania. You want to have all [18:01.830 --> 18:04.370] those objects that come out of Active Directory. One thing you [18:04.370 --> 18:07.190] can do is just throw a bunch of Boolean operators inside of it, [18:07.190 --> 18:09.490] and logically it doesn't matter if you and and or one thing, [18:09.490 --> 18:12.130] it's still going to be that same one thing. Additionally, you can [18:12.130 --> 18:15.410] also put in double negation. Again, logically this is still [18:15.410 --> 18:18.270] going to give you country equals Albania, the same number of [18:18.270 --> 18:23.150] objects. Additionally, if you wanted to do a Boolean operator, [18:23.150 --> 18:25.470] you can technically slide it right inside of the filter [18:25.470 --> 18:27.670] itself. So in this case, if we're looking for location [18:27.670 --> 18:30.830] equals Kukic, which is a city inside of Albania, you can see [18:30.830 --> 18:32.810] that bottom example, that Boolean is sitting directly [18:32.810 --> 18:36.750] inside of the group start, group end filters or tokens. In our [18:37.330 --> 18:40.050] parser that we wrote for this research, we handle this [18:40.050 --> 18:42.410] similarly, but do call out the distinction because it is [18:42.410 --> 18:45.550] extremely important for certain kinds of detections, as well as [18:45.550 --> 18:48.730] obfuscation and deobfuscation scenarios. Most of the time, [18:48.730 --> 18:51.070] though, you're dealing with a slightly more complex filter [18:51.070 --> 18:54.070] like this. So this is saying, I want to know when the country [18:54.070 --> 18:58.050] is Albania, and either the location is Kukic or Tirana, two [18:58.050 --> 19:01.470] cities. It's important to know that the Boolean operator has [19:01.470 --> 19:04.190] kind of a scope of influence. So in this case, there are two [19:04.190 --> 19:07.050] Booleans, and you can see the boxes around the filters that [19:07.050 --> 19:10.050] they affect. If we added in a third set, there are now three [19:10.050 --> 19:13.230] groups. And so as we're parsing it, we basically create a stack [19:13.230 --> 19:16.250] of Boolean operators to know exactly how many Booleans are [19:16.250 --> 19:20.070] affecting the filter that we're looking at. One really, really [19:20.070 --> 19:22.910] fun feature is the not Boolean operator. So let's slide that in [19:22.910 --> 19:26.830] there. The not only affects the first filter or the first [19:26.830 --> 19:29.690] Boolean operator that it modifies. So we can see location [19:29.690 --> 19:33.250] equals Kukic is modified by that not, but the filter just below [19:33.250 --> 19:37.150] it is completely, it doesn't modify it at all. So this is [19:37.150 --> 19:40.030] another one that we have to track, as well as a lot of crazy [19:40.030 --> 19:43.350] things like negation, traversal, because you can have lots of [19:43.350 --> 19:45.950] layers in between, and you have to track the Booles all the way. [19:45.970 --> 19:49.790] Lots of fun. Honestly, a lot of headaches. But yeah, it's built [19:49.790 --> 19:51.730] into the parser, so we don't have to think about that anymore. [19:51.730 --> 19:54.990] And we'll see that in the demos towards the end. My personal [19:54.990 --> 19:57.450] favorite obfuscation technique with Boolean operators is [19:57.450 --> 20:00.370] logical inversion. So for any math nerds in the house, this is [20:00.370 --> 20:04.530] known as DeMorgan's law, but basically not A or B is the same [20:04.530 --> 20:07.950] as not A and not B with the inverse sitting below. So what [20:07.950 --> 20:11.310] you can do is take any LDAP search filter, choose a spot and [20:11.310 --> 20:13.190] negate it. In this case, we're going to choose the whole [20:13.190 --> 20:16.130] filter. And now everything else kind of to the right of that is [20:16.130 --> 20:19.390] going to be in scope for obfuscation. So step number two [20:19.390 --> 20:22.130] is identifying within that in scope section, all the ands and [20:22.130 --> 20:25.810] ors and inverting them. And then the third step is locating [20:25.810 --> 20:28.330] all the filters and inverting them from a negation [20:28.330 --> 20:30.730] perspective. So none of these filters are negated. So we're [20:30.730 --> 20:34.350] going to add that not and those are now negated. Now, this is [20:34.350 --> 20:37.610] logically the same as what we started with. Again, this is a [20:37.610 --> 20:40.470] lot of headaches if you're parsing this manually. And so in [20:40.470 --> 20:43.590] the parser, we basically have a concept of what's the logical [20:43.590 --> 20:45.730] inclusion? Is this included, true or false? What's the [20:45.730 --> 20:48.770] logical Boolean? Is it and or? And we also maintain a stack of [20:48.770 --> 20:51.790] all those Boolean operator tokens for your convenience. So [20:51.790 --> 20:54.290] interview for the third token type of Boolean operator, we [20:54.290 --> 20:57.470] have the additive nature, double negation, and then DeMorgan's [20:57.470 --> 21:02.590] laws for the Boolean operator inversion. Oh, goodness. Okay. [21:02.630 --> 21:06.490] What is my least favorite LDAP token type? I'm assuming Boolean [21:06.490 --> 21:09.390] operator, but let's see what happens here. Yep, Boolean [21:09.390 --> 21:13.290] operator, because I'm afraid of getting tied up in knots. Oh, [21:13.290 --> 21:16.210] that's cringe, Clippy. Clippy's losing steam fast. Yeah, get [21:16.210 --> 21:18.730] that out of the way. Okay. All right, the fourth token type [21:18.730 --> 21:21.770] extensible match filter. So Sabi mentioned this before. This is [21:21.770 --> 21:24.630] for attributes that have bitwise values. It's an integer [21:25.650 --> 21:28.670] number, but it actually represents a base two add-ins [21:28.670 --> 21:32.290] for all the bitwise flags based on which attribute that it is. [21:33.050 --> 21:38.810] So it is, there are four values that are supported by the by [21:38.810 --> 21:41.230] active directories LDAP implementation, we're going to [21:41.230 --> 21:43.790] focus on the first two, because they're the most interesting in [21:43.790 --> 21:47.090] terms of obfuscation. And that's the and and the or. For me, I [21:47.090 --> 21:51.450] remember the or because it ends with dot 804. So 804 is or 803 [21:51.450 --> 21:55.890] is not or. All right, so here's an example. User account [21:55.890 --> 21:58.050] control, and you can see in the red is the extensible match [21:58.050 --> 22:01.210] filter. In this case, it's an 803, so that's an and, and it's [22:01.210 --> 22:06.030] the number 515, which is the base two add-ins 1, 2, and 512. [22:06.090 --> 22:08.150] So one of the things we can do is what we've called bitwise [22:08.150 --> 22:12.630] breakout. So we can break that 515 out into 1 and 514. Again, [22:12.630 --> 22:15.550] as long as we have the proper grouping of add-ins, we can do [22:15.550 --> 22:19.570] this. 514 is actually 2 and 512. So we can break that out even [22:19.570 --> 22:22.270] further. So from a detection perspective, we can spread our [22:22.270 --> 22:24.710] logic across many different filters, which is really, really [22:24.710 --> 22:29.730] complicated. But it's also fun. If you started with an or, the [22:29.730 --> 22:31.810] same trick applies. Just make sure that the Boolean operator [22:31.810 --> 22:34.410] you add is an or instead of an and and that it matches the [22:34.410 --> 22:39.150] extensible match filter. This is a pretty trivial example, but a [22:39.150 --> 22:42.010] lot of real world examples can get pretty crazy. Like this is a [22:42.010 --> 22:45.390] git domain user from PowerView. Massive number. You can imagine [22:45.390 --> 22:48.310] all the random groupings and regroupings of base two add-ins [22:48.310 --> 22:53.670] to produce the same value in your overall search filter. So [22:53.670 --> 22:56.410] another thing we can do is if you have a filter that is a [22:56.410 --> 22:59.270] precise value. So this is looking for the exact ones and [22:59.270 --> 23:03.910] zero set to equal this number. What you can do is use this [23:03.910 --> 23:07.250] little formula. You can add the extensible match filter of and [23:07.250 --> 23:10.270] for all the one bits. You can add the or extensible match [23:10.270 --> 23:13.290] filter for all the zero bits and negate it and then and both of [23:13.290 --> 23:17.190] those filters together. What's really cool about this is now we [23:17.190 --> 23:19.130] have extensible match filters and we can use the first [23:19.130 --> 23:22.970] breakout type to break those into smaller and smaller random [23:22.970 --> 23:24.890] groupings of those base two add-ins. So we're not going to [23:24.890 --> 23:28.610] take this further, but this could explode into 10, 15, 20 [23:28.610 --> 23:32.050] different filters all slammed together. So interview for the [23:32.050 --> 23:34.530] fourth token type of extensible match filter, we have the [23:34.530 --> 23:37.130] bitwise breakout with and and or and then also the precise [23:37.130 --> 23:40.090] breakout, which kind of combines the second one with the first [23:40.090 --> 23:40.810] one. [23:43.770 --> 23:48.730] Thanks, Thibaut. Let's look at what we can do to obfuscate a [23:48.730 --> 23:52.040] little the value. We are still in the filter section. So [23:53.710 --> 23:57.070] excluding a couple of attribute types, just like seeing here, it [23:57.070 --> 24:01.990] is still casing doesn't matter. So it's case sensitive. And we [24:01.990 --> 24:06.190] can also do prepended zeros to anything that are bitwise digits [24:06.190 --> 24:11.270] or numbers. And we got some undocumented feature regarding [24:11.270 --> 24:16.010] timestamps is that we originally noticed that sometimes [24:16.010 --> 24:20.290] milliseconds were present, but it didn't actually seem to [24:20.290 --> 24:24.430] matter. If you change the millisecond values or remove [24:24.430 --> 24:28.830] them, it turns out you can add actually add literally anything [24:28.830 --> 24:35.970] as long as you have a capital Z in it. So and technically, it is [24:35.970 --> 24:39.110] going to be treated still as a correct timestamp in the [24:39.110 --> 24:43.810] results. And it doesn't need to be only capital Z, it can also [24:43.810 --> 24:48.270] be it's hex encoding representation, which leads us to [24:48.270 --> 24:53.710] the next point, which is hex encoding for value obfuscation. [24:53.950 --> 24:57.630] And it's our favorite thing to do to be honest, the hex [24:57.630 --> 25:02.550] encoding itself, it exists to be able to to escape certain [25:02.550 --> 25:06.290] special characters, which Microsoft has detailed here very [25:06.290 --> 25:10.030] well. But you can also escape any printable characters that [25:10.030 --> 25:15.290] you want to as well. So you can swap these with the hex [25:15.290 --> 25:18.430] representations, and it's still going to be to give you the [25:18.430 --> 25:21.590] same results. And it's going to show just like this on the [25:21.590 --> 25:27.210] client side logs. Again, our parser, our parser parses codes [25:27.210 --> 25:32.430] decodes all the values. So it's all being handled. One [25:32.430 --> 25:36.330] undocumented thing is that Microsoft says that the hex [25:36.330 --> 25:39.090] representation should be followed by two characters [25:40.210 --> 25:44.670] representative SK hex character. But that's actually not true for [25:44.670 --> 25:49.010] the first 16 characters, you can drop the leading zero and it's [25:49.010 --> 25:54.110] still going to work. Wildcards, we mentioned a little bit even [25:54.110 --> 25:57.970] on the wildcards. So for example, instead of looking for [25:57.970 --> 26:02.450] the curb TGT, you can also just look for RBG and see what you [26:02.450 --> 26:08.170] get. These actually for wildcards, we are not the only [26:08.170 --> 26:12.430] ones who have been looking for evasion purposes. So even the [26:12.430 --> 26:17.350] researcher Hope Walker, these are two very well great posts [26:17.350 --> 26:21.170] blog posts recent, it's a researcher at specter ops, and [26:21.170 --> 26:27.490] she outlines using wildcards for evasion purposes. As a [26:27.490 --> 26:30.550] recap, for value, we can do casing, we can do prepended [26:30.550 --> 26:36.710] zeros, timestamps, hex encoding, and wildcards. The good news is [26:36.710 --> 26:40.690] that's all you can do with obfuscation. Nah, I'm lying, you [26:40.690 --> 26:45.090] guys, we got much more. So until now, we actually were looking [26:45.090 --> 26:49.810] for top and obfuscation. Let's see outside of it a little. And [26:49.810 --> 26:53.810] for example, for filter wide obfuscation, you can actually [26:53.810 --> 26:58.390] add group start and group end, as long as as much as you want, [26:58.390 --> 27:03.030] as long as you stay until the depth of 99. You can also add [27:03.030 --> 27:08.370] white space all over, and it is significant. And it can be new [27:08.370 --> 27:15.110] line, tab, etc. Garbage filters, again, need here actually you [27:15.110 --> 27:18.630] need to be careful if you're looking for if you're actually [27:18.630 --> 27:22.470] using logical or or logical end, because in case you're looking [27:22.470 --> 27:27.250] for logical end, you need to make sure the properties exist. [27:27.250 --> 27:33.010] But you can go crazy with ours. And lastly, is filter filter [27:33.010 --> 27:38.990] reordering. So until now, we only handled the filter. Let's [27:38.990 --> 27:43.930] see what we can do with base object. As a reminder, the base [27:43.930 --> 27:47.710] object is where in the active directory. So structure, we want [27:47.710 --> 27:50.770] to see we want to start the search, there are some good [27:50.770 --> 27:54.870] detection opportunities that we feel aren't discussed as much. [27:54.930 --> 27:58.210] And for example, like some offensive tools, just like [27:58.210 --> 28:02.770] certify, they have a very benign common and super search, super [28:02.770 --> 28:07.130] common search filter. So in this case is the base object, and [28:07.130 --> 28:11.110] it's looking for public key services, we are going to focus [28:11.670 --> 28:16.670] from a syntax perspective on a simple, really simple object [28:16.670 --> 28:20.710] like this. All the tricks we've seen until now, okay, for [28:20.710 --> 28:24.950] example, they still work, which is the casing, we can play, you [28:24.950 --> 28:29.510] can do also the hex encoding for the value portion, you can use [28:29.510 --> 28:34.150] the ID notation of the attributes, and also supports [28:34.150 --> 28:40.550] the ID prefix as well as your prefix. And white space, it [28:40.550 --> 28:44.450] actually can be added at the end, as well as between the [28:44.450 --> 28:49.910] slashes of the LDAP prefix. Something interesting is that [28:49.910 --> 28:53.550] it's true for the base object, but not for the value in the [28:53.550 --> 28:57.990] filter is that as long as hex is not present, you can actually [28:57.990 --> 29:01.210] encapsulate it with double quotes, and it will show up this [29:01.210 --> 29:05.450] way in client side logs, but it's not going to look like [29:05.450 --> 29:10.970] this on server side logs. Lastly, is the attribute [29:10.970 --> 29:14.670] selection. Basically, it's which attributes properties do you [29:14.670 --> 29:19.330] want to be returned in the results. And here also, casing [29:19.330 --> 29:23.490] doesn't matter, you can substitute just like previously, [29:23.490 --> 29:27.530] you can also use object identifier notation, also [29:27.530 --> 29:32.870] supports adding OID prefix and prepended zeros, add white space [29:32.870 --> 29:38.110] only after the attributes that are on the OID syntax. Not sure [29:38.110 --> 29:42.050] why, but yeah, a lot of trial and error, to be honest. We have [29:42.050 --> 29:46.930] the option also to add duplicate attributes, and garbage [29:46.930 --> 29:51.930] attributes, literally anything you want. And the person who's [29:51.930 --> 29:57.630] going to answer about this is no one else than Clippy. Hey, [29:57.630 --> 30:01.750] Daniel, what do you call this character? Asterix, wildcard or [30:01.750 --> 30:02.570] splat? [30:03.710 --> 30:07.370] I think this is an ages question. But all three are [30:07.370 --> 30:10.410] true. But there's a lot of space down there. So let's see what [30:10.410 --> 30:14.330] Clippy has to say. F, all the above. So two more important [30:14.330 --> 30:16.490] things here is from an input perspective and the attribute [30:16.490 --> 30:19.830] selection. If the only value defined is a wildcard, it will [30:19.830 --> 30:23.410] return all the properties, even just the same as if you don't [30:23.410 --> 30:26.590] define any attribute selection. What's fascinating is that in [30:26.590 --> 30:28.950] the server side logs, that wildcard is going to literally [30:28.950 --> 30:32.230] be printed as the string square brackets, all A-L-L, all [30:32.230 --> 30:36.110] lowercase. Now, if you'll notice, E is that if you have a [30:36.110 --> 30:39.410] list of attributes, and any one of those is a wildcard, then it [30:39.410 --> 30:42.730] will, the server side logs will translate that wildcard into [30:42.730 --> 30:46.490] this other string all with list. If you are, and you should be, [30:46.490 --> 30:49.790] if you are parsing these attribute selection values, you [30:49.790 --> 30:52.950] need to know that this weird string is prepended to the first [30:52.950 --> 30:55.170] attribute. So you have to do a really specific split and [30:55.170 --> 30:58.790] translation that we that we do in the logging module. But just [30:58.790 --> 31:02.170] know there's some weirdness that goes on there. Thanks, Clippy. [31:02.590 --> 31:05.290] All right, now that is actually the end of the obfuscation [31:05.290 --> 31:07.910] portion. So we've talked about the search filter, we've talked [31:07.910 --> 31:10.230] about the base object, the attribute selection. So for all [31:10.230 --> 31:13.710] the defenders in the room, what now? So from a solution [31:13.710 --> 31:17.150] perspective, we're going to focus on three steps. One is [31:17.150 --> 31:20.090] parsing, two is enriching, and then three is the actual [31:20.090 --> 31:22.950] detection itself. So from a parsing perspective, when we [31:22.950 --> 31:25.850] started this research, there was no parser for LDAP search [31:25.850 --> 31:29.470] filters. And so we naively said, let's just build a parser. How [31:29.470 --> 31:31.970] hard could it be? To be honest, that was over half of the [31:31.970 --> 31:35.150] research, but it was one of the most interesting and fulfilling [31:35.150 --> 31:38.430] parts of this. And so we wrote a C sharp state machine parser [31:38.430 --> 31:41.830] to firstly do tokenization. So that means when you have a [31:41.830 --> 31:43.930] string come in, that's the entire search filter, let's [31:43.930 --> 31:46.650] break it into tokens. So we know which ones are attributes, [31:46.650 --> 31:49.670] values, comparison operator, etc. Next, you want to organize [31:49.670 --> 31:52.610] those tokens into a representation that allows you to [31:52.610 --> 31:55.710] understand the structure of nested Boolean operators and [31:55.710 --> 31:57.970] filters and filter lists and all those sorts of things. And [31:57.970 --> 32:00.430] then you can move on to actual enrichment, which is step [32:00.430 --> 32:03.110] number two. So here's an example of using all the conversion [32:03.110 --> 32:06.690] modules within Mount Adaptive to start with a string, break it [32:06.690 --> 32:09.730] into tokens, and then every step of the way, we try to decode [32:09.730 --> 32:12.570] and enrich however much we can. So as Sabi mentioned, when [32:12.570 --> 32:14.910] there are hex values, we'll automatically decode them for [32:14.910 --> 32:18.970] you. But we leave the original syntax as well. One distinction [32:20.030 --> 32:22.990] between... so in our parsing, we do tokenization, and then we [32:22.990 --> 32:26.450] basically create a parse tree or a syntax tree, which is almost [32:26.450 --> 32:29.390] an abstract syntax tree, but we drop the abstract part because [32:29.390 --> 32:32.070] abstract says, let's drop things that don't need to be there, [32:32.070 --> 32:34.730] like insignificant white space. Well, by definition, [32:34.730 --> 32:36.930] obfuscation doesn't need to be there. So we actually want to [32:36.930 --> 32:39.990] keep all those insignificant things so we can recreate the [32:39.990 --> 32:43.510] input from that parse tree. And then after we break this into [32:43.510 --> 32:45.690] tokens and do those enrichments, we'll then group them into [32:45.690 --> 32:48.850] filters and branches and a tree structure to do certain kinds of [32:48.850 --> 32:51.410] obfuscation and detections that require that kind of tree [32:52.850 --> 32:55.610] grouping functionality as we go through and parse it. And then [32:55.610 --> 32:59.170] the final step is actually detect. So we try to make it as [32:59.170 --> 33:01.470] simple as possible. We wrapped all this inside of a single [33:01.470 --> 33:04.530] function called find evil. So you can pipe any number of [33:04.530 --> 33:06.850] search filters you want into find evil. And for each of those [33:06.850 --> 33:09.390] filters, it will parse it, do all the enrichment we just [33:09.390 --> 33:11.670] talked about. It will run it through all our complete [33:11.670 --> 33:14.250] detection rule set, which we are releasing with maladaptive. So [33:14.250 --> 33:17.430] 65 rules and counting. And then for each of those detections, [33:17.430 --> 33:20.390] the rule carries with it a dynamic score or weight, if you [33:20.390 --> 33:23.010] will, as well as an explanation. So it'll give you an example of [33:23.010 --> 33:25.070] what kind of thing it's looking for. And then it will actually [33:25.070 --> 33:28.350] show you the specific part of your search filter that flagged [33:28.350 --> 33:31.870] on that rule, as well as in the name, you can see. It'll [33:31.870 --> 33:34.210] actually pull out specific values. So it should be really [33:34.630 --> 33:37.390] colorfully obvious, as you'll see in the demo, of exactly why [33:37.390 --> 33:40.010] this thing was flagged for this rule. And if you look at the [33:40.010 --> 33:43.050] bottom, as I said, we spent over half the time just building [33:43.050 --> 33:46.310] this parser. We wrote and rewrote every piece of this [33:46.310 --> 33:49.030] parser two to three times to make it as fast as we possibly [33:49.030 --> 33:52.090] could. And in this example, we're parsing this search filter [33:52.090 --> 33:56.670] 100,000 times, doing full parsing, full detections, and [33:56.670 --> 34:00.590] it's clocking in at just under 4.4 seconds. And that's on a [34:00.590 --> 34:03.730] moderately spec laptop. Because we know that the number, the [34:03.730 --> 34:05.990] volume of search filters in production environments is [34:05.990 --> 34:08.610] massive. And so we wanted this to be really usable right out of [34:08.610 --> 34:13.510] the box. Oh, and shout out to Olaf Hartung at Falconforce. He [34:13.510 --> 34:15.530] was really instrumental in taking all these rules for us [34:15.530 --> 34:18.350] and running them multiple times across his entire client data [34:18.350 --> 34:21.210] set, since we don't have that data set, and then giving us [34:21.210 --> 34:23.150] feedback and stats on, hey, which rules need to be tuned a [34:23.150 --> 34:25.570] little bit. So, Olaf, if you're watching, thanks so much, buddy. [34:25.570 --> 34:26.150] We really appreciate it. [34:27.070 --> 34:29.810] So instead of talking more about the solution, let's go into the [34:29.810 --> 34:32.910] last section and actually just show a demo. If you haven't [34:32.910 --> 34:35.450] picked up on it by now, we really like to have fun. When [34:35.450 --> 34:37.470] you spend 2,000 hours on something, you have to trick [34:37.470 --> 34:40.270] yourself into being motivated, so we added colors however we [34:40.270 --> 34:43.430] can. This is our ASCII art, and it's actually a fully [34:43.430 --> 34:46.610] functioning LDAP query that will return any object that has a [34:46.610 --> 34:50.170] name property. Clippy seems to like it as well. I can't tell if [34:50.170 --> 34:52.630] he's hanging out or trying to eat the terminal or what's going [34:52.630 --> 34:56.710] on. So in the first example, this is that Albania, Cucos, [34:56.710 --> 34:59.950] Tirana filter example with a little bit of obfuscation. So if [34:59.950 --> 35:02.150] we tokenize it, we can see it breaks out which things are [35:02.150 --> 35:06.030] attributes, values, et cetera. If we do the enriched tokens, we [35:06.030 --> 35:08.450] can now see it says, hey, this is a defined attribute, and it [35:08.450 --> 35:11.370] translates to the letter L. And we have these other context [35:11.370 --> 35:14.090] objects as well. So if we look at the context object, remember [35:14.090 --> 35:16.850] this is things like the Boolean operator. We group all these [35:16.850 --> 35:19.790] things into filters so that we can write detection logic [35:19.790 --> 35:22.310] against the entire filter. So we can easily access the string [35:22.310 --> 35:24.670] values, but then we have a dictionary and list of the full [35:24.670 --> 35:26.710] token objects. So all the metadata nested from [35:26.710 --> 35:29.570] tokenization we can find in the filter. And then if we look at [35:29.570 --> 35:31.850] the context object for the Boolean operator, we'll see this [35:31.850 --> 35:35.210] is a logically inclusive filter. This is tracking that full stack [35:35.210 --> 35:38.130] of Boolean operators that you still have direct access to. And [35:38.130 --> 35:41.110] then every single value goes through the full value parsing. [35:41.110 --> 35:43.570] So any hex characters are parsed. At any time, you can [35:43.570 --> 35:46.610] look for the raw content or the decoded content. Pipe that into [35:46.610 --> 35:49.010] Find Evil, and we can see these are the individual rules that [35:49.010 --> 35:52.030] matched for this particular search filter. This is just [35:52.030 --> 35:54.530] showing a couple properties. In the next demos, you'll see a [35:54.530 --> 35:58.450] little better view of the entirety of the rules. Let's do [35:58.450 --> 36:00.730] another parsing example, this time using the bitwise value. [36:00.730 --> 36:03.470] So remember all the bitwise breakout where like 515 can be [36:03.470 --> 36:07.270] 1, 2, 5, 12? Well, here's a rule that flag and says, hey, if user [36:07.270 --> 36:10.950] account control attribute has the flag 128 set to true, then [36:10.950 --> 36:13.330] flag this alert. I won't go into the details of why that's an [36:13.330 --> 36:16.470] interesting detection, but what we want to show you is when we [36:16.470 --> 36:18.510] parse this value, we automatically know this is a [36:18.510 --> 36:21.270] bitwise attribute, and we parse the value to get those base two [36:21.270 --> 36:25.050] add-ins, either in a dictionary format or a list format. So you [36:25.050 --> 36:28.090] can immediately write detections for combinations of true and [36:28.090 --> 36:30.990] false. Now keep in mind, this is per filter, so that breakout [36:30.990 --> 36:33.530] stuff does complicate it a bit, but you can at least extract the [36:33.530 --> 36:37.090] flags and aggregate it back together for your final [36:37.090 --> 36:40.970] detections across the entirety of the search filter. The last [36:40.970 --> 36:44.890] parsing example is looking for some actually kind of crazy [36:44.890 --> 36:47.950] stuff. So decoding hex characters in this first example, [36:47.950 --> 36:50.910] that's easy sauce. So this is trusted domain, easy detection. [36:50.910 --> 36:53.350] But when it's things like wildcards, they're actually [36:53.350 --> 36:56.290] missing characters, so we can't precisely say what the person [36:56.290 --> 36:59.670] was looking for. But in our detection module, you have the [36:59.670 --> 37:02.730] ability to define strings of interest, like curbtgt, domain [37:02.730 --> 37:05.370] admins, domain controllers, and the parser and the detection [37:05.370 --> 37:07.730] rules will go through and actually expand the wildcards [37:07.730 --> 37:10.570] and say, hey, does this wildcarded string match any of [37:10.570 --> 37:13.430] your sensitive terms? And that also handles the two ANR [37:13.430 --> 37:15.550] scenarios that Sabi mentioned earlier, with the implicit [37:15.550 --> 37:19.330] wildcard or the explicit wildcard. So yeah, those are [37:19.330 --> 37:21.230] some really fun detections that go beyond just pure [37:21.230 --> 37:24.150] deobfuscation, but really kind of logically looking at some [37:24.150 --> 37:26.530] suspicious strings of interest. [37:27.390 --> 37:32.310] And finally, we've put all this together into a colorful [37:32.310 --> 37:36.450] interactive menu to make it fun to explore. We can test our [37:36.450 --> 37:41.310] input, the LDAP search filter, and we can explore the [37:41.310 --> 37:45.250] obfuscation menus for all the techniques we covered in this [37:45.250 --> 37:51.990] presentations. Wildcards are also supported. We can add [37:51.990 --> 37:56.490] obfuscation layer by layer, and we can also remove it. And if [37:56.490 --> 38:00.330] you're lazy, you can use all wildcards to randomly apply all [38:00.330 --> 38:07.870] the options. Let's test again. The search filter still works. [38:07.870 --> 38:12.230] Detection module is built in and findevils shows a full [38:12.230 --> 38:18.200] summary of detections, scores, explanations, and more colors. [38:19.090 --> 38:22.930] Lastly, if you don't like interactive menus, we have full [38:22.930 --> 38:28.350] CLI support. So the interactive menu lets you randomly choose [38:28.350 --> 38:32.710] ingredients, and you can copy out the receipt for non [38:32.710 --> 38:36.930] interactive user. All the pictures for pretty printing and [38:36.930 --> 38:40.730] detection summaries are also available via CLI. [38:49.930 --> 38:54.030] Thank you. It's always awkward in blue teamer talks. Was that a [38:54.030 --> 38:57.730] shell? Do we clap or not? Our apologies for not including a [38:57.730 --> 39:02.090] dramatic pause. Hopefully that was fun for everyone. We're [39:02.090 --> 39:04.570] almost done here. We just want to reiterate that Sabi and I are [39:04.570 --> 39:06.730] both defenders, and from the very beginning of this research, [39:06.730 --> 39:10.290] we knew that we had not seen people talking about this, and to [39:10.290 --> 39:12.770] be honest, attackers didn't really need this help. So why [39:12.770 --> 39:15.710] hand them a fully loaded machine gun when defenders still often [39:15.710 --> 39:18.090] don't even have the telemetry in the first place? So from the [39:18.090 --> 39:19.690] very beginning, we weren't strong armed. We decided that [39:19.690 --> 39:22.570] we wanted to release this in a unique kind of two-stage [39:22.570 --> 39:25.250] approach. So today what we've released is everything we've [39:25.250 --> 39:28.470] talked about, minus the obfuscation module. We're [39:28.470 --> 39:32.730] releasing a corpus of 1,337 benign obfuscated examples, so [39:32.730 --> 39:35.450] you only have to run our code to look at examples of obfuscated [39:35.450 --> 39:39.050] search filters. For anyone who's really ambitious, you have the [39:39.050 --> 39:41.630] full parser, and the deobfuscation modules look [39:41.630 --> 39:44.170] suspiciously like the obfuscation ones. So if you want [39:44.170 --> 39:46.710] to do a little bit, go for it. But just keep in mind, we spent [39:46.710 --> 39:49.110] over 1,000 hours on the obfuscation module, so there is [39:49.230 --> 39:52.750] a heck of a lot of craziness that we put in there. Our goal, [39:52.750 --> 39:55.790] pending a CFP response, is hopefully by the end of this [39:55.790 --> 39:59.110] year, to do a part two of this presentation to focus really [39:59.110 --> 40:02.810] deeply on all the differences in client and server-side logging, [40:03.030 --> 40:05.390] a lot of the weird scenarios we had to build into the parser to [40:05.390 --> 40:08.470] support all of this, and then at that point, releasing the [40:08.470 --> 40:12.230] obfuscation module. So yeah, just want to make that really [40:12.230 --> 40:14.290] clear. That's clear on the GitHub, which will be on the last [40:14.290 --> 40:17.110] slide as well. But again, as defenders, we wanted to try to [40:17.110 --> 40:19.750] be as creative as possible and help defenders not be [40:19.750 --> 40:23.190] completely throwing tomatoes at us up on the stage. And we made [40:23.190 --> 40:25.910] this very clear in the CFP process. Big red text, no [40:25.910 --> 40:29.150] surprises. So we're really happy that there was support in us [40:29.150 --> 40:32.990] doing that kind of a release. So the final takeaways, LDAP is [40:32.990 --> 40:36.870] still widely used by attackers. It's very valuable. And in our [40:36.870 --> 40:40.050] opinion, defensively, it's still kind of immature in terms of [40:40.610 --> 40:43.070] detection. It seems to be a lot of kind of string-based [40:43.070 --> 40:45.650] detections. And even looking at blog posts of people doing LDAP [40:45.650 --> 40:48.330] hunting, there just aren't as many of them as I would like to [40:48.330 --> 40:52.270] see, that we would like to see. And then lastly, we released [40:52.270 --> 40:55.730] maladaptive to help try to bring awareness to what can happen, to [40:55.730 --> 40:58.130] show that we shouldn't just be doing string-based detections, [40:58.130 --> 41:00.490] and we're providing the parser in all of our detection modules [41:00.490 --> 41:03.250] so that hopefully you can, right out of the gate, start using it [41:03.250 --> 41:05.490] in your environment if you already have a mechanism to get [41:05.490 --> 41:10.310] all of those search filters. Our unofficial takeaway is we wanted [41:10.310 --> 41:12.890] to leave you with something a little different. And so we [41:12.890 --> 41:16.950] wanted to leave you with our, each of our favorite Albanian [41:16.950 --> 41:19.590] proverb. So I'm going to go first. I'm not a native speaker, [41:19.590 --> 41:24.690] so forgive my pronunciation. But mine is rofsah malet, which [41:24.690 --> 41:27.490] literally means live long like a mountain. It's kind of a [41:27.490 --> 41:30.590] blessing of well-being. I like to think of it in this scenario [41:30.590 --> 41:33.430] as we just climbed a crazy mountain together. I'm a little [41:33.430 --> 41:36.550] out of breath, personally. But in this industry, we have to [41:36.550 --> 41:39.330] help each other out. We have to recognize the shoulders that we [41:39.330 --> 41:42.030] stand on. And so when you see someone else struggling up the [41:42.030 --> 41:44.330] mountain, trying to understand what you're learning, help them [41:44.330 --> 41:46.910] up, get them to the top, and then they'll be able to see the [41:46.910 --> 41:48.670] next mountain they're going to climb and the person they're [41:48.670 --> 41:50.010] going to bring along with them. [41:51.710 --> 41:56.870] And my favorite expression, and I think the audience would agree [41:56.870 --> 42:01.510] with me here, Debo, is tlutom jomokapsa letras, which it [42:01.510 --> 42:04.890] means, please no more paperclips. [42:07.590 --> 42:11.750] It was fun while it lasted. All right. And with that, we just [42:11.750 --> 42:14.110] want to say thank you so much for your time. Thank you, [42:14.110 --> 42:17.150] DEF CON and to all the organizers. We had such a great [42:17.150 --> 42:19.630] time putting this research together, and we're really happy [42:19.630 --> 42:22.450] to be here. Here's all of our contact information. Here's the [42:22.450 --> 42:25.070] link to Mount Adaptive. Please reach out, and we'll be up here [42:25.070 --> 42:27.410] for questions. But thank you again for your time. [42:37.170 --> 42:42.810] Any brave souls for questions? Questions or criticisms, [42:42.810 --> 42:48.030] everything is welcome. One right here, yeah. [42:53.930 --> 42:57.050] So the question is, what was our process for finding all the [42:57.050 --> 43:02.950] undocumented stuff? Well, sometimes luck, sometimes... I [43:02.950 --> 43:06.230] think the best answer that we can give is, people ask us, why [43:06.230 --> 43:08.570] do you make obfuscation frameworks? It's kind of a [43:08.570 --> 43:12.430] little twisted, but it's really a way of kind of working [43:12.430 --> 43:15.570] backwards and defining a grammar. Because it's all a [43:15.570 --> 43:18.190] language, right? What's linguistically, syntactically [43:18.190 --> 43:21.110] allowed in a language? Whether that's PowerShell or LDAP or [43:21.110 --> 43:25.250] anything else. So our understanding is, let's say, [43:25.250 --> 43:28.570] actually, when Sabi wrote the hex encoding function, to take [43:28.570 --> 43:31.510] values and do hex encoding, we wrote that function, we plugged [43:31.510 --> 43:34.530] it into our test harness, and one out of every 500 examples [43:34.530 --> 43:36.990] would fail. It wouldn't return the same results we expected. [43:36.990 --> 43:39.490] And we eventually realized that's because hex values, or [43:39.490 --> 43:43.230] hex characters in the value, is not allowed when the extensible [43:43.230 --> 43:45.450] match filter is defined, right? So that is now an [43:45.890 --> 43:48.830] incompatibility that no one said anywhere, but our tool helped [43:48.830 --> 43:51.030] us find because it found an example that broke what we'd [43:51.030 --> 43:53.550] expected to see. So that's how we found a lot of these [43:53.550 --> 43:55.570] examples. And then just some tricks you kind of learn along [43:55.570 --> 43:58.090] the way, like, hey, pre-pinning zeros, that seems like something [43:58.090 --> 44:00.010] that someone might have thought to ignore, because it's [44:00.010 --> 44:02.570] insignificant, but it still shows up in logs, therefore, [44:02.570 --> 44:04.810] it's meaningful to us. And so some of those tricks, you just [44:04.810 --> 44:07.930] kind of pick up along the way and keep carrying forward. But [44:07.930 --> 44:09.050] yeah, great question. Thank you. [44:09.750 --> 44:22.220] Yeah. Yeah, good question. So the question was, in our [44:22.220 --> 44:25.220] research, against the obfuscation techniques we found, [44:25.220 --> 44:28.240] how effective is Windows Defender or other tools like [44:28.240 --> 44:31.920] that? We don't have access to those tools. So actually don't [44:31.920 --> 44:35.960] know. In general, I'd say, you know, I've spent the last decade [44:35.960 --> 44:38.440] doing real-time detections, actually spending some time at [44:38.440 --> 44:42.280] Microsoft in Defender telemetry, looking at how we detect [44:42.280 --> 44:45.520] processes and stuff like that on the endpoint. So what I would [44:45.520 --> 44:47.640] say that a lot of red teamers criticize blue teamers for is [44:47.640 --> 44:50.540] why do you make static kind of rigid detections? Sometimes [44:50.540 --> 44:53.480] it's out of ignorance, sometimes more likely it's out of [44:53.480 --> 44:56.240] performance. So I mean, there are millions and millions and [44:56.240 --> 44:58.860] millions of search filters flying around doing crazy [44:58.860 --> 45:02.200] regexes to try to find it to try to find these bizarre scenarios [45:02.200 --> 45:05.100] probably is going to bring down performance overall. So from a [45:05.100 --> 45:07.600] product's perspective, that's I think why a lot of decisions are [45:07.600 --> 45:10.740] made, but we don't have any direct insight into Defender or [45:10.740 --> 45:14.200] anyone else on how they're stacking up against this. If [45:14.200 --> 45:16.600] anyone from Microsoft or anyone else wants to reach out, we'd [45:16.600 --> 45:18.620] be more than happy to share more of the research in detail [45:18.620 --> 45:21.140] and help if there's anything that we can do to protect the [45:21.140 --> 45:26.160] community in that regard. Great question. Thank you. Any last [45:26.160 --> 45:36.540] questions? Yes. The question was, did we have trouble with [45:36.540 --> 45:40.340] all the colors for formatting? Trouble to who? The answer is [45:47.500 --> 45:56.560] yes. Yeah. So in terms of we actually did, we split our [45:56.560 --> 45:59.040] programming actually partially. We use PowerShell core. So we [45:59.040 --> 46:01.180] did a lot of it in Windows, a lot of it on Mac, a little bit [46:01.180 --> 46:03.320] in Linux just to test compatibility. But yeah, in [46:03.320 --> 46:05.400] terms of color differences, we actually stuck with the original [46:05.400 --> 46:08.640] colors, the original 16. We experimented with the dark [46:08.640 --> 46:12.600] colors for things like distinguished name values. Those [46:12.600 --> 46:16.400] are the darkened version of all the RDNs to represent the [46:16.400 --> 46:19.500] overall tokens. But that darkness shows up better on [46:19.880 --> 46:23.000] Windows. On Mac, it actually doesn't quite show up as much. [46:23.000 --> 46:26.380] But yeah, so that was a factor we had to kind of play around [46:26.380 --> 46:29.420] with. But yeah, I like the color question. I've never gotten [46:29.420 --> 46:34.380] that before. So thank you. All right. I think with this, we're [46:34.380 --> 46:36.380] at time. We'll be around front if anyone else wants to talk or [46:36.380 --> 46:38.140] ask questions. But again, thank you everyone for coming to the [46:38.140 --> 46:39.240] talk. Have a good one. [46:39.460 --> 46:39.780] . [46:40.220 --> 46:40.540] .