Citrix中存在信息泄露漏洞,由于越界读取,未经授权的攻击者可以利用该漏洞获取到存储在内存的密钥。
该漏洞在八月下旬观察到在野利用。
其他
这个漏洞在10.19就已经分析完了,当时扫描了一下公网受影响服务器发现影响比较大,所以没有公开详情,在昨天国外安全研究员公开了PoC,所以现在才写分析文章。
hunter
web.title="Citrix Gateway"
参照 CVE-2023-3519 Citrix Gateway RCE搭建
14.1-4.42 192.168.52.100
14.1-8.50 192.168.52.105
13.1-49.15 192.168.52.95
初步分析
根据 官方通告可知两个漏洞都是对内存的操作不当造成的。对应的CVSS3分别如下
综合可以知道如下信息:
利用漏洞无需权限、使用网络请求即可利用、均为内存型漏洞,应该跟[[CVE-2023-3519 Citrix Gateway RCE|CVE-2023-3519)类似,对用户输入没做校验,其中CVE-2023-4966 应该是实现了越界读取内存。

diff nsppe文件,分析各个函数修改的地方。

在逐个分析各个函数之后,目光转到ns_aaa_oauth_send_openid_config函数。
在补丁中 ns_aaa_oauth_send_openid_config中对snprintf的返回值做了判断,在修复之前直接将snpritf的返回值放到了ns_vpn_send_response中,修复之后先判断返回值是否大于1FFFF。
snprintf将格式化的数据,写入内存中,原型为int snprintf(char *str, int n, char * format [, argument, ...]);,其中n为要写入的字符串的最大长度,snprintf最多会给内存写入n-1个字符,最后一个字符使用'\0',当要格式化后的字符串大于n时,会在n-1处截断。但此时,snprintf会返回格式化字符串的长度,而不是写入内存的长度。

向上追溯调用栈,ns_aaa_oauth_send_openid_config被 ns_vpn_process_unauthenticated_request调用,将 ns_vpn_process_unauthenticated_request 代码给AI分析调用到该函数的路径,可知调用路径为 /oauth/idp/.well-known/openid-configuration

此处猜测未修复版本中会使用snprintf的返回值作为长度参数进行读取。 curl请求该接口,可以看到响应中中会把我们请求的host放进去
$ curl -i -s -k -X $'GET' -H $'Host: curl.test.site' -H $'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0' -H $'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H $'Accept-Language: zh-CN,en-US;q=0.7,en;q=0.3' -H $'Accept-Encoding: gzip, deflate' -H $'Upgrade-Insecure-Requests: 1' -H $'Sec-Fetch-Dest: document' -H $'Sec-Fetch-Mode: navigate' -H $'Sec-Fetch-Site: none' -H $'Sec-Fetch-User: ?1' -H $'Te: trailers' -H $'Connection: close' -b $'NSC_TASS=/menu/neo' $'https://192.168.52.234/oauth/idp/.well-known/openid-configuration'
HTTP/1.1 200 OK
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Length: 717
Cache-control: no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Type: application/json; charset=utf-8
X-Citrix-Application: Receiver for Web
{"issuer": "https://curl.test.site", "authorization_endpoint": "https://curl.test.site/oauth/idp/login", "token_endpoint": "https://curl.test.site/oaut
h/idp/token", "jwks_uri": "https://curl.test.site/oauth/idp/certs", "response_types_supported": ["code", "token", "id_token"], "id_token_signing_alg_va
lues_supported": ["RS256"], "end_session_endpoint": "https://curl.test.site/oauth/idp/logout", "frontchannel_logout_supported": true, "scopes_supported
": ["openid", "ctxs_cc"], "claims_supported": ["sub", "iss", "aud", "exp", "iat", "auth_time", "acr", "amr", "email", "given_name", "family_name", "nic
kname"], "userinfo_endpoint": "https://curl.test.site/oauth/idp/userinfo", "subject_types_supported": ["public"]}
前面知道print_temp_rule大小为0x20000,返回值中共有6处重复了host,所以我们传入的host长度>21845(粗略估计)就可以触发溢出。再次请求,发现可以利用超长host读取到Citrix内存,实际测试发现host长度最多到24100左右。

借助这个漏洞,写了一个nuclei模板对公网扫描,对八百个独立IP扫描,截止至10.20,仍然有大约15%未修复,且通过这个漏洞可以读取到内存中的secret,后续可以借助这个secret绕过身份验证,请求后端接口。
这个接口也在oauth的配置中有提到 https://support.citrix.com/article/CTX234873/how-to-deploy-netscaler-as-both-oauth-sp-and-idp

ns_aaa_oauthrp_send_openid_config函数类似,也snprintf的返回值做了判断。

调试
关闭看门狗对nsppe进程发送的信号,而后直接在对应位置处下断点即可。
root@citrix3# nspf help
Usage: '/netscaler/nspf ((<process_name> | <pid>) <action> | query)'
where <process_name> is one of:
NSPPE-00 aslearn awsconfig bgpd de
imi isisd metricscollectomonuploadd nsaaad
nsaggregatord nscfsyncd nsclfsyncd nsclusterd nsconfigd
nscopo nsfsyncd nsgslbautosyncnslcd nslped
nsm nsnetsvc nsrised nstraceaggregatnsumond
ospf6d ospfd ptpd ripd ripngd
snmpd syshealthd
root@citrix3# /netscaler/nspf nsppe-00 pbmonitor 0
nspf NSPPE-00 pbmonitor 0
Removing pitboss monitor on process NSPPE-00 pid 37387
PoC
https://github.com/Chestnuts4/POC/blob/master/nuclei_poc/CVE-2023-4966_citrix_info_disclose.yaml
实际利用
通过漏洞可以读取到内存中的已登录会话的secret。
该漏洞整体分析、利用较为简单, 通过朴实无华的越界读取即可造成信息泄露,也无需进行内存布局。其实整体看nsppe,很多使用了snprintf的地方都对其返回值进行了判断,本次漏洞点没有对返回值做判断可能是因为开发时遗漏了。
另外即使修复该漏洞之后,已被劫持的会话仍然有效,需要使用如下命令清除已登录的会话
clar lb persistentSessions <vServer>
参考链接
https://support.citrix.com/article/CTX234873/how-to-deploy-netscaler-as-both-oauth-sp-and-idp
Created at 2023-10-26T10:18:12+08:00