界: Environment
本节包括的所有内容均与源代码无关,但对所创建产品的安全性仍然至关重要。因为本节涉及的问题与源代码没有直接关系,所以我们将它与其他章节分开。
PHP Misconfiguration: register_globals Enabled
Abstract
如果将 PHP 配置为对所有的 Environment、GET、POST、Cookie 及 Server 变量进行全局注册,会导致意外行为,使系统容易受到攻击者的攻击。
Explanation
如果启用
示例 1:以下代码容易受到 cross-site scripting 攻击。程序员假定
register_globals
选项,会导致 PHP 对 EGPCS(Environment、GET、POST、Cookie 及 Server)变量进行全局注册,这样一来,任何用户在任何 PHP 程序中都将能访问这些变量。如果程序员在编写程序时启用此选项,或多或少都会导致程序察觉不到它们所依赖于的数值来源,这会导致运行正常的环境发生意外行为,使系统容易受到恶意环境中的攻击者发起的攻击。由于认识到 register_globals
所隐含的安全隐患,在 PHP 4.2.0 中默认禁用了该选项,而在 PHP 6 中弃用并删除了该选项。示例 1:以下代码容易受到 cross-site scripting 攻击。程序员假定
$username
的值来源于由服务器控制的会话,但是攻击者可能会为 $username
提供一个恶意值来代替请求参数。如果启用 register_globals
选项,此代码会在它所生成的 HTML 内容中包含由攻击者提交的恶意值。
<?php
if (isset($username)) {
echo "Hello <b>$username</b>";
} else {
echo "Hello <b>Guest</b><br />";
echo "Would you like to login?";
}
?>
References
[1] M. Achour et al. PHP Manual
[2] Artur Maj Securing PHP
[3] Standards Mapping - Common Weakness Enumeration CWE ID 473
[4] Standards Mapping - OWASP API 2023 API8 Security Misconfiguration
[5] Standards Mapping - OWASP Mobile 2014 M1 Weak Server Side Controls
[6] Standards Mapping - OWASP Top 10 2004 A10 Insecure Configuration Management
[7] Standards Mapping - OWASP Top 10 2010 A6 Security Misconfiguration
[8] Standards Mapping - OWASP Top 10 2013 A5 Security Misconfiguration
[9] Standards Mapping - OWASP Top 10 2017 A6 Security Misconfiguration
[10] Standards Mapping - OWASP Top 10 2021 A05 Security Misconfiguration
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.10
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 3.0 Requirement 6.5.10
[13] Standards Mapping - Payment Card Industry Data Security Standard Version 3.1 Requirement 6.5.10
[14] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2 Requirement 6.5.10
[15] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2.1 Requirement 6.5.10
[16] Standards Mapping - Payment Card Industry Data Security Standard Version 4.0 Requirement 6.2.4
[17] Standards Mapping - Payment Card Industry Data Security Standard Version 4.0.1 Requirement 6.2.4
[18] Standards Mapping - Payment Card Industry Software Security Framework 1.0 Control Objective 4.2 - Critical Asset Protection
[19] Standards Mapping - Payment Card Industry Software Security Framework 1.1 Control Objective 4.2 - Critical Asset Protection
[20] Standards Mapping - Payment Card Industry Software Security Framework 1.2 Control Objective 4.2 - Critical Asset Protection
[21] Standards Mapping - Web Application Security Consortium Version 2.00 Application Misconfiguration (WASC-15)
desc.php.php_misconfiguration_register_globals