1 00:00:05,500 --> 00:00:07,300 How is everyone doing? 2 00:00:09,960 --> 00:00:11,880 I'm genuinely surprised. 3 00:00:11,880 --> 00:00:14,720 So either y'all went to bed early or you never went to bed. 4 00:00:14,720 --> 00:00:16,260 So thank you so much for being here. 5 00:00:16,260 --> 00:00:18,140 This talk is Maldaptive. 6 00:00:18,140 --> 00:00:23,440 Diving really, really deep into LDAP obfuscation, de-obfuscation and detection. 7 00:00:24,060 --> 00:00:25,640 My name is Daniel Bohannon. 8 00:00:25,680 --> 00:00:29,020 Everyone I know calls me Debo for short, so feel free to call me that. 9 00:00:29,020 --> 00:00:34,220 I'm a principal threat researcher for a startup company called Permiso Security doing cloud and identity stuff. 10 00:00:34,220 --> 00:00:41,920 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. 11 00:00:42,020 --> 00:00:44,520 And I have a little bit of a problem with obfuscation. 12 00:00:44,520 --> 00:00:50,920 It's kind of an obsession of mine of taking things that look normal and making them look just absolutely crazy. 13 00:00:51,120 --> 00:00:54,000 And then as a defender, looking for ways to detect those things. 14 00:00:54,040 --> 00:00:59,480 Another thing I'm really passionate about is coffee and books and all the great conversations that happen around both of those things. 15 00:01:00,780 --> 00:01:02,460 Hello, everyone. 16 00:01:02,460 --> 00:01:04,740 So I'm Sabayita. 17 00:01:04,740 --> 00:01:06,940 You can call me Sabi for short. 18 00:01:06,940 --> 00:01:08,980 I'm originally from Albania. 19 00:01:08,980 --> 00:01:16,160 I recently moved to Germany, Berlin, working for Solaris as a senior cyber security engineer. 20 00:01:16,300 --> 00:01:18,580 I'm passionate about cyber defense. 21 00:01:18,580 --> 00:01:28,180 Currently I'm also working on the field, doing a little incident response, detection engineering and time and time allows threat hunting. 22 00:01:28,260 --> 00:01:32,200 I do have also some experience in consulting and government. 23 00:01:32,460 --> 00:01:33,600 Love mountains. 24 00:01:33,600 --> 00:01:35,440 You can see even a goat there. 25 00:01:35,600 --> 00:01:39,100 And enjoy moving a lot at the Great Espresso. 26 00:01:40,660 --> 00:01:41,540 All right. 27 00:01:41,540 --> 00:01:46,040 So to kick things off, we're going to do a little historical lesson on Active Directory and LDAP. 28 00:01:46,040 --> 00:01:55,120 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. 29 00:01:55,320 --> 00:01:57,260 And then at the end, we'll talk more about our solution. 30 00:01:57,260 --> 00:01:59,500 You know, we don't like to just create problems. 31 00:01:59,500 --> 00:02:04,760 We want to actually have some real solutions there so that defenders can walk away equipped with something really beneficial. 32 00:02:05,020 --> 00:02:09,040 And then we'll do a demo and a tool release at the end. 33 00:02:09,200 --> 00:02:10,500 So let's get going. 34 00:02:11,240 --> 00:02:16,360 We are going to go back in time to the days of disco balls and DeLoreans, talking about the 1980s. 35 00:02:16,600 --> 00:02:22,100 The Directory Access Protocol, or the DAP, was a directory service kind of at that time. 36 00:02:22,100 --> 00:02:23,920 LDAP is the lightweight version. 37 00:02:23,920 --> 00:02:25,680 That's the L in LDAP. 38 00:02:25,760 --> 00:02:29,780 Between 93 and 97, you have three different versions of LDAP come onto the scene. 39 00:02:30,040 --> 00:02:34,100 In 1998, the Open LDAP Project released Open LDAP. 40 00:02:34,100 --> 00:02:42,180 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. 41 00:02:42,460 --> 00:02:46,320 So it's important to remember there's a server and client side component here. 42 00:02:46,420 --> 00:02:55,100 So Active Directory, we chose that because it's the most popular, most widely used application service, or directory service application in use. 43 00:02:55,100 --> 00:03:02,340 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. 44 00:03:02,520 --> 00:03:04,200 So that's the server side component. 45 00:03:04,200 --> 00:03:08,920 You have clients that will issue LDAP queries, or LDAP, what are called search filters. 46 00:03:09,040 --> 00:03:14,740 And LDAP is literally the protocol that allows that exchange of information between the client side and the server side. 47 00:03:15,600 --> 00:03:21,540 On the offensive side, LDAP, or AD in general, is quite a popular topic. 48 00:03:21,540 --> 00:03:30,080 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? 49 00:03:30,080 --> 00:03:36,120 Looking for really quick ways to get information from an offensive perspective, but also for defensive perspectives. 50 00:03:36,160 --> 00:03:53,160 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. 51 00:03:53,600 --> 00:03:59,060 So as defenders, we should then ask, okay, if attackers are using this, what are our data sources for defending? 52 00:03:59,520 --> 00:04:02,740 And so this is actually kind of a point of frustration for us. 53 00:04:02,740 --> 00:04:10,420 When we started this research, even until today, there's not that many options for production-ready telemetry gathering for LDAP search filters. 54 00:04:10,660 --> 00:04:14,640 What we use in our lab environment was Silk ETW by Ruben Boonen. 55 00:04:14,940 --> 00:04:23,900 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. 56 00:04:24,080 --> 00:04:30,480 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. 57 00:04:30,640 --> 00:04:36,680 So if you want this visibility in production, the best case right now is get Microsoft Windows Defender. 58 00:04:37,160 --> 00:04:43,080 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. 59 00:04:43,140 --> 00:04:47,960 If you want to have all the data so you can validate, then maybe explore your options a little bit. 60 00:04:49,180 --> 00:04:54,840 So another thing to keep in mind is there are big differences between client-side and server-side logs when it comes to LDAP. 61 00:04:54,960 --> 00:05:01,040 For all the hackers in the room, you're going to love client-side logs because it's basically like WYSIWYG. 62 00:05:01,040 --> 00:05:07,080 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. 63 00:05:07,080 --> 00:05:09,040 Awesome for obfuscation evasion. 64 00:05:09,040 --> 00:05:12,660 With an important caveat, it depends how you're issuing that query. 65 00:05:12,940 --> 00:05:22,540 So a lot of the mechanisms, like the ADDZ accelerator in PowerShell will use the WLDAP32.DLL to route that request. 66 00:05:22,540 --> 00:05:28,380 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. 67 00:05:28,880 --> 00:05:33,740 However, some folks have noticed there are many other ways to talk to an Active Directory server . 68 00:05:34,100 --> 00:05:42,420 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. 69 00:05:42,680 --> 00:05:48,940 So because of this, it's still a valuable data source, but it's important to look at the server-side logs as well. 70 00:05:49,720 --> 00:05:54,040 There is significant normalization that occurs in server-side logs. 71 00:05:54,040 --> 00:05:59,980 So a lot of the obfuscation we'll talk about is normalized, but there are still some interesting tricks that do persist. 72 00:06:00,680 --> 00:06:03,100 And yeah, that's all I'll say about that right now. 73 00:06:03,920 --> 00:06:14,620 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. 74 00:06:14,620 --> 00:06:18,020 This is something we've spent over 2,000 hours of R&D on. 75 00:06:18,140 --> 00:06:20,440 For the record, that's too much R&D. 76 00:06:20,440 --> 00:06:21,960 I don't recommend it to anybody. 77 00:06:22,040 --> 00:06:28,180 But here we are, so we're really happy to get this out there and then let our minds think about something else. 78 00:06:28,320 --> 00:06:32,100 And as I mentioned earlier, we're going to be doing a demo and tool release for MAL Adaptive. 79 00:06:32,100 --> 00:06:39,100 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. 80 00:06:39,100 --> 00:06:41,460 So how flexible can it really be? 81 00:06:41,480 --> 00:06:44,820 And we hope to convince you pretty quickly that it can be pretty flexible. 82 00:06:45,540 --> 00:06:52,460 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. 83 00:06:54,320 --> 00:07:00,960 So we're going to... let's dive deep into the anatomy of an LDAP search request. 84 00:07:00,960 --> 00:07:03,800 We'll be looking at RFC 4511. 85 00:07:04,040 --> 00:07:22,320 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, 86 00:07:22,320 --> 00:07:32,120 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. 87 00:07:32,660 --> 00:07:40,040 As defenders, most people focus on the filter for detecting malicious LDAP queries. 88 00:07:40,040 --> 00:07:44,940 So for this reason, it's also going to be our primary obfuscation focus. 89 00:07:44,940 --> 00:07:51,200 We don't want to overlook also the base object and attribute selection. 90 00:07:51,200 --> 00:07:56,540 So they are going to be our secondary and tertiary obfuscation focus. 91 00:07:56,540 --> 00:08:01,880 As filter is the main one, let's see what makes up a filter. 92 00:08:01,880 --> 00:08:04,320 So well, it's made up of tokens. 93 00:08:04,320 --> 00:08:15,600 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. 94 00:08:15,620 --> 00:08:19,700 So here, for example, we are looking, I'm looking for myself, basically. 95 00:08:20,740 --> 00:08:28,320 There are also two optional tokens, which is boolean operator and extensible match filter. 96 00:08:28,420 --> 00:08:32,260 Debo is going to talk about these in the upcoming slides. 97 00:08:32,260 --> 00:08:35,000 But just so you know, these are bitwise values. 98 00:08:35,000 --> 00:08:40,920 They have different meanings based on the attributes, and Microsoft documents all of these per attribute. 99 00:08:41,060 --> 00:08:45,640 So different numbers mean actually different things to different attributes. 100 00:08:48,200 --> 00:08:53,660 In this one, basically, we're looking for objects that are not disabled, let's say. 101 00:08:53,780 --> 00:08:57,520 Most people actually do not write simple filters like this. 102 00:08:57,520 --> 00:09:05,300 They do try to combine multiple filters, and they do that with a boolean operator to create a filter list. 103 00:09:08,490 --> 00:09:15,750 So it's not going to look actually as a pretty tree just like this one, but it's a single row, usually. 104 00:09:15,790 --> 00:09:26,910 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. 105 00:09:28,910 --> 00:09:30,010 Uh-oh. 106 00:09:30,010 --> 00:09:30,650 Sorry. 107 00:09:30,970 --> 00:09:33,790 No, we don't don't need help with PowerPoint transitions. 108 00:09:33,950 --> 00:09:35,090 Moving on. 109 00:09:37,870 --> 00:09:38,650 Hold on. 110 00:09:38,750 --> 00:09:41,970 It looks like you could use some help with crowd work. 111 00:09:42,650 --> 00:09:43,350 Hilarious. 112 00:09:43,350 --> 00:09:44,370 Oh, Clippy. 113 00:09:44,450 --> 00:09:46,510 I have trivia and jokes. 114 00:09:46,510 --> 00:09:46,950 I don't know. 115 00:09:46,950 --> 00:09:48,090 I could use that on a Sunday morning. 116 00:09:48,090 --> 00:09:48,890 How about y'all? 117 00:09:49,990 --> 00:09:53,430 What do you call the biggest LDAP search request in history? 118 00:09:54,050 --> 00:09:55,030 Any takers? 119 00:09:55,850 --> 00:09:58,670 It's pronounced ten and a half megabytes. 120 00:09:59,190 --> 00:10:01,570 Because that's the limit for a search request. 121 00:10:02,210 --> 00:10:04,830 Now, Clippy actually comes armed with sources. 122 00:10:05,170 --> 00:10:07,790 But just know that that's a lot of data. 123 00:10:07,930 --> 00:10:10,150 And keep in mind, LDAP is not just for querying information. 124 00:10:10,150 --> 00:10:11,690 It's also for updating records. 125 00:10:11,690 --> 00:10:20,450 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. 126 00:10:21,330 --> 00:10:22,250 All right. 127 00:10:22,290 --> 00:10:23,050 Thanks, Sabi. 128 00:10:23,050 --> 00:10:29,790 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. 129 00:10:30,650 --> 00:10:35,150 For all the defenders in the room, it's going to get dark and bleak before it gets bright again. 130 00:10:35,150 --> 00:10:37,690 But we promise there is a light at the end of the tunnel. 131 00:10:38,470 --> 00:10:46,410 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. 132 00:10:46,450 --> 00:10:48,710 And we're going to spend most of our time on the filter. 133 00:10:48,710 --> 00:10:54,770 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. 134 00:10:55,190 --> 00:10:59,690 There's a lot of things that we discovered that are not documented. 135 00:10:59,850 --> 00:11:01,230 Some of it was sheer luck. 136 00:11:01,230 --> 00:11:02,430 Some of it was brute forcing. 137 00:11:02,430 --> 00:11:09,990 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. 138 00:11:10,450 --> 00:11:16,630 And so we'll try to mention things that are undocumented and then also put this undocumented icon at the top. 139 00:11:17,010 --> 00:11:24,630 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. 140 00:11:27,150 --> 00:11:32,390 So let's see how what we can do to obfuscate the attribute. 141 00:11:32,390 --> 00:11:34,150 We can actually do casing. 142 00:11:34,150 --> 00:11:37,090 It is case sensitive, so we can play with it. 143 00:11:37,490 --> 00:11:42,410 We can use object, OID object identifier. 144 00:11:42,490 --> 00:11:56,870 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. 145 00:11:57,110 --> 00:12:08,410 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. 146 00:12:08,410 --> 00:12:12,070 It will also show just like this also on client side logs. 147 00:12:12,450 --> 00:12:18,010 Another thing we can do for attribute obfuscation is ambiguous name resolution. 148 00:12:18,150 --> 00:12:20,950 So the same applies as above. 149 00:12:20,950 --> 00:12:26,510 So we can use insensitive casing and OID notation even for the ANR. 150 00:12:26,510 --> 00:12:28,850 But what is exactly ANR? 151 00:12:28,850 --> 00:12:44,730 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. 152 00:12:44,850 --> 00:12:52,090 So basically everything is ended in a wildcard, except for some attributes that do not support this. 153 00:12:52,350 --> 00:13:03,970 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. 154 00:13:03,970 --> 00:13:09,490 So these four ones because it will treat it as a first name, last name, last name, first name. 155 00:13:10,350 --> 00:13:12,370 Some nice obfuscation tricks. 156 00:13:12,370 --> 00:13:16,790 So we can use ANR, for example, if we're trying to search for curb TGT. 157 00:13:17,050 --> 00:13:22,170 And we can also use which is the second example, only the some parts of it. 158 00:13:22,170 --> 00:13:24,770 And it's going to be an explicit wildcard. 159 00:13:24,770 --> 00:13:30,710 So we'll still even on the second example, we're still going to have the same results. 160 00:13:30,710 --> 00:13:42,650 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. 161 00:13:42,750 --> 00:13:48,530 So you can play with it, but you're still going to be to get the result of ANR. 162 00:13:48,550 --> 00:13:51,870 And return the curb TGT. 163 00:13:52,370 --> 00:13:57,230 And just as this also going to be handled from our detection framework. 164 00:13:57,490 --> 00:14:10,270 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. 165 00:14:11,290 --> 00:14:19,890 As a recap for attribute obfuscation, we can do casing, object identify notation, and ambiguous name resolution. 166 00:14:21,150 --> 00:14:22,910 Ah, Clippy again. 167 00:14:23,110 --> 00:14:26,350 Do you know where else ambiguous name resolution exists? 168 00:14:26,350 --> 00:14:27,890 We don't know Clippy. 169 00:14:27,890 --> 00:14:28,810 Where? 170 00:14:29,030 --> 00:14:34,830 Microsoft, what is more ambiguous than resolving to rename your products every six months? 171 00:14:34,830 --> 00:14:35,730 Am I right? 172 00:14:37,050 --> 00:14:40,050 I did not know Clippy was allowed to make Microsoft burns. 173 00:14:40,050 --> 00:14:41,290 I don't know if that was cleared. 174 00:14:41,310 --> 00:14:42,770 Thanks, Clippy. 175 00:14:43,130 --> 00:14:44,690 So one token down. 176 00:14:44,690 --> 00:14:46,090 We've talked about attributes. 177 00:14:46,170 --> 00:14:48,050 Next, we're gonna look at the comparison operator. 178 00:14:48,130 --> 00:14:50,270 Most of the time, this is an equals sign. 179 00:14:50,290 --> 00:14:57,570 When it comes to Active Directory's implementation of LDAP, you also have the approximately equal to because casing doesn't matter. 180 00:14:57,570 --> 00:15:03,630 But it does prevent you from using the wildcard and hex characters that we'll be talking a lot more about later. 181 00:15:03,630 --> 00:15:05,930 But we're really going to focus on the range operator. 182 00:15:05,930 --> 00:15:08,370 So greater than equal to less than equal to. 183 00:15:08,410 --> 00:15:17,030 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. 184 00:15:17,090 --> 00:15:30,770 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. 185 00:15:30,950 --> 00:15:36,030 So there are other ways logically that you can accomplish this equivalence, this presence filter . 186 00:15:36,810 --> 00:15:46,150 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. 187 00:15:46,230 --> 00:15:53,410 We do not know why, but there is an abnormal range or sorting for strings in Active Directory casing doesn't matter. 188 00:15:53,410 --> 00:15:54,110 So we get rid of those. 189 00:15:54,110 --> 00:16:01,710 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. 190 00:16:01,710 --> 00:16:07,870 This took us probably five days to find because it only occurred this bug only occurred like one out of 1000 iterations. 191 00:16:07,950 --> 00:16:10,550 But this is the ordering. 192 00:16:10,550 --> 00:16:14,350 So our obfuscation framework handles that, but just know it's kind of weird. 193 00:16:14,610 --> 00:16:18,390 Another thing we can do is use the range filters for precise values. 194 00:16:18,390 --> 00:16:21,690 So SAM account type equals this number ending with 368. 195 00:16:21,690 --> 00:16:23,130 This is another bitwise value. 196 00:16:23,130 --> 00:16:25,470 But let's say that detections were looking at this. 197 00:16:25,470 --> 00:16:34,070 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. 198 00:16:34,070 --> 00:16:35,850 So logically, you're left with an 8. 199 00:16:36,010 --> 00:16:39,910 If you're like me and are more visual person, I like to think of it as a timeline. 200 00:16:40,370 --> 00:16:45,470 And so greater than equal to 7, less than equal to 9, and then let's just pop off the 7 and 9. 201 00:16:45,470 --> 00:16:46,850 So you're left with the 8. 202 00:16:47,170 --> 00:16:53,790 There are a lot of kind of flavors or recipes we built into the obfuscation module, showing a couple of them here. 203 00:16:53,790 --> 00:16:56,790 One of my favorites is actually using ranges for exclusions. 204 00:16:56,990 --> 00:17:04,310 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. 205 00:17:04,310 --> 00:17:05,230 So you're left with 8. 206 00:17:05,230 --> 00:17:09,350 So again , those are all random options in the obfuscation filter, the obfuscation module. 207 00:17:09,350 --> 00:17:10,550 This works for numbers. 208 00:17:10,550 --> 00:17:14,310 It also works for strings with a caveat that suffixes are a little tricky. 209 00:17:14,730 --> 00:17:18,710 But yeah, it is still quite effective for those things. 210 00:17:18,710 --> 00:17:30,510 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. 211 00:17:30,670 --> 00:17:37,530 And defenders should be pretty familiar with some of these we just looked at because it's actually part of the Sharp Hound project. 212 00:17:37,990 --> 00:17:40,210 So that same account type, service principal name. 213 00:17:40,210 --> 00:17:47,230 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. 214 00:17:48,450 --> 00:17:51,070 So the third token type is the Boolean operator. 215 00:17:51,070 --> 00:17:56,830 Mostly we think of ands and ors, but when it comes to LDAP, the not is where things get really crazy really fast. 216 00:17:57,290 --> 00:17:59,150 So let's take a really practical example. 217 00:17:59,150 --> 00:18:01,230 Let's say you're looking for country equals Albania. 218 00:18:01,230 --> 00:18:03,770 You want to have all those objects that come out of Active Directory. 219 00:18:03,930 --> 00:18:11,430 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. 220 00:18:11,510 --> 00:18:14,190 Additionally, you can also put in double negation. 221 00:18:14,250 --> 00:18:18,970 Again, logically this is still going to give you country equals Albania, the same number of objects. 222 00:18:20,430 --> 00:18:26,250 Additionally, if you wanted to do a Boolean operator, you can technically slide it right inside of the filter itself. 223 00:18:26,250 --> 00:18:36,230 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. 224 00:18:36,350 --> 00:18:47,770 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. 225 00:18:47,950 --> 00:18:51,790 Most of the time, though, you're dealing with a slightly more complex filter like this. 226 00:18:51,790 --> 00:18:58,750 So this is saying, I want to know when the country is Albania, and either the location is Kukic or Tirana, two cities. 227 00:18:58,990 --> 00:19:03,170 It's important to know that the Boolean operator has kind of a scope of influence. 228 00:19:03,170 --> 00:19:07,810 So in this case, there are two Booleans, and you can see the boxes around the filters that they affect. 229 00:19:07,810 --> 00:19:10,710 If we added in a third set, there are now three groups. 230 00:19:10,710 --> 00:19:18,350 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. 231 00:19:18,550 --> 00:19:22,090 One really, really fun feature is the not Boolean operator. 232 00:19:22,090 --> 00:19:23,410 So let's slide that in there. 233 00:19:23,410 --> 00:19:28,750 The not only affects the first filter or the first Boolean operator that it modifies. 234 00:19:28,830 --> 00:19:36,750 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. 235 00:19:36,750 --> 00:19:45,950 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. 236 00:19:45,970 --> 00:19:46,870 Lots of fun. 237 00:19:46,870 --> 00:19:48,130 Honestly, a lot of headaches. 238 00:19:48,490 --> 00:19:51,730 But yeah, it's built into the parser, so we don't have to think about that anymore. 239 00:19:51,730 --> 00:19:53,650 And we'll see that in the demos towards the end. 240 00:19:54,310 --> 00:19:58,610 My personal favorite obfuscation technique with Boolean operators is logical inversion. 241 00:19:58,650 --> 00:20:07,550 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. 242 00:20:07,570 --> 00:20:12,050 So what you can do is take any LDAP search filter, choose a spot and negate it. 243 00:20:12,050 --> 00:20:13,910 In this case, we're going to choose the whole filter. 244 00:20:13,930 --> 00:20:18,370 And now everything else kind of to the right of that is going to be in scope for obfuscation. 245 00:20:18,470 --> 00:20:24,050 So step number two is identifying within that in scope section, all the ands and ors and inverting them. 246 00:20:24,310 --> 00:20:28,930 And then the third step is locating all the filters and inverting them from a negation perspective. 247 00:20:28,930 --> 00:20:30,410 So none of these filters are negated. 248 00:20:30,410 --> 00:20:33,130 So we're going to add that not and those are now negated. 249 00:20:33,210 --> 00:20:36,550 Now, this is logically the same as what we started with. 250 00:20:36,650 --> 00:20:39,530 Again, this is a lot of headaches if you're parsing this manually. 251 00:20:39,730 --> 00:20:43,830 And so in the parser, we basically have a concept of what's the logical inclusion ? 252 00:20:43,830 --> 00:20:45,030 Is this included, true or false? 253 00:20:45,030 --> 00:20:46,530 What's the logical Boolean? 254 00:20:46,530 --> 00:20:47,470 Is it and or? 255 00:20:47,470 --> 00:20:51,350 And we also maintain a stack of all those Boolean operator tokens for your convenience. 256 00:20:51,590 --> 00:20:59,550 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. 257 00:21:01,170 --> 00:21:02,170 Oh, goodness. 258 00:21:02,170 --> 00:21:02,590 Okay. 259 00:21:02,630 --> 00:21:05,410 What is my least favorite LDAP token type? 260 00:21:05,430 --> 00:21:08,510 I'm assuming Boolean operator, but let's see what happens here. 261 00:21:08,930 --> 00:21:12,550 Yep, Boolean operator, because I'm afraid of getting tied up in knots. 262 00:21:12,770 --> 00:21:14,670 Oh, that's cringe, Clippy. 263 00:21:14,770 --> 00:21:15,990 Clippy's losing steam fast. 264 00:21:15,990 --> 00:21:16,910 Yeah, get that out of the way. 265 00:21:16,910 --> 00:21:17,550 Okay. 266 00:21:17,670 --> 00:21:20,270 All right, the fourth token type extensible match filter. 267 00:21:20,470 --> 00:21:21,590 So Sabi mentioned this before. 268 00:21:21,590 --> 00:21:24,070 This is for attributes that have bitwise values. 269 00:21:24,070 --> 00:21:32,290 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. 270 00:21:33,050 --> 00:21:44,670 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. 271 00:21:44,670 --> 00:21:46,230 And that's the and and the or. 272 00:21:46,290 --> 00:21:49,510 For me, I remember the or because it ends with dot 804. 273 00:21:49,510 --> 00:21:52,850 So 804 is or 803 is not or. 274 00:21:53,870 --> 00:21:55,390 All right, so here's an example. 275 00:21:55,390 --> 00:21:58,730 User account control, and you can see in the red is the extensible match filter. 276 00:21:58,830 --> 00:22:06,030 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. 277 00:22:06,090 --> 00:22:08,870 So one of the things we can do is what we've called bitwise breakout. 278 00:22:08,890 --> 00:22:12,330 So we can break that 515 out into 1 and 514. 279 00:22:12,330 --> 00:22:16,170 Again, as long as we have the proper grouping of add-ins, we can do this. 280 00:22:16,290 --> 00:22:18,410 514 is actually 2 and 512. 281 00:22:18,410 --> 00:22:20,250 So we can break that out even further. 282 00:22:20,390 --> 00:22:25,590 So from a detection perspective, we can spread our logic across many different filters, which is really, really complicated. 283 00:22:26,510 --> 00:22:27,890 But it's also fun. 284 00:22:27,990 --> 00:22:30,610 If you started with an or, the same trick applies. 285 00:22:30,610 --> 00:22:35,710 Just make sure that the Boolean operator you add is an or instead of an and and that it matches the extensible match filter. 286 00:22:36,990 --> 00:22:41,130 This is a pretty trivial example, but a lot of real world examples can get pretty crazy. 287 00:22:41,130 --> 00:22:43,550 Like this is a git domain user from PowerView. 288 00:22:43,610 --> 00:22:44,570 Massive number. 289 00:22:44,570 --> 00:22:51,470 You can imagine all the random groupings and regroupings of base two add-ins to produce the same value in your overall search filter. 290 00:22:53,190 --> 00:22:56,930 So another thing we can do is if you have a filter that is a precise value. 291 00:22:56,930 --> 00:23:01,090 So this is looking for the exact ones and zero set to equal this number. 292 00:23:01,410 --> 00:23:04,450 What you can do is use this little formula. 293 00:23:04,450 --> 00:23:08,350 You can add the extensible match filter of and for all the one bits. 294 00:23:08,350 --> 00:23:14,450 You can add the or extensible match filter for all the zero bits and negate it and then and both of those filters together. 295 00:23:14,970 --> 00:23:24,430 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. 296 00:23:24,430 --> 00:23:30,570 So we're not going to take this further, but this could explode into 10, 15, 20 different filters all slammed together. 297 00:23:31,170 --> 00:23:40,810 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. 298 00:23:43,770 --> 00:23:45,190 Thanks, Thibaut. 299 00:23:45,610 --> 00:23:49,490 Let's look at what we can do to obfuscate a little the value. 300 00:23:49,490 --> 00:23:51,470 We are still in the filter section. 301 00:23:51,530 --> 00:23:58,590 So excluding a couple of attribute types, just like seeing here, it is still casing doesn't matter. 302 00:23:58,590 --> 00:24:00,110 So it's case sensitive. 303 00:24:00,810 --> 00:24:07,870 And we can also do prepended zeros to anything that are bitwise digits or numbers. 304 00:24:08,430 --> 00:24:21,090 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. 305 00:24:21,090 --> 00:24:33,130 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. 306 00:24:33,130 --> 00:24:39,790 So and technically, it is going to be treated still as a correct timestamp in the results. 307 00:24:39,790 --> 00:24:53,710 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. 308 00:24:53,950 --> 00:25:06,890 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. 309 00:25:06,890 --> 00:25:11,750 But you can also escape any printable characters that you want to as well. 310 00:25:12,170 --> 00:25:19,290 So you can swap these with the hex representations, and it's still going to be to give you the same results. 311 00:25:19,290 --> 00:25:23,030 And it's going to show just like this on the client side logs. 312 00:25:23,310 --> 00:25:28,970 Again, our parser, our parser parses codes decodes all the values. 313 00:25:28,970 --> 00:25:31,510 So it's all being handled. 314 00:25:32,050 --> 00:25:42,850 One undocumented thing is that Microsoft says that the hex representation should be followed by two characters representative SK hex character. 315 00:25:42,850 --> 00:25:50,510 But that's actually not true for the first 16 characters, you can drop the leading zero and it's still going to work. 316 00:25:51,190 --> 00:25:55,450 Wildcards, we mentioned a little bit even on the wildcards. 317 00:25:55,490 --> 00:26:03,310 So for example, instead of looking for the curb TGT, you can also just look for RBG and see what you get. 318 00:26:04,730 --> 00:26:11,590 These actually for wildcards, we are not the only ones who have been looking for evasion purposes. 319 00:26:11,590 --> 00:26:25,050 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. 320 00:26:26,570 --> 00:26:33,970 As a recap , for value, we can do casing, we can do prepended zeros , timestamps, hex encoding, and wildcards. 321 00:26:34,870 --> 00:26:38,610 The good news is that's all you can do with obfuscation. 322 00:26:39,030 --> 00:26:41,990 Nah, I'm lying, you guys, we got much more. 323 00:26:42,350 --> 00:26:46,370 So until now, we actually were looking for top and obfuscation. 324 00:26:46,370 --> 00:26:48,730 Let's see outside of it a little. 325 00:26:49,350 --> 00:27:01,430 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. 326 00:27:01,610 --> 00:27:07,250 You can also add white space all over, and it is significant. 327 00:27:07,270 --> 00:27:10,370 And it can be new line, tab, etc. 328 00:27:10,670 --> 00:27:27,250 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. 329 00:27:27,250 --> 00:27:29,950 But you can go crazy with ours. 330 00:27:30,270 --> 00:27:33,910 And lastly, is filter filter reordering. 331 00:27:34,410 --> 00:27:38,530 So until now, we only handled the filter. 332 00:27:38,530 --> 00:27:41,270 Let's see what we can do with base object. 333 00:27:42,230 --> 00:27:46,530 As a reminder, the base object is where in the active directory. 334 00:27:46,530 --> 00:27:54,870 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. 335 00:27:54,930 --> 00:28:04,130 And for example, like some offensive tools, just like certify, they have a very benign common and super search, super common search filter. 336 00:28:04,170 --> 00:28:17,770 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. 337 00:28:18,050 --> 00:28:37,370 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. 338 00:28:38,530 --> 00:28:46,950 And white space, it actually can be added at the end, as well as between the slashes of the LDAP prefix. 339 00:28:47,770 --> 00:29:07,630 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. 340 00:29:08,990 --> 00:29:11,970 Lastly, is the attribute selection. 341 00:29:11,970 --> 00:29:17,030 Basically, it's which attributes properties do you want to be returned in the results. 342 00:29:17,390 --> 00:29:37,570 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. 343 00:29:37,570 --> 00:29:41,310 Not sure why, but yeah, a lot of trial and error, to be honest. 344 00:29:41,450 --> 00:29:49,650 We have the option also to add duplicate attributes, and garbage attributes, literally anything you want. 345 00:29:50,790 --> 00:29:56,150 And the person who's going to answer about this is no one else than Clippy. 346 00:29:57,070 --> 00:30:00,090 Hey, Daniel, what do you call this character? 347 00:30:00,270 --> 00:30:02,570 Asterix, wildcard or splat? 348 00:30:03,710 --> 00:30:05,870 I think this is an ages question. 349 00:30:05,870 --> 00:30:07,890 But all three are true. 350 00:30:07,890 --> 00:30:10,070 But there's a lot of space down there. 351 00:30:10,070 --> 00:30:11,610 So let's see what Clippy has to say. 352 00:30:12,010 --> 00:30:13,530 F, all the above. 353 00:30:13,530 --> 00:30:17,370 So two more important things here is from an input perspective and the attribute selection. 354 00:30:17,490 --> 00:30:25,150 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. 355 00:30:25,150 --> 00:30:33,090 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. 356 00:30:33,310 --> 00:30:44,830 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. 357 00:30:44,990 --> 00:30:53,550 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. 358 00:30:53,550 --> 00:30:58,490 So you have to do a really specific split and translation that we that we do in the logging module. 359 00:30:58,490 --> 00:31:00,670 But just know there's some weirdness that goes on there. 360 00:31:01,150 --> 00:31:02,170 Thanks, Clippy. 361 00:31:02,590 --> 00:31:05,970 All right, now that is actually the end of the obfuscation portion. 362 00:31:05,970 --> 00:31:09,830 So we've talked about the search filter, we've talked about the base object, the attribute selection. 363 00:31:09,830 --> 00:31:12,710 So for all the defenders in the room, what now? 364 00:31:12,730 --> 00:31:16,770 So from a solution perspective, we're going to focus on three steps. 365 00:31:16,770 --> 00:31:21,270 One is parsing, two is enriching, and then three is the actual detection itself. 366 00:31:21,550 --> 00:31:26,630 So from a parsing perspective, when we started this research, there was no parser for LDAP search filters. 367 00:31:26,870 --> 00:31:29,330 And so we naively said, let's just build a parser. 368 00:31:29,330 --> 00:31:30,410 How hard could it be? 369 00:31:30,410 --> 00:31:36,490 To be honest, that was over half of the research, but it was one of the most interesting and fulfilling parts of this. 370 00:31:36,490 --> 00:31:40,690 And so we wrote a C sharp state machine parser to firstly do tokenization. 371 00:31:40,690 --> 00:31:44,650 So that means when you have a string come in, that's the entire search filter, let's break it into tokens. 372 00:31:44,650 --> 00:31:48,310 So we know which ones are attributes, values , comparison operator, etc. 373 00:31:48,330 --> 00:31:57,650 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. 374 00:31:57,650 --> 00:32:01,090 And then you can move on to actual enrichment, which is step number two. 375 00:32:01,090 --> 00:32:11,550 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. 376 00:32:11,550 --> 00:32:15,190 So as Sabi mentioned, when there are hex values, we'll automatically decode them for you. 377 00:32:15,190 --> 00:32:18,270 But we leave the original syntax as well. 378 00:32:18,390 --> 00:32:32,070 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, 379 00:32:32,070 --> 00:32:33,790 like insignificant white space. 380 00:32:33,870 --> 00:32:36,290 Well, by definition, obfuscation doesn't need to be there. 381 00:32:36,290 --> 00:32:41,990 So we actually want to keep all those insignificant things so we can recreate the input from that parse tree. 382 00:32:42,250 --> 00:32:55,250 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. 383 00:32:55,430 --> 00:32:57,810 And then the final step is actually detect. 384 00:32:57,810 --> 00:33:00,050 So we try to make it as simple as possible. 385 00:33:00,050 --> 00:33:03,130 We wrapped all this inside of a single function called find evil. 386 00:33:03,310 --> 00:33:06,250 So you can pipe any number of search filters you want into find evil. 387 00:33:06,250 --> 00:33:10,090 And for each of those filters, it will parse it, do all the enrichment we just talked about. 388 00:33:10,090 --> 00:33:14,170 It will run it through all our complete detection rule set, which we are releasing with maladaptive. 389 00:33:14,170 --> 00:33:15,850 So 65 rules and counting. 390 00:33:16,010 --> 00:33:22,010 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. 391 00:33:22,010 --> 00:33:24,330 So it'll give you an example of what kind of thing it's looking for. 392 00:33:24,330 --> 00:33:31,650 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. 393 00:33:31,650 --> 00:33:33,250 It'll actually pull out specific values. 394 00:33:33,250 --> 00:33:39,230 So it should be really colorfully obvious, as you'll see in the demo, of exactly why this thing was flagged for this rule. 395 00:33:39,390 --> 00:33:44,030 And if you look at the bottom, as I said, we spent over half the time just building this parser. 396 00:33:44,190 --> 00:33:49,770 We wrote and rewrote every piece of this parser two to three times to make it as fast as we possibly could. 397 00:33:49,910 --> 00:33:59,350 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. 398 00:33:59,390 --> 00:34:01,590 And that's on a moderately spec laptop. 399 00:34:01,610 --> 00:34:05,990 Because we know that the number, the volume of search filters in production environments is massive. 400 00:34:05,990 --> 00:34:08,970 And so we wanted this to be really usable right out of the box . 401 00:34:08,970 --> 00:34:12,850 Oh, and shout out to Olaf Hartung at Falconforce. 402 00:34:12,850 --> 00:34:23,370 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 . 403 00:34:23,370 --> 00:34:25,310 So, Olaf, if you're watching, thanks so much, buddy. 404 00:34:25,310 --> 00:34:26,150 We really appreciate it. 405 00:34:27,070 --> 00:34:31,870 So instead of talking more about the solution, let's go into the last section and actually just show a demo. 406 00:34:32,330 --> 00:34:35,210 If you haven't picked up on it by now, we really like to have fun. 407 00:34:35,210 --> 00:34:40,910 When you spend 2,000 hours on something, you have to trick yourself into being motivated, so we added colors however we can. 408 00:34:41,250 --> 00:34:47,370 This is our ASCII art, and it's actually a fully functioning LDAP query that will return any object that has a name property. 409 00:34:48,470 --> 00:34:49,630 Clippy seems to like it as well. 410 00:34:49,630 --> 00:34:53,190 I can't tell if he's hanging out or trying to eat the terminal or what's going on. 411 00:34:53,510 --> 00:34:59,710 So in the first example, this is that Albania, Cucos, Tirana filter example with a little bit of obfuscation. 412 00:34:59,750 --> 00:35:04,590 So if we tokenize it, we can see it breaks out which things are attributes, values, et cetera. 413 00:35:04,590 --> 00:35:10,170 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. 414 00:35:10,170 --> 00:35:12,490 And we have these other context objects as well. 415 00:35:12,490 --> 00:35:16,270 So if we look at the context object, remember this is things like the Boolean operator. 416 00:35:16,270 --> 00:35:21,010 We group all these things into filters so that we can write detection logic against the entire filter. 417 00:35:21,010 --> 00:35:25,490 So we can easily access the string values, but then we have a dictionary and list of the full token objects. 418 00:35:25,490 --> 00:35:28,870 So all the metadata nested from tokenization we can find in the filter. 419 00:35:29,030 --> 00:35:33,810 And then if we look at the context object for the Boolean operator, we'll see this is a logically inclusive filter. 420 00:35:33,870 --> 00:35:37,810 This is tracking that full stack of Boolean operators that you still have direct access to. 421 00:35:37,810 --> 00:35:41,110 And then every single value goes through the full value parsing. 422 00:35:41,110 --> 00:35:42,830 So any hex characters are parsed. 423 00:35:42,830 --> 00:35:46,050 At any time, you can look for the raw content or the decoded content. 424 00:35:46,110 --> 00:35:51,610 Pipe that into Find Evil, and we can see these are the individual rules that matched for this particular search filter. 425 00:35:51,670 --> 00:35:53,110 This is just showing a couple properties. 426 00:35:53,110 --> 00:35:56,850 In the next demos, you'll see a little better view of the entirety of the rules. 427 00:35:57,810 --> 00:36:00,650 Let's do another parsing example, this time using the bitwise value. 428 00:36:00,650 --> 00:36:04,550 So remember all the bitwise breakout where like 515 can be 1 , 2, 5, 12? 429 00:36:04,650 --> 00:36:11,530 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. 430 00:36:11,530 --> 00:36:24,890 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. 431 00:36:24,890 --> 00:36:28,430 So you can immediately write detections for combinations of true and false. 432 00:36:28,430 --> 00:36:39,710 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. 433 00:36:40,470 --> 00:36:45,370 The last parsing example is looking for some actually kind of crazy stuff. 434 00:36:45,370 --> 00:36:48,850 So decoding hex characters in this first example, that's easy sauce. 435 00:36:48,850 --> 00:36:50,910 So this is trusted domain, easy detection. 436 00:36:50,910 --> 00:36:57,310 But when it's things like wildcards, they're actually missing characters, so we can't precisely say what the person was looking for. 437 00:36:57,310 --> 00:37:11,710 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? 438 00:37:11,710 --> 00:37:18,050 And that also handles the two ANR scenarios that Sabi mentioned earlier, with the implicit wildcard or the explicit wildcard. 439 00:37:18,150 --> 00:37:26,530 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. 440 00:37:27,390 --> 00:37:35,070 And finally, we've put all this together into a colorful interactive menu to make it fun to explore. 441 00:37:35,070 --> 00:37:46,790 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. 442 00:37:46,870 --> 00:37:49,710 Wildcards are also supported. 443 00:37:50,730 --> 00:37:55,670 We can add obfuscation layer by layer, and we can also remove it. 444 00:37:55,670 --> 00:38:01,670 And if you're lazy, you can use all wildcards to randomly apply all the options. 445 00:38:02,530 --> 00:38:04,730 Let's test again. 446 00:38:05,210 --> 00:38:07,870 The search filter still works. 447 00:38:07,870 --> 00:38:18,200 Detection module is built in and findevils shows a full summary of detections, scores, explanations, and more colors. 448 00:38:19,090 --> 00:38:24,430 Lastly, if you don't like interactive menus, we have full CLI support. 449 00:38:24,430 --> 00:38:34,470 So the interactive menu lets you randomly choose ingredients, and you can copy out the receipt for non interactive user. 450 00:38:34,530 --> 00:38:40,730 All the pictures for pretty printing and detection summaries are also available via CLI. 451 00:38:49,930 --> 00:38:50,790 Thank you. 452 00:38:50,950 --> 00:38:52,910 It's always awkward in blue teamer talks. 453 00:38:52,930 --> 00:38:54,210 Was that a shell ? 454 00:38:54,210 --> 00:38:55,410 Do we clap or not? 455 00:38:55,970 --> 00:38:58,190 Our apologies for not including a dramatic pause. 456 00:38:58,710 --> 00:39:00,550 Hopefully that was fun for everyone. 457 00:39:01,510 --> 00:39:02,850 We're almost done here. 458 00:39:02,850 --> 00:39:12,230 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. 459 00:39:12,230 --> 00:39:17,250 So why hand them a fully loaded machine gun when defenders still often don't even have the telemetry in the first place? 460 00:39:17,250 --> 00:39:19,130 So from the very beginning , we weren't strong armed. 461 00:39:19,130 --> 00:39:23,150 We decided that we wanted to release this in a unique kind of two-stage approach. 462 00:39:23,150 --> 00:39:28,010 So today what we've released is everything we've talked about, minus the obfuscation module. 463 00:39:28,110 --> 00:39:36,450 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. 464 00:39:36,850 --> 00:39:43,670 For anyone who's really ambitious, you have the full parser, and the deobfuscation modules look suspiciously like the obfuscation ones. 465 00:39:43,670 --> 00:39:45,550 So if you want to do a little bit, go for it. 466 00:39:45,550 --> 00:39:51,770 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. 467 00:39:51,890 --> 00:40:06,530 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, 468 00:40:06,530 --> 00:40:09,750 and then at that point, releasing the obfuscation module. 469 00:40:10,670 --> 00:40:12,610 So yeah, just want to make that really clear. 470 00:40:12,610 --> 00:40:15,210 That's clear on the GitHub, which will be on the last slide as well. 471 00:40:15,210 --> 00:40:22,930 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. 472 00:40:22,930 --> 00:40:24,890 And we made this very clear in the CFP process. 473 00:40:24,890 --> 00:40:26,610 Big red text, no surprises. 474 00:40:26,610 --> 00:40:30,510 So we're really happy that there was support in us doing that kind of a release. 475 00:40:30,810 --> 00:40:35,090 So the final takeaways, LDAP is still widely used by attackers. 476 00:40:35,090 --> 00:40:36,210 It's very valuable. 477 00:40:36,210 --> 00:40:41,490 And in our opinion, defensively, it's still kind of immature in terms of detection. 478 00:40:41,530 --> 00:40:43,650 It seems to be a lot of kind of string-based detections. 479 00:40:43,650 --> 00:40:50,770 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. 480 00:40:51,030 --> 00:41:02,530 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, 481 00:41:02,530 --> 00:41:06,910 start using it in your environment if you already have a mechanism to get all of those search filters. 482 00:41:07,770 --> 00:41:12,030 Our unofficial takeaway is we wanted to leave you with something a little different. 483 00:41:12,190 --> 00:41:17,730 And so we wanted to leave you with our, each of our favorite Albanian proverb. 484 00:41:17,930 --> 00:41:18,670 So I'm going to go first. 485 00:41:18,670 --> 00:41:21,330 I'm not a native speaker, so forgive my pronunciation. 486 00:41:21,330 --> 00:41:26,710 But mine is rofsah malet, which literally means live long like a mountain. 487 00:41:26,710 --> 00:41:28,710 It's kind of a blessing of well-being. 488 00:41:28,950 --> 00:41:32,610 I like to think of it in this scenario as we just climbed a crazy mountain together. 489 00:41:32,610 --> 00:41:34,550 I'm a little out of breath, personally. 490 00:41:34,710 --> 00:41:37,110 But in this industry, we have to help each other out. 491 00:41:37,110 --> 00:41:39,950 We have to recognize the shoulders that we stand on. 492 00:41:39,950 --> 00:41:50,010 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. 493 00:41:51,710 --> 00:42:04,890 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. 494 00:42:07,590 --> 00:42:09,710 It was fun while it lasted. 495 00:42:10,270 --> 00:42:10,910 All right. 496 00:42:10,910 --> 00:42:13,810 And with that, we just want to say thank you so much for your time. 497 00:42:13,810 --> 00:42:15,370 Thank you, DEF CON and to all the organizers. 498 00:42:15,370 --> 00:42:20,250 We had such a great time putting this research together, and we're really happy to be here. 499 00:42:20,250 --> 00:42:21,950 Here's all of our contact information. 500 00:42:21,990 --> 00:42:23,930 Here's the link to Mount Adaptive. 501 00:42:23,930 --> 00:42:25,930 Please reach out, and we'll be up here for questions. 502 00:42:25,930 --> 00:42:27,410 But thank you again for your time. 503 00:42:37,170 --> 00:42:39,330 Any brave souls for questions? 504 00:42:41,550 --> 00:42:44,130 Questions or criticisms, everything is welcome. 505 00:42:46,550 --> 00:42:48,030 One right here, yeah. 506 00:42:53,930 --> 00:42:58,610 So the question is, what was our process for finding all the undocumented stuff? 507 00:42:59,630 --> 00:43:07,810 Well, sometimes luck, sometimes... I think the best answer that we can give is, people ask us, why do you make obfuscation frameworks? 508 00:43:07,810 --> 00:43:14,590 It's kind of a little twisted, but it's really a way of kind of working backwards and defining a grammar. 509 00:43:14,590 --> 00:43:15,810 Because it's all a language , right? 510 00:43:15,950 --> 00:43:19,090 What's linguistically, syntactically allowed in a language? 511 00:43:19,090 --> 00:43:21,890 Whether that's PowerShell or LDAP or anything else. 512 00:43:21,890 --> 00:43:34,890 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. 513 00:43:34,890 --> 00:43:36,810 It wouldn't return the same results we expected. 514 00:43:36,810 --> 00:43:44,770 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? 515 00:43:44,770 --> 00:43:52,030 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. 516 00:43:52,250 --> 00:43:54,110 So that's how we found a lot of these examples. 517 00:43:54,110 --> 00:44:03,770 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. 518 00:44:03,770 --> 00:44:06,810 And so some of those tricks, you just kind of pick up along the way and keep carrying forward. 519 00:44:07,770 --> 00:44:08,650 But yeah, great question. 520 00:44:08,650 --> 00:44:09,050 Thank you. 521 00:44:09,750 --> 00:44:10,630 Yeah. 522 00:44:20,360 --> 00:44:21,360 Yeah, good question. 523 00:44:21,360 --> 00:44:28,780 So the question was, in our research, against the obfuscation techniques we found, how effective is Windows Defender or other tools like that? 524 00:44:28,800 --> 00:44:30,380 We don't have access to those tools. 525 00:44:30,380 --> 00:44:32,600 So actually don't know. 526 00:44:33,020 --> 00:44:44,200 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. 527 00:44:44,200 --> 00:44:50,160 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? 528 00:44:50,160 --> 00:44:54,360 Sometimes it's out of ignorance, sometimes more likely it's out of performance. 529 00:44:54,620 --> 00:45:04,440 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. 530 00:45:04,440 --> 00:45:12,780 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. 531 00:45:13,220 --> 00:45:22,440 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. 532 00:45:22,920 --> 00:45:23,720 Great question. 533 00:45:23,720 --> 00:45:24,460 Thank you. 534 00:45:25,500 --> 00:45:27,020 Any last questions? 535 00:45:29,020 --> 00:45:29,900 Yes. 536 00:45:34,280 --> 00:45:38,500 The question was, did we have trouble with all the colors for formatting? 537 00:45:38,740 --> 00:45:39,840 Trouble to who? 538 00:45:39,840 --> 00:45:40,340 The answer is 539 00:45:47,500 --> 00:45:47,780 yes. 540 00:45:47,780 --> 00:45:47,860 Yeah. 541 00:45:49,400 --> 00:45:57,940 So in terms of we actually did, we split our programming actually partially. 542 00:45:57,940 --> 00:45:58,920 We use PowerShell core. 543 00:45:58,920 --> 00:46:02,760 So we did a lot of it in Windows, a lot of it on Mac, a little bit in Linux just to test compatibility. 544 00:46:03,000 --> 00:46:06,820 But yeah, in terms of color differences, we actually stuck with the original colors, the original 16. 545 00:46:06,980 --> 00:46:12,180 We experimented with the dark colors for things like distinguished name values. 546 00:46:12,460 --> 00:46:17,400 Those are the darkened version of all the RDNs to represent the overall tokens. 547 00:46:17,400 --> 00:46:20,500 But that darkness shows up better on Windows. 548 00:46:20,500 --> 00:46:23,000 On Mac, it actually doesn't quite show up as much. 549 00:46:23,000 --> 00:46:26,900 But yeah, so that was a factor we had to kind of play around with. 550 00:46:27,620 --> 00:46:28,980 But yeah, I like the color question. 551 00:46:28,980 --> 00:46:29,920 I've never gotten that before. 552 00:46:29,920 --> 00:46:30,780 So thank you. 553 00:46:33,060 --> 00:46:33,580 All right. 554 00:46:33,580 --> 00:46:34,680 I think with this, we're at time. 555 00:46:34,680 --> 00:46:36,840 We'll be around front if anyone else wants to talk or ask questions. 556 00:46:36,840 --> 00:46:38,520 But again, thank you everyone for coming to the talk. 557 00:46:38,520 --> 00:46:39,240 Have a good one. 558 00:46:39,460 --> 00:46:39,780 . 559 00:46:40,220 --> 00:46:40,540 .