Skip navigation.

幻影旅团

Ph4nt0m Security Team

[Tips]关于define()

Author: SuperHei
Date: 2007-04-18
http://www.ph4nt0m.org

很多php使用defined()来防止外部直接访问php文件,从而保证了只让内部php文件include等调用。如下面:
<?
//tag.php
if (!defined("X")) {
    echo "You Cannot Access This Script Directly, Have a Nice Day.";
    exit();
}
?>


这样的代码可以解决很多的安全问题,比如变量未定义[应该说在本文件内未定义]。

但是这样的在本地包含漏洞前就没什么意义了。比如进来看一代码

common.php文件里:
if ( !defined('X') )
{
    die('Do not access this file directly.');
}
if ( !isset($root_path) )
{
    $root_path = './';
}
require_once($root_path . 'config.php');

如果没有!defined('X') 的限制那么我们,这里$root_path未定义导致了一个远程包含。


而在改脚本又存在一个update-->include的2次攻击导致的本地包含,那么我们可以通过这个本地包含漏洞包含common.php导致突破!defined('X'),转化为远程包含。

php-fusion的一个Xday分析Security Week in Review(2007-04-20)

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies

January 2010
S M T W T F S
December 2009February 2010
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30