Taking Kerberos To The Next Level
Taking Kerberos To The Next Level
ABC.REALM KDC.REALM
ABC.REALM KDC.REALM
PAC TGS-REQ
Kerberos Security
krbtgt/REALM
Package
TGT
ABC.REALM KDC.REALM
PAC
HOST/ABC
TGS
Client Code Server Code
Local Kerberos Authentication
ABC.REALM KDC.REALM
PAC
AP-REQ
HOST/ABC
TGS
Client Code Server Code
Local Kerberos Authentication
ABC.REALM KDC.REALM
KEY: abc$@REALM
PAC
HOST/ABC
Access Token
TGS
Client Code Server Code
Local Kerberos Silver Ticket
Client
u: REALM\bob
pw: Password!
User Session
Local Kerberos Silver Ticket
Client
KEY: bob@REALM
❷ Convert
credentials to key
❸ Use key to
u: REALM\bob
pw: Password! build silver
KEY: bob@REALM CIFS/Client ticket
TGS
User Session
Local Kerberos Silver Ticket
Client
AcceptSecurityContext
❹ Build A-REQ
and accept
CIFS/Client Token (admin)
TGS
User Session
Demo Time
LSA Internals
and how to break them
PAC Signature Validation
Client KDC
KDC Signature
Server Signature
PAC
Local Checksum
❶ Compute local
checksum of PAC
with service key
KEY: bob@REALM
KDC Signature
Server Signature
PAC
Local Checksum
KDC Signature
Server Signature
PAC
❸ Send the KDC the
Local Checksum
checksum and
signature to validate
KDC Signature
KDC Signature
Local Checksum NETLOGON
Local Checksum
KERB_VERIFY_PAC_REQUEST
KDC Signature
Local Checksum
“SYSTEM” Equivalent
Logon Session:
SeTcbPrivilege || SYSTEM || LOCAL/NETWORK SERVICE
(auto) AcquireCredentialsHandle w/
Credentials Handle: SECPKG_CRED_INBOUND && NT AUTHORITY\SERVICE &&
!KerbGlobalValidateKDCPACSignature
“SYSTEM” Equivalent
Logon Session:
SeTcbPrivilege || SYSTEM || LOCAL/NETWORK SERVICE
(auto) AcquireCredentialsHandle w/
Credentials Handle: SECPKG_CRED_INBOUND && NT AUTHORITY\SERVICE &&
!KerbGlobalValidateKDCPACSignature
b0b@REALM b0b@REALM
PAC PAC
KEY: krbtgt@REALM
KRBTGT/REALM CIFS/ABC
TGT U2U Ticket
bob
We now need the session key from our
TGT to build the Silver Ticket
Trying to get a TGT + Session Key
KeyEncryption : AES256_CTS_HMAC_SHA1_96
Principal : krbtgt/[email protected]
NameType : SRV_INST No session
key ?
PS C:\> $ticket.SessionKey.Key | Format-HexDump
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Benjamin Delpy
@gentilkiwi
https://twitter.com/gentilkiwi/status/998219775485661184
Unconstrained Delegation TGT Extraction
InitializeSecurityContext
+ISC_REQ_DELEGATE
User Session
Unconstrained Delegation TGT Extraction
Session Session
Key Key
CIFS/KDC.REALM
TGS
❷ Authenticator is
encrypted with session
Authenticator
key and contains the
delegation TGT
AP-REQ
User Session
Unconstrained Delegation TGT Extraction
LsaCallAuthPackage
CIFS/KDC.REALM Checksum
TGS
Session
Authenticator Timestamp
Key
AP-REQ Authenticator
User Session
What can you add to the PAC ?
PAC->LogonInfo
Any domain SID which is not local
Domain SID account domain.
User ID
Any domain RIDs
Group IDs
500 - REALM\Administrator
… 512 - REALM\Domain Administrator
1000+ - User and Computer Accounts
Extra SIDs
Most SIDs which are not the local
…
account domain or NT AUTHORITY
Mandatory Integrity SID
Resource Domain SID Capability SIDs
Resource Group IDs
Most SIDs which are not the local
…
account domain or NT AUTHORITY
Demo Time
SeTokenCanImpersonate
Elevation
Check
Restrict to Session ID
Allowed
Identification Check
Can be controlled
by the PAC
SeTokenCanImpersonate
Elevation
Doesn’t apply Check
Ignored if user is ???
to us
not a UAC admin
Restrict to Session ID
Allowed
Identification Check
SeTokenCanImpersonate
Restrict to Session ID
Allowed
Identification Check
Hunting for Session Update Primitives
NtSetInformationToken(..., TokenSessionId, …)
LsapAuApiDispatchLogonUser LsapBuildAndCreateToken
LsapSetSessionToken
LsapCreateTokenEx
LsapApplyLoopbackSessionId
LsaISetSupplementalTokenInfo
LsapFilterElevatedTokenFull
LsapUpdateUserTokenSessionId
Hunting for Session Update Primitives
NtSetInformationToken(..., TokenSessionId, …)
LsapSetSessionToken
LsapCreateTokenEx
LsapApplyLoopbackSessionId
LsaISetSupplementalTokenInfo
LsapFilterElevatedTokenFull
Requires TCB
LsapUpdateUserTokenSessionId
Hunting for Session Update Primitives
NtSetInformationToken(..., TokenSessionId, …)
LsapAuApiDispatchLogonUser LsapBuildAndCreateToken
Deals with
LsapSetSessionToken elevated +
LsapCreateTokenEx linked tokens
LsapApplyLoopbackSessionId
LsaISetSupplementalTokenInfo
LsapFilterElevatedTokenFull
LsapUpdateUserTokenSessionId
Hunting for Session Update Primitives
NtSetInformationToken(..., TokenSessionId, …)
LsapAuApiDispatchLogonUser LsapBuildAndCreateToken
LsapSetSessionToken ???
LsapCreateTokenEx
Accessible via
LsapApplyLoopbackSessionId
AcceptSecurityContext
LsaISetSupplementalTokenInfo
LsapFilterElevatedTokenFull
LsapUpdateUserTokenSessionId
LSA Loopback Library
Local Security Authority
Hash Value Session ID
Kerberos Security BeginTracking … X
Package
InitializeSecurityContext
User Session X
LSA Loopback Library
Local Security Authority
Hash Value Session ID
Kerberos Security UpdateTracking FEEDACDC X
Package
AP-REQ
User Session X
LSA Loopback Library
Local Security Authority
Hash Value Session ID
Kerberos Security BeginTracking FEEDACDC X
Package
FEEDACDC 0
AP-REQ
User Session
LSA Loopback Library
Local Security Authority
LsapApplyLoopbackSessionId FEEDACDC 0
AcceptSecurityContext
No Fly Zone!
Loopback Security Buffer Hashing Bug
if (pBuffer.BufferType == SECBUFFER_TOKEN) {
BCryptHashData(hHash, pDirectionGuid, cbDirectionGuid);
BCryptHashData(hHash, pBuffer->pvBuffer, pBuffer->cbBuffer);
}
}
Security Buffer Types
Buffer Type Meaning Value
Hashed by LoopbackLibrary.
Original AP-REQ from
InitializeSecurityContext
Ignored by Kerberos.
Demo Time
Fixed in Windows 11 ?
Windows 10:
if (pBuffer.BufferType == SECBUFFER_TOKEN) {
BCryptHashData(hHash, pDirectionGuid, cbDirectionGuid);
BCryptHashData(hHash, pBuffer->pvBuffer, pBuffer->cbBuffer);
}
(Initialize/Accept)SecurityContext
User Session
No Fly Zone!
Modifying on the Wire
TGS-REP
TGS-REP
(evil)
bob@REALM bob@REALM
PAC w/admin PAC
CIFS/ABC CIFS/ABC
TGS U2U TGS U2U
Session Key
What about Credential Guard ?
Kerberos Considerations
When you enable Windows Defender Credential Guard,
you can no longer use Kerberos unconstrained
delegation or DES encryption. Unconstrained
delegation could allow attackers to extract Kerberos
keys from the isolated LSA process. Use constrained
or resource-based Kerberos delegation instead.
https://docs.microsoft.com/en-us/windows/security/identity-
protection/credential-guard/credential-guard-considerations
LSA Loopback Library
BYOKDC
Local Security Authority
KDC.FAKE
(Initialize/Accept)SecurityContext
User Session
No Fly Zone!
KDC Pinning
struct SECPKG_CALL_PACKAGE_PIN_DC_REQUEST {
ULONG MessageType;
ULONG Flags;
UNICODE_STRING DomainName;
UNICODE_STRING DcName;
ULONG DcFlags;
};
Package
❶ Pin our fake KDC to
localhost
LsaCallAuthPackage
krbtgt@FAKE
Custom KDC
User Session X
TGS-REP Local KDC
Client
bob@REALM
u: FAKE\bob
PAC w/admin
pw: WooHoo!
krbtgt@FAKE CIFS/CLIENT
fake credentials TGS U2U
Custom KDC
User Session X
Demo Time
“Security
Boundaries”
and where they aren’t
Service Account S4U2Self
Client
Local Security Authority
TGS-REP
+ PA-FOR-USER
KDC.REALM
KEY: svc@REALM
CNAME: Admin
LsaLogonUser(S4U, …)
Access Token
UPN: Admin We have
Realm: REALM
SeImpersonate but
User: REALM\Admin the token is locked to
Level: Identification
Service Account Session Identification
S4U TCB Privilege Check
KerbCreateTokenFromLogonTicket(...) {
if (MessageType == KerbTicketLogon || MessageType == KerbTicketUnlockLogon ||
MessageType == KerbS4ULogon || …
){
if (!ClientInfo.HasTcbPrivilege)
PrimaryCredentials->Flags |= PRIMARY_CRED_LOGON_NO_TCB;
}
}
LsapAuApiDispatchLogonUser(...) {
BOOL UseIdentify = PrimaryCredentials.Flags & PRIMARY_CRED_LOGON_NO_TCB;
LsapCreateV3Token(...
(UseIdentify ? TokenImpersonation : TokenPrimary),
(UseIdentify ? SecurityIdentification : SecurityImpersonation),
&Token
);
}
Service Account S4U2Self
Client
Local Security Authority
krbtgt/REALM
TGT
TGT Extraction
KDC.REALM
KRB_CRED
krbtgt/REALM
krbtgt/REALM
TGT
TGS-REP
+ PA-FOR-USER
KDC.REALM
KEY: svc@REALM KRB_CRED
CNAME: Admin krbtgt/REALM
AcceptSecurityContext
Access Token
KDC.REALM
User: REALM\Admin KEY: svc@REALM KRB_CRED
Level: Impersonation CNAME: Admin krbtgt/REALM
2.2.5. LSAP_TOKEN_INFO_INTEGRITY
AP-REQ
Ticket’s AD entry taken in
preference to Authenticator’s
Authorization
Data KERB-AD-RESTRICTION-ENTRY
bob@REALM
PAC
_LSAP_TOKEN_INFO_INTEGRITY {
Service Ticket Flags = RestrictedToken;
TokenIL = Medium;
MachineID = {FEED-ACDC};
}
Authorization
[...]
Data
info.MachineId ==
False
LsapGlobalMachineID
True
User is a Local Account Machine is not
Local && Token Filtering && a domain
Account is enabled controller
Network Auth Token
Filtering is enabled
True
False
True
info.Flags &
Filter Token True False No Filtering
LimitedToken
Kerberos UAC Bypass
Client
LsaCallAuthPackage
❶ Request service
RPC/CLIENT Auth ticket and session
TGS Data key from ticket
cache
Session
uac admin Key
RPC/CLIENT Auth
TGS Data
❷ Manually renew
Session the service ticket
Key
without any
Service Account Session authorization data
Kerberos UAC Bypass
Client
RPC/CLIENT Auth
TGS Data
❸ Pass clean ticket
to RPC server
Session
Key
(auto) AcquireCredentialsHandle w/
Credentials Handle: SECPKG_CRED_INBOUND && NT AUTHORITY\SERVICE &&
!KerbGlobalValidateKDCPACSignature
Subject:
Privileges:
SeSecurityPrivilege
SeTakeOwnershipPrivilege
SeLoadDriverPrivilege
...
Limitations of Time
NtApiDotNet (tooling used in presentation)
https://github.com/googleprojectzero/sandbox-attacksurface-analysis-tools
AppContainer Escapes
https://bugs.chromium.org/p/project-zero/issues/detail?id=2273