[英]Security for Flat File CMS (PAAS)
我正在建立一个使用php文件的平面文件cms。 用户将能够使用输入字段来重命名文件,并且新旧文件路径将通过ajax发送到我在其中测试安全性的服务器。 我意识到使用regex甚至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);
}
?>
如果new_path
类似于a/../../path/to/one/of/you/cms/core/file.php
如果认为恶意用户可能会覆盖CMS的某些文件。
您必须删除Web服务器的写许可权,才能删除CMS文件,以防止这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.