# Citrix Bleed: Leaking Session Tokens with CVE-2023-4966

Unauthenticated OpenID config endpoint used snprintf's would-be length to over-read static buffer, leaking NetScaler session tokens from memory.

- Payout: Research
- Severity: critical
- Program: Citrix
- Write-up by: Assetnote
- Disclosed: 2025-02-12
- CVE: CVE-2023-4966
- Write-up quality: 9/10
- Original: https://www.assetnote.io/resources/research/citrix-bleed-leaking-session-tokens-with-cve-2023-4966
- Library page: https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-citrix-bleed-leaking-session-tokens-with-cve-2023-4966
- Tags: area:devices domain:network impact:ato impact:data-leak kind:research platform:research sev:critical tech:oauth technique:reverse-engineering technique:source-review vuln:info-disclosure

**Target:** NetScaler ADC/Gateway nsppe binary, /oauth/idp/.well-known/openid-configuration endpoint
**Root cause:** snprintf return value (would-have-written length) was passed to ns_vpn_send_response instead of actual bytes written, so an oversized Host header caused the response to include memory past the 0x20000 print_temp_rule buffer.
**Steps:**
1. Patch-diff nsppe 13.1-49.15 vs 13.1-48.47 in Ghidra/BinDiff; ~50 functions changed
2. Spot added bounds check `if (uVar7 < 0x20000)` in ns_aaa_oauth_send_openid_config / ns_aaa_oauthrp_send_openid_config
3. Note snprintf return used as send length; hostname inserted 6x from Host header
4. Send `GET /oauth/idp/.well-known/openid-configuration HTTP/1.1` with `Host: a` repeated 24812 times
5. Response Content-Length 147441 includes leaked memory past buffer
6. Extract 65-byte hex string and replay as `Cookie: NSC_AAAC=...` to /logon/LogonPoint/Authentication/GetUserName to confirm valid session
**How found:** Prior NetScaler experience pointed to nsppe binary; patch diffing revealed a new bounds check around snprintf in OAuth OpenID config handlers, prompting hypothesis that snprintf's return semantics were misused.
**Exploitation:** Unauthenticated attacker sends oversized Host header to OpenID discovery endpoint; static global buffer over-read returns adjacent memory containing other users' NSC_AAAC session cookies, which are replayed to hijack authenticated sessions.
**Escalation:** Session token theft enables authentication bypass and account takeover of VPN users; mass exploitation observed in the wild per CISA advisories (not detailed here).
**Insight:** When auditing snprintf/similar, check whether the return value (would-be length) is used as a send/write length rather than the actual written count; also check whether attacker-controlled headers (Host) feed format strings that repeat many times to reach buffer limits.

## Proof of concept (copied exactly from the original report)

**Overlong Host header request triggering buffer over-read**

```
GET /oauth/idp/.well-known/openid-configuration HTTP/1.1
Host: a <repeated 24812 times>
Connection: close
```

**Leaked session token used as NSC_AAAC cookie**

```
POST /logon/LogonPoint/Authentication/GetUserName HTTP/1.1
Host: 192.168.1.51
Cookie: NSC_AAAC=59d2be99be7a01c9fb10110f42b188670c3a01f2245525d5f4f58455e445a4a42
```

