[00:00.000 --> 00:10.400] Okay. I am with the Packet Hacking Village, and this particular speaker is being sponsored by us. [00:10.400 --> 00:17.760] And we are delighted to present Brandon Colley, who is going to obviously talk to you about Active Directory. [00:17.760 --> 00:22.820] He has been... he'll tell a little bit about himself, but he works for Trimark Security, [00:22.820 --> 00:26.660] and I'm also proud to call him friend. Take it away. [00:26.660 --> 00:36.030] Thank you, Kathy. Friend Kathy. Investigator chick, everybody. [00:37.630 --> 00:42.190] All right. Can you guys hear me okay in the back? Awesome. Let's do this. [00:42.230 --> 00:47.230] So title, as you all know, is Winning the Game of Active Directory. [00:47.470 --> 00:54.310] So a little bit about myself is I served in an operations role, managed Active Directory for about 15 years [00:54.310 --> 01:00.270] for multiple different organizations before I joined Trimark about two and a half years ago. [01:00.270 --> 01:08.750] I was a senior security consultant for them and just got promoted to the service lead role for our Microsoft Cloud assessment. [01:09.050 --> 01:14.350] So I'm kind of joking and saying that this might be my last on-prem Active Directory presentation. [01:14.650 --> 01:19.390] So maybe next year you'll come to see, like, Winning the Game of Entra ID or something like that. [01:20.750 --> 01:25.990] Recently founded my own company and got a logo created, so I threw it up there. [01:25.990 --> 01:28.810] So B&R Consulting is a company that I just started. [01:28.810 --> 01:35.050] I'm a father. Here's one of my kids with me at a Chiefs game. I saw a Chiefs hat. Go Chiefs! [01:35.710 --> 01:42.170] And my wife Bridget came with me today, so I am a very loving husband, as I hope she'd also agree. [01:42.610 --> 01:46.010] First time at DEF CON as well, so... [01:51.320 --> 01:57.260] And so before we really start digging in, I want, I mean, the title of the game is How to Win the Game of Active Directory. [01:57.420 --> 02:01.860] So let's talk about what I'm talking about when I talk about the Game of Active Directory. [02:01.860 --> 02:06.640] So GoAD, as I like to call it, or somebody said GoAD. [02:06.640 --> 02:12.320] So Prebuilt Active Directory Lab is a multi-domain environment. [02:12.320 --> 02:21.140] They have multiple different builds that you can create and touts over 30 different vulnerable configurations just out of the box. [02:21.160 --> 02:25.200] It's created and maintained by Mayfly of Orange Cyber Defense. [02:25.200 --> 02:30.220] And Mayfly gave me permission to go ahead and use this in the presentation. [02:30.220 --> 02:34.300] He just wanted to know when it gets posted online, and he wants my slides. [02:34.300 --> 02:40.260] So it was originally created for penetration testers to practice attacking Active Directory. [02:40.260 --> 02:46.520] So real quick, where are my penetration testers in the audience, or any red team side people? [02:46.520 --> 02:48.520] How about anybody on the blue side? [02:48.860 --> 02:50.760] Okay, so we're heavily blue. Awesome. [02:50.760 --> 02:53.940] And then everyone else is just unaffiliated, I'm assuming. [02:54.440 --> 02:56.000] You don't get a vote. [02:57.060 --> 03:01.840] So when you start playing a game, first thing you have to do is character selection screen, right? [03:01.840 --> 03:08.220] So we can choose to be a penetration tester, which your job is to exploit vulnerabilities, misconfigurations. [03:08.720 --> 03:13.300] Moving to a little bit of a red teamer, you're going to start looking a little bit more at testing detections [03:13.300 --> 03:18.660] and doing a little bit more stealthy activities when performing Active Directory tests. [03:18.700 --> 03:24.700] And then our defenders, like most of you, are looking forward to learning how to harden your environments, [03:24.700 --> 03:27.840] performing consistent monitoring of those environments, [03:27.840 --> 03:32.040] and just consistently improving the overall security posture of your Active Directory. [03:32.860 --> 03:35.160] The other character you could choose is to be an adversary, [03:35.160 --> 03:39.720] so I'm going to assume that the rest of you who didn't raise your hands are my adversaries, right? [03:39.740 --> 03:41.620] But they don't play by the rules anyway. [03:42.740 --> 03:45.840] So the most important rule when you play a game is how do you win, right? [03:45.840 --> 03:48.900] And that's what I'm here to talk about, is how do you win the game of Active Directory. [03:48.960 --> 03:54.080] And a lot of people think that you can win the game of Active Directory by gaining domain admins, right? [03:54.080 --> 03:58.240] That's the keys to the kingdom. Once you get domain admin, it's game over. [03:58.380 --> 04:04.760] It may be a spill of data. Maybe you want some of that juicy information that's in Active Directory. [04:05.220 --> 04:11.180] Or maybe you just want to create persistence and you want to be slow and methodic about your efforts. [04:11.200 --> 04:17.360] However, I'm here to kind of challenge that a little bit and say that the way that you truly win the game of Active Directory, [04:17.360 --> 04:22.320] regardless of which character you choose, is to maintain a secure environment, [04:22.320 --> 04:28.320] continuously improve that environment, and implement the safeguards that are needed to keep your Active Directory safe. [04:28.320 --> 04:33.320] And also continuous progress. So what I'm here to do today is kind of show you both sides of that. [04:33.320 --> 04:37.760] I'm going to take a little bit of an attack methodology and also defense methodology. [04:37.760 --> 04:43.780] So we have a... Ted Mosby likes to say, we have a tightly scheduled evening of awesomeness ahead of us, so let's go. [04:43.780 --> 04:47.840] And I guess technically now it is evening. Or afternoon, anyway. [04:47.840 --> 04:51.640] So our agenda, we're going to stick with the gameplay idea. [04:52.160 --> 04:58.200] We've got three different levels. So level one, we're going to call Reconnaissance, Enumeration, PrivEsc. [04:58.200 --> 05:03.180] And then level four is when we pwn Active Directory, and that's really our end boss. [05:07.780 --> 05:19.540] So starting off with Reconnaissance, our first question when we are either protecting or attacking Active Directory is kind of what's visible with simply network access. [05:19.540 --> 05:27.420] No usernames, no passwords, we just are on the network, and maybe in this case we just know the IP address of a domain controller. [05:27.420 --> 05:33.680] So here's an example of using CrackMap Exec, and this is our first misconfiguration, which is called anonymous access. [05:33.680 --> 05:40.080] If this is configured in your domain, anybody with network access, direct line of sight to your domain controller, [05:40.080 --> 05:46.780] can query for a list of users, as well as some of the public information, such as description. [05:46.780 --> 05:53.040] And so here if we drill in, we identify that we've already got our first credential in Samuel, [05:53.040 --> 05:59.040] who must have had an administrator put his password in the description field for some odd reason. [06:00.440 --> 06:05.100] So how do we mitigate this, other than just don't put passwords in description fields, right? [06:05.100 --> 06:12.580] That's kind of the obvious one here, is removing these groups from your domain. [06:12.580 --> 06:20.440] Domain root, sorry. The pre-Windows 2000 group, I'm not saying to delete this from the domain root, [06:20.440 --> 06:26.680] but if the members of this include the everyone group, or the authenticated, I'm sorry, not authenticated, [06:26.680 --> 06:31.780] the anonymous logons group, then this is possible. [06:32.000 --> 06:36.180] In the Go lab, the screenshot on the right is actually how it was configured, [06:36.180 --> 06:40.100] is you're just giving root access to anonymous logon, [06:40.100 --> 06:45.800] and that's what enables the ability to see everything without having any sort of initial user. [06:46.560 --> 06:50.280] So once we've removed that, we rerun the attack, we get nothing. [06:50.440 --> 06:56.500] So we get an error message, nothing comes back, anonymous access no longer relevant, [06:56.500 --> 06:58.280] so now we have to dig in a separate way. [06:58.980 --> 07:02.880] So if we can't do it anonymously, we're going to have to build a user list. [07:02.880 --> 07:10.380] And so the game of Active Directory, if you've used it before, you may know it's based on the game of Thrones, [07:10.380 --> 07:12.700] which is kind of where the game of thing comes from, right? [07:12.700 --> 07:16.000] So this is a good place for us to start scraping credentials. [07:16.480 --> 07:19.300] I'm sorry, not credentials, usernames. [07:19.300 --> 07:25.340] So we're going to pull out the first names, last names, combine those, and form a user list. [07:25.520 --> 07:31.780] So the screenshot on the left is the user list that I'm using, which is a first name dot last name. [07:31.780 --> 07:35.660] That's the methodology that's used in the lab. [07:36.160 --> 07:41.360] But in your environments, it might be first initial dot last name, you might not have a dot, [07:41.360 --> 07:44.940] it might be your last name and then your first name, something like that. [07:44.940 --> 07:48.200] So we can go ahead and we can throw all of those into a user list. [07:49.060 --> 07:54.220] And then we can attack Active Directory, still anonymously, using a script like this. [07:54.220 --> 08:00.640] So this is just an in-map script that all you need to have is your user list in a text file. [08:00.640 --> 08:05.900] And again, the domain IP, and what it's going to do is it's going to attempt to authenticate to Kerberos, [08:05.900 --> 08:07.440] or it's going to query Kerberos. [08:08.660 --> 08:11.080] Kerberos is going to come back and tell you one of two things. [08:11.080 --> 08:14.560] It's either going to say, yeah, that's valid or no, that's invalid. [08:14.560 --> 08:19.640] So now we've got a list of nine valid accounts that were in that file. [08:19.640 --> 08:22.340] And so now we know who we can attack. [08:22.340 --> 08:25.780] And you guys might say, hey, it's not fair. You knew it was the Game of Thrones. [08:25.780 --> 08:26.940] So you knew who you were attacking. [08:26.940 --> 08:34.760] Well, there are plenty of lists out there on GitHub that you can just do a very top 100 common names, [08:34.760 --> 08:36.740] and you can do the same style of attack. [08:36.740 --> 08:40.380] And once you get one or two hits, then you kind of know the naming convention. [08:40.660 --> 08:46.560] And then you just go out to LinkedIn and you search up Microsoft or whoever you're attacking, [08:46.560 --> 08:48.120] and you scrape from there. [08:48.120 --> 08:52.080] So this is real-world stuff that you can obviously do. [08:53.860 --> 08:59.160] And so the reason that this works is it's ingrained in the Kerberos protocol. [08:59.160 --> 09:05.120] So if an account doesn't exist, then you're going to get this first error message, which is that the principle is unknown. [09:05.160 --> 09:09.900] If the user does exist, you're going to get one of those other two responses. [09:09.900 --> 09:13.400] And that's basically what happens under the covers of this nmap script. [09:13.400 --> 09:15.220] Sorry, I'm going to drink, and this is weird. [09:26.770 --> 09:35.690] Okay, so the fix for this is not easy and sometimes not even possible. [09:35.950 --> 09:40.910] And this is a no-fix bug, I guess you can say. [09:40.910 --> 09:44.770] Microsoft doesn't consider user enumeration to be a bug. [09:44.770 --> 09:51.010] So the best thing that we can really offer is just, if you're looking at being able to change things, [09:51.010 --> 09:56.030] is don't use the same email address that you use for your same account name or vice versa. [09:56.550 --> 10:03.590] Instead, maybe create some sort of non-standard naming convention by throwing something about the department or the type of person. [10:04.010 --> 10:09.930] Like I used to work at a university, so maybe like a F for faculty, S for staff, A for administration. [10:10.150 --> 10:14.110] Maybe you do F for finance, I for IT, something like that. [10:14.110 --> 10:17.730] Or probably the best thing to do is use multiple trailing digits. [10:18.470 --> 10:24.310] And this is going to exponentially create a whole lot more trouble where you're going to have to have a much larger user list [10:24.310 --> 10:29.030] and a whole lot more time to be able to really enumerate a full contents of Active Directory. [10:29.130 --> 10:31.010] And I understand that this is hard. [10:31.990 --> 10:37.310] Mitigations are more around password policies, which we're going to attack here in a little while. [10:37.890 --> 10:45.270] But because I talked about the Kerberos protocol, I want to go back through another anonymous thing that you can do, [10:45.270 --> 10:48.750] is attack Kerberos pre-authentication. [10:48.750 --> 10:50.710] And so this is known as an AS rep-roast. [10:50.710 --> 10:56.590] And so this is what it looks like when you perform an AS rep-roast attack using the ImpactKit toolkit. [10:57.250 --> 11:03.510] And accounts that do not require pre-authentication are going to come back and give us a password hash. [11:03.510 --> 11:09.370] So in this case, Brandon Stark, no relation by the way, gives us password hash for free. [11:11.390 --> 11:18.030] And with that, we can use Hashcat or John the Ripper or some other offline attack tool where we can throw this through, [11:18.030 --> 11:24.470] and I just threw it through a ROKU, which is just a typical user list, password list, sorry. [11:24.790 --> 11:30.070] And we get the cleartext credentials in just a matter of a few minutes. [11:34.670 --> 11:39.550] So fixing this is pretty easy. It's just a checkbox. [11:39.550 --> 11:44.150] So there is a Kerberos pre-authentication checkbox on user accounts. [11:44.150 --> 11:46.890] It says do not require Kerberos pre-authentication. [11:46.890 --> 11:52.450] This is a super, super legacy thing, pretty free of a win in an environment. [11:52.450 --> 11:57.750] So if you've got any of this in your environment, removing that checkbox is going to mitigate it, [11:57.750 --> 12:03.510] which means after we remove that checkbox, Brandon no longer gives out his password freely. [12:03.870 --> 12:10.230] So we're going to have to attack the passwords using some of the more well-known styles of password attacks. [12:18.400 --> 12:23.460] Okay, so password attacks kind of fall into a few different categories. [12:23.460 --> 12:27.660] And so we're going to attack password reuse by doing a password spray. [12:27.660 --> 12:38.640] And so password spray is trying a small handful of passwords against all usernames in an environment. [12:38.640 --> 12:43.580] So in this case, I used some of the passwords that I already found in the environment. [12:43.580 --> 12:48.660] And I'm just seeing if there's possible password reuse across user accounts. [12:48.660 --> 12:50.440] In this one, it didn't hit anything. [12:50.440 --> 12:58.240] But some common uses for this is things like using Summer 2024 or Defcon 32 or whatever, right? [12:58.260 --> 13:00.820] And just seeing kind of what hits. [13:03.140 --> 13:06.180] A similar attack is a credential stuff attack. [13:06.180 --> 13:09.960] And this is more commonly used with breach credentials. [13:09.960 --> 13:18.360] So this is also a password reuse attack, but it's more specific to the user account themselves or the user themselves. [13:18.360 --> 13:21.740] So if they use the same password, say, for LinkedIn, [13:21.740 --> 13:30.920] and we're able to identify that the email address that they signed in with LinkedIn was the same as the Active Directory that we're attacking, [13:30.920 --> 13:36.460] it's possible that we may be able to hit something using a credential stuffing attack. [13:36.660 --> 13:46.260] In this specific screenshot, I kind of lazily just used the same user list as the password list, [13:46.260 --> 13:51.920] which simulates the situation where a user has the same password as their username, [13:51.920 --> 13:58.580] which is not terribly common anymore, but used to be common around, like, service accounts and things like that. [13:58.580 --> 14:04.220] So if you've got passwords that haven't changed in your environment for a very long time, this may be possible. [14:04.760 --> 14:06.940] And so we did get a hit on that one. [14:07.160 --> 14:13.560] We got the account Hodor, which we'll use later in another authenticated attack. [14:13.560 --> 14:19.360] But so some of the things that we can do is, and I showcase here just checking out the password policy, [14:19.360 --> 14:23.240] to prove that you can view it as any user in the domain. [14:23.240 --> 14:30.100] So once you have that initial user, you can query the password policy and maybe tailor your password attacks a little bit more specific. [14:30.520 --> 14:35.180] And so if you're wondering why on earth someone could have the same username and password, [14:35.180 --> 14:39.620] it's due to the complexity requirement that's disabled in this lab. [14:39.620 --> 14:44.760] Also, the character limit is only five, which I have seen worse than that. [14:44.760 --> 14:47.640] So five, not the worst. [14:48.480 --> 14:53.060] Some other things that you want to do with your password policy, other than kind of the obvious two there, [14:53.060 --> 14:59.600] is looking at some of the account lockout threshold, and also some of the other password requirements in there. [14:59.600 --> 15:03.620] I do have a link to an article I wrote called Password Policy a la carte. [15:03.620 --> 15:08.600] That's going to be in my resources. So check that out after the talk. [15:09.900 --> 15:17.180] I do want to talk a little bit about account lockout, because it is an effective strategy to blocking some password style attacks. [15:17.200 --> 15:20.820] I'm not going to talk about monitoring, because that's another thing. [15:21.440 --> 15:25.180] But you can query things using password crack map exec. [15:25.180 --> 15:28.380] And so here I've just simulated something. [15:28.380 --> 15:34.860] This is an oopsie. So for the red teamers, you're probably somewhat familiar, hopefully not, with seeing something like this, [15:34.860 --> 15:39.880] where you see log on failure, log on failure, log on failure, and then you see account locked out. [15:39.880 --> 15:44.080] And hopefully this is just the one account and not like all the accounts, right? [15:44.580 --> 15:50.540] Mistakes happen. But log on failures are going to kind of reset that account lockout counter. [15:51.360 --> 15:53.880] So to help combat that, whether you're looking... [15:53.880 --> 15:59.580] I am showing the attack tools, but defense tools is kind of another way that you can look at stuff like this. [16:00.160 --> 16:09.280] When we rerun the crack map exec script using the user's flag authenticated, we can get the bad password count. [16:09.380 --> 16:13.120] So here we identify the very bottom account was the one that we accidentally locked out. [16:13.120 --> 16:22.620] The other ones are sitting at four, and so we can wait for those password resets to retime before you attempt to attack them again. [16:24.660 --> 16:33.900] So that concludes level one. Yes, so we gained three account credentials, but that's not necessarily the goal that we talked about. [16:33.940 --> 16:40.960] So the goal, rather than getting those credentials, is more so the vulnerabilities that we've identified as being able to patch. [16:40.960 --> 16:48.500] And so in level one, we talked about anonymous access, removing that from an environment, using a little bit more robust usernames, [16:48.500 --> 16:54.940] and how attacks like that might occur, Kerberos pre-authentication and how that's a pretty quick, easy win, [16:54.940 --> 16:58.400] and then improvements to password hygiene and account lockout. [16:59.740 --> 17:10.760] All right, so on to level two. I like that cute little bunny over there. [17:12.400 --> 17:22.060] So I called this one enumeration, and then I told myself, nah, I should change it, because this is a little bit more like privilege escalation and lateral movement stuff, [17:22.060 --> 17:26.100] and I realized that whatever, it's just hard, so we're just going to call it more hacks. [17:28.300 --> 17:33.880] So the main difference between this level and the first level is that we're doing a little bit more while authenticated. [17:34.000 --> 17:39.340] So what type of Active Directory presentation would be complete without talking about Kerberosting? [17:39.340 --> 17:45.320] So Kerberosting is an attack on accounts that have service principal names or SPNs. [17:45.320 --> 17:48.520] So here's what that looks like. It's an authenticated attack. [17:48.520 --> 17:55.640] You're able to identify both John Snow and the SQL service account are vulnerable to a Kerberosting attack. [17:56.100 --> 18:00.660] So we're going to take those hashes. We're going to throw those through Hashcat again. [18:02.060 --> 18:07.800] And here we cracked the John Snow account because it was a weak password. [18:09.240 --> 18:13.980] So you can run something like this. So this is a quick PowerShell search that you can run. [18:14.180 --> 18:19.780] Get AD user where you just are looking for accounts that have service principles. [18:20.100 --> 18:24.760] And these usually are not cleaned up because service accounts are scary. [18:24.760 --> 18:30.320] So if you're an administrator, you don't want to touch a service account because you don't know if it's being used or where it's used, [18:30.320 --> 18:35.180] and you dare not change the password because you have no idea where to change it, what's going to break, and change it back. [18:35.180 --> 18:38.040] Like what's going to happen, right? I've been there. I did that for 15 years. [18:38.040 --> 18:40.920] And no, I didn't do this. And no, I didn't change those passwords. [18:41.840 --> 18:48.740] But what I'm telling you we can do is we can look at things like LastLogon, which may not be 100% accurate, but it may be helpful. [18:49.760 --> 18:57.040] Is the account privileged? If it's privileged and it's Kerberostable, then that's pretty much a free win for an adversary. [18:57.040 --> 19:01.280] So specifically look at those first. [19:01.480 --> 19:06.160] For the remaining ones, go ahead and look at what the service principle says. [19:06.160 --> 19:12.360] So in our case, the John Snow account, and I realize that's a little bit small, but there's a HTTP setting in there. [19:12.360 --> 19:17.420] So there's a website that it's attempting to coordinate with called the wall.north, seven kingdoms, etc. [19:17.860 --> 19:20.940] If I check DNS for that, it doesn't even exist. [19:20.940 --> 19:27.220] So if I can't access that web server at all, then this service account's not doing anything. [19:27.260 --> 19:29.280] So we're going to go ahead and remove that. [19:29.280 --> 19:34.360] The one that's going to remain is the SQL service account because it actually is running SQL. [19:34.360 --> 19:36.060] It's required to do that. [19:36.100 --> 19:41.540] That one didn't crack because it's using a long, strong, complicated, random password. [19:41.820 --> 19:48.840] And so that's how you protect other accounts that are Kerberostable is with that. [19:48.840 --> 19:52.480] And so this is what the attack looks like now that we removed the service principle. [19:52.740 --> 19:56.440] John Snow no longer shows up as even being attackable. [20:02.480 --> 20:04.140] On path attacks. [20:07.460 --> 20:12.260] So this I like to claim to be God's gift to AD pentesters. [20:12.260 --> 20:14.360] Is that right, you pentesters? Right. [20:14.640 --> 20:20.720] This responder, you set this up and it'll just listen and respond to clients on the network. [20:23.360 --> 20:25.900] Client's going to come out and say, hey, I'm looking for so-and-so. [20:25.900 --> 20:28.900] And it's like, yeah, that's me. Yeah, that's me, too. That's me, too. [20:29.120 --> 20:35.600] And if we have it set up in this way, you can poison those requests and we can actually get NTLM hashes. [20:35.600 --> 20:39.080] In this case, it's NTLM v1 hashes for these accounts. [20:39.300 --> 20:43.880] And so we can do what we've done twice already is we can crack them hashes again with Hashcat. [20:44.400 --> 20:48.060] And so here we've got our third account that we've been able to crack. [20:48.060 --> 20:50.920] And this one was just from listening to the network. [20:52.940 --> 20:58.920] And while that's scary, the scarier thing that you can do is you can configure Responder to run in a similar way. [20:58.920 --> 21:06.540] But instead of giving you the hashed credentials, you can tell it to go ahead and pass those or relay those using NTLM RelayX. [21:06.540 --> 21:10.220] And you can relay that authentication attempt to a target or targets. [21:10.220 --> 21:13.880] So in this case, I'm targeting a web server, the one that ends in 22 there. [21:14.360 --> 21:18.440] And I'm just going to wait for Responder to get some authentication to happen. [21:18.440 --> 21:20.380] It's going to send that here. [21:20.380 --> 21:23.160] And then I told it to set up a Socks proxy. [21:23.160 --> 21:29.700] So I've got an active connection using Eddard Stark, which just happens to be an administrator on that web server. [21:29.920 --> 21:32.680] So now we've got a shell on our target. [21:32.680 --> 21:38.940] So we can do things like this, where we can interact with that session. [21:39.160 --> 21:41.440] And we can run Secret Stump on it. [21:43.200 --> 21:44.300] Pardon me. [21:44.660 --> 21:48.120] So you can see I specified no password. I don't need a password. [21:48.120 --> 21:50.540] I've already authenticated to it. I have an active session. [21:50.540 --> 21:52.500] And I can run Secret Stump against it. [21:52.540 --> 21:55.300] And I can dump the local SAM hashes. [21:55.300 --> 21:59.760] So this includes the local administrator account, any other local accounts that exist. [21:59.760 --> 22:03.720] Like a help desk account or something like that, that you've placed on systems. [22:03.720 --> 22:08.180] This will dump all local credentials on that server or workstation. [22:09.540 --> 22:12.760] Also more fun, it's going to extract saved credentials. [22:12.920 --> 22:15.960] So here we're attacking service account. [22:15.960 --> 22:20.220] So if you may recognize the SQL service account that was not Kerberoastable. [22:20.220 --> 22:22.220] You will not be Kerberoasting me. [22:23.240 --> 22:26.380] Was in plain text because it's configured as a service. [22:26.380 --> 22:30.080] It's running a service which is required for SQL Express. [22:30.080 --> 22:33.480] So that account was free on that machine. [22:34.220 --> 22:37.660] And so what can we do for on path attacks? [22:37.780 --> 22:44.220] So the quickest and probably the easiest of all of these is preventing the LLMNR, [22:44.220 --> 22:46.880] which is link local multicast name resolution. [22:46.880 --> 22:49.940] Yes, I had to write that down. And no, I'll not memorize that. [22:49.940 --> 22:54.180] I do have a great article linked for that one as well. [22:54.180 --> 22:56.140] Actually, I have articles for all these. [22:58.200 --> 23:02.400] You may have remembered or noticed that those hashes were NTLMV1 hashes, [23:02.400 --> 23:06.640] which are infinitely easier to attack than NTLMV2. [23:06.640 --> 23:11.220] So enforcing this on your domain controller and setting it to the highest security level [23:11.220 --> 23:15.860] of enforcing NTLMV2 to exist on your network. [23:15.860 --> 23:21.760] Ideally, not allowing NTLM at all and allowing Kerberos to do what it's supposed to do [23:21.760 --> 23:23.040] for the last 20 years. [23:24.140 --> 23:27.940] This is hard. And I don't know that I've ever fully seen this. [23:27.940 --> 23:31.380] I've seen people auditing it and really starting to get ready for it. [23:31.700 --> 23:35.100] Another thing that we've seen, I think twice at Trimark, [23:35.100 --> 23:37.220] is LDAP signing and channel binding. [23:37.640 --> 23:39.660] This is another thing that's incredibly difficult. [23:39.660 --> 23:42.560] It can break a lot of those non-Windows devices. [23:42.560 --> 23:47.740] I've also got a couple links to some articles that have been written about this as well. [23:49.780 --> 23:52.620] A thing that I don't think is all that hard, [23:52.620 --> 23:55.440] some administrators do think that this is hard, [23:55.440 --> 23:57.840] this is protecting the accounts themselves. [23:57.840 --> 24:01.740] So this might be a little bit easier to get through some of that change management for you, [24:02.220 --> 24:04.320] is using the protected users group. [24:04.320 --> 24:06.620] Because you're only impacting whatever users you put in it [24:06.620 --> 24:10.000] and not the enterprise when you're making domain controller changes. [24:10.000 --> 24:14.940] A coworker of mine, Jake Hildreth, which owns our Active Directory Security Assessments, [24:14.940 --> 24:16.580] he has a blog and a presentation. [24:16.580 --> 24:23.300] He's writing a tool to help assist with end users adding accounts to the protected users group. [24:23.700 --> 24:25.920] So again, I've got that in the resources. [24:27.500 --> 24:28.960] Alright, so level two is down. [24:28.960 --> 24:30.420] We Kerberos to John Snow. [24:30.420 --> 24:33.640] We crack the hash from Responder for Rob Stark. [24:33.640 --> 24:37.280] And we found the SQL service account running. [24:37.280 --> 24:38.900] So now we've got six accounts. [24:38.900 --> 24:43.520] And we've got five more vulnerabilities that we have patched. [24:43.520 --> 24:45.380] So we cleaned up SPNs. [24:45.380 --> 24:51.100] We disabled LLMNR and NTLM v1 by enforcing v2. [24:51.100 --> 24:54.820] We talked a little bit about at least thinking about LDAP signing and channel binding. [24:54.820 --> 24:57.260] And then also the protected users group, [24:57.260 --> 25:01.160] protecting those highly privileged users in your domain. [25:03.960 --> 25:06.440] So level three, I called Privesk. [25:06.440 --> 25:08.920] Again, this is maybe a little bit more lateral movement-y. [25:08.920 --> 25:12.940] Also some pretty domain crushing attacks in this one too. [25:13.820 --> 25:19.500] And I'm going to kind of start by going backwards just a smidge because I wanted to show Bloodhound just a little bit. [25:20.320 --> 25:25.080] Bloodhound is an amazing tool that you can use to scan your Active Directory environment. [25:25.080 --> 25:29.600] And here I'm just showcasing what paths are available to domain admin. [25:29.600 --> 25:32.660] And here I'm going to zoom in on the one that we just owned. [25:32.660 --> 25:34.740] So we just got that Rob Stark account. [25:35.200 --> 25:37.840] And Rob Stark is a member of the administrators group, [25:37.840 --> 25:41.660] which is just this very simple step away from domain admins. [25:41.740 --> 25:45.500] And so that one's just a little bit too boring because you can just add yourself to that group, right? [25:45.500 --> 25:47.200] So we're going to do something cool. [25:47.700 --> 25:51.340] And we're going to identify what ACL modification may look like. [25:51.420 --> 25:53.780] So here you might remember our old friend Samwell, [25:53.780 --> 25:57.740] who was our first attack with that description field misconfiguration. [25:57.740 --> 26:05.000] Well, Samwell, for whatever reason, has the ability, has a write DAQL on a GPO that's linked to the domain root. [26:05.380 --> 26:07.060] So what does that look like? [26:08.660 --> 26:11.620] So here's what it looks like when we look at the policy itself. [26:12.040 --> 26:18.040] We see that the delegation tab shows us that we have some privileges with Samwell. [26:18.040 --> 26:23.640] If we dig into him a little bit, we identify he doesn't look too terribly dangerous because he doesn't have write permission. [26:24.140 --> 26:28.260] He has read and he has delete. [26:28.380 --> 26:32.420] But we have to actually look at advanced to identify what the real threat to this is, [26:32.420 --> 26:37.580] which is that write DAQL permission, which translates to modify permissions and modify ownership. [26:38.140 --> 26:43.300] So Sam can give himself or anyone else access to modify this GPO. [26:43.440 --> 26:48.700] And there's a number of different things you can do once you can modify a GPO specifically at the domain root. [26:48.700 --> 26:55.480] One such example is just creating a file that's going to run at login for all users on all computers in your environment. [26:56.180 --> 26:58.440] So we can do some pretty messy stuff with that. [26:59.720 --> 27:02.180] So mitigating this is fairly simple. [27:02.180 --> 27:05.020] You just have to check out the GPOs. [27:05.120 --> 27:07.320] I don't have a script for this. [27:07.320 --> 27:08.360] I should probably write one. [27:08.360 --> 27:13.300] So I may write one and put it up on GitHub where you can actually scan some of the ACLs that might be dangerous. [27:13.300 --> 27:17.420] But specifically start with your domain root and then move on to domain controllers, [27:17.420 --> 27:23.580] move to other protected OUs to identify group policies that maybe have delegation. [27:23.880 --> 27:25.380] Also ownership. [27:25.380 --> 27:29.540] So identify who has owner on your GPOs. [27:30.120 --> 27:35.860] And so if we clean that up, then we're in a lot better shape for any of that ACL modification. [27:37.220 --> 27:39.500] So I'm going to take us a little bit back. [27:39.500 --> 27:45.560] So you remember when we attacked the web server that we were targeting with stuff? [27:45.560 --> 27:47.220] I don't really remember either. [27:47.220 --> 27:55.060] But basically what we did was we were able to gain the local credentials for that web server. [27:55.140 --> 27:59.800] And what we can do with local credentials is we can do a pass the hash attack. [28:00.540 --> 28:03.360] So in this example, we're using the administrator. [28:03.360 --> 28:06.680] This could be, like I said, a help desk account or any other local account. [28:06.680 --> 28:10.560] And we can target all other known IPs in that domain. [28:10.880 --> 28:14.200] And this could be servers, this could be workstations. [28:14.580 --> 28:18.980] And in this case, we identify that very first one, the Castle Black. [28:18.980 --> 28:22.120] That's the one that we attacked. We expected that one to show up as pwned. [28:22.120 --> 28:26.340] But that bottom one, Winterfell, is actually a domain controller. [28:26.920 --> 28:29.900] I mean, this is a lab, so this is fairly unrealistic. [28:29.900 --> 28:33.780] But the reason this works is because when you promote your first domain controller, [28:33.780 --> 28:38.680] it's going to use that credential as the domain administrator credential. [28:39.700 --> 28:42.620] So just a little bit of digression on that. [28:42.940 --> 28:46.960] But with that, we don't even need to know what the password is for that administrative account. [28:46.960 --> 28:49.580] We can just pass that hash and authenticate. [28:49.580 --> 28:55.660] And here I'm using EvilWinRM, and you can see at the bottom that I've got a shell on our domain controller. [28:56.600 --> 29:00.340] And solution for this is to use something like LAPS. [29:00.340 --> 29:08.600] So old admins like myself maybe remember the days before LAPS was a thing where you would use a GPO, [29:08.600 --> 29:12.160] and you'd set the local administrator account on all machines. [29:12.220 --> 29:19.120] And thanks to the cpassword, where everybody could read that, we've now got cleartext credentials. [29:19.120 --> 29:24.780] So other than even just reuse and passing the hash, cpassword has cleartext creds. [29:24.780 --> 29:28.240] That's not even an attack that I showcased in this. [29:28.240 --> 29:31.520] It's fairly old. We do still see it on old GPOs. [29:31.520 --> 29:34.660] Even if they're unlinked, they still have some cpasswords in them. [29:34.660 --> 29:36.620] So you may check that. [29:36.620 --> 29:38.280] But this is what LAPS looks like. [29:38.400 --> 29:43.060] I've got articles on that as well, because I'm not going to go super into LAP. [29:43.900 --> 29:47.800] I am going to go a little bit into Kerberos delegation, though. [29:53.420 --> 29:57.700] So Kerberos delegation is a required feature of Windows. [29:59.380 --> 30:02.800] An example would be when a user authenticates to a web server, [30:02.800 --> 30:08.720] and then that web server needs to authenticate on behalf of that user to a database server, for example, [30:08.720 --> 30:13.920] to be able to provide the correct results for the user that's asking. [30:14.120 --> 30:16.800] So it's kind of a security thing. It's pretty much built in. [30:16.940 --> 30:19.980] But in this case, when we talk about delegation, we're talking about impersonation, [30:19.980 --> 30:24.780] which means that web server has the ability to impersonate any user in the domain. [30:26.140 --> 30:31.180] And so what that looks like, specifically when we're attacking unconstrained delegation, [30:31.180 --> 30:36.540] is we have a shell on that web server that we had shown that we attacked earlier. [30:37.180 --> 30:41.620] And since it's set up for unconstrained delegation, we either wait, [30:41.620 --> 30:47.520] or we can coerce an administrator to log into that system that we're in control of. [30:47.760 --> 30:52.660] And so here, using Mimikatz, I was able to export the tickets for Brandon. [30:53.480 --> 30:57.940] Brandon was very impressionable admin at the time. [31:01.020 --> 31:06.660] So Brandon logged into our server that we had control of. [31:07.300 --> 31:11.880] Using Mimikatz, we were able to set up what's called a pass-the-ticket attack. [31:11.880 --> 31:14.400] And then we load that ticket into our session. [31:14.400 --> 31:20.620] And we can view that using that klist tickets to identify that we have that cached ticket for Brandon. [31:20.620 --> 31:24.820] And then that last command in the bottom is just opening a PowerShell session [31:24.820 --> 31:30.120] to a domain controller. So we're authenticating as a domain admin to a domain controller. [31:31.640 --> 31:37.780] And now we've got a shell on the domain. We run whoami. We just look at sysvol. [31:37.780 --> 31:41.020] And so now we've basically owned that domain controller. [31:41.320 --> 31:44.960] I've got a lot more attacks to go, so I'm not going to stop there though. [31:44.960 --> 31:47.420] So how do we stop this specifically? [31:47.740 --> 31:53.600] So moving unconstrained delegation to constrained delegation is a good way to mitigate this. [31:53.600 --> 31:57.460] You can specify the specific service or server that's required [31:57.460 --> 32:02.780] instead of just allowing delegation to occur wherever it needs. [32:04.900 --> 32:08.220] That, again, can be somewhat difficult to identify. [32:08.740 --> 32:12.500] So what I like to do, even in the... I'm not saying don't do that, [32:12.500 --> 32:17.160] but what I am saying do is mark accounts as sensitive and cannot be delegated. [32:17.160 --> 32:21.660] So all of your administrators, this is kind of a baby step to the protected users group, [32:21.660 --> 32:25.280] set them up like this because, like I said, Brandon was very impressionable [32:25.280 --> 32:29.800] and he could be tricked to logging into wherever because he's an admin. [32:29.800 --> 32:33.120] You know, somebody in user calls, he logs in wherever they tell him to log in [32:33.120 --> 32:35.540] as his domain admin credentials, right? What could go wrong? [32:36.560 --> 32:40.400] So now that I've set Brandon as sensitive, he can't be delegated, [32:40.400 --> 32:45.260] on the right here is what we just did, so that's what the attack looked like in Mimikatz. [32:45.340 --> 32:51.020] If that attack were to attempt... be attempted when the account was set up, [32:51.020 --> 32:55.600] he was still... he still logged in and we can still look at some stuff in Mimikatz, [32:55.600 --> 32:59.240] but we don't have that ticket granting ticket, which means we can't load it into the session [32:59.240 --> 33:00.960] and we can't attack that account anymore. [33:05.910 --> 33:09.210] All right, so level three is over. We don't have any new accounts, [33:09.210 --> 33:12.030] but we're kind of beyond that now. You know, we've kind of gotten to the point [33:12.030 --> 33:16.610] where we're already on the precipice of domain admin. [33:16.610 --> 33:20.330] We've already kind of gained that full domain compromise. [33:21.090 --> 33:26.370] So what we've learned in level three is how to fix ACL and ownership issues, [33:26.370 --> 33:29.810] specifically on GPOs, but other objects are also important. [33:30.530 --> 33:33.950] Configuring LAPS to prevent things like local administrative credentials [33:33.950 --> 33:37.350] being on multiple machines, being able to perform lateral movement, [33:37.970 --> 33:40.750] implementing constrained delegation instead of unconstrained, [33:40.750 --> 33:43.350] and then protecting your admin accounts using the account is sensitive [33:43.350 --> 33:45.150] and cannot be delegated flag. [33:46.530 --> 33:48.270] All right, now the fun one. [33:54.880 --> 33:58.500] Okay, we're going to Pwn AD. So the print nightmare. [33:59.020 --> 34:04.420] I don't know if you all remember this. It was three years ago, I think now, [34:04.420 --> 34:07.240] and this I like to call the attack that got me into InfoSec. [34:07.300 --> 34:10.640] So I told you I worked for TriMark for two and a half years now. [34:11.160 --> 34:13.740] Print nightmare came out when I was still a sysadmin. [34:13.920 --> 34:18.540] It let me poke at it and prove to my administrators that it was exploitable, [34:18.540 --> 34:22.140] so we had something to do. So this is what that looks like. [34:22.140 --> 34:26.340] So running a CrackMap exec tool as well as the impact tool, [34:26.340 --> 34:30.500] we identified that the spooler is running on our target system, [34:30.500 --> 34:34.520] and the protocols necessary to perform the attack are also available. [34:37.900 --> 34:40.880] So what this attack looks like is we can just host a malicious DLL [34:41.640 --> 34:45.580] on a Samba share from this Kali box. This is where the screenshots are coming from. [34:46.160 --> 34:51.640] Using the cube 0x0 exploit, we can target the domain controller, [34:51.640 --> 34:54.380] and we're using just a regular user account, so that Hodor account [34:54.380 --> 34:59.020] that we grabbed, no administrative credentials in the domain whatsoever, [34:59.020 --> 35:02.500] can authenticate to that domain controller, and because the print spooler [35:02.500 --> 35:08.520] is available on that server, we can throw this nightmare DLL at it, [35:08.520 --> 35:12.480] and it says exploit completed. And what that exploit does [35:13.500 --> 35:16.480] is it's created a new account for us in the domain. [35:16.480 --> 35:21.500] It's called PrintNightmare2, and it is in the administrators group. [35:24.510 --> 35:28.370] And this is my favorite mitigation, because it's the easiest mitigation. [35:28.370 --> 35:33.630] So we just disable the print spooler. And yes, I know PrintNightmare has been patched. [35:33.630 --> 35:38.030] Thank goodness. So not this specific attack is available everywhere anymore, [35:38.030 --> 35:41.510] but the print spooler is used in so many coercion attacks that can occur now [35:41.510 --> 35:48.330] that I like to say, if you're not printing or performing printing as a print server, [35:48.330 --> 35:52.070] then you have no need to run the print spooler whatsoever. [35:52.150 --> 35:56.930] So disable it either manually here or use a GPO to disable it, [35:56.930 --> 36:01.330] and here you see on the right-hand side that that server is no longer vulnerable to attack. [36:04.750 --> 36:10.150] So our last attack is going to be one of the Active Directory certificate services, [36:10.150 --> 36:16.590] so ADCS, vulnerable configuration that we're going to attack using the Certify tool. [36:16.590 --> 36:19.490] So this has been very popular over the last couple years. [36:19.490 --> 36:23.870] About two years ago or so, we saw this as a critical vulnerability [36:23.870 --> 36:26.530] on almost every single assessment that we did. [36:26.650 --> 36:30.070] Thankfully, things have gotten a little bit better in the industry now, [36:30.070 --> 36:31.590] but this is what that looks like. [36:31.590 --> 36:35.190] So we're going to run our Certify tool with a find command. [36:35.190 --> 36:39.610] This is just using a regular user account to a domain controller. [36:42.180 --> 36:46.680] So our output is going to include all the vulnerabilities that exist in that domain [36:46.680 --> 36:49.220] if it's running certificate services. [36:49.220 --> 36:51.460] And I'm going to drill into that because it's hard to see. [36:52.340 --> 36:57.940] So the specific one that we're going to pick out is called ESC1 or Escalation 1. [36:57.940 --> 37:01.780] This is from the Certify pre-owned stuff that Spectrops put out. [37:01.780 --> 37:03.440] It's also in the resources. [37:04.520 --> 37:09.100] So what makes this vulnerable is that enrollee supply subject, [37:09.100 --> 37:13.940] which equals the subject alternative name, can be applied when you enroll a certificate. [37:15.260 --> 37:20.600] The second half of that puzzle is who can enroll dangerous certificates. [37:20.660 --> 37:24.320] So in this case, we have domain users, have enrollment rights, [37:24.320 --> 37:27.360] and that means that anybody can enroll a certificate [37:27.360 --> 37:30.940] and they can specify that they are whoever they want to be. [37:32.640 --> 37:39.300] And so we can go take the next step and we can run Certify and request our certificate. [37:39.300 --> 37:42.520] So here we can see we're targeting that ESC1 template. [37:42.520 --> 37:45.480] We're telling it that we want to be administrator. [37:46.040 --> 37:51.080] We can tell it whatever we want, but of course we want to be the administrator account. [37:51.080 --> 37:59.290] So we've saved that private key locally, and now we're going to authenticate with it. [37:59.290 --> 38:01.630] So now we run the Certify Auth command. [38:01.630 --> 38:08.390] We specify the PFX, the domain controller, and we've now got the credential cache, [38:08.390 --> 38:13.330] so the Kerberos credential, as well as the hash for the administrator account, [38:14.170 --> 38:16.470] which means we can do bad things. [38:17.930 --> 38:20.630] So we can run secrets dump using that hash. [38:20.630 --> 38:24.190] We could also authenticate with that C cache file doing that, [38:24.190 --> 38:27.250] and we can dump the entirety of the domain controller. [38:27.250 --> 38:31.290] So here we've got the SAM, but that's not even really what we want. [38:31.290 --> 38:36.850] We want the NTDS.DIT file, so this contains the entire contents of Active Directory [38:36.850 --> 38:39.590] and all the NT hashes for every single user. [38:39.590 --> 38:43.590] And we did this with very little privilege whatsoever. [38:43.670 --> 38:48.750] So in that context, that attack was game over, right? [38:48.750 --> 38:50.110] But we're not quite done. [38:50.110 --> 38:52.570] We still have some work to do because we're learning that domain admin [38:52.570 --> 38:55.850] doesn't mean that we're finished as administrators. [38:56.530 --> 39:01.270] So we need to investigate why the vulnerable template existed in the first place. [39:01.270 --> 39:02.870] So this is what I said earlier. [39:02.870 --> 39:05.250] It's that two-piece, the domain users. [39:05.250 --> 39:06.650] It doesn't have to be domain users. [39:06.650 --> 39:11.830] It could just be a subset of regular user accounts that could enroll certificates. [39:11.830 --> 39:15.130] So the bigger issue is that supply and the request. [39:15.390 --> 39:20.110] So a little bit better of a mitigation is to require manager approval for specific certificates. [39:20.110 --> 39:22.370] There's a number of different things that you can do. [39:24.370 --> 39:27.530] And this is what the certificate that was issued looks like. [39:28.010 --> 39:31.950] So here you'll see the subject was Brandon because he was the one that requested the certificate, [39:31.950 --> 39:35.890] but he requested it using the subject alternative name as administrator. [39:35.890 --> 39:38.790] So that's what it looks like when a certificate's enrolled. [39:41.630 --> 39:45.870] And so we already talked about how you can detect it, but how can you do it automatically? [39:45.910 --> 39:51.870] So this is another tool that a friend of mine, Jake, has put out called Locksmith. [39:51.970 --> 39:55.130] You can run this whether you're on the blue side or the red side. [39:55.130 --> 40:01.930] This is a fantastic tool that discovers several different misconfigurations in environments. [40:01.930 --> 40:05.070] So this is what it looks like when it detects ESC1. [40:05.070 --> 40:08.990] I think the coolest thing that it does is it provides fixes for you. [40:09.230 --> 40:13.590] So it can output some PowerShell that will actually mitigate this, [40:13.590 --> 40:18.090] and it looks at not only ESC1 but all the way through 8 with the exception of 7 [40:18.090 --> 40:23.390] and also looks at some auditing being enabled, which does not happen by default in ADCS. [40:23.550 --> 40:26.790] So it provides fixes for every single one of these as well. [40:31.680 --> 40:35.220] And so technically we created the Brandon Rocks account, [40:35.220 --> 40:37.500] but I wanted to put it up here because I hope you agree. [40:38.000 --> 40:38.480] So... [40:40.800 --> 40:43.620] We got our last two vulnerabilities patched. [40:43.620 --> 40:49.500] So two more mitigations is to disable that print spooler and run Locksmith in your environment. [40:49.720 --> 40:51.640] Our game is still not over, though. [40:51.640 --> 40:55.920] So even though we've reached the end boss and we've fought it, there's always that next level. [40:55.920 --> 40:57.860] Our princess is always in another castle. [40:57.860 --> 41:00.980] There's always something else you can do. There's always that next step. [41:01.440 --> 41:07.060] Active Directory is not done with new vulnerabilities that come out on a regular basis. [41:07.060 --> 41:11.420] It's old, but there's new research that occurs every day. [41:11.420 --> 41:17.420] So I urge you all to get an assessment done, get a pen test done, try out some of these tools. [41:17.420 --> 41:20.400] So this is a list of all of the resources that I used. [41:20.600 --> 41:25.060] So use if you have permission to run these tools, everybody, please. [41:25.220 --> 41:28.740] I'm not telling you to go hack yourself without permission. [41:29.900 --> 41:32.040] I'll hold that up there just for a second. [41:32.040 --> 41:35.440] I will share these on my GitHub. [41:37.600 --> 41:40.680] Because here's a list of all of those resources I talked about. [41:40.920 --> 41:43.260] As well as the character selection screen. [41:43.260 --> 41:48.920] So I put this back up because I love AI art and how bad it is at spelling things, specifically. [41:49.620 --> 41:55.400] I also told it to give me a character selection screen for the game of Active Directory. [41:55.400 --> 41:58.520] And it came back with this, and everybody is sad. [42:01.800 --> 42:04.780] Every single person has a frown on their face. [42:04.780 --> 42:09.700] Like this guy bottom, like three from the right, he's got circles under his eyes. [42:09.700 --> 42:10.640] I don't know, he's beat up. [42:10.640 --> 42:15.140] And then there's the names of them. There's dad and oh lordy and doy. [42:15.320 --> 42:16.800] It's fantastic. [42:17.100 --> 42:20.160] So with that, thank you all for coming. [42:20.160 --> 42:22.040] Packed house, fantastic, guys. [42:33.790 --> 42:37.450] So you can follow me or find me on pretty much everything. [42:37.450 --> 42:39.710] Tech Brandon, GitHub's Tech Brandon. [42:40.250 --> 42:41.670] Twitter, LinkedIn. [42:42.130 --> 42:44.430] Thank you, Packet Hacking Village, thank you, DEF CON. [42:44.570 --> 42:48.150] I do think I've got a decent amount of time for questions. [42:48.150 --> 42:52.790] So if anyone wants to stick around and has any questions, I will do my best. [42:57.110 --> 42:57.530] Cool. [42:57.530 --> 43:01.730] Or you can go early and you can go get a snack, because it's lunchtime.