Swing'Blog 浮生若梦 Swing'Blog 浮生若梦
  • Home
  • |
  • About
  • |
  • Articles
  • |
  • RSS
  • |
  • Categories
  • |
  • Links

CVE-2023-4966 citrix 内存泄漏

2023-10-24 Updated on 2023-10-24 漏洞分析

Table of Contents

  1. 漏洞细节
  2. Reference link
TL; DR

10月18日的时候注意到思杰官网发布了一个安全公告: NetScaler ADC and NetScaler Gateway Security Bulletin for CVE-2023-4966 and CVE-2023-4967 。其中提到一个敏感信息泄露的漏洞。在今天(10月24日),assetnote 发布了一些细节文章,这里简单记录下。

漏洞细节

这里以 13.0-47 的固件为例子, 从固件拉出 nsppe 这个程序,用 IDA 打开分析。 搜索文章提到的字符串可以看到如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  want_to_write_len = snprintf(
print_temp_rule,
0x10000,
(unsigned int)"{\"issuer\": \"https://%.*s\", \"authorization_endpoint\": \"https://%.*s/oauth/id"
"p/login\", \"token_endpoint\": \"https://%.*s/oauth/idp/token\", \"jwks_uri\": \"h"
"ttps://%.*s/oauth/idp/certs\", \"response_types_supported\": [\"code\", \"token\","
" \"id_token\"], \"id_token_signing_alg_values_supported\": [\"RS256\"], \"end_sess"
"ion_endpoint\": \"https://%.*s/oauth/idp/logout\", \"frontchannel_logout_supported"
"\": true, \"scopes_supported\": [\"openid\", \"ctxs_cc\"], \"claims_supported\": ["
"\"sub\", \"iss\", \"aud\", \"exp\", \"iat\", \"auth_time\", \"acr\", \"amr\", \"em"
"ail\", \"given_name\", \"family_name\", \"nickname\"], \"userinfo_endpoint\": \"ht"
"tps://%.*s/oauth/idp/userinfo\"}",
......
hostname);
authv2_json_resp = 1;
if ( (unsigned int)ns_vpn_send_response(a1, 0x100040LL, print_temp_rule, want_to_write_len) )
{

这里可以看到,snprintf函数被用于将hostname参数拼接到print_temp_rule变量中,并根据返回的长度,通过ns_vpn_send_response函数返回HTTP请求的结果。这种对snprintf的使用方法是一个常见的错误。这里的hostname参数是由 HTTP 请求中的 Host 头决定的,因此这个参数的长度我们是完全可以控制的。这让我想到一个长亭之前发布的一篇经典文章 实战栈溢出:三个漏洞搞定一台路由器。也是使用snprintf 从缓冲区泄漏内存。

image.png

总结一下就是, snprintf 这个函数应该返回的是 ”想要写入buffer 的字符串长度“ , 而不是实际写入buffer的字符长长度。可以从一个 DEMO 看出这个效果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
➜  Desktop cat test.c
int main() {
char buf[8];
memset(buf,0,8);
int n1 = snprintf(buf, 8, "%s", "aaa");
printf("buf: %s\n", buf);
printf("n1: %d\n", n1);
memset(buf,0,8);
int n2 = snprintf(buf, 8, "%s", "aaaabbbbccccdddd");
printf("buf: %s\n", buf);
printf("n2: %d\n", n2);
}
➜ Desktop ./a.out
buf: aaa
n1: 3
buf: aaaabbb
n2: 16

可以看到,当我想写入 16长度的字符串的时候, n2的值为 16, 而不是实际写入的长度。

The functions snprintf() and vsnprintf() do not write more than size bytes (including the terminating null byte (’\0’))

PoC:

具体一样长度能不能泄漏出 token , 看起来和版本还是有关系的,至少我这个版本在 CVE-2023-4966这个利用中是打不出来的。应该和不同缓冲区的大小不一样?猜测的,具体我就不进一步调试了。

另外到达这个函数的路由,通过对这个函数 ns_aaa_oauth_send_openid_config 进行交叉引用一下子就看到了:

image.png

Reference link

Citrix Bleed: Leaking Session Tokens with CVE-2023-4966
实战栈溢出:三个漏洞搞定一台路由器

分类: 漏洞分析
标签: CVE-2023-4966
← Prev CVE-2024-21626 容器逃逸漏洞分析
Next → CVE-2023-27997-FortiGate-SSLVPN-HeapOverflow

Comments

© 2015 - 2026 Swing
Powered by Hexo Hexo Theme Bloom