
Python implementation of copyfail (CVE-2026-31431)
Python port of badsectorlabs/copyfail-go (CVE-2026-31431). Linux only; requires Python 3.10+ (os.splice).
This tool does not use the /etc/passwd page-cache trick.
su binary with embedded shellcode (same payloads as the Go main.go), then executes su.su as a setuid root program, not from making getpwnam() think your UID is 0 via /etc/passwd.Other public Python PoCs for the same CVE may patch /etc/passwd in the page cache and then instruct you to run su <user>. That is a different target file and a different follow-up than this script.
Authorized testing only — use only on hosts you own or are explicitly permitted to assess.
chmod +x copyfail_su.py
# Interactive-style flow (same idea as copyfail-go without --exec)
./copyfail_su.py --backup /tmp/su.bak
# Run another program elevated (passes path as argv to su; uses exec-argv1 payload)
./copyfail_su.py --backup /tmp/su.bak --exec /full/path/to/binary
After a successful run, restore the real su.
--backupThe PoC corrupts the page cache for /usr/bin/su. Do not assume the on-disk file is still trustworthy until you verify or reinstall.
Reinstall the package that owns /usr/bin/su (find it first, then reinstall):
rpm -qf /usr/bin/su then sudo dnf reinstall shadow-utils (use the reported package name).dpkg -S /usr/bin/su then sudo apt install --reinstall <package>.Verify: sudo rpm -V <package> for unexpected changes to /usr/bin/su, or debsums on Debian-style systems.
Optional: reboot after reinstall to avoid stale cache assumptions.
If you cannot reinstall as root: recovery boot, Live USB, or replace /usr/bin/su from a known-good same distro/version/arch image; ensure ownership root:root and mode 4755 ().
-rwsr-xr-x