php "include()"安全漏洞?

标签 php security include

include 的 PHP 手册中,有一份用户贡献声明如下:

include() when used to load configuration information has a scary security flaw, if someone corrupts the PHP header in the included file it will happily print the config file to every page which includes it as plain text.

Luckily there is a quick and easy workout for this behaviour (which is alluded to in this article):

<?php
ob_start();//Hook output buffer
include("config.php");
ob_end_clean();//Clear output buffer
?> 

我知道以下内容将阻止任何输出,直到输出缓冲区被清除/取消 Hook /无论如何。然而,我不确定的是,如果有人损坏了包含文件中的 PHP header - 是否可以在客户端/远程完成,或者如果我不小心给出了php 文件有不同的文件扩展名吗?

长话短说:外部用户如何破坏 php header ?

最佳答案

好吧,假设您有一个文件 seekritpasswords.php您包含的内容,并且它包含您的数据库凭据。您将拥有一个类似于以下内容的文件:

<?php

$db_user = 'fred';
$db_passwd = 'barney';
$db_name = 'wilma';
$db_host = 'betty';

php“ header ”是 <?php部分。如果它被损坏,比如添加一个空格,或者完全删除它等等...那么该文件就不再是 php 脚本,因为它不包含触发“php 模式”的 header 。它只是纯文本,并像任何其他纯文本文件一样被视为常规输出。请记住,不存在 PHP 脚本这样的东西。只有包含一个或多个 PHP block 的文件,并且这些 block 由 <?php ?> 分隔。标签集。

关于php "include()"安全漏洞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8125366/

相关文章:

php - 在php类中动态声明变量

php - 如果页面中有错误,则重定向到自定义错误页面

java - 在java中读取System.in的权限

php - Smarty,包含 css/javascript 文件

php - 使用带有单词边界的 MySQL 和 REGEX 的 Codeigniter Query Builder 增加了额外的空间

java - Jersey REST-Servlet 中的 RolesAllowed 注释不起作用

android - 有没有一种简单的方法可以在 Ionic2 中存储密码?

c - Visual Studio 引用头文件和源文件

C循环依赖

php - 安装了 Composer ,但得到/usr/bin/env : php: No such file or directory