Skip to content

Commit fa27de4

Browse files
committed
Fix cross-realm Kerberos credential lookup in CCache
CCache.parseFile() failed to find service tickets and TGTs in cross-realm scenarios because it hardcoded the lookup realm to the ccache's default principal realm. When a ticket was stored under a different realm (e.g. HOST/target@CHILD.DOMAIN vs the ccache's PARENT.DOMAIN), the lookup missed it entirely. Add fallback searches that scan all credentials by SPN prefix regardless of realm. This fixes atexec, dcomexec, smbexec, wmiexec, and psexec when using cross-domain Kerberos tickets.
1 parent 20c643e commit fa27de4

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

impacket/krb5/ccache.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,31 @@ def parseFile(cls, domain='', username='', target=''):
636636
principal = '%s@%s' % (target.upper(), domain.upper())
637637
creds = ccache.getCredential(principal)
638638

639+
if creds is None:
640+
# Cross-realm: the ticket might be stored under a different realm
641+
for c in ccache.credentials:
642+
serverPrincipal = c['server'].prettyPrint().decode('utf-8')
643+
if serverPrincipal.upper().startswith(target.upper() + '@'):
644+
creds = c
645+
principal = serverPrincipal.upper()
646+
LOG.debug('Found cross-realm credential for %s' % principal)
647+
break
648+
639649
TGT = None
640650
TGS = None
641651
if creds is None:
652+
# Try TGT for the specified domain first
642653
principal = 'krbtgt/%s@%s' % (domain.upper(), domain.upper())
643654
creds = ccache.getCredential(principal)
655+
if creds is None:
656+
# Cross-realm: look for any krbtgt ticket
657+
for c in ccache.credentials:
658+
serverPrincipal = c['server'].prettyPrint().decode('utf-8')
659+
if serverPrincipal.upper().startswith('KRBTGT/'):
660+
creds = c
661+
principal = serverPrincipal.upper()
662+
LOG.debug('Found cross-realm TGT: %s' % principal)
663+
break
644664
if creds is not None:
645665
LOG.debug('Using TGT from cache')
646666
TGT = creds.toTGT()

0 commit comments

Comments
 (0)