AttackingandDefendinghybridAD BsidesSG 2021
AttackingandDefendinghybridAD BsidesSG 2021
1
Anurag Khanna - @khannaanurag
2
@khannaanurag, @Th1ruM | BSides Singapore 2021
Thirumalai Natarajan - @Th1ruM
Takeaway: Understand the Hybrid Active Directory, the attack surface and how defenders
can detect and protect hybrid AD.
4
@khannaanurag, @Th1ruM | BSides Singapore 2021
Introduction - Azure Active Directory
Authentication Protocol
Domain Structure
Kerberos
Domain/Forest
Oauth/SAML/OpenIDConnect
Tenant Azure AD
≠
External Trust Trusts B2B users
Azure AD is Microsoft's cloud-based identity and access management (IAM) solution. Azure AD is used by default for
Microsoft 365 auth, it can sync with on-premise AD & provide auth to other cloud-based services.
5
*https://docs.microsoft.com/en-us/azure/active-directory/fundamentals/active-directory-compare-azure-ad-to-ad
Identity Models
Cloud Only
With cloud-only identity, all your users, groups, and contacts are created and stored in the
Identity
Password Hash
AAD Connect synchronizes a hash, of a user's password’s hash from an on-premises Active
Synchronization
Azure AD Connect
Pass-through
Authentication decision is passed to On-Prem AD using AAD Connect. This implementation
authentication
validates users' passwords directly against on-premises Active Directory
(PTA)
Federated Allows federation of on-premises environment with Azure AD and use this federation for
AD FS
authentication authentication and authorization. This sign-in method ensures that all user authentication
(AD FS) occurs on-premises
6
Active Directory Federation
Service (AD FS)
7
@khannaanurag, @Th1ruM | BSides Singapore 2021
Federated authentication (AD FS) Introduction
User
You can federate your on-premises environment with Azure
AD and use this federation for authentication and
authorization.
2U
se
p
ss
Ap
r
3 U
ce
re
ss
6 R ser di
Ac
re
ce
e ct
n
sp en
ac
io
on te ed
at
se rs
er
to
ic
cr
Us
fr AD
pl
om ed
e FS
Ap
AD nt
7 i
1 FS al
s
10
@khannaanurag, @Th1ruM | BSides Singapore 2021
Golden SAML Attack
Golden SAML
Attacker 6 Attacker forges SAML Token Token Signing Certificate User Immutable ID
2U
Token Signing Certificate from an organization’s AD FS server enables attackers to
se bypass MFA and access cloud services as any user.
p
ss
Ap
r
3 U
ce
re
s
6 R ser di
Ac
s
r
ce
e ec
n
sp en te
ac
io
on te d
at
se rs
er
to
ic
fr cr
Us
AD
pl
om ed
FS
Ap
AD e nt
7 i
1 FS al
s
“The token signing certificate is considered the bedrock of security in regards to ADFS. If someone were to get
hold of this certificate, they could easily impersonate your ADFS server.” - Microsoft
12
@khannaanurag, @Th1ruM | BSides Singapore 2021
Where is Token Signing Certificate?
AD FS Server
<SigningToken>
<IsChainIncluded>false</IsChainIncluded>
<IsChainIncludedSpecified>false</IsChainIncludedSpecified>
<FindValue>FFB60178F833C4F76DD44B272CA018571BF1C2E8</FindValue>
<RawCertificate><REDACTED>></RawCertificate> 1
<EncryptedPfx><REDACTED></EncryptedPfx>
<StoreNameValue>My</StoreNameValue>
Encrypted Certificate
<StoreLocationValue>CurrentUser</StoreLocationValue>
<X509FindTypeValue>FindByThumbprint</X509FindTypeValue>
</SigningToken>
ADFS Config file
Domain Controller
• Encrypted TSC stored in AD FS Config file PS > $key = (Get-ADObject -filter 'ObjectClass -eq "Contact" -and name -ne
• Distributed Key Management (DKM) used "CryptoPolicy"' -SearchBase "CN=ADFS,CN=Microsoft,CN=Progr
am Data,DC=threathunting,DC=dev" -Properties thumbnailPhoto).thumbnailPhoto
to store the secret value used to derive the PS > [System.BitConverter]::ToString($key)
16-BB-54-BB-9B-95-80-1D-2E-6E-F2-5D-0A-94-09-8F-D6-25-9A-A7-4C-07-20-08-A6-4C-
symmetric key in an Active Directory 7C-47-18-27-7A-29
container
• Readable by AD FS service account 2
DKM Key Array
13
@khannaanurag, @Th1ruM | BSides Singapore 2021
Who can access this information?
IdentityReference : THREATHUNTING\adfs1
ActiveDirectoryRights : CreateChild, Self, WriteProperty, DeleteTree, GenericRead, WriteOwner
AccessControlType : Allow
15
@khannaanurag, @Th1ruM | BSides Singapore 2021
Remotely – AD FS config Sync (New Attack Surface)
16
@khannaanurag, @Th1ruM | BSides Singapore 2021
Securing AD FS
• Enable AD FS Auditing
• Enable Admin logs
• Configure Domain auditing for AD FS DKM requests
• Enable Security auditing for AD FS events
• Limit access to AD FS Server over the network
• Limit port 80/http access over the network only to other AD FS servers
• Limit accounts that have access to AD FS
• Consider AD FS as part of Tier 0
17
@khannaanurag, @Th1ruM | BSides Singapore 2021
Securing AD FS
18
@khannaanurag, @Th1ruM | BSides Singapore 2021
Golden SAML Attack – Remediation Steps
19
@khannaanurag, @Th1ruM | BSides Singapore 2021
Azure AD Connect
20
@khannaanurag, @Th1ruM | BSides Singapore 2021
Azure AD Connect
21
Azure AD Connect Key Accounts
- Local Virtual Service Account is used by default (on AAD Connect server). Used to run
ADSync service
the synchronization service and access the SQL database.
account
- MSA/GMSA domain accounts can also be used
22
@khannaanurag, @Th1ruM | BSides Singapore 2021
Abusing Pass Through Authentication – Credential Harvesting &
Skeleton Key attack
23
@khannaanurag, @Th1ruM | BSides Singapore 2021
Pass Through Authentication Method – Authentication Flow
2 User redirected to AAD
On-Premises
6
PTA Agent 7 Agent validates credentials against AD
decrypts password
using its private 8 AD returns result Threat Actor
key Workflow
AD
AAD Connect
On-Premises
25
@khannaanurag, @Th1ruM | BSides Singapore 2021
Hunting for AAD PTA Spy
Detection Hunting
26
@khannaanurag, @Th1ruM | BSides Singapore 2021
Abusing Azure AD Connect accounts – Privilege Escalation
& Lateral Movement
27
@khannaanurag, @Th1ruM | BSides Singapore 2021
Password Hash Synchronization Method
28
@khannaanurag, @Th1ruM | BSides Singapore 2021
Attack Flow – Target Azure AD connect accounts
After compromising Azure AD Connect Server, TA
extract two account’s password
29
@khannaanurag, @Th1ruM | BSides Singapore 2021
Privilege Escalation – Domain Dominance
30
@khannaanurag, @Th1ruM | BSides Singapore 2021
Lateral Movement to Cloud from On-prem
AADUser :
[email protected]
AADUserPassword : }l-yx{&8;>Fm:}90 3. Identify the cloud Immutable ID for the targeted user
ADDomain1 : THREATHUNTING.DEV PS > Get-AADIntUser -UserPrincipalName [email protected] | select
ADUser1 : MSOL_5a91e78a2787 DirSyncEnabled, ObjectID, UserPrincipalname
ADUserPassword1 : k0|ITGG*::$:SJ)!2Y0kG-^%Yp%e+=m7ed@Lae^zpDXN9V0k-
}9=1=0tB]=DsA=&C;m42HQI%]Ye/t?@h>:baOK0@s-
WIy+*+_(brXh(K9i3*#(._tz#f=s&O&d|54r
31
@khannaanurag, @Th1ruM | BSides Singapore 2021
Defending Azure AD Connect
32
@khannaanurag, @Th1ruM | BSides Singapore 2021
Azure AD Connect Secure Implementation
33
@khannaanurag, @Th1ruM | BSides Singapore 2021
Implement Microsoft Tier Model
• Secure Azure AD Connect the same as a domain controller and other Tier 0
resources
• Place Azure AD Connect servers in Tier 0 zone
• Restrict interactive access to limited Tier 0 privileged accounts
• Place the Key accounts of AAD connect server in a dedicated OUs in AD
- Tier 0 accounts can only manage this OU object
34
@khannaanurag, @Th1ruM | BSides Singapore 2021
Credential Management
35
@khannaanurag, @Th1ruM | BSides Singapore 2021
Conditional Access Policies for Azure AD Connect Accounts
36
@khannaanurag, @Th1ruM | BSides Singapore 2021
Object Filtering – Limit Privileged OUs Synchronization
37
@khannaanurag, @Th1ruM | BSides Singapore 2021
Selective Password Hash Synchronization
• Synchronization rules
• Restrict Privileged and
Service Accounts
38
@khannaanurag, @Th1ruM | BSides Singapore 2021
Administrative Access Management
39
@khannaanurag, @Th1ruM | BSides Singapore 2021
Monitoring & Detection
40
@khannaanurag, @Th1ruM | BSides Singapore 2021
Thanks for listening!
@khannaanurag
@Th1ruM