MrAriaNet/cPanel-Fix
GitHub: MrAriaNet/cPanel-Fix
针对 CVE-2026-41940 和 CVE-2026-31431 的 cPanel/Linux 服务器安全修复与加固脚本,集版本评估、补丁升级、内核模块屏蔽、CSF 防火墙调整及可选运维加固于一体。
Stars: 1 | Forks: 2
# cPanel 与内核安全辅助脚本
一个用于修复 **CVE-2026-41940** (cPanel)、**CVE-2026-31431** (内核 "Copy Fail")、CSF、可选域名/代理清理以及可选运维加固的 **`security-remediation.sh`** 脚本。
**维护者:** [Aria Jahangiri Far](https://github.com/MrAriaNet)
## 克隆
```
git clone https://github.com/MrAriaNet/cPanel-Fix.git
cd cPanel-Fix
chmod +x security-remediation.sh
sudo ./security-remediation.sh # assess only
sudo ./security-remediation.sh --fix-all # cPanel + kernel + merge CSF panel ports
```
在你的账号下将其发布为一个新仓库(例如 `https://github.com/MrAriaNet/cPanel-Fix`),使用 `git init`、`git add`、`git commit`、`git push`。
## 标志位 (快速参考)
| 标志位 | 作用 |
|------|----------------|
| *(默认)* | 评估 CVE/cPanel 版本、CSF `TCP_IN`、内核 `algif_aead` |
| `--fix-cpanel` | `upcp --force`,重启 `cpsrvd`,清空原始会话/缓存/预认证 |
| `--purge-cpanel-sessions` | 仅清空会话 + 重启 |
| `--fix-kernel` | modprobe 黑名单 + 卸载 `algif_aead` |
| `--fix-csf` | 将 **2083,2087,2095,2096** 合并到 `TCP_IN` 中,执行 `csf -r` |
| `--csf-strip-panel-ports` | 从 `TCP_IN` 中移除锁定端口集 (**不可**与 `--fix-csf` 同时使用) |
| `--extra-hardening-csf` | 激进的 `csf.conf` + **固定的** `TCP_IN` + `csf -r` / `csf -ra` (**不可**与 `--fix-csf` 同时使用) |
| `--list-domains` | 打印 `/etc/userdomains` (`用户域名`);可选 `--domain-list-output=/path` |
| `--remove-service-subdomains` | 根据每行内容执行 `proxydomains` + `servicedomains remove` |
| `--extra-hardening` | 关闭 `rpcbind`,WHM Terminal UI 标志,`whmapi1` 调整,`compilers off` |
| `--fix-all` | 仅执行 `--fix-cpanel` + `--fix-kernel` + `--fix-csf` |
| `-y` / `--non-interactive` · `--dry-run` | 作用显而易见 |
**冲突:** 如果将 **`--fix-csf`** 与 **`--csf-strip-panel-ports`** 或 **`--extra-hardening-csf`** 混合使用,脚本将退出。
## 行为说明
- **cPanel:** 将 **`cpanel -V`** 与 [安全通告](https://support.cpanel.net/hc/en-us/articles/40073787579671-Security-CVE-2026-41940-cPanel-WHM-WP2-Security-Update-04-28-2026) 中每行的最低内置版本进行比较;未知层级 → 仅发出警告。
- **CSF:** Python 脚本编辑 **`/etc/csf/csf.conf`** (带引号的 `TCP_IN`);备份使用 **`.bak.`** 时间戳。
- **内核:** 根据 [Copy Fail](https://copy.fail/#copy-fail) 临时屏蔽 **`algif_aead`**;真正的修复 = 打过补丁的内核包。
- **域名:** 代理剥离针对 **80/443** 的主机式域名;结合 CSF 进行端口级别的控制 ([代理知识库](https://support.cpanel.net/hc/en-us/articles/4405754485527-How-to-remove-service-subdomains-WHM-cPanel-Webmail-Webdisk-))。
- **额外加固:** 清单式的步骤 (WHM 调整等);**`--extra-hardening-csf`** 会用一个简短的列表覆盖 **`TCP_IN`** - 除非你修改脚本,否则预计 **不支持 2087 / 自定义应用**。
## 示例
```
./security-remediation.sh --fix-kernel --dry-run
./security-remediation.sh --list-domains --domain-list-output=/root/domains.tsv
./security-remediation.sh --remove-service-subdomains
./security-remediation.sh --extra-hardening
```
## 遭遇疑似入侵后
使用 cPanel 的 **`ioc_checksessions_files.sh`** 脚本(来自 [其 CVE 页面](https://support.cpanel.net/hc/en-us/articles/40073787579671-Security-CVE-2026-41940-cPanel-WHM-WP2-Security-Update-04-28-2026));检查 `/var/cpanel/sessions` 和访问日志。
## 撤销操作
恢复 **`csf.conf`** / **`csf.conf.bak.*`**,在安装修复后的内核后移除 modprobe 插入配置,如果必须回滚 `upcp`,请遵循 cPanel 的策略。
## 参考文献
- [CVE-2026-41940](https://support.cpanel.net/hc/en-us/articles/40073787579671-Security-CVE-2026-41940-cPanel-WHM-WP2-Security-Update-04-28-2026)
- [CVE-2026-31431](https://copy.fail/#copy-fail)
- [Qualys - CVE-2026-41940](https://threatprotect.qualys.com/2026/04/30/cpanel-and-whm-authentication-bypass-vulnerability-exploited-in-the-wild-cve-2026-41940/)
## 致谢
**Saeed Yavari** ([@iSaeedYavari](https://t.me/iSaeedYavari)) - 提供了在 **`--extra-hardening`** / **`--extra-hardening-csf`** 中体现的上下文和加固清单。
## 免责声明
请仅在你自己管理或经授权测试的系统上使用。
© Aria Jahangiri Far - [github.com/MrAriaNet](https://github.com/MrAriaNet)
标签:algif_aead, Bash, Burp Suite 替代, cPanel, CSF防火墙, CVE-2026-31431, CVE-2026-41940, GitHub Advanced Security, Go语言工具, Linux内核, Shell脚本, Web报告查看器, WHM, 安全加固, 安全基线, 安全渗透, 应用安全, 教学环境, 漏洞修复, 漏洞缓解, 端点安全, 系统管理员, 网络安全培训, 自动化运维, 补丁管理, 运维工具, 逆向工具