平面文件CMS(PAAS)的安全性

时间:2015-06-09 15:19:38

标签: php

我正在构建一个使用php文件的平面文件cms。用户将能够使用输入字段重命名文件,旧的和新的文件路径将通过ajax发送到我测试安全性的服务器。我意识到使用正则表达式甚至OR运算符可以更轻松地完成此操作。我把OR运算符拿出来,这样这个帖子的字符串就不会太长了。至于正则表达式,我希望能够更好地控制我发送回客户端的错误。

CMS本身就像一个PAAS,它位于每个用户将拥有的所有单个站点文件夹之上的目录中。我的目标是阻止用户注入可能干扰其他(相邻)用户文件夹的代码或上面父目录中的cms本身。

我还没有解析路径的有效性。我只是想知道恶意用户如何能够利用我到目前为止所写的内容。

<?php
 $old_path = $_POST['file'].'.php'; // path/to/file.php
 $new_path = $_POST['new_file'].'.php'; // path/to/newfile.php';
  if(strstr($new_path,"<?")){
    echo "Sorry, path cannot contain script tags";
  }elseif(strstr($new_path,"?>")){
    echo "Sorry, path cannot contain script tags";
  }elseif (strstr($new_path,">")){
    echo "Sorry, path cannot contain script tags";
  }elseif (strstr($new_path,"<")){
    echo "Sorry, path cannot contain script tags";    
  }elseif($new_path[0]==="." OR $new_path[0]==='/' OR $new_path[0]==='\\'){
    echo 'Sorry first character of path cannot be a period or slash';
  }else{

    //this is set when the user logs in based on details in a database
    $users_dedicated_directory = $_SESSION['userfolder'].'/';

    // add the users folder when renaming just for more control
    $old_path = $users_dedicated_directory.$old_path;

    // add the users folder when renaming just for more control
    $new_path = $users_dedicated_directory.$old_path;

    rename($old_path,$new_path);

    //trim the users folder name. Send it back to the client  
    echo explode($users_dedicated_directory,$new_path);    
   }   
?>

1 个答案:

答案 0 :(得分:0)

如果认为恶意用户可能会覆盖CMS的某些文件,new_path类似于a/../../path/to/one/of/you/cms/core/file.php

您必须删除网络服务器的写入权限才能阻止CMS文件。

相关问题