About define()

本文讨论了PHP中通过defined()函数防止文件被外部直接访问的方法及其局限性,并介绍了一种利用本地包含漏洞转化成远程包含攻击的可能性。
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'),转化为远程包含。
 
In the provided references, there is no direct mention of "UD" within the given contexts [^1]. However, based on general knowledge in programming and technical terminology, "UD" could stand for several concepts depending on its specific usage: ### Possible Definitions of UD 1. **User-Defined**: In many programming languages such as C++ or Python, "UD" might refer to user-defined types, functions, or objects. For example, a `class` defined by users in object-oriented programming would fall under this category. 2. **Up/Down Counters**: In digital electronics and embedded systems, "UD" may represent up/down counters that increment (`U`) or decrement (`D`) values. 3. **Undefined Behavior**: Within the realm of software development, particularly when discussing standards like those in C/C++, "UD" sometimes refers to undefined behavior where program results are unpredictable due to violations of language rules. 4. **Uniform Distribution**: When dealing with statistical algorithms implemented through coding practices—especially random number generation—"UD" occasionally signifies uniform distribution properties ensuring equal probabilities across all possible outcomes during sampling processes. Without additional contextual clues from your query about which precise aspect you're interested in regarding 'UD', it remains ambiguous whether one should focus more narrowly upon certain interpretations over others mentioned above. ```python # Example demonstrating User Defined Class in Python class UDExample: def __init__(self, value): self.value = value def display(self): print(f"The Value is {self.value}") example_instance = UDExample(42) example_instance.display() ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值