PHP <= 5.2.5 Safe Mode Bypass



########################## WwW.BugReport.ir #########################################
#
# AmnPardaz Security Research & Penetration Testing Group
#
# Title: PHP <= 5.2.5 Safe Mode Bypass
# Vendor: http://www.php.net
# Vulnerable Function: tempnam()
# Vulnerable Version: tested on 5.2.5 , 5.2.4 (prior versions also may be affected)
# Platform : any
# Exploitation: Local
# Exploit: Available
# Fix Available: No!
###################################################################################

####################
- Description:
####################

"PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML."

####################
- Vulnerability:
####################

+--> Safe Mode Bypass
string tempnam ( string dir, string prefix )
Creates a file with a unique filename in the specified directory.
Quick review from the source shows that there is open_basedir check but not
Safe mode!
/main/php_open_temporary_file.c
See the related exploit for more details

####################
- POC
####################
http://www.bugreport.ir/?/22/exploit
Original advisory: http://www.bugreport.ir/?/22

####################
- Credit :
####################
AmnPardaz Security Research & Penetration Testing Group
Contact: admin[4t}bugreport{d0t]ir
WwW.BugReport.ir
WwW.AmnPardaz.com



Relevant Pages

  • [Full-disclosure] copy() Safe Mode Bypass PHP 4.4.2 and 5.1.2
    ... PHP is an HTML-embedded scripting language. ... The PHP safe mode is an attempt to solve the shared-server security problem. ... if (wrapper!= NULL) ...
    (Full-Disclosure)
  • Re: IIS6 and PHP
    ... Enable the PHP scripting language engine under Apache. ... ; every request. ... Maximum number of persistent links. ... Default host for mysql_connect(doesn't apply in safe mode). ...
    (microsoft.public.inetserver.iis)
  • Re: fopen - append works, write fails (but file is truncated)
    ... PHP info below shows ... ... the file (with owner "nobody") and no errors occurs after that. ... happen if safe mode was on, ... Append mode works in both ...
    (comp.lang.php)
  • [Full-disclosure] tempnam() open_basedir bypass PHP 4.4.2 and 5.1.2
    ... [tempnam() open_basedir bypass PHP 4.4.2 and 5.1.2] ... PHP is an HTML-embedded scripting language. ... create/symlink failed, no inodes free ...
    (Full-Disclosure)
  • Suexec/SafeMode Hybrid [repost]
    ... I am in love with Suexec. ... secure (i.e. by not running scripts in 777 directories, ... So then I looked at suexec with php, which pretty much breaks embedded php ... This would be similar to the way safe mode presently operates (as in, ...
    (php.general)