Remote File Inclusion

User input controls the file that the server-side language includes and a remote address is accepted, so the server fetches and runs code from an attacker's server.

SeverityCritical
CVSS 3.19.8 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H Open in the calculator
CVSS 4.09.3 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator
CWECWE-98: Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion')
OWASP Top 10A05:2025 Injection
MITRE ATT&CKT1190 Exploit Public-Facing Application, T1059 Command and Scripting Interpreter
CategoryInjection

Description

The application passes a value supplied by the user to the language's file inclusion mechanism, typically PHP's include or require statements, and the platform allows that value to be a remote address. Supplying the URL of a file on a server the attacker controls makes the application fetch the file and run it as part of the page, so the attacker's code executes on the server directly, without any need to place a file there first. On Windows servers, a UNC path to an attacker's file share can have the same effect where outbound SMB connections are allowed, because it is treated as a local path.

That code runs with the privileges of the web server process, and an attacker typically uses it to install a web shell for persistent access, read application data and configuration secrets, and use the host as a foothold to attack internal systems. No user interaction or authentication is needed where the affected page is public, and exploitation is simple and reliable. In PHP, however, remote inclusion requires the allow_url_include setting, which is off by default, so remote file inclusion is now found mainly on legacy or deliberately reconfigured systems.

The weakness typically shows itself on a test when a URL pointing to a server under the tester's control, placed in an include parameter, causes the application to request it, and a harmless test script served from there is executed, for example printing a marker string. Scanners, including OWASP ZAP and Nuclei, test for remote file inclusion by referencing external resources.

Remediation

Remove the ability to include code from outside the application:

  • Never pass user input to include, require or equivalent functions. Map each permitted value to a fixed local file in the code.
  • Turn allow_url_include off, and allow_url_fopen off as well unless the application needs it for other purposes.
  • Restrict outbound connections from web servers, including HTTP, HTTPS and SMB, to the destinations they genuinely need.
  • Set open_basedir to limit the directories PHP can open, and run the web server with an account that cannot write to the application's code directories.
  • Check the server for signs of earlier exploitation, such as unfamiliar scripts in the web root, before relying on the fix.
; php.ini allow_url_include = Off allow_url_fopen = Off open_basedir = /var/www/app/ ; add upload_tmp_dir and session.save_path to open_basedir if they lie outside it

Confirm the fix by repeating the original request with an external URL and checking that no request reaches the external server and no remote code runs.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding