codesource/copyfail-check

GitHub: codesource/copyfail-check

一个用于检测 Linux 系统是否存在 CVE-2026-31431 Copy Fail 提权漏洞暴露面的 Shell 脚本,可检查内核版本、模块状态、启动参数和发行版补丁情况。

Stars: 1 | Forks: 0

# copyfail-check ## CVE-2026-31431 — Copy Fail **Copy Fail** 是 Linux 内核 `algif_aead` 加密模块中的一个高危本地权限提升(LPE)漏洞。2017 年引入的一个逻辑缺陷允许任何无特权的本地用户向任何可读文件的页缓存中写入 4 个可控字节——足以覆盖 setuid 二进制文件并获取 root 权限。一个可工作的 732 字节 Python 概念验证代码已存在并公开发布。 | | | |---|---| | **CVE** | CVE-2026-31431 | | **CVSS** | 7.8(高危) | | **披露日期** | 2026年4月29日 | | **影响范围** | Linux 内核 4.13 – 6.x(2017–2026) | | **受影响发行版** | Ubuntu、RHEL、SUSE、Debian、Amazon Linux 及大多数其他发行版 | | **可远程利用** | 否 — 需要本地访问权限 | | **补丁可用性** | 部分可用 — 请查看您的发行版公告 | ### 脚本检查内容 | 检查项 | 需要 root 权限? | |---|---| | 内核版本 — 是否在受影响范围内(≥ 4.13) | 否 | | `algif_aead` 模块 — 已加载、存在于磁盘或已被列入黑名单 | 否 | | 启动参数 — 是否存在 `initcall_blacklist=algif_aead_init` | 否 | | AF_ALG 套接字可达性 — 利用路径是否开放 | 否 | | SELinux 状态 | 否 | | AppArmor 状态 | **是** — 无 root 权限时仅显示部分输出 | | 发行版补丁状态 — 内核变更日志中是否列出 CVE | 否 | ### 兼容性 该脚本设计用于所有主流 Linux 发行版: | 发行版家族 | 包管理器检查 | 模块路径 | |---|---|---| | Debian、Ubuntu | `dpkg` + 内核变更日志 | `/lib/modules/` | | RHEL、CentOS、Amazon Linux | `rpm`(`kernel`、`kernel-rt`) | `/lib/modules/` | | SUSE、openSUSE | `rpm`(`kernel-default`) | `/lib/modules/` | | Arch Linux | `pacman` + 公告链接 | `/usr/lib/modules/` | | Fedora | `rpm` + `/usr/lib/modules/` 备用路径 | `/usr/lib/modules/` | ### 快速运行(单台服务器) 无 root 权限 — 大部分检查可正常运行: ``` curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/main/check_copyfail.sh | bash ``` 有 root 权限 — 完整结果,包括 AppArmor 状态: ``` curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/main/check_copyfail.sh | sudo bash ``` ### 下载并先检查(推荐) ``` curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/main/check_copyfail.sh -o check_copyfail.sh less check_copyfail.sh bash check_copyfail.sh # without root sudo bash check_copyfail.sh # full results ``` ### 在多台服务器上运行 **SSH 循环** ``` for HOST in server1 server2 server3; do echo "=== $HOST ===" ssh "$HOST" "curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/main/check_copyfail.sh | sudo bash" done ``` **Ansible** ``` - name: Check Copy Fail vulnerability hosts: all tasks: - name: Run check script script: check_copyfail.sh become: yes ``` **并行 SSH** ``` pssh -h hosts.txt -i \ "curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/main/check_copyfail.sh | sudo bash" ``` ### 示例输出 ``` ============================================================ Copy Fail CVE-2026-31431 – Vulnerability Check ============================================================ >>> Kernel Version [INFO] Running kernel: 5.15.0-107-generic [WARN] Kernel 5.15.0-107-generic is in the affected range (4.13 – 6.x). >>> algif_aead Module Status [WARN] algif_aead module is currently LOADED — system is exploitable. [WARN] Module file found at: /lib/modules/5.15.0-107-generic/kernel/crypto/algif_aead.ko [WARN] algif_aead is NOT blacklisted — it can be loaded on demand. >>> Kernel Boot Parameter Mitigation [WARN] initcall_blacklist=algif_aead_init is NOT set in boot parameters. >>> AF_ALG Socket Reachability [WARN] AF_ALG sockets are reachable by this user — exploit path is open. >>> Mandatory Access Control (SELinux / AppArmor) [WARN] Neither SELinux nor AppArmor tools detected — no MAC layer present. >>> Distribution Patch Status [WARN] Could not confirm CVE-2026-31431 is listed as fixed in running kernel's changelog. ============================================================ SUMMARY ============================================================ !! LIKELY VULNERABLE — No confirmed mitigation detected. Recommended actions (in order of preference): 1. Apply your distro's kernel update as soon as available. 2. Add to /etc/modprobe.d/copyfail.conf: blacklist algif_aead install algif_aead /bin/true Then run: sudo depmod -a && sudo update-initramfs -u 3. Add to kernel boot parameters (grub): initcall_blacklist=algif_aead_init 4. Immediately unload the module if loaded: sudo rmmod algif_aead ============================================================ ``` ### 缓解措施 按优先级顺序应用以下措施: **1. 修补内核** *(最佳解决方案)* ``` # Debian / Ubuntu sudo apt update && sudo apt upgrade linux-image-$(uname -r) # RHEL / CentOS / Amazon Linux sudo yum update kernel # SUSE sudo zypper update kernel-default ``` **2. 将模块列入黑名单** *(立即生效,持久有效)* ``` sudo tee /etc/modprobe.d/copyfail.conf << 'EOF' blacklist algif_aead install algif_aead /bin/true EOF sudo depmod -a # Debian/Ubuntu sudo update-initramfs -u # RHEL/Fedora sudo dracut -f ``` **3. 立即卸载模块** *(立即生效,重启后失效)* ``` sudo rmmod algif_aead ``` **4. 内核启动参数** *(黑名单的替代方案)* 将 `initcall_blacklist=algif_aead_init` 添加到 GRUB 配置中并重启。 ## 参考资料 - [copy.fail](https://copy.fail/) — 官方漏洞页面 - [Xint/Theori 技术分析](https://xint.io/blog/copy-fail-linux-distributions) - [NVD — CVE-2026-31431](https://nvd.nist.gov/vuln/detail/CVE-2026-31431) - [CERT-EU 公告 2026-005](https://cert.europa.eu/publications/security-advisories/2026-005/) - [Microsoft 安全博客](https://www.microsoft.com/en-us/security/blog/2026/05/01/cve-2026-31431-copy-fail-vulnerability-enables-linux-root-privilege-escalation/) - [The Hacker News](https://thehackernews.com/2026/04/new-linux-copy-fail-vulnerability.html) ## 许可证 MIT — 自由使用,不含任何保证。在以 root 身份运行脚本之前请务必先审查。
标签:0day挖掘, algif_aead, AppArmor, CopyFail, Cutter, CVE-2026-31431, SELinux, Shell脚本, 内核安全, 内核模块, 协议分析, 安全合规, 安全资源, 应用安全, 本地提权, 权限提升, 漏洞靶场, 系统安全审计, 网络代理, 网络安全, 补丁检测, 防御检测, 隐私保护