Home page logo

fulldisclosure logo Full Disclosure mailing list archives

PHP 5.2.12/5.3.1 session.save_path safe_mode and open_basedir bypass
From: Maksymilian Arciemowicz <cxib () securityreason com>
Date: Thu, 11 Feb 2010 12:21:31 +0100

[ PHP 5.2.12/5.3.1 session.save_path safe_mode and open_basedir bypass ]

Credit: Grzegorz Stachowiak
Provided by: SecurityReason.com
- Written: 31.01.2010
- Public:  11.02.2010

SecurityRisk: Medium
Affected Software:
PHP 5.2.12
PHP 5.3.1

Advisory URL: http://securityreason.com/achievement_securityalert/82
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.

A visitor accessing your web site is assigned a unique id, the so-called
session id. This is either stored in a cookie on the user side or is
propagated in the URL.

session.save_path defines the argument which is passed to the save
handler. If you choose the default files handler, this is the path where
the files are created. Defaults to /tmp. See also session_save_path().

There is an optional N argument to this directive that determines the
number of directory levels your session files will be spread around in.
For example, setting to '5;/tmp' may end up creating a session file and
location like /tmp/4/b/1/e/3/sess_4b1e384ad74619bd212e236e52a5a174If .
In order to use N you must create all of these directories before use. A
small shell script exists in ext/session to do this, it's called
mod_files.sh. Also note that if N is used and greater than 0 then
automatic garbage collection will not be performed, see a copy of
php.ini for further information. Also, if you use N, be sure to surround
session.save_path in "quotes" because the separator (;) is also used for
comments in php.ini.

---- 1. session.save_path safe mode and open basedir bypass ---
session.save_path can be set via ini_set(), session_save_path()
functions. In session.save_path there should be path where you will save
yours tmp files. But syntax for session.save_path is:




N - can be also a string (N should be numeric).


1. session_save_path("/DIR/WHERE/YOU/HAVE/ACCESS")
2. session_save_path("5;/DIR/WHERE/YOU/HAVE/ACCESS")

The main problem came when we use multiple ';' character and when we
will create fake directory structure to reduce '../'.

Proof of Concept:
0. Create directories:




1. set open_basedir = /byp
2. create test.php
3. php test.php

Warning: session_save_path(): open_basedir restriction in effect.
File(/humhum) is not within the allowed path(s): (/byp) in /byp/test.php
on line 3
4. subdir.php
5. php subdir.php
6. cd puf
7. create byp.php


8. php byp.php
9. ls /humhum

The main problem is located in session.c. PHP doesn't check, that we
have used next ';' after first. Creating fake directory structure

mkdir ';a'
mkdir '../;a'

we can reduce directory level using '../' .

--- 2. Fix ---
Revision 294272

--- 3. Credit ---
Founded by: Grzegorz Stachowiak
Written by: Maksymilian Arciemowicz
Fixed by  : Ilia Alshanetsky

--- 4. Contact ---
- Grzegorz.Stachowiak
    stachowiak [a,t} analogicode (d_0t} pl

- Maksymilian Arciemowicz
    cxib {a.t] securityreason [d0_t} com


http://securityreason.com/exploit_alert/ - Exploit Database
http://securityreason.com/security_alert/ - Vulnerability Database

Attachment: signature.asc
Description: OpenPGP digital signature

Full-Disclosure - We believe in it.
Charter: http://lists.grok.org.uk/full-disclosure-charter.html
Hosted and sponsored by Secunia - http://secunia.com/

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]