Remote File Inclusion Exploitation
Remote File Inclusion executes PHP code fetched from an attacker-controlled URL. It requires allow_url_include = On in the PHP configuration, which is disabled by default on modern installs. When it's enabled, it's a direct path to code execution without needing to write anything to disk on the target. Confirm RFI is active before proceeding: a false positive wastes time and generates noise. For local file inclusion techniques, see LFI exploitation. For fuzzing parameters to identify inclusion points, see file inclusion fuzzing.
- Confirm RFI by hosting a test file and checking if the server fetches it.
- Web shell deployment hosts a PHP shell on your server and includes it via the vulnerable parameter.
- Reverse shell delivers interactive access through the hosted shell's cmd parameter.
- Filter bypasses use null bytes, URL encoding, and double encoding to evade protocol checks.
Confirm RFI is Active
Host a test file on your Kali machine and point the vulnerable parameter at it. An incoming request on your HTTP server confirms the target is fetching remote URLs:
RFICONFIRM
RFICONFIRM in the response means the server fetched your file and included its content. If there is no output but your HTTP server received a request, the content is being included but not displayed: still confirmed, just blind.
Deploy a Web Shell
Host a minimal PHP web shell and include it via the vulnerable parameter:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Get a Reverse Shell
Set up your listener and host a reverse shell payload:
If bash is not available, use the mkfifo method or a Python reverse shell via the cmd parameter on the hosted shell. Run the HTTP server on a different port from the netcat listener.
Filter Bypasses
Some applications filter http:// but miss other protocols or encoding variants:
References
-
PayloadsAllTheThings: File InclusionREPO: PayloadsAllTheThings: File Inclusion, github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion (opens in new tab)
RFI payload collection and filter bypass techniques