Vulnerabilities > CVE-2007-4850 - Permissions, Privileges, and Access Controls vulnerability in PHP 5.2.4/5.2.5

047910
CVSS 5.0 - MEDIUM
Attack vector
NETWORK
Attack complexity
LOW
Privileges required
NONE
Confidentiality impact
PARTIAL
Integrity impact
NONE
Availability impact
NONE
network
low complexity
php
CWE-264
nessus
exploit available

Summary

curl/interface.c in the cURL library (aka libcurl) in PHP 5.2.4 and 5.2.5 allows context-dependent attackers to bypass safe_mode and open_basedir restrictions and read arbitrary files via a file:// request containing a \x00 sequence, a different vulnerability than CVE-2006-2563.

Vulnerable Configurations

Part Description Count
Application
Php
2

Common Attack Pattern Enumeration and Classification (CAPEC)

  • Accessing, Modifying or Executing Executable Files
    An attack of this type exploits a system's configuration that allows an attacker to either directly access an executable file, for example through shell access; or in a possible worst case allows an attacker to upload a file and then execute it. Web servers, ftp servers, and message oriented middleware systems which have many integration points are particularly vulnerable, because both the programmers and the administrators must be in synch regarding the interfaces and the correct privileges for each interface.
  • Leverage Executable Code in Non-Executable Files
    An attack of this type exploits a system's trust in configuration and resource files, when the executable loads the resource (such as an image file or configuration file) the attacker has modified the file to either execute malicious code directly or manipulate the target process (e.g. application server) to execute based on the malicious configuration parameters. Since systems are increasingly interrelated mashing up resources from local and remote sources the possibility of this attack occurring is high. The attack can be directed at a client system, such as causing buffer overrun through loading seemingly benign image files, as in Microsoft Security Bulletin MS04-028 where specially crafted JPEG files could cause a buffer overrun once loaded into the browser. Another example targets clients reading pdf files. In this case the attacker simply appends javascript to the end of a legitimate url for a pdf (http://www.gnucitizen.org/blog/danger-danger-danger/) http://path/to/pdf/file.pdf#whatever_name_you_want=javascript:your_code_here The client assumes that they are reading a pdf, but the attacker has modified the resource and loaded executable javascript into the client's browser process. The attack can also target server processes. The attacker edits the resource or configuration file, for example a web.xml file used to configure security permissions for a J2EE app server, adding role name "public" grants all users with the public role the ability to use the administration functionality. The server trusts its configuration file to be correct, but when they are manipulated, the attacker gains full control.
  • Blue Boxing
    This type of attack against older telephone switches and trunks has been around for decades. A tone is sent by an adversary to impersonate a supervisor signal which has the effect of rerouting or usurping command of the line. While the US infrastructure proper may not contain widespread vulnerabilities to this type of attack, many companies are connected globally through call centers and business process outsourcing. These international systems may be operated in countries which have not upgraded Telco infrastructure and so are vulnerable to Blue boxing. Blue boxing is a result of failure on the part of the system to enforce strong authorization for administrative functions. While the infrastructure is different than standard current applications like web applications, there are historical lessons to be learned to upgrade the access control for administrative functions.
  • Restful Privilege Elevation
    Rest uses standard HTTP (Get, Put, Delete) style permissions methods, but these are not necessarily correlated generally with back end programs. Strict interpretation of HTTP get methods means that these HTTP Get services should not be used to delete information on the server, but there is no access control mechanism to back up this logic. This means that unless the services are properly ACL'd and the application's service implementation are following these guidelines then an HTTP request can easily execute a delete or update on the server side. The attacker identifies a HTTP Get URL such as http://victimsite/updateOrder, which calls out to a program to update orders on a database or other resource. The URL is not idempotent so the request can be submitted multiple times by the attacker, additionally, the attacker may be able to exploit the URL published as a Get method that actually performs updates (instead of merely retrieving data). This may result in malicious or inadvertent altering of data on the server.
  • Target Programs with Elevated Privileges
    This attack targets programs running with elevated privileges. The attacker would try to leverage a bug in the running program and get arbitrary code to execute with elevated privileges. For instance an attacker would look for programs that write to the system directories or registry keys (such as HKLM, which stores a number of critical Windows environment variables). These programs are typically running with elevated privileges and have usually not been designed with security in mind. Such programs are excellent exploit targets because they yield lots of power when they break. The malicious user try to execute its code at the same level as a privileged system call.

Exploit-Db

descriptionPHP 5.2.5 cURL 'safe mode' Security Bypass Vulnerability. CVE-2007-4850. Remote exploit for php platform
idEDB-ID:31053
last seen2016-02-03
modified2008-01-23
published2008-01-23
reporterMaksymilian Arciemowicz
sourcehttps://www.exploit-db.com/download/31053/
titlePHP <= 5.2.5 cURL 'safe mode' Security Bypass Vulnerability

Nessus

  • NASL familyUbuntu Local Security Checks
    NASL idUBUNTU_USN-628-1.NASL
    descriptionIt was discovered that PHP did not properly check the length of the string parameter to the fnmatch function. An attacker could cause a denial of service in the PHP interpreter if a script passed untrusted input to the fnmatch function. (CVE-2007-4782) Maksymilian Arciemowicz discovered a flaw in the cURL library that allowed safe_mode and open_basedir restrictions to be bypassed. If a PHP application were tricked into processing a bad file:// request, an attacker could read arbitrary files. (CVE-2007-4850) Rasmus Lerdorf discovered that the htmlentities and htmlspecialchars functions did not correctly stop when handling partial multibyte sequences. A remote attacker could exploit this to read certain areas of memory, possibly gaining access to sensitive information. This issue affects Ubuntu 8.04 LTS, and an updated fix is included for Ubuntu 6.06 LTS, 7.04 and 7.10. (CVE-2007-5898) It was discovered that the output_add_rewrite_var function would sometimes leak session id information to forms targeting remote URLs. Malicious remote sites could use this information to gain access to a PHP application user
    last seen2020-06-01
    modified2020-06-02
    plugin id33575
    published2008-07-24
    reporterUbuntu Security Notice (C) 2008-2019 Canonical, Inc. / NASL script (C) 2018 and is owned by Tenable, Inc. or an Affiliate thereof.
    sourcehttps://www.tenable.com/plugins/nessus/33575
    titleUbuntu 6.06 LTS / 7.04 / 7.10 / 8.04 LTS : php5 vulnerabilities (USN-628-1)
  • NASL familyMacOS X Local Security Checks
    NASL idMACOSX_SECUPD2008-005.NASL
    descriptionThe remote host is running a version of Mac OS X 10.5 or 10.4 that does not have the security update 2008-005 applied. This update contains security fixes for a number of programs.
    last seen2020-06-01
    modified2020-06-02
    plugin id33790
    published2008-08-01
    reporterThis script is Copyright (C) 2008-2018 Tenable Network Security, Inc.
    sourcehttps://www.tenable.com/plugins/nessus/33790
    titleMac OS X Multiple Vulnerabilities (Security Update 2008-005)
  • NASL familyMandriva Local Security Checks
    NASL idMANDRIVA_MDVSA-2009-022.NASL
    descriptionA vulnerability in PHP allowed context-dependent attackers to cause a denial of service (crash) via a certain long string in the glob() or fnmatch() functions (CVE-2007-4782). A vulnerability in the cURL library in PHP allowed context-dependent attackers to bypass safe_mode and open_basedir restrictions and read arbitrary files using a special URL request (CVE-2007-4850). An integer overflow in PHP allowed context-dependent attackers to cause a denial of serivce via a special printf() format parameter (CVE-2008-1384). A stack-based buffer overflow in the FastCGI SAPI in PHP has unknown impact and attack vectors (CVE-2008-2050). A buffer overflow in the imageloadfont() function in PHP allowed context-dependent attackers to cause a denial of service (crash) and potentially execute arbitrary code via a crafted font file (CVE-2008-3658). A buffer overflow in the memnstr() function allowed context-dependent attackers to cause a denial of service (crash) and potentially execute arbitrary code via the delimiter argument to the explode() function (CVE-2008-3659). PHP, when used as a FastCGI module, allowed remote attackers to cause a denial of service (crash) via a request with multiple dots preceding the extension (CVE-2008-3660). An array index error in the imageRotate() function in PHP allowed context-dependent attackers to read the contents of arbitrary memory locations via a crafted value of the third argument to the function for an indexed image (CVE-2008-5498). The updated packages have been patched to correct these issues.
    last seen2020-06-01
    modified2020-06-02
    plugin id36294
    published2009-04-23
    reporterThis script is Copyright (C) 2009-2019 Tenable Network Security, Inc.
    sourcehttps://www.tenable.com/plugins/nessus/36294
    titleMandriva Linux Security Advisory : php (MDVSA-2009:022)
  • NASL familyMacOS X Local Security Checks
    NASL idMACOSX_SECUPD2008-007.NASL
    descriptionThe remote host is running a version of Mac OS X 10.5 or 10.4 that does not have the security update 2008-007 applied. This security update contains fixes for the following products : - Apache - Certificates - ClamAV - ColorSync - CUPS - Finder - launchd - libxslt - MySQL Server - Networking - PHP - Postfix - PSNormalizer - QuickLook - rlogin - Script Editor - Single Sign-On - Tomcat - vim - Weblog
    last seen2020-06-01
    modified2020-06-02
    plugin id34374
    published2008-10-10
    reporterThis script is Copyright (C) 2008-2018 Tenable Network Security, Inc.
    sourcehttps://www.tenable.com/plugins/nessus/34374
    titleMac OS X Multiple Vulnerabilities (Security Update 2008-007)
  • NASL familyCGI abuses
    NASL idPHP_4_4_9.NASL
    descriptionAccording to its banner, the version of PHP installed on the remote host is older than 4.4.9. Such versions may be affected by several security issues : - There are unspecified issues in the bundled PCRE library fixed by version 7.7. - A buffer overflow in the
    last seen2020-06-01
    modified2020-06-02
    plugin id33849
    published2008-08-08
    reporterThis script is Copyright (C) 2008-2018 Tenable Network Security, Inc.
    sourcehttps://www.tenable.com/plugins/nessus/33849
    titlePHP < 4.4.9 Multiple Vulnerabilities
  • NASL familyCGI abuses
    NASL idPHP_5_2_6.NASL
    descriptionAccording to its banner, the version of PHP installed on the remote host is older than 5.2.6. Such versions may be affected by the following issues : - A stack-based buffer overflow in FastCGI SAPI. - An integer overflow in printf(). - An security issue arising from improper calculation of the length of PATH_TRANSLATED in cgi_main.c. - A safe_mode bypass in cURL. - Incomplete handling of multibyte chars inside escapeshellcmd(). - Issues in the bundled PCRE fixed by version 7.6.
    last seen2020-06-01
    modified2020-06-02
    plugin id32123
    published2008-05-02
    reporterThis script is Copyright (C) 2008-2018 Tenable Network Security, Inc.
    sourcehttps://www.tenable.com/plugins/nessus/32123
    titlePHP < 5.2.6 Multiple Vulnerabilities

Seebug

bulletinFamilyexploit
descriptionBUGTRAQ ID: 27413 CVE ID:CVE-2007-4850 CNCVE ID:CNCVE-20074850 PHP是一款流行的网络编程语言。 PHP cURL存在'safe mode'安全绕过问题,远程攻击者可以利用漏洞访问受限制文件,获得敏感信息。 var_dump(curl_exec(curl_init(&quot;file://safe_mode_bypass\x00&amp;qu ot;.__FILE__))); is caused by error in curl/interface.c - --- #define PHP_CURL_CHECK_OPEN_BASEDIR(str, len, __ret) if (((PG(open_basedir) &amp;&amp; *PG(open_basedir)) || PG(safe_mode)) &amp;&amp; strncasecmp(str, &quot;file:&quot;, sizeof(&quot;file:&quot;) - 1) == 0) { php_url *tmp_url; if (!(tmp_url = php_url_parse_ex(str, len))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, &quot;Invalid URL '%s'&quot;, str); php_curl_ret(__ret); } if (!php_memnstr(str, tmp_url-&gt;path, strlen(tmp_url-&gt;path), str + len)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, &quot;URL '%s' contains unencoded control characters&quot;, str); php_url_free(tmp_url); php_curl_ret(__ret); } if (tmp_url-&gt;query || tmp_url-&gt;fragment || php_check_open_basedir(tmp_url-&gt;path TSRMLS_CC) || (PG(safe_mode) &amp;&amp; !php_checkuid(tmp_url-&gt;path, &quot;rb+&quot;, CHECKUID_CHECK_MODE_PARAM)) ) { php_url_free(tmp_url); php_curl_ret(__ret); } php_url_free(tmp_url); } - --- 如果tmp_url = php_url_parse_ex(str, len): str = &quot;file://safe_mode_bypass\x00&quot;.__FILE__ 并且此函数返回: tmp_url-&gt;path = __FILE__ curl_init()函数检查tmp_url-&gt;path的safemode和openbasedir。不是实际路径: Details : SecurityReason Advisory Topic : PHP 5.2.5 cURL safe_mode bypass SecurityAlert : 51 CVE : CVE-2007-4850 SecurityRisk : Medium alert Remote Exploit : No Local Exploit : Yes Exploit Given : No Credit : Maksymilian Arciemowicz Date : 22.01.2008 Affected Software : PHP 5.2.5 and 5.2.4 Advisory Text : -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [PHP 5.2.5 cURL safe_mode bypass ] Author: Maksymilian Arciemowicz (cXIb8O3) SecurityReason Date: - - Written: 21.08.2007 - - Public: 22.01.2008 SecurityReason Research SecurityAlert Id: 51 CVE: CVE-2007-4850 SecurityRisk: Medium Affected Software: PHP 5.2.4 and 5.2.5 Advisory URL: http://securityreason.com/achievement_securityalert/51 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. PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP's ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication. These functions have been added in PHP 4.0.2. - --- 1. cURL --- This is very similar to CVE-2006-2563. http://securityreason.com/achievement_securityalert/39 The first issue [SAFE_MODE bypass] var_dump(curl_exec(curl_init(&quot;file://safe_mode_bypass\x00&amp;qu ot;.__FILE__))); is caused by error in curl/interface.c - --- #define PHP_CURL_CHECK_OPEN_BASEDIR(str, len, __ret) if (((PG(open_basedir) &amp;&amp; *PG(open_basedir)) || PG(safe_mode)) &amp;&amp; strncasecmp(str, &quot;file:&quot;, sizeof(&quot;file:&quot;) - 1) == 0) { php_url *tmp_url; if (!(tmp_url = php_url_parse_ex(str, len))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, &quot;Invalid URL '%s'&quot;, str); php_curl_ret(__ret); } if (!php_memnstr(str, tmp_url-&gt;path, strlen(tmp_url-&gt;path), str + len)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, &quot;URL '%s' contains unencoded control characters&quot;, str); php_url_free(tmp_url); php_curl_ret(__ret); } if (tmp_url-&gt;query || tmp_url-&gt;fragment || php_check_open_basedir(tmp_url-&gt;path TSRMLS_CC) || (PG(safe_mode) &amp;&amp; !php_checkuid(tmp_url-&gt;path, &quot;rb+&quot;, CHECKUID_CHECK_MODE_PARAM)) ) { php_url_free(tmp_url); php_curl_ret(__ret); } php_url_free(tmp_url); } - --- if you have tmp_url = php_url_parse_ex(str, len) where: str = &quot;file://safe_mode_bypass\x00&quot;.__FILE__ and this function will return: tmp_url-&gt;path = __FILE__ curl_init() functions checks safemode and openbasedir for tmp_url-&gt;path. Not for real path. - --- if (argc &gt; 0) { char *urlcopy; urlcopy = estrndup(Z_STRVAL_PP(url), Z_STRLEN_PP(url)); curl_easy_setopt(ch-&gt;cp, CURLOPT_URL, urlcopy); zend_llist_add_element(&amp;ch-&gt;to_free.str, &amp;urlcopy); } - --- 最后一步curl_init()函数只拷贝file://safe_mode_bypass到urlcopy。 主要问题存在于php_url_parse_ex()函数中,如果curl_init() &quot;file://host/somewhere/path.php&quot;,php_url_parse_ex()就会选择/somewhere/path.php到路径变量,看起来不错,但不能使用,当你检查实际路径时,使用file:///etc/passwd是正确的,但是会在file://和/etc/passwd之间,php_url_parse_ex()会选择主机和返回路径给/passwd。 PHP PHP 5.2.5 PHP PHP 5.2.4 可参考如下补丁程序: <a href=http://cvs.php.net/viewcvs.cgi/php-src/NEWS?revision=1.2027.2.547 target=_blank>http://cvs.php.net/viewcvs.cgi/php-src/NEWS?revision=1.2027.2.547</a> .2.1047&amp;view=markup
idSSV:2859
last seen2017-11-19
modified2008-01-25
published2008-01-25
reporterRoot
sourcehttps://www.seebug.org/vuldb/ssvid-2859
titlePHP cURL 'safe mode'安全绕过漏洞

Statements

contributorMark J Cox
lastmodified2009-09-30
organizationRed Hat
statementWe do not consider these to be security issues. For more details see http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=169857#c1 and http://www.php.net/security-note.php