We have a great opportunity to see the best looking speaker. Oh, here he is, sorry. At least that's what he tells me. So, uh, anyway, we're gonna be learning a little bit about some, uh, Active Directory, uh, attacks, uh, this afternoon. Thanks. Hi, Defcon. So, uh, I'm Nikhil Mittal, and I'm going to talk about, uh, minimal rights and A's for Active Directory dominance. Uh, so let's get started. Couple of things about me. I'm a hacker. I, I like to research stuff when it comes to Windows security. Mostly on the user line part. Uh, that too on PowerShell, on Active Directory, et cetera. Uh, I'm, I speak, I train at conferences, uh, I'm with pentesteracademy.com, uh, and I'm, uh, uh, uh, uh, uh, uh, uh, uh, you can find me on Twitter as Nikhil underscore M-I-T-T. So please take a pic and tag me there. Uh, I blog regularly on labofapenetrationtester.com, and, uh, I maintain a few open source toolkits for, uh, for offensive security research like Nishang. Uh, there was one, uh, there's one, uh, one for the defensive part as well called Deploy Deception, which I released last year. Uh, I generally like to, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, I seriously like to, uh, uh, to learn and research about, uh, methodologies to break into, into, uh, environments of course where I have the permissions to do so. I've previously spoken at DefCon, of course, at, uh, Black Hat and a few more conferences. So what we are going to discuss today is, uh, this is the agenda, right? That is, we will begin with a very quick introduction to what aces or ACLs are when it comes to the access control model in active directory. Uh, then the philosophy and then the focus and then what the real immune system is, uh, of uh minimal rights, what what what do I mean by minimal rights, why are they required? Uh then we uh have a quick look at uh the a toolkit called RACE which I'm going to uh release with today's talk. Then persistence, how we can use uh different methodologies uh uh commands from RACE for persistence and on demand privilege on demand privilege escalation. Uh these would be covered both for non-domain controller machines and member uh both for domain controller and member machines in Active Directory. Then we look for some stat uh attacks which are specific to the domain controller. And then a quick look at defenses, past work, future, etcetera. So uh those of you who are not really familiar with how access control model works in Active Directory, uh this is how it works. When you want or a process wants to access a resource, which in the uh SDDL lingo is called secureable, whenever you want to access that, uh your thread or process token has the following uh information. It contains your user sets, that's visible right? Your user sets, your group sets, uh privilege information and other access information like etc. When your the process token presents uh itself to the target object or the secureable, the system does the following checks. Uh it compares with, now the system has an ACL, an access control list, the one which we are interested in right now is called DECL, which is it's a list, it is made up of entries. Now the system checks each and every ACE for any particular specific allow or deny entry for your access token. It keeps checking for each entry as long as it founds either an allow or a deny. That's uh that's how basically access control model works. Now when we talk about uh let's say uh there-there's an access control entry let's say for each and every trustee right? The list contains uh entries for different trustees. Now when we talk about let's say domain admins, we say domain admins have, and we have seen that, we know that uh uh external assets for a domain admins have privileges or permissions over all the objects or most of the objects in a domain. So why is that? It is because domain admins have entries or aces on multiple objects on all the objects in in the in the entire domain, right? That is what allows domain admins to be domain admins, right? To control different objects. Now this is that was I'm not going to delve deeper into how SDDL looks like or how ACLs look like, etc. Uh that I save for a longer discussion. Now once we understand that, once we know that how access control model works in Active Directory, how important aces or ACLs are, then we can begin a discussion on minimal permissions. So domain admins or other high privilege groups or users usually have full control permissions over different objects on machines or in domain. Now that's good right? Full control is awesome but that is something which we do not desire all the time. Why don't we stick to only those permissions which are required for a specific attack? Right? Uh for example if you want to reset password of a domain user, do we really need full permissions or full control or generic all over that particular user object? No we don't. And that is something what the philosophy or the methodology of minimal permissions is. We stick to whatever we require for a particular task so that we are a lot more stealthy, a lot more silent and we can still get the objectives or the goals of our assessment or our attack or whatsoever. So for example let's let's take this as an example. You want to connect to a domain controller or any machine using powershell remoting. Now by default you must be a part a member of the local administrators group. Right? Now why is it possible? Uh it is because administrators or the the local group administrators it has full access on the ACL of the powershell end point we are taking it as an example. It has full control over the the ACL of the powershell end point to which you connect, which allows them to access it. Now what if we add permissions for a user which we control, which is our proxy user or our uh foothold you serve. We add the permissions for that particular user to the ACL of the powershell remoting end point, but in place of having full control which is not required here, we go ahead and selectively choose the permissions required. That is what the minimal permissions part is, right? And throughout the talk, that is something which we are going to use. We sort out what minimal permissions or rights are required to access a particular resource or a securable object and then we uh modify the permissions, get those privileges and execute the task. We are going to avoid full control or generic all as long as possible. Now, we are going to use the race toolkit which would be available on my github repository. It is a powershell module which you can use to uh which has a lot of functions and code which you can use to execute the attacks which we are going to discuss. Uh race makes use of Microsoft sign active directory module, the one which you will find on any machine where the ADR set is installed. So I maintain a mirror of that or you can copy it from any domain controller or any machine where the the ADR set is installed. Right? So let's get started. Uh we are going to discuss both persistence and privilege escalation. Uh please note that we are not going to use any patchable exploit. There is no no exploit discussion uh in the talk. In cases we talk specifically about modifying ACLs, we have to assume that on member machines we have the local admin privileges and on the domain controllers we have the domain admin privileges. Right? So by the when we do the modification of ACLs and when we abuse that in in a real world assessment or in during a real world attack there is a time gap. Right? So when we do the modification of ACLs and when we abuse that you once have the local admin privileges now you need to hold on to that. That is something which we are going to discuss. So please don't be disappointed that we already have those privileges. Right? This is a persistence or a backdoor scenario which we will be discussing in in most of the cases. Uh so we'll begin with very simple well known techniques. Not well known ones probably. Simple ones. Then we'll move on to a bit more complex ones as we move ahead. So let's pick up a little bit of time. So let's start off with a PowerShell remoting the the thing which we started the discussion. Now to allow code execution without administrator rights we need to modify the permissions or the ACL of the PowerShell endpoint. Right? If you run for example get PS session configuration on any Windows machine you will get a list of all the remoting endpoints enabled on that particular box. So we are going to modify the ACLs of the default one, the default endpoint and provide a one of our or one of the user's V control privileges to connect to that machine. So from the race toolkit if you use the following command uh we are trying to add or modify the privileges uh sorry modify the ACL of the PowerShell remoting on the machine specified in the computer name parameter for the user lab user. Right? So uh let's have a look at its demonstration. So what we are going to do we are going to modify the ACL of the default uh PowerShell remoting endpoint on a domain controller with the domain admin privileges. Right? That's what we are looking at. So we use overpass the hash to start a session as domain admin. Uh once we uh have those privileges uh we can go ahead and modify the ACL on the domain controller using this command. Right? You may uh get this error when you run this particular command because we modify the ACL of the PowerShell remoting endpoint for this current session so you may get an IO operation error which we can safely ignore. Now what we did was to modify the ACL for the lab user. Now as lab user that is the current user for this particular uh machine we can access the domain controller. Right? You may like to keep in mind that the privileges will still be of that non-special user. Right? So could you please give me a so what really loud? Thank you. So we'll see uh what is the benefit of having privileges whoops privileges on a domain controller even even as a normal user. Right? So let's go ahead and see what we can do. Similarly we can go for WMI. WMI, if you uh know that WMI is a two-part authentication process you must have privileges one to connect to the decom endpoint. Second you must have the privileges or permissions to connect to a particular namespace. So when we do the similar stuff for WMI we need to modify multiple ACLs for the decom decom endpoint as well as the WMI namespaces. So when we do uh uh a single process we can actually have the WMI So WMI is another method of replicating the similar attack. Now one failure which I would like to uh share with you is for the WMI permanent event consumers. So WMI supports permanent event consumers which are fantastic for persistence. They persist across reboots, execute your commands with system privileges which uh is desirable when you want to backdoor a target machine. Now when I tried the same stuff with uh modifying the ACL of the root subscription namespace which is used by the permanent event consumers, it was possible to create permanent events but it was not possible to get a command execution out of it. Right? So if if uh this interests you, you may like to explore this further. Or if you really have used WMI, you really know it well, you may like to uh uh take a look at it and see what correct me later on. Now, what if you would like to have on-demand privilege escalation. That is we have persistence with privileges. For example, the two uh scenarios we saw PowerShell demoting and WMI. In that case, we did not have local admin privileges or administrator privileges with persistence. What if you would like to have the persistence along with uh high privileges? In that case, we will have persistence with privileges. What if you only want to have the persistence with privileges? Tony? Kalau. one very useful option is using or abusing Windows services ACLs. Now ACLs have their own uh sorry services have their own ACLs right or security descriptors we can modify that as well to uh get back doors or persistence with administrative privileges. Now unlike the WMI and PowerShell remoting part which no one really cares about there is minimal logging other than the access logs there is absolutely no logging by default when you modify ACL of a PowerShell uh remoting endpoint. But of course in case of services uh this is not going to be the same this is a bit not a bit this is noisy in the logs as simple as that. Now there could be uh a plethora of services which are interesting service control manager or SCM is the one which is of the interest which is of the interest right? SCM provides this is the service manager right? It provides the ability to create configure start stop services so if we have generic all so in this case we need generic all if we have generic all permissions on the SC manager service we can create config uh start stop services uh which means that we can for example we can create a new service which runs a system and a user which we control has the ability to create a new service which runs a system and a user the permissions to start and stop the service, right? Or we can simply go ahead, create a service, and provide a user vcontrol, generic all permissions on that particular service. What would that mean? That means the user vcontrol can modify the configuration of the service, make it run as system, and change the executable path of the service to run the payload we desire, right? That is something which we are doing here. Uh we provide a user, once again we are going to use lab user as a proxy user all the time. We provide lab user rights which are equivalent to what the built-in administrators have on SC manager on the target machine, that's one. Then we create a new service, evilsvc for example, which runs as local system. And lab user has permissions to start it or configure it, right? Once the service is started, there is another user you can use the same user or another proxy user to the local administrators group. So really not silent but that is the easiest way you can abuse uh the the services, right? Now if uh I mean if you use SC manager creating a service is still a lot more noisy than simply reconfiguring a service. So in place of that, what we can do, because we are assuming the local administrator privileges on the target machine, we reconfigure an existing service and provide our proxy user local uh sorry all permissions on that particular service so that our our proxy user can reconfigure the service, run it as system and point it to the payload we want, right? So that is the uh the service permissions issue. Let's have a look at this one. So we start uh a partial session with privileges of a user who is a local admin on the target machine. Uh we load up the the RISC toolkit. And modify the ALG service on the target machine so that the user lab user which we control has the permissions to change whatever we want on the target service. So here you can see that uh the the SDDL of the ALG service has these entries for the built-in administrator script, right? This BA stands for the built-in administrator here. So what we simply did was to copy that entry and provide it to one of the users which we control, right? Once that is done, then we as lab user we go ahead and uh run the following command. So as uh the user for which we modified it. Okay, just use the So now we actually wanna run the logic. So we run the uh service to checkledit and we uh uh empty, so we run it. And we change the configuration of the ALG. How could we do that? Because we modified the STDL or ACL of the target service. So although the service startedfähled, let's try to access the target machine now using powershell remoting because by default we need administrative privileges for that. So uh we run this we can successfully connect to the target machine. Just to be sure let's have a look at the uh membership of the local administrators group there. You can see that our current user our proxy user has access to uh it's a member of the local administrators group. Right? Now we have seen two interesting methods three interesting methods. So powershell remoting and WMI provides two of the ways to access a machine. Third one is remote registry. Now remote registry is not enabled by default on the desktop OS like Windows 10 but it is enabled on the server version. So it's not the source of Windows. Now we can use uh registry stores a lot of interesting information it provides you uh command execution privileges remotely. For example we can abuse the permissions on uh uh well known auto runs keys to get command execution. Now you will like to notice that not only the domain objects but services and registry keys have permissions as well. So as a very simple example. Uh we can modify ACLs of the popular or the infamous uh remote registry key which allows us to connect to remote remote registry even without having local admin privileges. And then we modify the permissions of the image file execution key. What does this mean? What uh with this command executed on any target machine it's this is a very the famous sticky keys option, right? I chose this as a very simple example. You modify these keys on a machine. The command also disables NLA. If you use MSTC or RDP to connect to this machine, you will get the login prompt and then you press shift keys five times and you will have your payload executed as a system. That's what, what it does. Very famous, probably may be detected uh by some antiviruses, even that is possible but I chose this one because this is an example which is the most easiest one to understand. Now when we discussed WMI, I say that WMI is a two part authentication. We need to be able to authenticate to the DCOM endpoint as well as to the namespace. Now if we are already modifying the ACLs of the DCOM endpoint, why don't we use that? To execute commands on the target machine. That is exactly what this particular command does. You modify the privileges or ACL uh ACL of the DCOM endpoint and then you can run command on that particular machine using DCOM. There is no need to modify ACLs of any namespace whatsoever. Right? Now another interesting option when, when it comes to PowerShell remoting, Microsoft introduced J-E-A which uh is also pronounced or called as JAW. Just enough administration a few years back. Now JAW, which is a DSC technology, what it does is it is useful for allowing non-admins to do admin uh tasks. And how, how does it happen? How it works? By default anyone connecting to the JAW endpoint using PowerShell remoting will have admin privileges. Regardless of what privileges they have in the domain, on the domain machines they will have whomsoever is connecting to the JAW endpoint will have local admin privileges and on the domain control, controller they will have the domain admin privileges. Right? Which doesn't, doesn't sound right. But the access is controlled by the number of commands or commandlets uh they can run. Right? Whenever you configure a JAW endpoint, you, you need to define the access to the JAW endpoint. You need to define a role capability. That role capability severely limits what commands you can run on a target machine, even with admin privileges. For example, you can for, let's say you just want to provide restart permissions to a group or a user, you can simply expose just a single commandlet restart dash computer with a single parameter called let's say dash force. That is the, the type of control which JAW provides you. Right? Uh, so, uh, so, uh, so, uh, uh, uh, so as I said, it is, and for, for domain controllers, the domain admin privileges you get are limited to the domain controller. You cannot access any network resource with those privileges. Now, how do, uh, how are the privileges provided to anyone connecting to the, to the JAW endpoint? There is a virtual user created for, uh, every connection. Now, the problem, of course, is if you specify as to the, to the JAW endpoint, there is a virtual user created for, uh, every connection. Now, the problem, of course, is if you specify as to the JAW endpoint, there is no risk, while defining the role capability file, it is possible to expose all of the commands, not only the powershell commands, or commandlets, but also the built in commands, the, uh, executables that is also poss- that can also be exposed on a JAW endpoint. Because we are discussing a persistence mechanism, or on-demand privilege escalation with persistence, what we are going to do, we are going to create or register a new JAW endpoint, on the JAW endpoint, on the JAW endpoint, using a endpoint which allows everything every command every command led to to anyone who connects to that particular endpoint and the results are terrific or uh terrifying depending on what side you belong. So once again if we have administrative privileges on a machine on a member machine or on a domain controller we can create a new remoting endpoint or a JEA endpoint and then we can simply go ahead and connect to this. Here you can see that in place of normal enter PS session and the computer name parameter we are also adding a configuration name. This is the name of configuration which gets added onto the target machine. Are there any logs? Uh not at all. This is as silent as it can be. Of course there will be access logs are all the time a four six two four and a four six three four and uh that would be for this virtual user right? So it would still be possible to track you if someone is looking at the access logs other than that there are I mean access logs are there even if you run NAT user slash DOM. So that is something which uh is not very uh doesn't really stand out. Now let's have a look at its demo. So what we are going to do here is we are going to create a JEA endpoint onto the domain controller so that when we connect to it we get local admin privileges on the DC. Right? So we run this on the DC. Here you can see that we create Microsoft dot PowerShell 64 uh config. Uh then when we run this particular command as user which we control you can see that we can access the DC. Let's have a look at our privileges. So we are running as this particular virtual user and if you have a look at our privileges those are useful for local adminstration on the DC but not useful for accessing accessing any network resource. Right? So this is uh- this is very useful and very silent. So now we can go ahead, we can uh- the registry stores a lot of uh- interesting credentials as well. So what we can do by modifying permissions for multiple registry keys, we can go ahead and extract credentials from them. What are the credentials stored in registry? Machine account hash, local users hash, uh- domain cache credentials. So right now we are going to make use of uh- code from damp toolkit, that's what included in uh- the race toolkit as well. So by using following commands, we can access or we can extract information from the registry. Now to answer the so what, which I asked you guys to shout, if- even if remote registry is not running on the target machine or it is filtered out on the firewall, we can simply go ahead, modify the uh- the powershell remoting ACL, then we can run the commands to extract credentials from the registry without having domain admin privileges. And what is the least which we can do with the machine account hash of the DC? At least the DC sync attack. Right? So I'm- I think I'm done with the uh- the uh- the uh- the uh- the uh- the uh- the uh- the uh- the uh- the uh- the uh- the uh- the uh- the uh- the uh- the uh- domain control. So, I think I am running out of time. So, let's uh- skip out uh- past the demo. Another interesting group is DNS admins. DNS admins is basically uh- the domain admin if you are running DNS service on your domain controller. It is also not a part of the protected users' group. So we can either modify the ACL of the domain- uh- the DNS object, or the domain- uh- DNS admins group is not a protected group. And we can have our privileges. We can do. And is back. This is very specific to the DC. Right? Same goes for the DSRM admin which is the built in administrator on the DC, the local administrator on the DC. It's log on behavior is controlled with a particular registry key which we can modify the permissions to. So once we have the machine uh the local account hash, let's define the permissions, then we can modify the permissions of the registry key, the log on behavior, and we can access the domain controller as a local admin. Same goes for the resource based constraint delegation part, the RBCD. Right? Uh exchange groups are also very uh interesting. Exchange groups are not part of the protected groups. Their ACLs are not protected by admin SD holder. So the uh we can modify the ACL of the exchange windows permissions group which itself has rights to modify the ACL of the domain object. So by using this cascading effect, we can actually run attacks like at least uh DC sync on the domain object. Right? So I need to skip pass through this one actually. Then there are some uh well known ones like user request, user request, user object ACL. We can modify the ACL of a user object to reset its password or to force set an SPN of the user and then Kerberost it. Or we can modify the permissions of the admin SD holder. This is very well known. Right? Or we can run the DC sync attack by modifying the ACL of the domain object itself. This is also very well known. Uh finally we can run the DC sync attack if you have not . This is forest . By default you need domain admin privileges to run the DC shadow attack. But it is possible to use minimal permissions we can filter to these permissions. Run DC shadow without having to have privileges. So this is a summary of whatever we have discussed. So this is more of a reference slide for those who are not uh did not attend the talk so that they can come back and have a look at it later on. Now uh this is not something which was discovered uh just months back. The minimal permissions have been in use for so long that when I was researching I found articles at least which date back to 2001 where uh they discuss the ACLs of the Decom endpoint. So in in in slide notes you will find that there is one for Decom from 2001, another one for WMI from 2002. And there was some phenomenal work uh which is in French. I think this was in this is this was in 2014. A couple of years back at DEF CON there was a very excellent presentation about uh DACL backdoors. In fact uh DC Sync and Admin ST holder are uh one of some of the attacks which uh these guys discussed in much detail. Now of course event logs are our best bet when it comes to uh detecting these attacks other than of course protecting your domain administrators or local administrators. Right? If someone would not have that access in the first place these attacks would not be possible. Uh by default ACL modification has no detection at all. Uh even though even if you enable it it is easier for the domain objects for service and data to be detected. So you can see that uh the uh the WMI points for special remote points it's it is still hard to detect these attacks or best other than that as we uh as we discussed earlier access logs are the best things which you have four six two four and a four six three four in case of a non admin access four six seven two in case of an admin access. Right? You can refer to this uh document or this article from Microsoft. To uh to have a look at why or how to detect ACL changes. The tools which we can use for uh ACL auditing other than logging. Bloodhound of course. AD ACL scanner. And uh Pink Castle. You can use all of these three anyone which you want to detect or to audit ACLs. And also uh a shameless self plug. You can use deploy deception the tool I wrote to create decoy users and objects which have interesting ACLs to uh to uh trap or or deceive an attacker in using that. Right? So uh for future work what we have uh what I have not explored is when you change service permissions those are stored in the Windows registry. So that would be a very interesting part to discover or to to have a look at. As we said uh discussed earlier WMI permanent event consumers not really uh successful uh I was not really successful with that but that may be uh an interesting point. For the race toolkit uh specifically uh I I have not worked on hiding the ACs once we have modified the ACL. That would be an interesting part. More registry auto runs would also be really interesting. So uh that would be all. Please fire your questions right now or you can contact me on Twitter or on my email. That would be all. Thank you.