CWE-98: Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion')
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
The PHP application receives input from an upstream component, but it does not restrict or incorrectly restricts the input before its usage in "require," "include," or similar functions.
扩展描述
In certain versions and configurations of PHP, this can allow an attacker to specify a URL to a remote location from which the product will obtain the code to execute. In other cases in association with path traversal, the attacker can specify a local file that may contain executable statements that can be parsed by PHP.
常见后果
影响范围: Integrity Confidentiality Availability
技术影响: Execute Unauthorized Code or Commands
说明: The attacker may be able to specify arbitrary code to be executed from a remote location. Alternatively, it may be possible to use normal program behavior to insert php code into files on the local machine which can then be included and force the code to execute since php ignores everything in the file except for the content between php specifiers.
潜在缓解措施
阶段: Architecture and Design
策略: Libraries or Frameworks
描述: Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid [REF-1482].
阶段: Architecture and Design
策略: Enforcement by Conversion
阶段: Architecture and Design
描述: For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
阶段: Architecture and Design Operation
策略: Sandbox or Jail
有效性: Limited
阶段: Architecture and Design Operation
策略: Environment Hardening
描述: Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.
阶段: Implementation
策略: Input Validation
有效性: High
阶段: Architecture and Design Operation
策略: Attack Surface Reduction
阶段: Architecture and Design Implementation
策略: Attack Surface Reduction
阶段: Operation
策略: Firewall
描述: Use an application firewall that can detect attacks against this weakness. It can be beneficial in cases in which the code cannot be fixed (because it is controlled by a third party), as an emergency prevention measure while more comprehensive software assurance measures are applied, or to provide defense in depth [REF-1481].
有效性: Moderate
阶段: Operation Implementation
策略: Environment Hardening
描述: Develop and run your code in the most recent versions of PHP available, preferably PHP 6 or later. Many of the highly risky features in earlier PHP interpreters have been removed, restricted, or disabled by default.
阶段: Operation Implementation
策略: Environment Hardening
阶段: Operation
策略: Environment Hardening
描述: Set allow_url_fopen to false, which limits the ability to include files from remote locations.
有效性: High
检测方法
方法: Manual Analysis
Manual white-box analysis can be very effective for finding this issue, since there is typically a relatively small number of include or require statements in each program.
有效性: High
方法: Automated Static Analysis
观察示例
参考: CVE-2004-0285
Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
参考: CVE-2004-0030
Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
参考: CVE-2004-0068
Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
参考: CVE-2005-2157
Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
参考: CVE-2005-2162
Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
参考: CVE-2005-2198
Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
参考: CVE-2004-0128
Modification of assumed-immutable variable in configuration script leads to file inclusion.
参考: CVE-2005-1864
PHP file inclusion.
参考: CVE-2005-1869
PHP file inclusion.
参考: CVE-2005-1870
PHP file inclusion.
参考: CVE-2005-2154
PHP local file inclusion.
参考: CVE-2002-1704
PHP remote file include.
参考: CVE-2002-1707
PHP remote file include.
参考: CVE-2005-1964
PHP remote file include.
参考: CVE-2005-1681
PHP remote file include.
参考: CVE-2005-2086
PHP remote file include.
参考: CVE-2004-0127
Directory traversal vulnerability in PHP include statement.
参考: CVE-2005-1971
Directory traversal vulnerability in PHP include statement.
参考: CVE-2005-3335
PHP file inclusion issue, both remote and local; local include uses ".." and "%00" characters as a manipulation, but many remote file inclusion issues probably have this vector.
参考: CVE-2009-1936
chain: library file sends a redirect if it is directly requested but continues to execute, allowing remote file inclusion and path traversal.
引入模式
| 阶段 | 说明 |
|---|---|
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| PLOVER | - | PHP File Include | - |
| OWASP Top Ten 2007 | A3 | Malicious File Execution | CWE More Specific |
| WASC | 5 | Remote File Inclusion | - |