用Suhosin加强PHP脚本语言安全性

简介: http://www.hardened-php.net/suhosin/  Hardened-PHP 最近推出了 Suhosin 測試版(beta version),這是一個從原始碼層面提升 PHP 安全性的系統,所以不論是已知和尚未發現的安全性漏洞,不論這些漏洞出現在應用程式還是在 PHP 的核心部分,Suhosin 的安全關卡都可以防止這些漏洞做成破壞。

http://www.hardened-php.net/suhosin/

 

 

Hardened-PHP 最近推出了 Suhosin 測試版(beta version),這是一個從原始碼層面提升 PHP 安全性的系統,所以不論是已知和尚未發現的安全性漏洞,不論這些漏洞出現在應用程式還是在 PHP 的核心部分,Suhosin 的安全關卡都可以防止這些漏洞做成破壞。

Suhosin 是一個韓語的音譯,意思大約是守護天使,但是別誤會 Hardened-PHP 是由韓國人組成,它其實是由三名知名的 PHP 保安專家和 PHP 核心編程人員合作的網站。

Suhosin 由兩部分組成,第一部份是 PHP 核心的補丁,提供低階的安全保護,例如緩衝區溢滿等,第二部分是一個 PHP 擴充模組,提供多項保護功能,包括:

  • 自動把 cookies 加密/解密
  • 容許關閉 preg_replace() 中的 /e 選項
  • 容許關閉 eval()
  • 透過設定函式呼叫層數的限制,避免出現無窮遞歸(infinite recursion)
  • 防止應用程式修改 memory_limit
  • 保護 mail() 免受「newline 攻擊」
  • 保護 preg_replace() 免受「/0 攻擊」
  • 自動加密/解密 session 數據
  • 保護 session 免受騎劫
  • 若果用戶呈交的資料包含 GLOBALS、_GET、_COOKIE 等敏感名稱,一律過濾掉
  • 容許設定用戶呈交的資料的數量和長度上限
  • 從上載檔案中自動禁止那些可以在伺服器上執行的程式

 

http://blog.m6699.com/diomedea/article/29073.html

 

http://www.93198.com/Article/wl/Php/3707.html

 

http://www.jefflei.com/post/295.html

 

當apache的errorlog出現configured request variable name length limit exceeded

 

之前在寫Picasa2Wordpress的時候,測試的時候,遇到一個詭異的問題,在我有權限能access的機器們上面跑,就是有一台跑不起來,後來查了一下apache2的log才發現,原來是php suhosin module的問題,預設最大的POST及GET變數名稱最大只能夠是64字元,但是Picasa POST出去的卻遠超過,所以就被檔下來了。

解決方法很簡單,編輯/etc/php5/apache2/conf.d/suhosin.ini,加上下面這三行即可:

suhosin.request.max_varname_length=128
suhosin.get.max_name_length=128
suhosin.post.max_name_length=128

搞定收工。

 

http://advosys.ca/papers/web/62-php-hardening-suhosin.html

 

I've always compiled Suhosin with any of the Apache builds I've made in WHM on production/public servers. On every server CodeCall has been on, it has been there. The purpose of Suhosin is to protect servers and users from known flaws in PHP.

I never had a problem with it before. I've seen it strip variables and prevent server requests in the log files and it always seemed to help. Last night I ran into something annoying: Suhosin limits the character length for any request variable. It doesn't truncate the value as you might expect, it drops the variable completely.

I needed the ability to post considerably long string queries for ASCIIBin. For some reason the variables were being dropped and an empty BIN was being created. I couldn't figure out why. It worked fine on my test box (which didn't have suhosin) and I could see the data before actual POST using JavaScript. After some time I came to realize that Suhosin was the culprit.

The Fix
Taking a look at the documentation for Suhosin, you can figure out fairly quick that post.max_value_length is the configuration variable limiting character size.

Quote:
Defines the maximum length of a variable that is registered through a POST request.

The default character limit is 65,000.

Method 1: Obviously, you can just disable Suhosin to fix the problem. Remove the suhosin.o file from your php.ini config file and restart Apache.

Method 2: You probably want to keep Suhosin around so a different approach is to edit the configuration file. The file is named suhosin.ini, following the PHP ini configuration system. I added these lines:

Code:
suhosin.post.max_vars = 5000
suhosin.post.max_value_length = 500000
suhosin.request.max_vars = 5000
suhosin.request.max_value_length = 500000

Restart apache.

Method 3: Alternatively, you can change these values per user using .htaccess. Edit the .htaccess file in the user directory and set the parameters to what you want. Here is an example:

Code:
php_value suhosin.post.max_vars 5000
php_value suhosin.post.max_value_length 500000
php_value suhosin.request.max_vars 5000
php_value suhosin.request.max_value_length 500000


Conclusion
I hope this helps you if you ever run into the same situation. Perhaps it will save you some time. I know if there had been a post labeled "PHP POST character limit" and was indexed by google, I would have an hour of my time saved. Alas, there isn't so I'm making one.

目录
相关文章
|
存储 安全 PHP
PHP应用开发中的安全性考虑与实践
在当前互联网应用盛行的背景下,PHP作为一种广泛应用于Web开发的编程语言,其安全性显得尤为重要。本文探讨了PHP应用开发中的几个关键安全性考虑因素,并提供了一些实用的安全实践建议,旨在帮助开发人员构建更加安全可靠的应用程序。 【7月更文挑战第11天】
231 4
|
SQL 安全 JavaScript
在多用户环境中,如何确保 PHP Shell 的安全性?
在多用户环境中,如何确保 PHP Shell 的安全性?
228 1
|
安全 JavaScript Java
PHP与其他语言安全性对比?
【7月更文挑战第15天】PHP与其他语言安全性对比?
342 1
|
安全 PHP 开发者
PHP的开源代码如何影响其安全性?
【7月更文挑战第15天】PHP的开源代码如何影响其安全性?
238 1
|
SQL 安全 PHP
【PHP开发专栏】PHP预处理语句与安全性
【4月更文挑战第30天】PHP预处理语句提升Web开发安全与性能。本文分三部分介绍原理、使用方法及安全性。预处理语句防止SQL注入,提高代码可维护性和性能。创建预处理语句对象,绑定参数,执行并释放资源。通过占位符增强代码可读性,减少数据库负担,实现高效查询。
336 2
|
安全 编译器 测试技术
深入PHP 7新特性:性能与安全性的双重提升
在数字时代的浪潮中,PHP作为一门流行的编程语言,其发展从未止步。随着PHP 7的推出,开发者社区迎来了一系列令人振奋的新特性,这些改进不仅加速了代码的执行效率,还增强了应用的安全性。本文将深入探讨PHP 7中的几项关键更新,揭示它们如何影响日常的编程实践,并指引开发者如何充分利用这些新工具来构建更快、更安全的应用程序。
|
编译器 PHP 开发者
PHP 8 新特性解析:提升性能与安全性
随着技术的不断进步,PHP 8作为一种流行的服务器端脚本语言,在性能和安全性方面有了许多值得关注的新特性。本文将深入探讨PHP 8的一些重要更新,包括Just In Time编译器、Union Types、Named Arguments等,帮助开发者更好地利用这些新功能提升应用程序的性能和安全性。
|
SQL 安全 PHP
解析php安全性问题中的:Null 字符问题
解析php安全性问题中的:Null 字符问题
328 0