需要实现的目标:
- 允许使用PHP、MySQL、FTP,不允许使用SSH登录
- FTP目录限制在用户的home目录下
- 每一个vhost在运行php时不可读取其他目录,防止被挂马后影响其他应用
Virtualmin/Webmin安装
sudo apt-get install webmin webmin-virtual-server
模块设置
在System Settings -> Features and Plugins中,关闭不必要的模块。我只保留如下模块:
|
禁止SSH
由于不允许虚拟主机以ssh方式访问,直接在System Customization -> Custom Shells中,保留/bin/false(勾选其enabled, admin, Mailbox, default).
由于不允许虚拟主机以ssh方式访问,直接在System Customization -> Custom Shells中,保留/bin/false(勾选其enabled, admin, Mailbox, default).
限制FTP根目录
在Limits and Validation -> FTP Directory Restrictions,这里
勾上Active,选择Users' home directories,以及Users' home directories。
限制php读取目录
在System settints -> Edit Server Template中,选择Apache Website,
找到Default PHP execution mode,使用mod_php运行。(使用FastCGI模式似乎无法使用php_admin_value配置……)
在Directives and settings for new websites的配置模板中加入一行:
php_admin_value open_basedir "${HOME}/public_html:/tmp"
即:
ServerName ${DOM} ServerAlias www.${DOM} DocumentRoot ${HOME}/public_html php_admin_value open_basedir "${HOME}/public_html:/tmp" ErrorLog /var/log/virtualmin/${DOM}_error_log CustomLog /var/log/virtualmin/${DOM}_access_log combined ScriptAlias /cgi-bin/ ${HOME}/cgi-bin/ DirectoryIndex index.html index.htm index.php index.php4 index.php5 <Directory ${HOME}/public_html> Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch allow from all AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch </Directory> <Directory ${HOME}/cgi-bin> allow from all AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch </Directory>
这样就限制了php脚本读取其他文件目录了。
另一替代方法是使用apache的mod_chroot,但是只能限制整个apache的运行环境,无法根据vhost分别设置,也不易和virtualmin脚本结合,故舍弃,可以参考这里:http://wiki.ubuntu.org.cn/Apache%E8%AE%BE%E7%BD%AEChroot%E7%8E%AF%E5%A2%83
完成&测试
建立一个virtual server,各选项默认即可。
检查以下内容:
- SSH无法登录
- FTP登录后,访问被限制在用户目录下
- 上传PHP木马,确定只可访问public_html目录