Good afternoon, DEF CON. All right, so my name's Kerry. I was a software developer for 18 years within the DRM and security solution space. And around four years ago, actually, to this week, I joined the InfoSec game and joined Pentest Partners to get involved in all the cool stuff that we all do. So I've been dedicated to red teaming and offensive security tooling for the last two years and an author of several tools that I've released to the community, including Boffnet, Sweet Potato and SharpBlock. I more recently become a member of the Rubius maintainer team. So what we're going to cover on this talk today, so I'm going to give a very quick introduction to Kerberos. I'm going to go into some Active Directory specifics on authentication and authorization. I'm going to quickly cover some of spoofing attacks from previous vulnerabilities, namely the Sam the Admin group of CVEs. And then I'll cover the premise of this talk, which is a new spoofing vector. So a quick introduction then to some changes that have been made to Rubius to exploit, I should say, on a new set of enumeration tools for this spoofing vector. And then finally, what can be done to sort of mitigate this new vector. So what is Kerberos? So it's an authentication protocol used by Windows and Unix Linux based operating systems. The machines are joined to a common realm to facilitate mutual authentication of principals in the realm. So a principal being a sort of user or a computer that was within that realm. And they're identified by both a name and a principal type. Now Kerberos doesn't actually deal with authorization. It only deals with authentication. So the authorization is left to the implementer of that periodic Kerberos stack. And Windows and Unix and Linux hosts can be joined to the same realm. So what does a principal name look like? So it's made of the typical name string so, that would be the SAM account name, so John.doe or it could be a use principal name which is typically in the form of email address. even an LDAP distinguished name is a valid principal name. And of course, the service principal names for computer accounts or service account. And there's also the name type. This name type is a hint to the Kerberos authentication scheme so that the KDC has an idea of what sort of name principal it is. And as you can see from the table below at the bottom, there's a number of different principal types there. But the most common for users is the NT principal type. So Active Directory actually uses a fairly complex search algorithm for when you're authenticating with the principal. It uses multiple attributes within LDAP to actually find the user that you're looking at. And then as far as authorization decisions are made, it's always made from what's called the privileged attribute certificate that's embedded in the user. And that's inside the Kerberos ticket, collectively known as the PAC, I guess. Principal name collisions can occur, and this has led to previous vulnerabilities and privilege escalations in the past. So I've tried to sort of simplify Active Directory's method of searching for a principal. So the default, when you actually log into a Windows machine, it uses the name type of NT principal. It uses the name type of NT principal, And let's say for this example, we've got a username of John Doe. Now, by default, it will go to the right-hand side of that search. So because we're using the NT principle, Active Directory will actually search the SAM account name field first. And then if a user is not found, it will then actually append a dollar to the end of the name, just in case that you're actually authenticating with a computer account, because computer accounts generally have a dollar at the end of their name. And then finally, if it still hasn't been able to find a user, it will switch to the left-hand side of that flowchart, where it will search the user principle name field instead. And then if there's no username found at that stage, you get a user not found error. And of course, any time in between those stages, if a user is found, it then will try and authenticate the password. So the actual ticket makeup within an Active Directory, so the green area is what you'd say is part of the actual Kerberos RFC. That contains sort of the client name or the CNAME, and the service that the ticket is destined for on a start and end date. And then the Microsoft-specific sort of come into play, which is the red area of the ticket. Now, you can actually have a ticket with the pack missing altogether. And now when it comes to Windows-based authorization, even though the out-to-green ticket is actually valid, and it has a client name that's within Active Directory, you'll actually log on as an anonymous logon if the pack is missing. So as far as Windows is concerned, you always need the pack really to validate the user within Active Directory. So with that in mind, so what actually happened with the SAMLyAdmin group of CVEs? So back before the patch for the SAMLyAdmin CVEs, you could actually request the TGT without the pack present. So what the actual vulnerability was, you would do that. You'd actually request the TGT without the pack being embedded inside it. Now, the ticket is valid for eight hours. So in between that TGT that you've requested, so let me rewind a little. So first, you actually create a machine account using the Mac. Now, that machine account would be named similar to, let's say, Domain Controller. The only difference is the SAM account name field won't have the dollar at the end. So it's exactly the same name, but it doesn't contain the dollar at the end. And then you request your packless TGT, which means that the only thing in the ticket is the CNAME itself. So there's no pack in there at all. Then you rename the account to something else. Nothing that exists within AD, but you do have at least a Kerberos ticket now that looks like the Domain Controller ticket. Now, because you've renamed the account, you then request a service ticket from the KDC. And the KDC will realize that there's no pack embedded inside that ticket. So it will use the same search criteria as I just covered on some of the previous slides, but it'll use the the official Kerberos CNAME that's embedded in the green part of that ticket. And because you've renamed the account in between the point where you've got the TGT, it would it would have then actually found the real Domain Controller account and embed the pack for the real Domain Controller. And that resulted in a privilege escalation. So this is going back to the search algorithm again. This is the area within the SAM, the admin group of CVEs that were affected. So this is the right hand side there where the SAM account name is searched and then it would depend the dollar and so on and so forth. So what did they do to fix the SAM, the admin? Basically, you can't request the packless TGT. Microsoft deemed it that it wasn't a reliable way to identify users within AD unless you had a pack embedded within it. There were some other hardening attempts, so the SAM account name fields also now must end with a dollar whenever an unprivileged user creates it. And a few other hardening artifacts were made to the user account control settings. But you can actually still request the packless service ticket. So what's the new spoofing vector? So obviously, SAM account name had been looked at previously, and it has been hardened quite considerably since that group of CVEs. So I decided to have a look at the user principal name attribute and see what we could do with that. So the user principal name or the UPN is made up of the username element, the at and a domain suffix that basically looks like an email address. Now, to modify that, if you have a particular attribute within Active Directory, you're looking to have write permission on the public information attribute set or generic write over a computer or user account within Active Directory. So these are the sort of the prerequisites needed to to abuse it. But duplicated UPNs are not allowed in the same way the duplicate SAM account names are not allowed. So how exactly can we can we spoof if no duplicates are allowed? Well, as it turns out, you can actually set an invalid user principal name within Active Directory. It doesn't actually have to have the domain suffix. So for you can see from the screenshot there, we've got the John Doe account where the SAM account name is set to John Doe. But you can actually still update the user principal name to mimic that of another account. So let's say the domain administrator in this case. But there's another another difference to the search algorithm then is going back to the the name type hint that I talked about earlier. If you specify the name type as NT enterprise as opposed to principal, which is the typically the default one used within Windows, the search algorithm changes and it actually searches the user principal name first before SAM account name. So as I'm sure you can you can gleaned on that. Basically, you can get your spoofed account name to be found first prior to the real the real account to sit in within Active Directory. So as part of this, I made some updates to Rubius and they should be live on the current master branch on GitHub. And basically a new argument has been added to specify the principal type. So you can spell from the group that we've seen at the start of the slides. You can actually now specify the principal type that you're using. So as an example there on the left, that's how you would typically authenticate using Rubius at the moment. And by default, that would use the NT principal. Type as opposed to the enterprise type. So in a typical Active Directory network, the screen on the left there would actually you'd be tempted to log on as the domain admin. And since the domain admin password is not super secret, you get a pre authentication failure because the password is wrong. But going back to the modified John Doe account that I just showed you earlier, once you add the principal type of enterprise, the search algorithm changes and then it actually ends up for finding your John Doe account. But. The ticket that you actually get back contains administrator as the username. So from the outset, the ticket actually does look like a domain admin, but it's not the the pack inside that ticket still identifies John Doe. It's only the outer green part of the tickets that I showed you earlier that make it look like it's a domain admin. So what abuse factors do we have for this? So like I said, Windows is completely out. It purely relies on the pack for authorization. But when it comes to Kerberos authentication on your Linux and Unix machines, which leverages the GSS API, they tend to do things differently. Like I said, the pack is very specific to sort of Windows based environments. So what tends to happen is GSS API stack will actually rely on the green parts of the ticket for validating the username. And then the permissions for the user is done as a second stage. So. It may do an LDAP search on that name that is extracted from the ticket, and more often than not, that ends up being the same account name that is searching on. But of course, we've we've authenticated using the user principal name, but other solutions also include mapping Kerberos principal names to local account names. So, for example, you can create a machine using root dollar and that will actually log you in as root on Linux. Andrew Bartlett actually discovered that, who was the person that discovered the original SAM, the admin group of CVs. And he basically realized that using the Mac permissions and having the ability to create a machine with a low privilege user, you could call the machine root dollar, pass that ticket to SSH, and then you'd be logged in as root. And that issue actually still exists today and it's a no fix. So, I think that's a good point. Now, the issue with that, though. You can't actually in person. It existing 80 users because you wouldn't be able to create the machine in the first place because you'd get a collision with the SAM account name if you were trying to impersonate another user. So that's where this new technique comes into play, where you can now actually impersonate valid Active Directory users. So these are the services that I've seen so far that implement GL Kerberos authentication via GSS API. So SSH. I've confirmed is vulnerable to this, as well as Postgres database. I just haven't had the time to check all the others yet. But essentially, if any of these are claiming Kerberos authentication and GSS API support and they don't look at the Windows pack, they're all going to be vulnerable to this sort of attack, would be my guess. OK, so on to the demo. So both of these are live already. So I made them live just before the talk. So Rubius has the new argument so that you can specify the principal type. And I've also created a new set of Python tools to allow you to enumerate potential vulnerable Linux or Unix hosts within an Active Directory network. So it's a little bit small, but we'll work through it. So what I've set up here is, again, we're going back to the John Doe account and to be able to all the prerequisites to be able to actually abuse this issue is having generic writeover in account. Now, you'd need to authenticate as the user. So shadow credentials has worked, for example. So you don't necessarily need to do anything in your prevail. I've changed in the users' password. You can still use shadow credentials with this sort of technique. So are we're gonna do now is just change the properties of the user principal name from where it was to administrative. administrator. Okay. And you'll see, obviously, an active directory that the user principal name is now set and ready to spoof, but the SAM account name is left as it is, so we're using John Doe. So I'm just going to show that, without specifying the principal type, you'd essentially be trying to log on to the domain admin, which is incorrect in this case. So when that authenticates, you get a pre-authentication failure. But then if we use the new principal type argument and specify enterprise, the search algorithm changes, and now we're authenticated as John Doe, but with the username of administrator. And if you look at K-List, you'll see that that has been imported, and from the, you know, just looking at it, it does look like an administrator or domain admin, but the pack actually says differently. Now, the geolocation API tool, what the way that works is, it does a search with inside active directory for looking at the operating system field of every computer object, and any that don't have the word Windows in there, it assumes it to be a Linux or basically non-Windows-based host. And then once it compiles that list of machines, it will then try and connect to each one of them over SSH to determine what authentication schemes it supports, and then if it does realize that particular host supports a GSS API, it flags that host as potentially vulnerable. So, you can see in the output here, there are two machines found. One is Ubuntu, and one is CentOS. Now, Ubuntu, and I believe all other Debian based Linux operating systems don't have GSS API enabled by default, but CentOS, Red Hat Enterprise Server, they do. So, the minute you join a CentOS or Red Hat based Linux server to an active directory network, you're going to be sort of vulnerable to this sort of attack. And then the final stage is now that we've got our ticket imported and ready to use, we can use SSH with the minus K argument to indicate that we want to use Kerberos authentication. You have to fully qualify the username, so you'll see administrator at adging.com, and here we connect it. But the big question is, of course, what groups are we a member of? So, by doing a quick ID, we can actually see whether we are logged into the Ubuntu or at the CentOS host as the domain admin. So, I did contact MSRC about this, and they basically said the issue I reported is as designed. I was sort of questioning whose design they were talking about. So, I had a quick look at what the RFC says, and the RFC says it quite clear, as far as I'm concerned, principle names that differ only in the name type should identify the same principle. So, they are not listening as far as I can see to what the Kerberos RFC spec says. So, what sort of mitigation? Well, Microsoft themselves could hardly use a principle name by ensuring they all have a domain suffix. Or, additionally, they could cross the domain, which would be a very check the user principal name against the SAM account name to make sure that there are no collisions there but in the meantime defenders out there what so what kind of approaches can you take i guess disable anything that's gss api based authentication that's joined to an active directory realm or the less drastic approach may be monitoring for sort of user principal name updates that don't conform to a valid upn and then obviously investigate those sort of anomalies so i think i'm running out of time for actual questions so what i will do if anybody does want to ask a question we'll certainly i'll certainly hang around outside if needed i want to give a big shout out actually to charlie clark aka exploit ph he's been a sort of a great sounding board for some of these Kerberos shenanigans i'll say that we've we've discussed on this talk thanks for listening