#!/bin/bash echo "[*] Testing whether CVE-2022-0492 can be exploited for container escape" # Setup test dir test_dir=/tmp/.cve-2022-0492-test if ! mkdir -p $test_dir ; then echo "ERROR: failed to create test directory at $test_dir" exit 1 fi # Test whether escape via CAP_SYS_ADMIN is possible if mount -t cgroup -o memory cgroup $test_dir >/dev/null 2>&1 ; then if test -w $test_dir/release_agent ; then echo "[!] Exploitable: the container can escape as it possesses CAP_SYS_ADMIN and runs without AppArmor or SELinux. Note that it likely doesn't need CVE-2022-0492 to escape." umount $test_dir && rm -rf $test_dir exit 0 fi umount $test_dir fi # Test whether escape via user namespaces is possible while read -r subsys do if unshare -UrmC --propagation=unchanged bash -c "mount -t cgroup -o $subsys cgroup $test_dir 2>&1 >/dev/null && test -w $test_dir/release_agent" >/dev/null 2>&1 ; then echo "[!] Exploitable: the container can abuse user namespaces to escape" rm -rf $test_dir exit 0 fi done <<< $(cat /proc/$$/cgroup | grep -Eo '[0-9]+:[^:]+' | grep -Eo '[^:]+$') # Cannot escape via either method rm -rf $test_dir echo "[+] Contained: cannot escape via CVE-2022-0492"