Powered by Typecho)))
Optimized by EAimTY
现在很多linux虚拟主机商,都会开通shell权限给用户,方便管理,但是这样一来也带来了巨大的安全问题。先说说运行环境,Apache(suexec+fcgid)+php+mysql,所有用户均有shell权限。
默认情况下,一旦某个站点存在漏洞或者某位用户心存不轨,同服务器站点数据很容易被窃取。以下为例:
A,B站点同属服务器C。
比如A站点的用户发现B站点有漏洞,爆出了物理路径,但无法注入无法取得上传权限。
默认情况下,网站文件一般权限都会设置权限至少755,则漏洞就会产生(若设置成751,则html等静态文件无法读取,711会造成无法列举目录内文件,无法找到首页)。
A用户在得到了B站点的路径的情况下,完全可以通过shell登录窃取到B站点的机密配置文件如config.php等,从而窃取到B的数据库资料。
当然有一个办法,能避免文件被窃取。目录设置为755,动态文件设置为751/711/600(不给其他用户读的权限),静态文件设置成604/644
但这样做是无比的麻烦。。。
后继:通过配置ACL权限,额外分配给Apache运行用户读取和执行权限,并结合上述设置,能杜绝掉跨站攻击,而只需要设置目录或者文件权限为750即可。cgi(php)程序文件的权限可设置为600或400也能照常运行。但目录必须至少为750才能保证程序正常运行。
完美的方案是部署ACL+grsecurity+jailkit了。即便是爆了路径,也无法窃取到资料。
ACL+grsecurity+jailkit
目录最好设置成750,否则会出现403错误
php等cgi程序,去掉其他用户的任何权限,防止在开通了shell的情况下被跨站攻击
/home 目录本身为751(根据suexec配置选项所得)
/home下所有目录默认750,并分配如下ACL权限,web-httpd为Apache运行身份,www-data为nginx运行身份
/home/cgi-system/ 目录为751,子目录及其文件为750
setfacl -m u:web-httpd:rx,g:web-httpd:rx,u:www-data:rx,g:www-data:rx,o::- -R /home
setfacl -d -m u:web-httpd:rx,g:web-httpd:rx,u:www-data:rx,g:www-data:rx,o::- -R /home
logs目录设置用户可读
#setfacl -m u:user:r,g:user:r -R /home/user/logs
setfacl -d -m u:user:r,g:user:r -R /home/user/logs
/home/username 目录属性为710/750
下级目录和文件属主为用户本身,权限750
参考
http://linux.chinaunix.net/techdoc/beginner/2009/10/27/1141592.shtml
http://www.cnblogs.com/cabin/archive/2010/09/18/1830180.html
http://www.ibm.com/developerworks/cn/linux/l-acl/
http://ljh0242.blog.163.com/blog/static/5697009020088223959537/
setfacl 2.2.39 -- set file access control lists Usage: setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ... -m, --modify=acl modify the current ACL(s) of file(s) -M, --modify-file=file read ACL entries to modify from file -x, --remove=acl remove entries from the ACL(s) of file(s) -X, --remove-file=file read ACL entries to remove from file -b, --remove-all remove all extended ACL entries -k, --remove-default remove the default ACL --set=acl set the ACL of file(s), replacing the current ACL --set-file=file read ACL entries to set from file --mask do recalculate the effective rights mask -n, --no-mask don't recalculate the effective rights mask -d, --default operations apply to the default ACL -R, --recursive recurse into subdirectories -L, --logical logical walk, follow symbolic links -P, --physical physical walk, do not follow symbolic links --restore=file restore ACLs (inverse of `getfacl -R') --test test mode (ACLs are not modified) --version print version and exit --help this help text
参考资料:http://www.ibm.com/developerworks/cn/linux/l-acl/
http://hi.chinaunix.net/?595633/viewspace-29371