KDC_ERR_WRONG_REALM. Impacket prints it, the terminal stops, and the usual advice is to move to a Windows host and reach for Rubeus. The error is not a dead end — it is a referral the client did not follow. The protocol knew where to go. The wrapper did not ask.

The KDC had already answered. Nobody had read the answer.

TL;DR

A cross-realm service ticket is three round trips, not one. Your home KDC cannot issue a ticket for a service in the other forest, so it hands back a referral — a TGT for the remote realm’s ticket-granting service. A compliant client takes that TGT to the foreign KDC and gets the real service ticket. Native libkrb5 tools do this automatically. Modern Impacket has a referral loop too, but it keeps contacting the KDC pinned by -dc-ip, so the second hop never reaches the foreign KDC. That is the difference between kvno/ldapsearch working across the trust and certipy/a one-shot getST.py stopping at KDC_ERR_WRONG_REALM. Read the ccache, pre-warm the SPN the next client will ask for, and use a target-realm principal for Impacket’s TGS path.

Context — what this post is. Appendix C of the box writeup and Read the Bits, Not the Integer both name the three failure modes in order. This post explains the mechanism behind them — the RFC layer, the three tickets, and why one family of tools follows the referral while the other stops. It is not a repeat of either walkthrough.

The Canonical Sources

  1. RFC 4120 §1.2, Cross-Realm Operation — the model: realms share inter-realm keys, the client obtains a TGT for the remote realm’s TGS from its local realm, and the remote TGS honours it. This is the section that describes the referral.
  2. RFC 4120 §3.3.3.2 — the KDC side: when the server in the presented TGT is the ticket-granting service but the TGT came from another realm, the KDC looks up the inter-realm key, decrypts, and adds the issuing realm to the transited field. Do not cite §8.4 here — §8 is “Interoperability Requirements”, not cross-realm operation. That mis-citation is common enough to be worth naming. KDC_ERR_WRONG_REALM (68) is listed in §7.5.9 as Reserved for future use: the error is an implementation behaviour, not an RFC signal that no referral was available.
  3. MIT libkrb5 behaviour — the implementation that actually follows the referral. kvno, ldapsearch -Y GSSAPI and ldapmodify -Y GSSAPI all use it. The box writeup is the evidence file: every cross-forest LDAP operation that worked went through this library.

The RFC defines the chain. libkrb5 implements it. The wrapper is one implementation with a gap, not the protocol.

The Two krb5.conf Lines That Matter

The merged config from the box, extended with the settings that keep cross-realm resolution predictable:

ini
[libdefaults]
dns_lookup_kdc = false
dns_lookup_realm = false
default_realm = PING.HTB
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
dns_canonicalize_hostname = false

[realms]
PING.HTB = {
    kdc = dc1.ping.htb
    admin_server = dc1.ping.htb
    default_domain = ping.htb
}

PONG.HTB = {
    kdc = dc2.pong.htb
    admin_server = dc2.pong.htb
    default_domain = pong.htb
}

[domain_realm]
.ping.htb = PING.HTB
ping.htb = PING.HTB
.pong.htb = PONG.HTB
pong.htb = PONG.HTB

The smaller merge got the first hops moving; Kerberos can be picky across a trust, so this is the version to standardise on.

Two DNS settings do the quiet work — one in the block, one deliberately left out of it:

  • dns_canonicalize_hostname = false — set here as hardening, not a fix for an observed failure. When true, Kerberos canonicalises dc1.ping.htb through forward DNS before realm lookup; if the lab DNS returns anything other than the name you typed, the principal changes and the ticket no longer matches the service.
  • rdns = false — present in the earlier minimal config, dropped here deliberately. It only adds a reverse lookup to that same canonicalisation step, and krb5.conf(5) says plainly that when dns_canonicalize_hostname is false, it has no effect. Realm selection is a different path: with dns_lookup_realm = false and both [domain_realm] mappings explicit, libkrb5 reads the config and stops. Keeping the line would suggest it guards something it cannot reach.

Both [realms] entries are needed so the client knows which KDC to contact after it receives the referral. Both [domain_realm] mappings tell it which realm a hostname belongs to before the first request. One realm is not enough for a two-KDC chain.

Both settings implement one principle: do not trust the network for identity information; trust the config file.

The Three Tickets — klist as a Map

After kvno ldap/dc1.ping.htb with a PONG ccache, the cache holds three principals:

text
krbtgt/[email protected]      home TGT        your identity, sealed with PONG's krbtgt key
krbtgt/[email protected]      referral TGT    PONG's endorsement, sealed with the inter-realm key
ldap/[email protected]    service ticket  PING's authorisation, sealed with PING's ldap service key

Read the middle line first. It is the trust made visible. If it is missing from a libkrb5 cache, the native tools cannot follow the referral — but a tool with its own trust walk, or a target-realm principal that never needs the hop, can still work. kvno is the cleanest way to put it there: it asks for the service ticket, follows the referral through native libkrb5, and leaves everything it fetched in the ccache. It also mutates the cache, so copy it first if you need the pre-referral state.

The inter-realm key

When PING and PONG established the forest trust, their KDCs negotiated a shared secret — the inter-realm key — stored in each domain’s trusted domain object, backed by the trust account. The referral TGT is sealed with that key, so PING’s KDC can decrypt it and know PONG issued it. That is why the three-ticket chain is proof of anything: each ticket is sealed with a different key, and each key validates one step of the delegation.

The Referral Chain in Plain Terms

Ask PONG’s KDC for a service ticket to ldap/dc1.ping.htb, and PONG cannot issue it — it does not control PING. It does not return an error. It returns a cross-realm TGT: a ticket for krbtgt/[email protected], encrypted with the inter-realm key. That is the KDC saying, “I cannot help you, but take this to PING’s KDC.”

A compliant client then sends a second TGS-REQ to the PING KDC with that referral TGT. PING’s KDC decrypts it with the inter-realm key, sees a legitimate cross-realm authentication, and issues the final service ticket. Done.

text
TGS-REQ  -> PONG KDC : ldap/dc1.ping.htb
TGS-REP  <- PONG KDC : krbtgt/[email protected]   (referral)
TGS-REQ  -> PING KDC : ldap/dc1.ping.htb + referral TGT
TGS-REP  <- PING KDC : ldap/[email protected] (service ticket)

Three tickets, three round trips, two KDCs. Most writeups show only the final ticket. The referral is the interesting one.

A referral is a successful TGS reply, not an error

The first TGS-REQ gets a successful reply. Its server field is krbtgt/[email protected], not the ldap/dc1.ping.htb that was requested. A conforming client notices the mismatch, stores the referral TGT and sends a second TGS-REQ to PING’s KDC. libkrb5 does this automatically. An implementation that only checks “did I get a ticket?” mistakes the referral for the answer.

KDC_ERR_WRONG_REALM is a different failure

KDC_ERR_WRONG_REALM (68) is not the referral. RFC 4120 §7.5.9 lists it as Reserved for future use; in practice Impacket surfaces it when the realm it is talking to does not match the one it expects — its own error text in this run printed KDC_ERR_WRONG_REALM(Reserved for future use). A referral is a successful response carrying a different ticket. The error is a failed response carrying no path forward. Conflating the two hides the distinction this post exists to make.

Why Impacket Stops — The Pinned KDC

Reading Impacket’s source clarifies the failure. getKerberosTGS — the function behind getST.py and certipy — takes the TGT it was handed, sends a TGS-REQ to the KDC it was pointed at, and does not look for a cached service ticket first. Current versions do have a referral loop: if the returned ticket’s server field is krbtgt/[email protected] instead of the requested ldap/dc1.ping.htb, the function extracts the new realm and calls itself again. But the recursion passes the same kdcHost through to sendReceive, so with -dc-ip pinned to the PONG DC the second request still goes to PONG, now stamped with realm PING, and the KDC answers KDC_ERR_WRONG_REALM (68). An error response carries no ticket, so there is no referral for the loop to follow. The live failures are consistent with that mechanism, not with a total absence of referral support.

A warm cache does not change that. In a live re-run, a three-ticket r.martinelli cache — home TGT, referral TGT, and the exact ldap/[email protected] service ticket, all visible in klist — still failed one-shot against PONG with the same error. The cache was complete; the TGS path never read it.

libkrb5 sees the same referral, contacts the foreign KDC, and completes the chain. That is RFC-compliant behaviour.

The cache does matter to a different Impacket path. The SMB/WMI login code is a cache consumer: it looks for the exact SPN it is about to use, and if it finds it, it never asks a KDC. In the same re-run, smbclient.py with no cifs/dc1.ping.htb ticket in the cache asked PONG and died on the referral. After kvno cifs/dc1.ping.htb, the identical command printed [+] Returning cached credential for CIFS/[email protected] and [+] Using TGS from cache, then listed shares. wmiexec.py touches two SPNs: CIFS for its SMB session and HOST for the DCOM connection. With only CIFS cached, the missing HOST ticket either sends a fresh TGS-REQ or makes CCache.toTGS() rewrite the cached ticket’s sname in memory (Changing sname from … to … and hoping for the best), so both need pre-warming. Because kvno appends to the existing ccache, one kvno cifs/dc1.ping.htb host/dc1.ping.htb call warms both in the same file. The lookup is exact-SPN and read-only; Impacket never writes a fetched TGS back to the ccache. So pre-warming is not a repair for the TGS path; it is a hand-off to whatever consults the cache. Pre-warm the SPNs the next tool will actually ask for.

Add --debug to any Impacket command to see whether it reached a KDC or read the cache — the log lines make the two paths unambiguous.

Two caveats worth stating plainly:

  • Impacket is not uniformly broken. The two-hop manual referral technique drives getST.py manually — first -spn krbtgt/<parent> against the child, then cifs/<parent-dc> against the parent. Walking the referral by hand works because each call points -dc-ip at the KDC that owns that hop; the built-in loop cannot change host.
  • Pre-warming the ccache with native kvno proves the referral and feeds cache consumers — GSSAPI clients and Impacket’s SMB/WMI path — but it does not repair the pinned-KDC TGS path, so getST.py and certipy still fail. That distinction is why the two rows below differ.

Certipy vs Impacket — Different Bugs, Same Symptom

The two failures look identical in the terminal and need different fixes:

Layer Problem Fix
Impacket getKerberosTGS Referral loop exists, but keeps the -dc-ip-pinned KDC Use a native Kerberos client, or drive the hops manually with two getST.py calls, each with its own -dc-ip
Certipy Ccache realm mismatch — with PONG tickets cached, its TGS path targets the wrong realm Use a ccache whose default principal is in the target realm; pre-warming a foreign-realm ccache is not enough

The kvno ldap/dc1.ping.htb step before the certificate work is therefore not a certipy workaround. Live testing showed that a pre-warmed PONG ccache still fails in certipy with KDC_ERR_WRONG_REALM(Reserved for future use), even with explicit -u, -dc-host, -target-ip and -ldap-scheme. A ccache whose default principal is a PING user works immediately. In practice that means a ccache for a PING account — on the box, c.roberts, a PING user whose cache came from getTGT.py 'ping.htb/c.roberts:...' and later from certipy auth -pfx c.roberts.pfx. Either route writes a cache whose default realm is PING.HTB; certipy reads that principal and keeps its LDAP and TGS calls inside PING. Adding PING service tickets to r.martinelli’s cache does not move its default realm, so certipy still starts at PONG and still stops. kvno is how you prove the referral exists and how you prepare a cache for GSSAPI clients — not how you fix an Impacket TGS path.

The Tool Matrix

Tool Cross-realm Mechanism Why it works or fails
kvno Yes libkrb5 Follows referrals per RFC 4120; mutates the ccache
ldapsearch -Y GSSAPI Yes libkrb5 Same
ldapmodify -Y GSSAPI Yes libkrb5 Same — this did the real template write
bloodyAD Yes badldap (msldap lineage) + pure-Python Kerberos Own cross-realm trust walk; does not use libkrb5
pypsrp Yes SPNEGO + system Kerberos Needs a kvno-pre-warmed ccache and negotiate_service="HTTP"
impacket getST (RBCD path) N/A — one realm S4U2Proxy Both SPN and KDC were inside PONG, so there is no hop to follow
impacket smbclient (pre-warmed SPN) Yes, if that exact SPN is cached SMB cache lookup Reads the cached TGS and never asks a KDC; a miss falls back to the one-shot TGS-REQ and fails
impacket getKerberosTGS No, with -dc-ip pinned Custom KRB5 Has a referral loop, but reuses the pinned KDC host
certipy No with a foreign-realm ccache Impacket KRB5 Fails on the referral even pre-warmed; works with a target-realm principal
nxc --use-kcache Partial Varies by module Some modules use the system library, some do not

What actually makes a tool cross-realm capable

The dividing line is not “native versus Python”. A tool works if it delegates TGS request logic to the system libkrb5, consumes a ticket libkrb5 already fetched into the cache, or implements the trust walk itself:

text
ldapsearch / ldapmodify ➜ libldap + SASL/GSSAPI ➜ libkrb5 ➜ follows referral ➜ works
bloodyAD                ➜ badldap + pure-Python ➜ own trust walk ➜ works
pypsrp                  ➜ SPNEGO + GSSAPI       ➜ libkrb5 ➜ follows referral ➜ works

impacket smbclient      ➜ SMB cache lookup      ➜ pre-warmed exact SPN ➜ works
impacket getKerberosTGS ➜ custom KRB5           ➜ pinned KDC, no host hop   ➜ fails
certipy                 ➜ Impacket KRB5 + ccache ➜ realm routing ➜ partial

A custom stack can follow the chain — the two-hop getST.py forge does exactly that, pointing each call at the KDC that owns that hop. Impacket’s built-in loop cannot change KDC host.

The getST.py row in the RBCD path deserves its own sentence: the gMSA, svc_sql and the KDC were all in PONG, so S4U2Self ➜ S4U2Proxy never crossed a realm boundary. PONG’s KDC handled the whole chain. No referral was involved, which is why it worked while other Impacket calls failed.

The KRB5CCNAME hand-off

The day-to-day practice is four steps. Get the home TGT, force the referral chain with native kvno, verify the cache, then hand that same ccache to a GSSAPI client. The lab clock ran eight hours fast; a classic ntpdate against the DC fixed the skew, so the commands below carry no fake_time wrapper. Set the two addresses once before anything runs:

zsh
➜ export target_dc1_ip=10.129.245.56
➜ export target_dc2_ip=192.168.2.2

Get the home TGT:

zsh
➜ getTGT.py 'pong.htb/r.martinelli' \
    -aesKey 61e48d17cfe9507a3095dfb84b218a4b803aa0984b123e432bc2a40fc5f7fe98 \
    -dc-ip $target_dc2_ip
[*] Saving ticket in r.martinelli.ccache

Pre-warm — force the referral before any wrapper runs. Both KDCs are reachable over the tunnel; no proxy wrapper needed:

zsh
➜ env KRB5CCNAME='r.martinelli.ccache' \
kvno ldap/dc1.ping.htb

ldap/[email protected]: kvno = 7

Verify — three tickets, not one or two:

zsh
➜ klist r.martinelli.ccache
Ticket cache: FILE:r.martinelli.ccache
Default principal: [email protected]

Valid starting       Expires              Service principal
11/20/2026 20:29:03  11/21/2026 06:29:03  krbtgt/[email protected]
	renew until 11/21/2026 20:29:01
11/20/2026 20:29:12  11/21/2026 06:29:03  krbtgt/[email protected]
	renew until 11/21/2026 20:29:01
11/20/2026 20:29:13  11/21/2026 06:29:03  ldap/[email protected]
	renew until 11/21/2026 20:29:01

Hand it to a GSSAPI client — ldapsearch, ldapmodify, pypsrp:

zsh
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapsearch -LLL -H ldap://dc1.ping.htb -Y GSSAPI -N \
    -b '' -s base supportedLDAPVersion

SASL/GSSAPI authentication started
SASL username: [email protected]
SASL SSF: 256
SASL data security layer installed.
dn:
supportedLDAPVersion: 3
supportedLDAPVersion: 2

The klist between steps 2 and 4 is not optional. If only one or two tickets appear, the consumer will fail later and you will not know why. This is the concrete version of “pre-warm before the client”: those clients reuse the cached tickets instead of fetching their own. The SMB/WMI path reads only the exact SPN it asks for, so when the next tool is an SMB or WMI wrapper rather than an LDAP client, pre-warm every SPN it touches — cifs/dc1.ping.htb for smbclient.py, and host/dc1.ping.htb as well for wmiexec.py, which uses both. kvno appends to the existing ccache, so kvno cifs/dc1.ping.htb host/dc1.ping.htb warms both in one call. certipy still needs a ccache whose default principal belongs to the target realm; getST.py is different — it can be driven across the same trust by hand, one hop per call.

Walking the referral with getST.py

getST.py takes one -dc-ip. Each hop belongs to a different realm, so each call points at the DC that owns the realm it is asking. The output is a new ccache per call, never the cache named by KRB5CCNAME. The run below started from a cache holding only the home TGT.

Hop one — ask the PONG DC for the referral:

zsh
➜ env KRB5CCNAME='Pong_gMSA$.ccache' \
getST.py -k -no-pass -spn krbtgt/PING.HTB \
    -dc-ip $target_dc2_ip 'PONG.HTB/Pong_gMSA$'
[*] Getting ST for user
[*] Saving ticket in Pong_gMSA$@[email protected]
zsh
➜ klist 'Pong_gMSA$@[email protected]'
Ticket cache: FILE:Pong_gMSA$@[email protected]
Default principal: Pong_gMSA$@PONG.HTB

Valid starting       Expires              Service principal
11/20/2026 03:09:05  11/20/2026 11:37:13  krbtgt/[email protected]

Hop two — hand that file to the PING DC and ask for the service ticket:

zsh
➜ env KRB5CCNAME='Pong_gMSA$@[email protected]' \
getST.py -k -no-pass -spn HTTP/dc1.ping.htb \
    -dc-ip $target_dc1_ip 'PONG.HTB/Pong_gMSA$'
[*] Getting ST for user
[*] Saving ticket in Pong_gMSA$@[email protected]
zsh
➜ klist 'Pong_gMSA$@[email protected]'
Ticket cache: FILE:Pong_gMSA$@[email protected]
Default principal: Pong_gMSA$@PONG.HTB

Valid starting       Expires              Service principal
11/20/2026 03:09:06  11/20/2026 11:37:13  HTTP/[email protected]

Point the wrapper at the second file. Point it at the original ccache and the ticket is invisible; point it at the hop-one file and it has the referral but not the service ticket.

The contrast with kvno is the hand-off. From a cache holding only the home TGT, one kvno call fetches the referral and the service ticket and appends both to the same file:

zsh
➜ env KRB5CCNAME='Pong_gMSA$.ccache' \
kvno HTTP/dc1.ping.htb

HTTP/[email protected]: kvno = 7
zsh
➜ klist 'Pong_gMSA$.ccache'
Ticket cache: FILE:Pong_gMSA$.ccache
Default principal: Pong_gMSA$@PONG.HTB

Valid starting       Expires              Service principal
11/20/2026 01:37:13  11/20/2026 11:37:13  krbtgt/[email protected]
	renew until 11/21/2026 01:37:11
11/20/2026 01:38:01  11/20/2026 11:37:13  krbtgt/[email protected]
	renew until 11/21/2026 01:37:11
11/20/2026 01:38:02  11/20/2026 11:37:13  HTTP/[email protected]
	renew until 11/21/2026 01:37:11

kvno hands off the same file. getST.py hands off a chain of files, and the last one is the only one the service cares about.

Swap HTTP/dc1.ping.htb for ldap/dc1.ping.htb and the two calls are identical; only the final ticket name changes. The run used the gMSA cache — the principal is incidental.

How To Actually Read It — Operators and Defenders

  • Configure both realms before touching a trust — krb5.conf with both [realms] entries and both [domain_realm] mappings.
  • Use native kvno <spn> first. Read the resulting klist. If the referral TGT is absent, stop and fix the config.
  • Hand the pre-warmed ccache to GSSAPI clients — or pre-warm every SPN the next SMB/WMI wrapper will ask for: cifs/ for SMB, and host/ as well for wmiexec.py. One kvno call with both SPNs appends them to the same ccache. Do not assume a wrapper will fetch what is missing; for Impacket’s TGS path, use a ccache whose default principal is already in the target realm.
  • Expect strongerAuthRequired on DCs that enforce LDAP signing. Native ldapsearch -Y GSSAPI negotiates signing; -no-ldap-signing strips it and gets refused.
  • “Zero results” is not a tool failure — check which forest’s Configuration partition you queried.
  • Do not pivot to a Windows host just because Impacket printed an error code. The error is carrying information.

Real Domain Walkthrough — PingPong

All KDC requests to pong.htb traverse the tunnel — port 88 on 192.168.2.2 has to be routable before kvno runs, not just before the LDAP writes. A tunnel that only carries LDAP will make every Kerberos step look like a tool failure. Both the writeup and this re-run used ligolo; the prerequisite is identical.

strongerAuthRequired

DC2 requires integrity protection on every LDAP bind. -no-ldap-signing tells Impacket to strip the GSSAPI signature; the DC refuses. Native ldapsearch -Y GSSAPI negotiates signing automatically. One flag’s difference between a refusal and a session.

Zero results, not an error

PONG.HTB has no AD CS infrastructure. Its Configuration partition is queryable and empty of certificate templates. Certipy was answering a question about the wrong forest — a perfectly correct answer to the wrong question. BloodHound’s foreign security principal edges were what pointed at the PING side in the first place.

The cross-forest trust as BloodHound drew it

KDC_ERR_WRONG_REALM (68)

Running Impacket-based enumeration with a PONG ticket against dc1.ping.htb stops at the referral. Running the same request through ldapmodify -Y GSSAPI goes through libkrb5, hops from the PONG KDC to the PING KDC, and lands the write. The error is the referral the client declined to follow.

The ldapmodify write that got through

The template write — the OR of Bit 0 into 0xa2000000 — was done with native LDAP because that was the only path that crossed the trust. The wrapper could not reach the object; the protocol could. That is why the chain reads the way it does.

What the klist proved

The three-ticket klist after kvno is the proof that the hop happened: home TGT, referral TGT, service ticket. No forged ticket, no Windows host, no Rubeus — just a client that asked the second KDC the question the first KDC had referred.

The Wrapper Assumes; The Protocol Asks

Every tool in the matrix is correct inside the environment it was written for. The native library assumes it may have to ask another KDC and is built to follow the answer. Impacket assumes the KDC it was pointed at can answer the question. When that assumption breaks, the failure looks like a tool bug and is really a protocol question nobody asked.

A short version worth keeping: when the wrapper stops at a realm boundary, ask the protocol yourself.

When the Wrapper Works — One Realm, No Referral

None of this matters when everything lives in one realm. The Westbridge AD CS chain stayed inside westbridge.hsm, and bloodyAD did the whole write in a single command. The RBCD getST.py call on PingPong also stayed in PONG — the SPN and the KDC were both local. A wrapper is the right tool when there is no referral to follow. The skill is recognising which situation you are in before you blame the tool.

Closing — Read the Referral, Not the Wrapper

KDC_ERR_WRONG_REALM is not the end of a path. It is the KDC telling you where the path goes next, in the only language a ticket can speak. Native libkrb5 reads it. A wrapper that expects one answer does not.

If you take one thing from this post: read the ccache, not the error. The middle ticket — krbtgt/[email protected] — is the trust made visible. Once you can see it, the rest of the chain is just asking the second KDC the question the first one referred.