DefaultLdapRealm 在启用认证缓存时,一次成功登录后接受任意密码| CVE | CVE-2026-129349 |
| 组件 | Apache Shiro DefaultLdapRealm(也包括 JndiLdapRealm),core/src/main/java/org/apache/shiro/realm/ldap/DefaultLdapRealm.java |
| 受影响版本 | 截至 3.0.0 的所有 Apache Shiro 版本,仅当使用 DefaultLdapRealm/JndiLdapRealm 且 authenticationCachingEnabled = true(非默认配置)时受影响 |
| 修复版本 | 3.0.1 — DefaultLdapRealm 的构造函数不再默认安装 AllowAllCredentialsMatcher |
| CWE | CWE-287(认证不当),CWE-613(会话过期不足的类似情形:过期的缓存认证) |
| 影响 | 认证绕过:知道(或猜到)任意有效用户名的攻击者,在该用户登录过一次之后,即可用任意密码——包括空字符串——以该用户身份通过认证 |
| 向量 | 任何由受影响 realm 配置支撑的认证路径;网络位置取决于到达应用的路径 |
| 触发条件 | 一次有效登录会填充认证缓存;此后针对同一用户的每个 UsernamePasswordToken 都会被接受而无需执行 LDAP 绑定,因为缓存的 AuthenticationInfo 由 AllowAllCredentialsMatcher 进行匹配 |
| 致谢 | Apache Shiro 安全公告(ASF 线程 1whn52ht402lhc782c3s843c9hho8b4y) |
Apache Shiro 的 DefaultLdapRealm 历史上会在其构造函数中安装
AllowAllCredentialsMatcher——“凭据匹配并非必要,LDAP 目录会自动完成”。这一
推理仅在每次认证都执行 LDAP 绑定时才成立。
当 authenticationCachingEnabled = true 时,缓存的认证会完全跳过
绑定,仅由匹配器单独运行——而一个接受任何内容的匹配器
会把缓存变成一扇敞开的大门。上游修复
(shiro-root-3.0.0...shiro-root-3.0.1)恰好是删除两行代码:
public DefaultLdapRealm() {
- //Credentials Matching is not necessary - the LDAP directory will do it automatically:
- setCredentialsMatcher(new AllowAllCredentialsMatcher());
//Any Object principal and Object credentials may be passed to the LDAP provider, so accept any token:
setAuthenticationTokenClass(AuthenticationToken.class);
这个实验环境运行的是真实的 DefaultLdapRealm(存在漏洞的 3.0.0 与已修复的 3.0.1,这是两个构建版本之间唯一的差异),针对真实的内存 LDAP 目录(UnboundID LDAP SDK)以及真实的缓存管理器——正是安全公告中所述的配置——并端到端地证明了该绕过。
Shiro 的 AuthenticatingRealm.getAuthenticationInfo(token) 首先通过缓存来解析认证:
AuthenticationInfo info = getCachedAuthenticationInfo(token); // cache hit → no LDAP bind
if (info == null) {
info = doGetAuthenticationInfo(token); // the LDAP bind
cacheAuthenticationInfo(token, info); // prime the cache
}
assertCredentialsMatch(token, info); // ← the only remaining check
在 DefaultLdapRealm 直至 3.0.0 的版本中,assertCredentialsMatch 会查询构造函数安装的 AllowAllCredentialsMatcher,其 doCredentialsMatch 无条件返回 true。由此产生的后果均在本实验中复现:
AuthenticationInfo 存入缓存;前提条件很明确:authenticationCachingEnabled 并非默认值,正如公告所述(“仅当使用 DefaultLdapRealm(或 JndiLdapRealm)且 authenticationCachingEnabled 设置为 true 时,而这不是默认值”)。启用该选项的部署——一种常见的性能选择——会带有此绕过漏洞。
| 服务 | 镜像 | 角色 |
|---|---|---|
shiro-vuln | cve-2026-129349:vuln | shiro-core 3.0.0——该 realm 安装了 AllowAllCredentialsMatcher |
shiro-fixed | cve-2026-129349:fixed | shiro-core 3.0.1——构造函数不再安装它(改用基类的 SimpleCredentialsMatcher) |
poc | cve-2026-129349-poc:local | 仅使用标准库的 Python 驱动 |
每个服务都是一个单独的 Java 进程,它会启动 (1) 一个 UnboundID 内存 LDAP 目录(dc=lab、ou=people、uid=alice,带有预置密码,使用 bind-DN 认证)以及 (2) 一个 HTTP 端点(/login?username=&password=),该端点调用真实的 realm.getAuthenticationInfo(new UsernamePasswordToken(...))。该 realm 完全按照公告进行配置:DefaultLdapRealm + JndiLdapContextFactory(ldap://127.0.0.1:1389)+ MemoryConstrainedCacheManager + authenticationCachingEnabled(true)。两个镜像仅在 shiro.version Maven 属性上有所不同。
./run-lab.sh build # compiles the service against 3.0.0 and 3.0.1
./run-lab.sh up # cve129349lab network, shiro-vuln, shiro-fixed
./run-lab.sh sweep # check / exploit / probe / mitigation on both sides
./run-lab.sh down
针对单侧的单模式:
podman run --rm --network cve129349lab cve-2026-129349-poc:local \
exploit --host=shiro-vuln
poc/poc.py(仅使用标准库):
wrong-password、x、空字符串和 0 以该用户身份进行认证;报告每一个被接受的垃圾凭据。| 运行 | shiro-vuln (3.0.0) | shiro-fixed (3.0.1) |
|---|---|---|
check 有效登录前的错误密码 | false(LDAP bind 拒绝) | false |
check 有效登录 | true | true |
check 有效登录后的错误密码 | true — 绕过 | false(IncorrectCredentialsException) |
exploit 垃圾密码 | wrong-password、x、``、0 全部被接受 | 均不被接受 |
probe 空密码,热缓存 | true | false |
probe 未知用户 | false(无缓存条目 → bind 失败) | false |
probe /reset 后的错误密码 | false(再次变为冷缓存) | false |
| 报告的匹配器 | AllowAllCredentialsMatcher | SimpleCredentialsMatcher |
捕获的运行记录:evidence/check-*-run.txt、evidence/exploit-*-run.txt、evidence/probe-*-run.txt、evidence/mitigation-*-run.txt、evidence/versions.txt、evidence/0day-sweep.txt。
cve129349lab 网络上均受资源限制。探测矩阵同时兼作修复构建上的状态扫描(evidence/0day-sweep.txt):在 3.0.1 上,所有错误凭据形式在冷缓存和热缓存下均被拒绝,未知主体被拒绝,有效登录仍然成功,且 /reset 恢复冷缓存语义。未发现其他未受保护的状态。
README.md this write-up
run-lab.sh environment driver (build / up / sweep / down)
Makefile convenience targets
poc/poc.py the PoC (check / exploit / probe / mitigation)
poc/Dockerfile runner image (python:3.12-alpine)
lab/lab.Dockerfile multi-stage build (maven → temurin JRE)
lab/pom.xml the ONLY version difference: shiro.version property
lab/src/.../LdapLab.java real DefaultLdapRealm + real in-memory LDAP service
evidence/ captured runs of every mode on both sides
TRACKING.md excluded (working record)