php的扩展suhosin,PHP扩展--Suhosin保护PHP应用系统

什么是Suhosin?

Suhosin是一个PHP程序的保护系统。它的设计初衷是为了保护服务器和用户抵御PHP程序和PHP核心中,已知或者未知的缺陷。

Suhosin有两个独立的部分,使用时可以分开使用或者联合使用。

第一部分是一个用于PHP核心的补丁,它能抵御缓冲区溢出或者格式化串的弱点;

第二部分是一个强大的PHP扩展,包含其他所有的保护措施。

下载安装补丁

##高版本不需要,折中选择是否打补丁

wget http://download.suhosin.org/suhosin-patch-5.3.3-0.9.10.patch.gz

gunzip suhosin-patch-5.3.3-0.9.10.patch.gz

cd php-5.3.3/

patch -p 1 -i ../suhosin-patch-5.3.3-0.9.10.patch

./configure --with-php-config=/usr/local/bin/php-config

make

make install

安装扩展

wget http://download.suhosin.org/suhosin-0.9.37.1.tar.gz

tar zxvf suhosin-0.9.37.1.tar.gz

cd suhosin-0.9.37.1/

phpize

./configure --with-php-config=/usr/local/bin/php-config

make

make install

在php.ini下加入suhosin.so即可

extension=suhosin.so

96640d75a918f2d6e64da4e7574f6e6a.png

扩展应用

加密功能

Session加密

SESSION里的数据通常在服务器上的明文存放的。这里通过在服务端来加解密$_SESSION。这样将Session的句柄存放在Memcache或数据库时,就不会被轻易攻破,很多时候我们的session数据会存放一些敏感字段。

这个特性在缺省情况下是启用的,也可以通过php.ini来修改:

suhosin.session.encrypt = On

suhosin.session.cryptkey = zuHywawAthLavJohyRilvyecyondOdjo

suhosin.session.cryptua = On

suhosin.session.cryptdocroot = On

;; IPv4 only

suhosin.session.cryptraddr = 0

suhosin.session.checkraddr = 0

Cookie加密

Cookie在客户端浏览器的传输的HTTP头也是明文的。通过加密cookie,您可以保护您的应用程序对众多的攻击,如

Cookie篡改:攻击者可能会尝试猜测其他合理的cookie值来攻击程序。

跨应用程序使用Cookie:不正确配置的应用程序可能具有相同的会话存储,如所有会话默认存储在/tmp目录下,一个应用程序的cookie可能永远不会被重新用于另一应用,只要加密密钥不同。

Cookie加密在php.ini中的配置:

suhosin.cookie.encrypt = On

;; the cryptkey should be generated, e.g. with ‘apg -m 32‘

suhosin.cookie.cryptkey = oykBicmyitApmireipsacsumhylWaps1

suhosin.cookie.cryptua = On

suhosin.cookie.cryptdocroot = On

;; whitelist/blacklist (use only one)

;suhosin.cookie.cryptlist = WALLET,IDEAS

suhosin.cookie.plainlist = LANGUAGE

;; IPv4 only

suhosin.cookie.cryptraddr = 0

suhosin.cookie.checkraddr = 0

Blocking Functions

测试

##默认PHP的Session保存在tmp路径下

ll -rt /tmp | grep sess

##扩展未开启时查看某条sesson的数据

cat sess_ururh83qvkkhv0n51lg17r4aj6

//记录是明文的

##扩展开启后查看某条sesson 的数据

cat sess_ukkiiiheedupem8k4hheo0b0v4

//记录是密文的

可见加密对安全的重要性

阻断功能

白名单

##显式指定指定白名单列表

suhosin.executor.func.whitelist = htmlentities,htmlspecialchars,base64_encode

suhosin.executor.eval.whitelist = htmlentities,htmlspecialchars,base64_encode

echo htmlentities(‘‘);

eval(‘echo htmlentities("");‘);

黑名单

##显式指定指定黑名单列表

suhosin.executor.func.blacklist = assert,unserialize,exec,popen,proc_open,passthru,shell_exec,system,hail,parse_str,mt_srand

suhosin.executor.eval.whitelist = assert,unserialize,exec,popen,proc_open,passthru,shell_exec,system,hail,parse_str,mt_srand

通过日志来查看非法调用黑白名单

suhosin.simulation = 1

suhosin.log.file = 511

suhosin.log.file.name = /tmp/suhosin-alert.log

其他配置项

suhosin.executor.include.max_traversal 扩目录的最大深度,可以屏蔽切换到非法路径

suhosin.executor.include.whitelist 允许包含的URL,用逗号分隔

suhosin.executor.include.blacklist 禁止包含的URL,用逗号分隔

suhosin.executor.disable_eval = On 禁用eval函数

suhosin.upload.max_uploads

suhosin.upload.disallow_elf

suhosin.upload.disallow_binary

suhosin.upload.remove_binary

suhosin.upload.verification_script 上传文件检查脚本,可以来检测上传的内容是否包含webshell特征

原文:http://www.cnblogs.com/linzhenjie/p/5485465.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值