POC详情: 5e9e2dd7d4686c6f04bface7d5d827b7c0afe858

来源
关联漏洞
标题: Git 后置链接漏洞 (CVE-2021-21300)
描述:Git是一套免费、开源的分布式版本控制系统。 Git 存在后置链接漏洞,该漏洞允许攻击者利用特别制作的存储库导致just-checked脚本执行而克隆到一个不区分大小写的文件系统。
介绍
# CVE-2021-21300: Arbitrary Code Execution via Malicious Git Hooks

## 📌 Summary

CVE-2021-21300 is a critical vulnerability in Git (versions 2.14.2 to 2.30.1) that allows attackers to execute arbitrary code on victim machines by exploiting symbolic links and case-insensitive file systems.

---

## 🧠 Problem Statement

- **Vulnerability**: Arbitrary code execution via malicious Git hooks.
- **Root Cause**: Case-insensitive filesystems (e.g., Windows/macOS) resolve `A/post-checkout` as `.git/hooks/post-checkout`.
- **Impact**: Attackers can inject and execute malicious hooks when a user clones the infected repository.

---

## 🔍 Theoretical Background

### The Trick

Git allows user-defined hooks stored in `.git/hooks/`. On case-insensitive file systems:
- A crafted folder like `A/post-checkout` may be interpreted as `.git/hooks/post-checkout`.
- A symbolic link replaces `A/` with `.git/hooks/`, bypassing restrictions.

### The Exploit

1. Create directory `A` and a file `A/post-checkout` containing malicious commands.
2. Stage the directory and its contents for Git.
3. Remove the directory and replace `A` with a symlink to `.git/hooks/`.
4. When Git executes `A/post-checkout`, it actually runs the malicious file in `.git/hooks/`.

---

## ⚠️ Trigger Conditions

- Case-insensitive filesystem (Windows/macOS).
- Symbolic link to `.git/hooks/`.
- Global Git LFS filters enabled.
- Victim has permission to execute malicious code.

---

## 🛠️ Attack Workflow

### Malicious Repo Generation
- Create `.gitattributes` to trigger LFS processing of `A/post-checkout`.
- Add a malicious script `A/post-checkout` (e.g., prints "PWNED").
- Add fake files `A/a`, `A/b` to make it look legitimate.
- Replace `A/` with symlink to `.git/hooks/`.
- Commit and push the changes.

---

## 🛡 Existing Defenses

### Configuration-Based
- Disable symbolic link following:
  ```sh
  git clone -c core.symlinks=true
  git config --system core.symlinks true
##💡 **Other Potential Defenses**
- Automate Safe Cloning with Git Alias
- Make directory.
- Enable case sensitivity (Windows):
  ```sh
  fsutil file setcasesensitiveinfo <DESTINATION FOLDER> enable
- Clone into that directory.

- Create a Git alias to automate these steps for safer cloning.
文件快照

[4.0K] /data/pocs/5e9e2dd7d4686c6f04bface7d5d827b7c0afe858 ├── [ 10] a -> .git/hooks ├── [4.0K] A │   ├── [ 0] a │   ├── [ 0] b │   └── [ 26] post-checkout └── [2.2K] README.md 2 directories, 4 files
神龙机器人已为您缓存
备注
    1. 建议优先通过来源进行访问。
    2. 如果因为来源失效或无法访问,请发送邮箱到 f.jinxu#gmail.com 索取本地快照(把 # 换成 @)。
    3. 神龙已为您对POC代码进行快照,为了长期维护,请考虑为本地POC付费,感谢您的支持。