首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >平面文件CMS (PAAS)的安全性

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

Stack Overflow用户
提问于 2015-06-09 23:19:38
回答 1查看 143关注 0票数 1

我正在建立一个平面文件cms使用php文件。用户将能够使用输入字段重命名文件,新旧文件路径将通过ajax发送到服务器,我在那里测试安全性。我意识到使用正则表达式甚至OR操作符可以更容易地做到这一点。我去掉了OR操作符,这样对于这篇文章来说字符串就不会太长。至于正则表达式,我希望对发送回客户端的错误有更多的控制。

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

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

代码语言:javascript
复制
<?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);    
   }   
?>
EN

回答 1

Stack Overflow用户

发布于 2015-06-09 23:50:44

如果new_path是类似a/../../path/to/one/of/you/cms/core/file.php的东西,如果认为恶意用户可以覆盖您的内容管理系统的一些文件。

你必须移除web服务器对你的CMS文件的写权限,以防止这种情况发生。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30736247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档