Date: 20 December 2004
References: ESB-2004.0810 ESB-2005.0063 ESB-2005.0607
Click here for printable version
Click here for PGP verifiable version
-----BEGIN PGP SIGNED MESSAGE-----
AUSCERT External Security Bulletin Redistribution
ESB-2004.0795 -- Multiple vulnerabilities in PHP 4 and 5
20 December 2004
AusCERT Security Bulletin Summary
Product: PHP 5.0.2 and prior
PHP 4.3.9 and prior
Operating System: UNIX variants
Mac OS X
Impact: Execute Arbitrary Code/Commands
CVE Names: CAN-2004-1064 CAN-2004-1063 CAN-2004-1019
- --------------------------BEGIN INCLUDED TEXT--------------------
- -----BEGIN PGP SIGNED MESSAGE-----
-= Security Advisory =-
Advisory: Multiple vulnerabilities within PHP 4/5
Release Date: 2004/12/15
Last Modified: 2004/12/15
Author: Stefan Esser [firstname.lastname@example.org]
Application: PHP4 <= 4.3.9
PHP5 <= 5.0.2
Severity: Several vulnerabilities within PHP allow
local and remote execution of arbitrary code
Vendor Status: Vendor has released bugfixed versions.
PHP is a widely-used general-purpose scripting language that is
especially suited for Web development and can be embedded into HTML.
During the development of Hardened-PHP which adds security hardening
features to the PHP codebase, several vulnerabilities within PHP
were discovered that reach from bufferoverflows, over information
leak vulnerabilities and path truncation vulnerabilities to
safe_mode restriction bypass vulnerabilities.
[01 - pack() - integer overflow leading to heap bufferoverflow ]
Insufficient validation of the parameters passed to pack() can
lead to a heap overflow which can be used to execute arbitrary
code from within a PHP script. This enables an attacker to
bypass safe_mode restrictions and execute arbitrary code with
the permissions of the webserver. Due to the nature of this
function it is unlikely that a script accidently exposes it to
[02 - unpack() - integer overflow leading to heap info leak ]
Insufficient validation of the parameters passed to unpack() can
lead to a heap information leak which can be used to retrieve
secret data from the apache process. Additionally a skilled
local attacker could use this vulnerability in combination with
01 to bypass heap canary protection systems. Similiar to 01 this
function is usually not used on user supplied data within
[03 - safe_mode_exec_dir bypass in multithreaded PHP ]
When safe_mode is activated within PHP, it is only allowed to
execute commands within the configured safe_mode_exec_dir.
Unfourtunately PHP does prepend a "cd [currentdir] ;" to any
executed command when a PHP is running on a multithreaded unix
webserver (f.e. some installations of Apache2). Because the name
of the current directory is prepended directly a local attacker
may bypass safe_mode_exec_dir restrictions by injecting shell-
commands into the current directory name.
[04 - safe_mode bypass through path truncation ]
The safe_mode checks silently truncated the file path at MAXPATHLEN
bytes before passing it to realpath(). In combination with certain
malfunctional implementations of realpath() f.e. within glibc this
allows crafting a filepath that pass the safe_mode check although
it points to a file that should fail the safe_mode check.
[05 - path truncation in realpath() ]
PHP uses realpath() within several places to get the real path
of files. Unfourtunately some implementations of realpath() silently
truncate overlong filenames (f.e. OpenBSD, and older NetBSD/FreeBSD)
This can lead to arbitrary file include vulnerabilities if something
like "include "modules/$userinput/config.inc.php"; is used on such
[06 - unserialize() - wrong handling of negative references ]
The variable unserializer could be fooled with negative references
to add false zvalues to hashtables. When those hashtables get
destroyed this can lead to efree()s of arbitrary memory addresses
which can result in arbitrary code execution. (Unless Hardened-PHP's
memory manager canaries are activated)
[07 - unserialize() - wrong handling of references to freed data ]
Additionally to bug 07 the previous version of the variable
unserializer allowed setting references to already freed entries in
the variable hash. A skilled attacker can exploit this to create
an universal string that will pass execution to an arbitrary
memory address when it is passed to unserialize(). For AMD64 systems
a string was developed that directly passes execution to code
contained in the string itself.
It is necessary to understand that these strings can exploit a
bunch of popular PHP applications remotely because they pass f.e.
cookie content to unserialize().
Examples of vulnerable scripts:
- Invision Board
- Woltlab Burning Board 2.x
- Serendipity Weblog
Proof of Concept:
The Hardened-PHP project is not going to release exploits for any
of these vulnerabilities to the public.
The Common Vulnerabilities and Exposures project (cve.mitre.org) has
assigned the name CAN-2004-1018 to issues 01, 02, the name
CAN-2004-1019 to issues 06, 07, the name CAN-2004-1063 to issue 03
and the name CAN-2004-1064 to issues 04, 05.
It is strongly recommended to upgrade to the new PHP-Releases as
soon as possible, because a lot of PHP applications expose the
easy to exploit unserialize() vulnerability to remote attackers.
Additionally we always recommend to run PHP with the Hardened-PHP
pub 1024D/0A864AA1 2004-04-17 Hardened-PHP Signature Key
Key fingerprint = 066F A6D0 E57E 9936 9082 7E52 4439 14CC 0A86 4AA1
Copyright 2004 Stefan Esser. All rights reserved.
- -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
- -----END PGP SIGNATURE-----
- --------------------------END INCLUDED TEXT--------------------
You have received this e-mail bulletin as a result of your organisation's
registration with AusCERT. The mailing list you are subscribed to is
maintained within your organisation, so if you do not wish to continue
receiving these bulletins you should contact your local IT manager. If
you do not know who that is, please send an email to email@example.com
and we will forward your request to the appropriate person.
NOTE: Third Party Rights
This security bulletin is provided as a service to AusCERT's members. As
AusCERT did not write the document quoted above, AusCERT has had no control
over its content. The decision to follow or act on information or advice
contained in this security bulletin is the responsibility of each user or
organisation, and should be considered in accordance with your organisation's
site policies and procedures. AusCERT takes no responsibility for consequences
which may arise from following or acting on information or advice contained in
this security bulletin.
NOTE: This is only the original release of the security bulletin. It may
not be updated when updates to the original are made. If downloading at
a later date, it is recommended that the bulletin is retrieved directly
from the author's website to ensure that the information is still current.
Contact information for the authors of the original document is included
in the Security Bulletin above. If you have any questions or need further
information, please contact them directly.
Previous advisories and external security bulletins can be retrieved from:
If you believe that your computer system has been compromised or attacked in
any way, we encourage you to let us know by completing the secure National IT
Incident Reporting Form at:
Australian Computer Emergency Response Team
The University of Queensland
Internet Email: firstname.lastname@example.org
Facsimile: (07) 3365 7031
Telephone: (07) 3365 4417 (International: +61 7 3365 4417)
AusCERT personnel answer during Queensland business hours
which are GMT+10:00 (AEST).
On call after hours for member emergencies only.
-----BEGIN PGP SIGNATURE-----
-----END PGP SIGNATURE-----