In this repository you'll find a reference implementation for an eBPF-based runtime detection for the runc and Docker vulnerabilities CVE-2024-21626
, CVE-2024-23651
, CVE-2024-23652
and CVE-2024-23653
. It hooks into Linux syscalls (e.g., chdir
, mount
) and function invocations of the Docker daemon and associates them with Docker builds and container processes to identify exploitations of these vulnerabilities.
For a static analysis-based approach, please see this.
CVE-2024-21626 is a vulnerability in the runc
container runtime allowing an attacker to break out of the container isolation and achieve full root RCE via a crafted image that exploits an issue within the WORKDIR
instruction's handling. Since there's a "race" condition between the time some file descriptors to the host are opened and closed, an attacker can create a Dockerfile with the following instruction WORKDIR /proc/self/fd/[ID]
(with ID being a system dependent file descriptor) that will point to the underlying host machine's file system. This can be exploited when running:
docker build
- In 2 cases:- When the Dockerfile being built contains the exploit triggerting instruction.
- When the Dockerfile being built refers to a base image via the
FROM
instruction that contains anONBUILD
command triggering the exploit e.e.ONBUILD WORKDIR /proc/self/fd/[ID]
. TheONBUILD
instruction injects the command not in the image that contains it but in the image that uses it as a base image. This means that if a base image is compromised or intentionally nefarious i.e. hosted on Dockerhub or other public container registries, exploitation if possible even if nothing changes in the image that thedocker build
command actually builds.
docker run
Thus, this vulnerability can put both build systems and production environments at risk.
CVE-2024-23651 is a vulnerability in Docker where a RUN
command is using the --mount=cache
flag. There's a time-of-check/time-of-use (TOCTOU) vulnerability between the check that a source
dir exists on the Docker daemon's host and the actual call to the mount
syscall. An attacker is able to craft a Dockerfile that would plant a symlink in between these two calls to induce an arbitrary bind mount that results in full root RCE on the host.
This vulnerability only affects the docker build
command.
CVE-2024-23653 is a vulnerability in Docker that occurs when using a custom Buildkit LLB generator is used with the # syntax
directive. The generator can use the Client.NewContainer and Container.Start GRPC calls to execute a new container during build. The StartRequest.SecurityMode argument is not appropriately checked against the privilege expectations of the docker daemon or docker build call, which allows the GRPC caller to create a privileged container during build. This new privileged container can then be escaped to gain full root RCE on the build host.
This vulnerability only affects the docker build
command.
CVE-2024-23652 is an arbitrary deletion vulnerability in Docker. When RUN --mount
is used in a Dockerfile, if the target of the mount does not exist it will be created for that environment. When the execution completes this created directory will be cleaned up. If the executing command changes the path used for the mount to a symbolic link, the cleanup procedure will traverse this symbolic link and potentially clean up arbitrary directories in the host root filesystem.
This vulnerability only affects the docker build
command.
The build-time detection applies to all 4 vulnerabilities.
- Compile the detector binary:
GOOS=linux GOARCH={{amd64/arm64}} go build
. - Run the compiled binary in the background using
sudo
(as required by eBPF) in your build environment (i.e.,sudo ebpf-detector &
). - If an exploitation of one of the vulnerabilities is detected, you'll see
Leaky vessels vulnerability detected
printed toSTDOUT
, alongside the respective CVE, vulnerability name and additional forensics.
The run-time detection applies the WORKDIR
vulnerability only (CVE-2024-21626).
- Build the container image of the detector using the provided
Dockerfile
and push it to an image registry. - Populate the
image
value in thedetector.yaml
(marked withTODO
). - Run the detector as a DaemonSet in your Kubernetes cluster by running
kubectl apply -f detector.yml
. - If a WORKDIR vulnerability exploitation is detected, you'll see
Leaky Vessels vulnerability detected
printed in the DaemonSet pod logs.
Unit tests need to run in sudo
, as they rely on eBPF: sudo go test ebpf-detector/...
.
- Requires root access / running containers in privileged mode (required by eBPF).
- The runtime
WORKDIR
exploitation (CVE-2024-21626
) happens during container initialization, so it won't be detected on running containers. The detection also assumes the container runtime iscontainerd
. - The Buildkit Mount Cache Race (
CVE-2024-23651
) and Buildkit Build-time Container Teardown Arbitrary Delete (CVE-2024-23652
) detections are timing-based and may have false negatives due to race conditions. - Tested in the following environments:
- Ubuntu 20.04/22.04 (AMD64)
- GKE (Ubuntu and Alpine Linux, AMD64)
- EKS (Ubuntu and Alpine Linux, AMD64) - supported by EKS version >= 1.25
- Ubuntu 22.04 (ARM64)
For updated list of bugs and issues see the project issues.
Contributions are welcome. See CONTRIBUTING.md for details.
The Leaky Vessels Dynamic Detector is under the Apache-2.0 license. See LICENSE for more information.