一、什么是Suhosin?
Suhosin是一个PHP程序的保护系统。它的设计初衷是为了保护服务器和用户抵御PHP程序和PHP核心中,已知或者未知的缺陷。Suhosin有两个独立的部分,使用时可以分开使用或者联合使用。第一部分是一个用于PHP核心的补丁,它能抵御缓冲区溢出或者格式化串的弱点;第二部分是一个强大的PHP扩展,包含其他所有的保护措施。
二、下载地址
使用Gentoo linux或者 FreeBSD的朋友,可以ports中找到Suhosin。使用OpenSuSE linux ,Mandriva Linux,Debian Linux的朋友在发行版发布的包中找到Suhosin
http://www.hardened-php.net/suhosin/download.html
打开后,下载Suhosin Extension 0.9.31,Suhosin Patch要对应PHP的版本下载
三、特性列表
1)引擎保护(仅补丁)
2)各种特性
3)运行时保护
4)Session 保护
5)过滤特性
6)日志特性(略)
参考http://www.hardened-php.net/suhosin/a_feature_list.html
四、安装Suhosin
1)下载,地址上面已经给出
2)解压和打补丁
# tar jxvf php-5.2.10.tar.bz2
# gunzip suhosin-patch-5.2.10-0.9.7.patch.gz
# cd php-5.2.10
# patch -p 1 -i ../suhosin-patch-5.2.10-0.9.7.patch
# ./configure --your-options
# make
# make install
安装扩展
# tar zxvf suhosin-0.9.31.tgz
# cd subosin-0.9.31
# phpize
# ./configure –with-php-config=/usr/local/php/bin/php-config(这个路径根据自己实际情况设置)
# make
# make install
然后编辑php.ini 加入extension=suhosin.so
重启httpd,写一个phpinfo()页,如下
五、配置
所有配置选项参考
http://www.hardened-php.net/suhosin/configuration.html
六、代码测试
eval执行漏洞
//ex2.php
$var = "var";
if (isset($_GET["arg"]))
{
$arg = $_GET["arg"];
eval("$var = $arg;");
echo "$var =".$var;
}
?>
suhosin有三个选项控制eval
suhosin.executor.eval.whitelist 白名单
suhosin.executor.eval.blacklist 黑名单
suhosin.executor.disable_eval 禁用eval
很多程序需要eval,所以我们不能禁用,使用黑名单禁止一些危险的函数
编辑php.ini
[Suhosin]
suhosin.executor.eval.blacklist=phpinfo,fputs,fopen,fwrite
根据实际情况自行设定
未设置前
设置后
包含漏洞
suhosin.executor.include.max_traversal 包含的最大目录深度,在包含的文件名中有多少个../就禁止,例如值为2时,../../etc/passwd会禁止,值为3则允许,对于大多数程序,这个值设为4或5比较合适
suhosin.executor.include.whitelist 允许包含的URL,用逗号分隔
suhosin.executor.include.blacklist 禁止包含的URL,用逗号分隔
if (isset($_GET["arg"]))
{
$arg = $_GET["arg"];
require_once($arg);
}
?>
未设置前
设置suhosin.executor.include.max_traversal=3
上传漏洞
suhosin.upload.max_uploads
suhosin.upload.disallow_elf
suhosin.upload.disallow_binary
suhosin.upload.remove_binary
suhosin.upload.verification_script 上传文件检查脚本
可以自己写一个脚本检查上传文件是否有webshell特征,然后suhosin.upload.verification_script 的值是这个脚本的绝对路径
注入漏洞
suhosin.sql.bailout_on_error 还不支持 -_-#
其他更深入的防护措施,还有待研究,参考suhosin选项
http://www.hardened-php.net/suhosin/configuration.html