AD Security 101
AD Security 101
An introduction
Domain controllers
Domain
Forest
Tree (DNS)
Group Policy
Active Directory Components
Domain
Domain
Forest Default partitions
Configuration
(mandatory)
Tree (DNS) Schema
Domain
Configuration Partition
Forest cn=configuration,dc=domain,dc=com
Domain controllers
In other words: the DC is the server that runs AD and
Domain provides access to other computers on the network
Forest
There are usually multiple (at least two) DCs for
Tree (DNS)
redundancy since AD is usually one of the most critical
Organizational units and Sites services in an enterprise network
Domain controllers
Domain
Forest
Tree (DNS)
Group Policy
Active Directory Components
Domain
Group policies are managed from a central console
Forest (the Group Policy Management Console) and can be
scoped to specific users, groups, organizational units
Tree (DNS) and more
Organizational units and Sites Most group policy settings eventually turn into a
Group Policy
registry key that is set on the target computer
Active Directory Components
On every Windows computer, a dedicated
Active Directory data store
service („Group Policy Client“) checks if
Domain controllers there are new settings to be applied
Domain
Computer settings are applied on startup
Forest and every 90-120 minutes later
Tree (DNS)
Executives
Delegation rights
Protocols
• Most tools use the LDAP protocol (TCP 389) to enumerate AD which is
the best choice in most cases because
• Structured queries make it fast
• Network traffic is encrypted if LDAPS (TCP 636) is available
• LDAP log volume is VERY high, which makes it expensive for defenders to act
on it
• There is however also a legacy, SMB-based protocol called SAMR
• It is slow, there aren’t many tools and you only get a limited set of results but
it can be useful if firewall restrictions are in place
• https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-
samr/4df07fab-1bbc-452f-8e92-7853a3c7e380
Exercise 1:
Reconnaissance
NTLM
as a part of the MS-NLMP NT hash
authentication protocol, which the hash algorithm which is
is used to authenticate a user used to store a password
over the network
NTLM Intro
MS-NLMP is a challenge-/response-based authentication scheme for
authentication over the network
MS-NLMP includes
• LM (Lan Manager)
• NTLM (NT Lan Manager Version 1)
• NTLMv2 (NT Lan Manager Version 2)
NTLM Summary
Protocol Message calculation Hash used as input Security provided
LM DES LM Hash (DES) Extremely weak
NTLMv1 DES NT Hash (MD4) Very weak
NTLMv2 HMAC-MD5 NT Hash (MD4) Weak – yeah, that's the
best we got :-(
Bottomline
All flavors of NTLM are old and weak and it would be best to not use
them at all
However, this is a very complicated endeavor in real life due to
compatibility problems
NTLM/MS-NLMP basic authentication flow
NTLM/MS-NLMP basic authentication flow
• The client sends its username to the server
• The server generates a random 16 byte number (challenge/nonce) and sends it to the
client
• The client encrypts the challenge with the hash of its password and sends the result to
the server (this is the “response”, we’ll follow up on this in a minute)
• The server sends the following three items to the Domain Controller for verification
• Username
• Challenge sent to the client
• Response received from the client
• The DC uses the username to retrieve the corresponding password hash from the AD
database and encrypts the servers challenge
• If the results match (the client's response and the response calculated by the DC),
authentication is successful
LM/NTLM Response
Please note: the hash values are strongly simplified for demonstration purposes and do not represent real values.
NTLMv2 Response
Please note: the hash values are strongly simplified for demonstration purposes and do not represent real values.
NTLM Attack Vectors in a Nutshell
Pass-the-Hash
• Using the hash of a password without knowledge of the cleartext password to
authenticate against other devices on the network.
Overpass-the-Hash
• Get a Kerberos ticket from a NTLM hash, again without knowledge of the cleartext
password.
Relay
• Relay an incoming NTLM authentication attempt to another host. Mix of protocols
possible.
Pass-the-Hash Attack
• The Pass-the-Hash attack abuses the
previously described fact, that the password
of the user is not required to successfully
authenticate over the network, as long as the
hash of the password is available
• Cracking the password is no longer
necessary(!)
• Typical attack vectors are
• Password hashes of local admin accounts, as long
as they are identical across systems (e.g. all
clients)
• Hashes of privileged accounts (e.g. service
accounts or administrators) acquired from
memory
Exercise 2:
Pass-the-Hash
Caveat: disabling the SMB service in Windows is not possible without wracking
your host (feel free to try), so you need to do some port bending magic
Common (passive) relay vectors
(1) Highly privileged user (e.g. Helpdesk
user with local admin rights on clients) tries
to access compromised host via SMB (4) Attacker forwards incoming
authentication to target host
(2) Attacker blocks SMB traffic
(5) Attacker is successfully
(3) Windows explorer automatically authenticated as "ServiceA"
IT Admin‘s
Helpdesk User falls back to HTTP (Webdav) Compromised Client
or Admin Client
Scenario #2: Helpdesk user tries to access a compromised host via SMB (using explorer.exe)
In this scenario, the attacker can operate on a compromised corporate machine because we mitigiate the
SMB-caveat from the last scenario by redirecting the victim to HTTP
Common (passive) relay vectors
Coerced • https://github.com/leechristensen/SpoolSample
• VSSTriger by Wh04m1001
• Relies on MS-FSRVP
• Needs the FS-VSS-Agent installed which is not installed by default but
might be installed to facilitate backups of the host
Coerced Authentication – sample scenario
PC1 Domain
Controller
Attacker
Exercise 3:
Coerced
Authentication
Source: https://www.thehacker.recipes/ad/movement/ntlm/relay
Kerberos
The guard dog who protects the gate
to the underworld
This is Jack. Jack
attends
SecureCon – a
conference for
security experts.
AS issues Ticket-Granting Ticket to User after initial Authentication
User authenticates againts TGS and receives Service-Ticket (also called TGS in short)
Optional (Step 6 / 7)
• Verify Service Ticket PAC (VERIFY-PAC)
• Target service cross-validates PAC with KDC to verify user information
• Typically not active due to performance reasons
• Application Server Response (AP-REP)
• User can request authentication of the target service in step 5 (Mutual
authentication)
• Service encrypts the timestamp with the session key, which should only be
known by the user and the service and sends it back to the user for
verification
Kerberos Attack Vectors in a Nutshell
Kerberoasting (TGSRoasting)
• Offline password guessing against a ticket you grab from network or memory.
ASREProasting
• Offline password guessing against a user with disabled (default = on) Pre-Authentication
Pass-the-Ticket
• Like PTH but with Tickets, still no knowledge about the cleartext password needed
Silver Ticket
• Fake tickets against a single principal. Think: impersonate any User on one host
Golden Ticket
• Fake tickets against the DC. Think: impersonate any User on all hosts in the domain
Delegation
• Fake tickets by design against one or more hosts. Too complicated to explain in one sentence - more on this later ☺
Kerberoasting (TGSroasting)
The service ticket the KDC issues (see TGS-REP) is encrypted with the long-term-
key of the target principal
In case of RC4, the long-term-key is the NTLM hash of the users password
• Request a service ticket for any principal (any account with an SPN) with weak encryption (RC4)
• Extract the ticket from memory (see PTT)
• Run an offline attack on the accounts password (hashcat -m 13200)
Kerberoasting (TGSroasting)
If you can modify a user object however (think: ACL), then you can apply
targeted Kerberoasting ☺
Exercise 4:
Kerberoasting
Extraction and injection can be done without elevation if applied to your own logon
session
• Rubeus.exe dump
• Rubeus.exe ptt /ticket:…
Silver Ticket Usually means faking tickets against a regular account – typically a service account due
to SPN requirement
This means you can impersonate any account against that one account (or application
that runs in the context of that account)
Golden Means faking tickets against the krbtgt account, which allows an attacker to create
arbitrary TGTs
Ticket
Silver Ticket
Example
Example
The delegation features in Active Directory have been added to the Kerberos
protocol as an extension called MS-SFU (S4U) as documented here
• https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-sfu
• Unconstrained
• Constrained
• Resource-based Constrained
Unconstrained Delegation
User01 authenticates against a computer SRV01, which is enabled for
unconstrained delegation and requests a service ticket for that computer
The domain controller places a copy of the user’s TGT into the service
ticket that is returned to the user
The computer can decrypt the ticket and is in possession of the users TGT
– therefore, the computer can now impersonate the user without any
constrains ( == unconstrained)
https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html
Unconstrained Delegation
Unconstrained delegation is very powerful since you can impersonate any user (possibly
also an administrator) as long as you get them to authenticate against you
(think: Print Spooler Bug)
Microsofts recommends guarding any host enabled for unconstrained delegation like you
would guard a DC
Unconstrained Delegation
• S4U2Proxy
• S4U2Self
Classic constrained delegation is configured outbound (on the principal that is allowed to
delegate)
Constrained Delegation / S4U2Proxy
User01 authenticates against a computer SRV01 which is enabled for
constrained delegation and requests a service ticket for that computer
SRV01 can present the service ticket for himself from User01 to the
authentication service and get a new service ticket for User01 to SRV02
SRV01 can take the service ticket to impersonate User01 against SRV02
https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html
S4U2Proxy
Constrained Delegation / S4U2Self
Since users might authenticate via many different protocols other than Kerberos
(e.g. web form, basic, ntlm,…) the S4U2Self allows a so called protocol transition
• A host invoking S4U2Self basically requests a service ticket for a random user to itself from the
authentication service
• The host then uses this very service ticket as an input for the S4U2Proxy process
Since users might authenticate via many different protocols other than Kerberos
(e.g. web form, basic, ntlm,…) the S4U2Self allows a so called protocol transition
• A host invoking S4U2Self basically requests a service ticket for a random user to itself from the
authentication service
• The host then uses this very service ticket as an input for the S4U2Proxy process
Basically every principal can control for himself which other principal is
allowed to delegate against him
Resource-based Constrained Delegation
In RBCD however, it does not matter which user invokes the delegation
since permissions are set at the delegation target.
Resource-based Constrained Delegation
• msDS-AllowedToActOnBehalfOfOtherIdentity
If you have control over this attribute, you can allow any other principal to
delegate against the target host - this opens another ACL-based attack path
Resource-based Constrained Delegation
This opens an interesting attack path using a special service account that usually
exists in every organisation: the account that joins computers to the domain
• The default ACLs allow some degree of control over all computer it joined (think: all clients,
including IT)
• This account let‘s us create a principial with an SPN (another computer) which we need for the RBCD
attack
Resource-based Constrained Delegation
This opens an interesting attack path using a special service account that usually
exists in every organisation: the account that joins computers to the domain
• The default ACLs allow some degree of control over all computer it joined (think: all clients,
including IT)
• This account let‘s us create a principial with an SPN (another computer) which we need for the RBCD
attack
Resource-based Constrained Delegation
http://www.selfadsi.de/deep-inside/ad-security-descriptors.htm#ACEInheritedTypeGUID
Access Control in Active Directory
• A complex access right allows to further restrict access to a certain
attribute or a group of attributes.
• These attributes are defined by the field “object type/object ace
type”
• An example of a complex right is the “Send-As” permission
http://www.selfadsi.de/deep-inside/ad-security-descriptors.htm#ACEInheritedTypeGUID
ACL-based vectors
Based on what type of object you have access to, different techniques can be
used
• User: reset the users password or apply targeted kerberoasting
• Computer: use RBCD to get admin
• Group Policy: deploy logon script, install service...endless possibilities ;-)
Neo4j Graph DB
Bloodhound.exe (UI)
Sharphound
• Write access on a highly privileged group, which allows an attacker to add/remove himself
to/from the group as desired
• Write access on a group policy object, which allows an attacker to run code as system on
affected computer objects
• Write access on a computer object, which allows an attacker to gain admin privileges on
that machine through resource-based constrained delegation
DCSync
This allows an attacker to replicate content from the Active Directory database like a
regular Domain Controller does
The attacker has access to the password hashes of all accounts in the domain and can
impersonate them using other techniques like Pass-the-Hash/Overpass-the-Hash
The so called „DCSync privilege“ actually consists of two different rights that need to
be granted in the ACL of the domain object
• Replicating Directory Changes
• Replicating Directory Changes All
Golden Ticket
Golden Tickets are crafted TGTs with arbitrary usernames and group-
memerships (e.g. domain admins, enterprise admins,…).
Since they rely on the password hash of the krbtgt account, golden tickets
usually have a very long lifetime (at least one year).