GitHack — 一个git泄露利用脚本

当前大量开发人员使用git进行版本控制,对站点自动部署。  如果配置不当,可能会将.git文件夹直接部署到线上环境。这就引起了git泄露漏洞。

GitHack是一个.git泄露利用脚本,通过泄露的.git文件夹下的文件,还原重建工程源代码。

渗透测试人员、攻击者,可以进一步审计代码,挖掘:文件上传,SQL注射等安全漏洞。

脚本的工作原理

  1. 解析.git/index文件,找到工程中所有的: ( 文件名,文件sha1 )
  2. 去.git/objects/ 文件夹下下载对应的文件
  3. zlib解压文件,按原始的目录结构写入源代码

它的优点

  1. 速度快,默认20个工作线程
  2. 尽量还原所有的源代码,缺失一部分文件不影响脚本工作
  3. 脚本不需要执行额外的git命令,All you need is python
  4. 脚本无需浏览目录

可能的改进

存在文件被gc打包到git\objects\pack的情况,稍后可测试下看能否直接获取并解压这个文件,还原源代码

用法示例

GitHack.py http://www.hoolai.com/.git/

执行中截图:

GitHack

执行结果:

GitHack_result

获取代码:https://github.com/lijiejie/GitHack

参考资料:

Git Index Formart

非常感谢 sbp 的 gin – a Git index file parser,脚本中使用了他的解析源代码,为适用python 2.x和Windows作了细微的改动

《GitHack — 一个git泄露利用脚本》上有17条评论

  1. Traceback (most recent call last): File “C:UsersArthur.KillerDesktopGitHack-masterGitHack.py”, line 85, inmodule> s = Scanner() File “C:UsersArthur.KillerDesktopGitHack-masterGitHack.py”, line 34, in_init__ os.mkdir(self.domain)WindowsError: [Error 5] : ‘xxxx.com’这个是BUG?

  2. E:\Python27\Python脚本\GitHack>python GitHack.py http://www.openssl.org/.git/
    [+] Download and parse index file …
    Traceback (most recent call last):
    File “GitHack.py”, line 101, in
    s = Scanner()
    File “GitHack.py”, line 36, in __init__
    data = self._request_data(sys.argv[-1] + ‘/index’)
    File “GitHack.py”, line 53, in _request_data
    return urllib2.urlopen(request).read()
    File “E:\Python27\lib\urllib2.py”, line 154, in urlopen
    return opener.open(url, data, timeout)
    File “E:\Python27\lib\urllib2.py”, line 435, in open
    response = meth(req, response)
    File “E:\Python27\lib\urllib2.py”, line 548, in http_response
    ‘http’, request, response, code, msg, hdrs)
    File “E:\Python27\lib\urllib2.py”, line 467, in error
    result = self._call_chain(*args)
    File “E:\Python27\lib\urllib2.py”, line 407, in _call_chain
    result = func(*args)
    File “E:\Python27\lib\urllib2.py”, line 654, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
    File “E:\Python27\lib\urllib2.py”, line 435, in open
    response = meth(req, response)
    File “E:\Python27\lib\urllib2.py”, line 548, in http_response
    ‘http’, request, response, code, msg, hdrs)
    File “E:\Python27\lib\urllib2.py”, line 473, in error
    return self._call_chain(*args)
    File “E:\Python27\lib\urllib2.py”, line 407, in _call_chain
    result = func(*args)
    File “E:\Python27\lib\urllib2.py”, line 556, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
    urllib2.HTTPError: HTTP Error 404: Not Found

    E:\Python27\Python脚本\GitHack>

  3. Traceback (most recent call last):
    File “githack.py”, line 16, in
    context = ssl._create_unverified_context()
    AttributeError: ‘module’ object has no attribute ‘_create_unverified_context’

发表评论

您的电子邮箱地址不会被公开。