「配枪朱丽叶。」

RootのCTF学习笔记。

BJDCTF2020/BUUUCTF-WEB: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__);
}
?>

https://s2.ax1x.com/2020/01/28/1KEKA0.png
得到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()的RCE,以前学习过如果preg_replace()的第一个参数存在/e模式修饰符,则允许代码执行,可是这道题有一个strtolower("\\1")。
学习了一下这个文章:
xz.aliyun.com
最后的payload如下:
https://s2.ax1x.com/2020/01/28/1KEGjJ.png
或者是引用题里给的函数去解:
https://s2.ax1x.com/2020/01/29/1Qea4I.png