This repository provides a single, self‑contained script to detect likely Copy Fail (CVE‑2026‑31431) exploitation attempts and harden a host until kernel patches can be applied.
Copy Fail is a Linux kernel local privilege escalation that uses AF_ALG + splice() to perform a controlled 4‑byte write into the page cache of any readable file, enabling in‑memory modification of setuid binaries (for example /usr/bin/su) without touching disk.
Important: This tool does not fix the kernel bug. It helps you:
- Detect suspicious activity that matches the public exploit chain.
- Apply temporary hardening measures.
- Quickly verify whether your host appears vulnerable.
Public writeups and PoCs (for example, by Theori/Xint Code and community repos) describe a compact (≈700‑byte) Python exploit that works on most current distributions. Although implementations differ, they share the same basic steps:
-
Open an AF_ALG crypto socket
- The exploit uses the Linux userspace crypto API (
AF_ALG) with an AEAD/algif_aeadalgorithm, typically via Python’ssocketmodule. - It configures a context that triggers a buggy “in‑place” copy path in the kernel’s
authencesncrypto template.
- The exploit uses the Linux userspace crypto API (
-
Abuse
splice()into the crypto socket- The exploit opens a target file that is readable but often privileged, typically a setuid binary such as
/usr/bin/su. - Using
splice(), it maps that file into the AF_ALG socket pipeline so the kernel will operate directly on the file’s page cache pages.
- The exploit opens a target file that is readable but often privileged, typically a setuid binary such as
-
Trigger a failed crypto operation that corrupts page cache
- By providing invalid or mismatched authentication data, the HMAC check fails as expected, but the kernel leaves a small (4‑byte) overwrite in the page cache.
- The attacker controls:
- The target file (any readable file, usually a setuid root binary).
- The offset into the cached pages.
- The 4‑byte payload written [web:3].
-
Stage payload into a setuid binary and execute it
- The exploit repeats the primitive across successive offsets to build a small “patch” into the cached image of
/usr/bin/suor a similar binary - When the attacker later runs
su, the process executes the modified, in‑memory binary and yields a root shell, even though the on‑disk file remains clean.
- The exploit repeats the primitive across successive offsets to build a small “patch” into the cached image of
-
Why detection is hard
- Traditional file integrity monitoring tools only look at disk; they see no change, because the exploit modifies the page cache only.
- Container boundaries are also bypassed, because all containers share the host kernel and its page cache.
Kadir’s IOC toolkit focuses on covering these aspects from a defender’s point of view, with auditd rules, eBPF monitoring of AF_ALG + splice chains, and page‑cache vs disk divergence detection for setuid binaries, plus Sigma rules for SIEMs. This project takes the same ideas but compresses them into a single, simpler script.
The copyfail-guard.sh script provides:
-
Vulnerability check
- Detects whether the running kernel is likely affected (based on version heuristics and presence of vulnerable modules such as
algif_aeadandauthencesn).
- Detects whether the running kernel is likely affected (based on version heuristics and presence of vulnerable modules such as
-
Detector
- Checks for suspicious patterns in recent logs:
AF_ALGsocket creation by unprivileged users (if auditd rules exist).- Unusual
suinvocations following crypto/audit events.
- Optionally verifies hash drift of key setuid binaries (e.g.
/usr/bin/su,/usr/bin/passwd) by:- Comparing against a baseline file of known good hashes.
- Warning if the current hash differs from the stored one (which may indicate a prior compromise, disk tampering, or a missed Copy Fail payload).
- Checks for suspicious patterns in recent logs:
-
Mitigator / Hardening
- Optionally:
- Restricts use of
AF_ALGto root using simple sysctl and file permission checks, where viable. - Suggests disabling the vulnerable module (
algif_aead) if it is loadable as a module and you can blacklist it. - Assists with kernel patch validation (shows current kernel and advises on updating).
- Restricts use of
- Optionally:
-
Reporting
- Prints a concise report:
- Kernel and module status.
- Detection findings (suspicious events, hash mismatches).
- Recommended next actions.
- Prints a concise report:
This is intentionally minimal: it does not replace a full eBPF + SIEM stack, but gives a single file you can drop onto a host or container for quick triage.
curl -O https://raw.githubusercontent.com/Eremiel/CopyFailMitigation/refs/heads/main/copyfail-guard.sh
chmod +x copyfail-guard.sh(Replace with your actual repo URL.)
sudo ./copyfail-guard.sh detectThis will:
- Check whether the system appears vulnerable.
- Look for suspicious
AF_ALGusage and recentsuexecutions. - Compare setuid binary hashes against a local baseline file (if present).
sudo ./copyfail-guard.sh baselineThis:
- Computes hashes for common setuid binaries (configurable inside the script).
- Stores them in
./copyfail-baseline.sha256. - Should be run once on a known‑good system, ideally immediately after installing vendor security updates.
sudo ./copyfail-guard.sh hardenThis attempts to:
- Tighten permissions around AF_ALG interfaces where possible.
- Suggest or assist in blacklisting vulnerable modules (no automatic editing of system files unless you opt in inside the script).
- Remind you to install vendor kernel patches.
Note: Hardening may break workloads that depend on user‑space crypto via AF_ALG. Use with care in production.
Detection report (example):
[+] Kernel: 5.15.0-101-generic
[!] Kernel version appears in affected range for CVE-2026-31431 (Copy Fail)
[+] Module algif_aead: loaded
[+] Module authencesn: present (built-in or available)
[+] Baseline file: ./copyfail-baseline.sha256
[+] su: hash matches baseline
[+] passwd: hash matches baseline
[+] No suspicious AF_ALG audit events for unprivileged users in last 24h
Status: VULNERABLE KERNEL, NO IOC DETECTED
Recommendation: Apply vendor kernel updates and re-run this tool after reboot.
Hardening report (example):
[+] Attempting basic hardening (non-destructive)
[+] Suggested: blacklist algif_aead in /etc/modprobe.d/blacklist-copyfail.conf
[+] Suggested: ensure kernel updates are installed from your distribution
Status: HARDENING SUGGESTED (manual steps required)
- This script does not inspect raw page‑cache state and cannot reliably prove that no in‑memory tampering occurred.
- Logs and audit rules may be incomplete or absent; sophisticated attackers may clear traces.
- The only definitive mitigation is to update the kernel to a fixed version released by your Linux vendor.
- For high security environments, consider deploying:
- eBPF monitors that correlate
AF_ALG+splice()usage per PID. - SIEM integration with Copy Fail–specific Sigma rules (as in Kadir’s IOC toolkit).
- eBPF monitors that correlate
- Xint Code / Theori – Copy Fail technical analysis.
- Vendor and CERT advisories for CVE‑2026‑31431.
- Community IOC toolkit repository description and posts (Kadir’s
copy-fail-CVE-2026-31431-IOC).
Use this script and documentation as a starting point and adapt it to your environment’s logging, monitoring, and compliance requirements.