Goal Reached Thanks to every supporter β€” we hit 100%!

Goal: 1000 CNY Β· Raised: 1000 CNY

100.0%

CVE-2021-21300 PoC β€” malicious repositories can execute remote code while cloning

Source
Associated Vulnerability
Title:malicious repositories can execute remote code while cloning (CVE-2021-21300)
Description:Git is an open-source distributed revision control system. In affected versions of Git a specially crafted repository that contains symbolic links as well as files using a clean/smudge filter such as Git LFS, may cause just-checked out script to be executed while cloning onto a case-insensitive file system such as NTFS, HFS+ or APFS (i.e. the default file systems on Windows and macOS). Note that clean/smudge filters have to be configured for that. Git for Windows configures Git LFS by default, and is therefore vulnerable. The problem has been patched in the versions published on Tuesday, March 9th, 2021. As a workaound, if symbolic link support is disabled in Git (e.g. via `git config --global core.symlinks false`), the described attack won't work. Likewise, if no clean/smudge filters such as Git LFS are configured globally (i.e. _before_ cloning), the attack is foiled. As always, it is best to avoid cloning repositories from untrusted sources. The earliest impacted version is 2.14.2. The fix versions are: 2.30.1, 2.29.3, 2.28.1, 2.27.1, 2.26.3, 2.25.5, 2.24.4, 2.23.4, 2.22.5, 2.21.4, 2.20.5, 2.19.6, 2.18.5, 2.17.62.17.6.
Readme
# 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.
File Snapshot

[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
Shenlong Bot has cached this for you
Remarks
    1. It is advised to access via the original source first.
    2. Local POC snapshots are reserved for subscribers β€” if the original source is unavailable, the local mirror is part of the paid plan.
    3. Mirroring, verifying, and maintaining this POC archive takes ongoing effort, so local snapshots are a paid feature. Your subscription keeps the archive online β€” thank you for the support. View subscription plans β†’