FreeBSD VuXML: Documenting security issues in FreeBSD and the FreeBSD Ports Collection

php -- open_basedir Race Condition Vulnerability

Affected packages
php4 < 4.4.4_1
5 <= php4 < 5.1.6_2
php5 < 4.4.4_1
5 <= php5 < 5.1.6_2
php-suhosin < 0.9.6
4 <= mod_php4 < 4.4.4_1
5 <= mod_php4 < 5.1.6_2
4 <= mod_php5 < 4.4.4_1
5 <= mod_php5 < 5.1.6_2
4 <= php4-cgi < 4.4.4_1
5 <= php4-cgi < 5.1.6_2
4 <= php4-cli < 4.4.4_1
5 <= php4-cli < 5.1.6_2
4 <= php4-dtc < 4.4.4_1
5 <= php4-dtc < 5.1.6_2
4 <= php4-horde < 4.4.4_1
5 <= php4-horde < 5.1.6_2
4 <= php4-nms < 4.4.4_1
5 <= php4-nms < 5.1.6_2
4 <= php5-cgi < 4.4.4_1
5 <= php5-cgi < 5.1.6_2
4 <= php5-cli < 4.4.4_1
5 <= php5-cli < 5.1.6_2
4 <= php5-dtc < 4.4.4_1
5 <= php5-dtc < 5.1.6_2
4 <= php5-horde < 4.4.4_1
5 <= php5-horde < 5.1.6_2
4 <= php5-nms < 4.4.4_1
5 <= php5-nms < 5.1.6_2

Details

VuXML ID edabe438-542f-11db-a5ae-00508d6a62df
Discovery 2006-10-02
Entry 2006-10-05
Modified 2013-04-01

Stefan Esser reports:

PHP's open_basedir feature is meant to disallow scripts to access files outside a set of configured base directories. The checks for this are placed within PHP functions dealing with files before the actual open call is performed.

Obviously there is a little span of time between the check and the actual open call. During this time span the checked path could have been altered and point to a file that is forbidden to be accessed due to open_basedir restrictions.

Because the open_basedir restrictions often not call PHP functions but 3rd party library functions to actually open the file it is impossible to close this time span in a general way. It would only be possible to close it when PHP handles the actual opening on it's own.

While it seems hard to change the path during this little time span it is very simple with the use of the symlink() function combined with a little trick. PHP's symlink() function ensures that source and target of the symlink operation are allowed by open_basedir restrictions (and safe_mode). However it is possible to point a symlink to any file by the use of mkdir(), unlink() and at least two symlinks.

References

Bugtraq ID 20326
CVE Name CVE-2006-5178
URL http://secunia.com/advisories/22235/
URL http://www.hardened-php.net/advisory_082006.132.html