Home  >  Article  >  php教程  >  动态网页中直接不让访问PHP程序文件

动态网页中直接不让访问PHP程序文件

WBOY
WBOYOriginal
2016-06-21 08:57:591028browse

由于我们有需要用到某些php文件,而又不希望别人直接访问这个文件,我们可以在其他包含文件比如global.php中定义一个参数,在被访问页面data.php前面判断是否定义了该参数,没有定义则禁止访问。

在global.php中定义

以下为引用的内容:

define('ROOT','./');
?>
在data.php文件中判断:


//data.php
if (!defined("ROOT")) {
 echo "You Cannot Access This Script Directly, Have a Nice Day.";
 exit();
}
?>

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

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

common.php文件里:

以下为引用的内容:

if ( !defined('ROOT') )
{
 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'),转化为远程包含。



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn